Class: ARbDrone
- Inherits:
-
Object
- Object
- ARbDrone
- Defined in:
- lib/arbdrone.rb,
lib/arbdrone/control.rb,
lib/arbdrone/version.rb,
lib/arbdrone/nav_data.rb,
lib/arbdrone/tcp_control.rb
Defined Under Namespace
Modules: Control, NavData, TcpControl Classes: Version
Instance Attribute Summary collapse
-
#control ⇒ Object
Returns the value of attribute control.
-
#control_config ⇒ Object
Returns the value of attribute control_config.
-
#navdata ⇒ Object
Returns the value of attribute navdata.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ARbDrone
constructor
A new instance of ARbDrone.
- #run ⇒ Object
- #run_control ⇒ Object
- #run_control_config ⇒ Object
- #run_navdata ⇒ Object
- #stop_control ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ARbDrone
Returns a new instance of ARbDrone.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/arbdrone.rb', line 10 def initialize( = {}) @drone_ip = .delete(:drone_ip) || '192.168.1.1' @drone_firmware_port = .delete(:drone_firmware_port) || 5551 @drone_navdata_port = .delete(:drone_navdata_port) || 5554 @drone_video_port = .delete(:drone_video_port) || 5555 @drone_control_port = .delete(:drone_control_port) || 5556 @drone_raw_capture_port = .delete(:drone_raw_capture_port) || 5557 # unused? tcp? @drone_tcp_console_port = .delete(:drone_tcp_console_port) || 5558 # unused? @drone_tcp_control_port = .delete(:drone_tcp_control_port) || 5559 @listen_ip = .delete(:listen_ip) || '0.0.0.0' end |
Instance Attribute Details
#control ⇒ Object
Returns the value of attribute control.
8 9 10 |
# File 'lib/arbdrone.rb', line 8 def control @control end |
#control_config ⇒ Object
Returns the value of attribute control_config.
8 9 10 |
# File 'lib/arbdrone.rb', line 8 def control_config @control_config end |
#navdata ⇒ Object
Returns the value of attribute navdata.
8 9 10 |
# File 'lib/arbdrone.rb', line 8 def navdata @navdata end |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/arbdrone.rb', line 22 def run EventMachine.run do @control = run_control @control_config = run_control_config @navdata = run_navdata end end |
#run_control ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/arbdrone.rb', line 30 def run_control connection = EventMachine.open_datagram_socket @listen_ip, @drone_control_port, Control connection.setup @drone_ip, @drone_control_port # Send messages every 20ms to ensure we stay connected to the Drone @control_timer = EventMachine.add_periodic_timer 0.02 do connection. end connection end |
#run_control_config ⇒ Object
41 42 43 44 45 |
# File 'lib/arbdrone.rb', line 41 def run_control_config connection = EventMachine.connect @drone_ip, @drone_tcp_control_port, TcpControl connection.control_channel = @control connection end |
#run_navdata ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/arbdrone.rb', line 52 def run_navdata # We have to bind the socket to 0.0.0.0 so we can receive multicast packets connection = EventMachine.open_datagram_socket '0.0.0.0', @drone_navdata_port, NavData connection.setup @drone_ip, @drone_navdata_port ip = IPAddr.new('224.1.1.1').hton + IPAddr.new(@listen_ip).hton connection.set_sock_opt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip) connection. connection end |
#stop_control ⇒ Object
47 48 49 50 |
# File 'lib/arbdrone.rb', line 47 def stop_control @control.land @control_timer.cancel end |