artoo 0.5.0 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/.yardopts +1 -1
  4. data/CONTRIBUTORS.md +16 -0
  5. data/Gemfile +10 -9
  6. data/Gemfile.lock +31 -35
  7. data/README.md +110 -19
  8. data/Rakefile +0 -1
  9. data/api/assets/javascripts/artoo/controllers/robot.js.coffee +5 -8
  10. data/api/public/core.js +7 -12
  11. data/api/public/partials/robot-detail.html +1 -1
  12. data/bin/robi +1 -1
  13. data/examples/christmas_roomba.rb +16 -19
  14. data/examples/hello_api_multiple.rb +3 -2
  15. data/examples/notifications.rb +2 -2
  16. data/examples/sphero_messages.rb +9 -3
  17. data/lib/artoo/adaptors/test.rb +28 -0
  18. data/lib/artoo/connection.rb +5 -0
  19. data/lib/artoo/delegator.rb +1 -1
  20. data/lib/artoo/device.rb +13 -0
  21. data/lib/artoo/drivers/counter.rb +28 -0
  22. data/lib/artoo/drivers/pinger.rb +8 -11
  23. data/lib/artoo/drivers/random.rb +27 -0
  24. data/lib/artoo/drivers/test.rb +23 -0
  25. data/lib/artoo/master.rb +4 -2
  26. data/lib/artoo/robot.rb +11 -103
  27. data/lib/artoo/robot_class_methods.rb +147 -0
  28. data/lib/artoo/version.rb +1 -1
  29. data/test/robot_test.rb +3 -3
  30. data/test/test_helper.rb +1 -2
  31. metadata +10 -44
  32. data/bin/sphero.sh +0 -8
  33. data/bin/sphero_linux_bind.sh +0 -25
  34. data/bin/sphero_linux_socat.sh +0 -8
  35. data/examples/sphero2.rb +0 -26
  36. data/lib/artoo/adaptors/ardrone.rb +0 -41
  37. data/lib/artoo/adaptors/ardrone_navigation.rb +0 -33
  38. data/lib/artoo/adaptors/ardrone_video.rb +0 -35
  39. data/lib/artoo/adaptors/firmata.rb +0 -33
  40. data/lib/artoo/adaptors/roomba.rb +0 -51
  41. data/lib/artoo/adaptors/sphero.rb +0 -58
  42. data/lib/artoo/drivers/ardrone.rb +0 -15
  43. data/lib/artoo/drivers/ardrone_navigation.rb +0 -25
  44. data/lib/artoo/drivers/ardrone_video.rb +0 -27
  45. data/lib/artoo/drivers/button.rb +0 -59
  46. data/lib/artoo/drivers/led.rb +0 -48
  47. data/lib/artoo/drivers/motor.rb +0 -69
  48. data/lib/artoo/drivers/pinger2.rb +0 -27
  49. data/lib/artoo/drivers/roomba.rb +0 -179
  50. data/lib/artoo/drivers/servo.rb +0 -59
  51. data/lib/artoo/drivers/sphero.rb +0 -105
  52. data/lib/artoo/drivers/wiichuck.rb +0 -61
  53. data/lib/artoo/drivers/wiiclassic.rb +0 -139
  54. data/lib/artoo/drivers/wiidriver.rb +0 -102
  55. data/test/adaptors/ardrone_test.rb +0 -24
  56. data/test/adaptors/firmata_test.rb +0 -25
  57. data/test/adaptors/sphero_test.rb +0 -24
  58. data/test/drivers/ardrone_navigation_test.rb +0 -11
  59. data/test/drivers/ardrone_test.rb +0 -11
  60. data/test/drivers/ardrone_video_test.rb +0 -11
  61. data/test/drivers/led_test.rb +0 -56
  62. data/test/drivers/motor_test.rb +0 -40
  63. data/test/drivers/roomba_test.rb +0 -87
  64. data/test/drivers/servo_test.rb +0 -45
  65. data/test/drivers/sphero_test.rb +0 -54
  66. data/test/drivers/wiichuck_test.rb +0 -11
  67. data/test/drivers/wiiclassic_test.rb +0 -11
  68. data/test/drivers/wiidriver_test.rb +0 -54
@@ -1,35 +0,0 @@
1
- require 'artoo/adaptors/adaptor'
2
-
3
- module Artoo
4
- module Adaptors
5
- # Connect to a ARDrone 2.0 video data stream
6
- # @see http://rubydoc.info/gems/hybridgroup-argus/0.2.0/Argus/TcpVideoStreamer TCP Video Streamer Documentation
7
- # @see http://rubydoc.info/gems/hybridgroup-argus/0.2.0/Argus/PaVEParser PaVEParser Documentation
8
- class ArdroneVideo < Adaptor
9
- attr_reader :ardrone, :video_parser
10
-
11
- # Creates connection to Argus TCP Video Streamer and
12
- # Argus PaVE Parser starting a stream with ardrone device
13
- # @return [Boolean]
14
- def connect
15
- require 'argus' unless defined?(::Argus)
16
- @ardrone = Argus::VideoStreamer.new(connect_to_tcp, port.host, port.port)
17
- @ardrone.start(connect_to_udp)
18
- super
19
- end
20
-
21
- # Closes ardrone connection
22
- # @return [Boolean]
23
- def disconnect
24
- ardrone.close
25
- super
26
- end
27
-
28
- # Calls ardrone actions using method missing
29
- # @see https://github.com/hybridgroup/argus/blob/master/lib/argus/drone.rb hybridgroup-argus Drone
30
- def method_missing(method_name, *arguments, &block)
31
- ardrone.send(method_name, *arguments, &block)
32
- end
33
- end
34
- end
35
- end
@@ -1,33 +0,0 @@
1
- require 'artoo/adaptors/adaptor'
2
-
3
- module Artoo
4
- module Adaptors
5
- # Connect to Arduino using Firmata
6
- # @see http://rubydoc.info/gems/hybridgroup-firmata/0.3.0/Firmata/Board HybridGroup Firmata Documentation
7
- class Firmata < Adaptor
8
- attr_reader :firmata
9
-
10
- # Creates connection with firmata board
11
- # @return [Boolean]
12
- def connect
13
- require 'firmata' unless defined?(::Firmata)
14
- @firmata = ::Firmata::Board.new(connect_to)
15
- @firmata.connect
16
- super
17
- return true
18
- end
19
-
20
- # Closes connection with firmata board
21
- # @return [Boolean]
22
- def disconnect
23
- super
24
- end
25
-
26
- # Uses method missing to call Firmata Board methods
27
- # @see http://rubydoc.info/gems/hybridgroup-firmata/0.3.0/Firmata/Board Firmata Board Documentation
28
- def method_missing(method_name, *arguments, &block)
29
- firmata.send(method_name, *arguments, &block)
30
- end
31
- end
32
- end
33
- end
@@ -1,51 +0,0 @@
1
- require 'artoo/adaptors/adaptor'
2
-
3
- module Artoo
4
- module Adaptors
5
- # Connect to a Roomba
6
- # @see http://www.irobot.com/en/us/robots/Educators/Create.aspx Roomba information
7
- class Roomba < Adaptor
8
- finalizer :finalize
9
- attr_reader :sp
10
-
11
- # Closes connection if already connected
12
- # @return [Boolean]
13
- def finalize
14
- if connected?
15
- @sp.close
16
- end
17
- end
18
-
19
- # Creates serial or tcp connection
20
- # @return [Boolean]
21
- def connect
22
- if port.is_serial?
23
- @sp = connect_to_serial
24
- @sp.dtr = 0
25
- @sp.rts = 0
26
- else
27
- @sp = connect_to_tcp
28
- end
29
- super
30
- end
31
-
32
- # Send bytes to device
33
- def send_bytes(bytes)
34
- bytes = [bytes] unless bytes.respond_to?(:map)
35
- bytes.map!(&:chr)
36
- Logger.debug "sending: #{bytes.inspect}"
37
- res = []
38
- bytes.each{|b| res << @sp.write(b) }
39
- Logger.debug "returned: #{res.inspect}"
40
- end
41
-
42
- # Closes connection to device
43
- # @return [Boolean]
44
- def disconnect
45
- @sp.close
46
- super
47
- end
48
-
49
- end
50
- end
51
- end
@@ -1,58 +0,0 @@
1
- require 'artoo/adaptors/adaptor'
2
-
3
- module Artoo
4
- module Adaptors
5
- # Connect to a Sphero device
6
- # @see http://gosphero.com Sphero information
7
- # @see http://rubydoc.info/gems/hybridgroup-sphero HybridGroup Sphero Documentation
8
- class Sphero < Adaptor
9
- finalizer :finalize
10
- attr_reader :sphero
11
-
12
- # Number of retries when connecting
13
- RETRY_COUNT = 5
14
-
15
- # Closes connection with device if connected
16
- # @return [Boolean]
17
- def finalize
18
- if connected?
19
- sphero.close
20
- end
21
- end
22
-
23
- # Creates a connection with Sphero object with retries
24
- # @return [Boolean]
25
- def connect
26
- @retries_left = RETRY_COUNT
27
- require 'sphero' unless defined?(::Sphero)
28
- begin
29
- @sphero = ::Sphero.new(connect_to)
30
- super
31
- return true
32
- rescue Errno::EBUSY => e
33
- @retries_left -= 1
34
- if @retries_left > 0
35
- retry
36
- else
37
- Logger.error e.message
38
- Logger.error e.backtrace.inspect
39
- return false
40
- end
41
- end
42
- end
43
-
44
- # Closes connection with device
45
- # @return [Boolean]
46
- def disconnect
47
- sphero.close
48
- super
49
- end
50
-
51
- # Uses method missing to call sphero actions
52
- # @see http://rubydoc.info/gems/hybridgroup-sphero/Sphero Sphero documentation
53
- def method_missing(method_name, *arguments, &block)
54
- sphero.send(method_name, *arguments, &block)
55
- end
56
- end
57
- end
58
- end
@@ -1,15 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Ardrone driver behaviors
6
- # @see https://github.com/hybridgroup/argus/blob/master/lib/argus/drone.rb Argus::Drone docs for supported actions
7
- class Ardrone < Driver
8
- COMMANDS = [:start, :stop, :hover, :land, :take_off, :emergency, :front_camera, :bottom_camera, :up, :down, :left, :right, :forward, :backward, :turn_left, :turn_right].freeze
9
-
10
- def start
11
- connection.start(false) # send false, so Argus does not use NavMonitor
12
- end
13
- end
14
- end
15
- end
@@ -1,25 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Ardrone navigation driver behaviors
6
- class ArdroneNavigation < Driver
7
-
8
- # Starts driver and handle updates from device
9
- def start_driver
10
- every(interval) do
11
- handle_update
12
- end
13
-
14
- super
15
- end
16
-
17
- # Receives data from navigation and publishes
18
- # and event in update topic for it
19
- def handle_update
20
- navdata = connection.receive_data
21
- publish(event_topic_name("update"), navdata)
22
- end
23
- end
24
- end
25
- end
@@ -1,27 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Ardrone video driver behaviors
6
- class ArdroneVideo < Driver
7
-
8
- # Starts drives and handles video frame
9
- def start_driver
10
- every(interval) do
11
- handle_frame
12
- end
13
-
14
- super
15
- end
16
-
17
- # Retrieves frame from video connection
18
- # and publishes data to update and frame
19
- # event topics
20
- def handle_frame(*params)
21
- video = connection.receive_data
22
- publish(event_topic_name("update"), "video", video)
23
- publish(event_topic_name("frame"), video.frame)
24
- end
25
- end
26
- end
27
- end
@@ -1,59 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Button driver behaviors for Firmata
6
- class Button < Driver
7
- COMMANDS = [:is_pressed?].freeze
8
-
9
- DOWN = 1
10
- UP = 0
11
-
12
- # @return [Boolean] True if pressed
13
- def is_pressed?
14
- (@is_pressed ||= false) == true
15
- end
16
-
17
- # Sets values to read and write from button
18
- # and starts driver
19
- def start_driver
20
- connection.set_pin_mode(pin, Firmata::Board::INPUT)
21
- connection.toggle_pin_reporting(pin)
22
-
23
- every(interval) do
24
- connection.read_and_process
25
- handle_events
26
- end
27
-
28
- super
29
- end
30
-
31
- def handle_events
32
- while i = find_event("digital-read-#{pin}") do
33
- update(events.slice!(i).data.first)
34
- end
35
- end
36
-
37
- def find_event(name)
38
- events.index {|e| e.name == name}
39
- end
40
-
41
- def events
42
- connection.async_events
43
- end
44
-
45
- # Publishes events according to the button feedback
46
- def update(value)
47
- if value == DOWN
48
- @is_pressed = true
49
- publish(event_topic_name("update"), "push", value)
50
- publish(event_topic_name("push"), value)
51
- else
52
- @is_pressed = false
53
- publish(event_topic_name("update"), "release", value)
54
- publish(event_topic_name("release"), value)
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,48 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # The LED driver behaviors
6
- class Led < Driver
7
-
8
- COMMANDS = [:on, :off, :toggle, :brightness].freeze
9
-
10
- # @return [Boolean] True if on
11
- def is_on?
12
- (@is_on ||= false) == true
13
- end
14
-
15
- # @return [Boolean] True if off
16
- def is_off?
17
- (@is_on ||= false) == false
18
- end
19
-
20
- # Sets led to on status
21
- def on
22
- @is_on = true
23
- connection.set_pin_mode(pin, Firmata::Board::OUTPUT)
24
- connection.digital_write(pin, Firmata::Board::HIGH)
25
- end
26
-
27
- # Sets led to off status
28
- def off
29
- @is_on = false
30
- connection.set_pin_mode(pin, Firmata::Board::OUTPUT)
31
- connection.digital_write(pin, Firmata::Board::LOW)
32
- end
33
-
34
- # Toggle status
35
- # @example on > off, off > on
36
- def toggle
37
- is_off? ? on : off
38
- end
39
-
40
- # Change brightness level
41
- # @param [Integer] level
42
- def brightness(level=0)
43
- connection.set_pin_mode(pin, Firmata::Board::PWM)
44
- connection.analog_write(pin, level)
45
- end
46
- end
47
- end
48
- end
@@ -1,69 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # L293 or other H-bridge style motor driver behaviors for Firmata
6
- class Motor < Driver
7
- COMMANDS = [:forward, :backward, :stop, :speed, :current_speed].freeze
8
-
9
- attr_reader :leg1_pin, :leg2_pin, :speed_pin, :current_speed
10
-
11
- # Create new Motor
12
- def initialize(params={})
13
- super
14
-
15
- raise "Invalid pins, please pass an array in format [leg1, leg2, speed]" unless (pin && pin.is_a?(Array) && pin.size == 3)
16
- @leg1_pin = pin[0]
17
- @leg2_pin = pin[1]
18
- @speed_pin = pin[2]
19
- @current_speed = 0
20
- end
21
-
22
- # Starts connection to read and process and driver
23
- def start_driver
24
- every(interval) do
25
- connection.read_and_process
26
- end
27
-
28
- super
29
- end
30
-
31
- # Sets movement forward
32
- # @param [Integer] s speed
33
- def forward(s)
34
- set_legs(Firmata::Board::LOW, Firmata::Board::HIGH)
35
- speed(s)
36
- end
37
-
38
- # Sets movement backward
39
- # @param [Integer] s speed
40
- def backward(s)
41
- set_legs(Firmata::Board::HIGH, Firmata::Board::LOW)
42
- speed(s)
43
- end
44
-
45
- # Stops
46
- def stop
47
- speed(0)
48
- end
49
-
50
- # Set motor speed
51
- # @param [Integer] s speed (must be an integer between 0-255)
52
- def speed(s)
53
- raise "Motor speed must be an integer between 0-255" unless (s.is_a?(Numeric) && s >= 0 && s <= 255)
54
- @current_speed = s
55
- connection.set_pin_mode(speed_pin, Firmata::Board::PWM)
56
- connection.analog_write(speed_pin, s)
57
- end
58
-
59
- private
60
-
61
- def set_legs(l1, l2)
62
- connection.set_pin_mode(leg1_pin, Firmata::Board::OUTPUT)
63
- connection.digital_write(leg1_pin, l1)
64
- connection.set_pin_mode(leg2_pin, Firmata::Board::OUTPUT)
65
- connection.digital_write(leg2_pin, l2)
66
- end
67
- end
68
- end
69
- end
@@ -1,27 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Pings itself
6
- class Pinger2 < Driver
7
-
8
- COMMANDS = [:ping].freeze
9
-
10
- # Publishes events to update and alive event topics
11
- # with random number
12
- def start_driver
13
- every(interval) do
14
- @count = rand(100000)
15
- publish(event_topic_name("update"), "alive", @count)
16
- publish(event_topic_name("alive"), @count)
17
- end
18
-
19
- super
20
- end
21
-
22
- def ping
23
- "pong"
24
- end
25
- end
26
- end
27
- end