artoo 0.5.0 → 1.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,179 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # The Roomba driver behaviors
6
- class Roomba < Driver
7
-
8
- COMMANDS = [:start, :safe_mode, :full_mode, :forward, :stop, :fast_forward,
9
- :backwards, :nudge_left, :nudge_right, :turn_left, :turn_right,
10
- :turn_around, :drive, :play, :song, :beep].freeze
11
-
12
- # Sets Direction constant values
13
- module Direction
14
- STRAIGHT = 32768
15
- CLOCKWISE = 65535
16
- COUNTERCLOCKWISE = 1
17
- end
18
-
19
- # Sets speed constant values
20
- module Speed
21
- MAX = 500
22
- SLOW = 250
23
- NEG = (65536 - 250)
24
- ZERO = 0
25
- end
26
-
27
- # Sets notes constant values
28
- module Note
29
- B = 95
30
- D = 98
31
- G = 91
32
- C = 96
33
- A = 93
34
- QUARTER = 16
35
- HALF = 57
36
- WHOLE = 114
37
- end
38
-
39
- # Sets mode constant values
40
- module Mode
41
- FULL = 132
42
- SAFE = 131
43
- START = 128
44
- end
45
-
46
- # Sets song constant values
47
- module Song
48
- SONG = 140
49
- PLAY = 141
50
- end
51
-
52
- # Sends start mode
53
- def start
54
- send_bytes(Mode::START)
55
- sleep 0.2
56
- end
57
-
58
- # Sends safe mode
59
- def safe_mode
60
- start
61
- send_bytes(Mode::SAFE)
62
- sleep 0.1
63
- end
64
-
65
- # Sends full mode
66
- def full_mode
67
- start
68
- send_bytes(Mode::FULL)
69
- sleep 0.1
70
- end
71
-
72
- # Move forward
73
- # @param [Integer] seconds
74
- # @param [Constant] velocity
75
- # @see Speed
76
- def forward(seconds, velocity = Speed::SLOW)
77
- drive(velocity, Direction::STRAIGHT, seconds)
78
- stop if seconds > 0
79
- end
80
-
81
- # Stop movement
82
- def stop
83
- drive(Speed::ZERO, Direction::STRAIGHT)
84
- end
85
-
86
- # Move forward with fast speed
87
- # @param [Integer] seconds
88
- def fast_forward(seconds)
89
- drive(Speed::MAX, Direction::STRAIGHT, seconds)
90
- stop if seconds > 0
91
- end
92
-
93
- # Move backward
94
- # @param [Integer] seconds
95
- def backwards(seconds)
96
- drive(Speed::NEG, Direction::STRAIGHT, seconds)
97
- stop if seconds > 0
98
- end
99
-
100
- # Nudge left
101
- def nudge_left
102
- turn_left(0.25)
103
- end
104
-
105
- # Turn left
106
- # @param [Integer] seconds
107
- def turn_left(seconds = 1)
108
- drive(Speed::SLOW, Direction::COUNTERCLOCKWISE, seconds)
109
- stop if seconds > 0
110
- end
111
-
112
- # Turn right
113
- # @param [Integer] seconds
114
- def turn_right(seconds = 1)
115
- drive(Speed::SLOW, Direction::CLOCKWISE, seconds)
116
- stop if seconds > 0
117
- end
118
-
119
- # Nudge right
120
- def nudge_right
121
- turn_right(0.25)
122
- end
123
-
124
- # Turn around
125
- def turn_around
126
- turn_left(1.6)
127
- end
128
-
129
- # Drive
130
- # @param [Integer] v speed
131
- # @param [Integer] r direction
132
- # @param [Integer] s seconds (waiting time)
133
- # @see Speed
134
- # @see Direction
135
- def drive(v, r, s = 0)
136
- vH,vL = split_bytes(v)
137
- rH,rL = split_bytes(r)
138
- send_bytes([137, vH, vL, rH, rL])
139
- sleep(s) if s > 0
140
- end
141
-
142
- # Split bytes (hex)
143
- # @param [Integer] num
144
- def split_bytes(num)
145
- [num >> 8, num & 255]
146
- end
147
-
148
- # Play song
149
- # @param [Integer] song_number
150
- def play(song_number = 0)
151
- send_bytes([Song::PLAY, song_number])
152
- end
153
-
154
- # Save song
155
- # @param [Collection] notes
156
- # @param [Integer] song_number
157
- # @see Notes
158
- def song(notes, song_number = 0)
159
- note_group = notes.flatten.compact
160
- l = note_group.length / 2
161
- send_bytes([Song::SONG, song_number, l] + note_group)
162
- end
163
-
164
- # Play song
165
- # @param [Collection] notes
166
- # @param [Integer] song_number
167
- # @see Notes
168
- def play_song(notes, song_number = 0)
169
- song(notes, song_number)
170
- play(song_number)
171
- end
172
-
173
- # Beeps with a G note
174
- def beep
175
- play_song([Note::G, Note::WHOLE])
176
- end
177
- end
178
- end
179
- end
@@ -1,59 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Servo behaviors for Firmata
6
- class Servo < Driver
7
- COMMANDS = [:move, :min, :center, :max].freeze
8
-
9
- attr_reader :current_angle
10
-
11
- # Create new Servo with angle=0
12
- def initialize(params={})
13
- super
14
-
15
- @current_angle = 0
16
- end
17
-
18
- # Starts connection to read and process and driver
19
- def start_driver
20
- every(interval) do
21
- connection.read_and_process
22
- end
23
-
24
- super
25
- end
26
-
27
- # Moves to specified angle
28
- # @param [Integer] angle must be between 0-180
29
- def move(angle)
30
- raise "Servo angle must be an integer between 0-180" unless (angle.is_a?(Numeric) && angle >= 0 && angle <= 180)
31
-
32
- @current_angle = angle
33
- connection.set_pin_mode(pin, Firmata::Board::SERVO)
34
- connection.analog_write(pin, angle_to_span(angle))
35
- end
36
-
37
- # Moves to min position
38
- def min
39
- move(0)
40
- end
41
-
42
- # Moves to center position
43
- def center
44
- move(90)
45
- end
46
-
47
- # Moves to max position
48
- def max
49
- move(180)
50
- end
51
-
52
- # converts an angle to a span between 0-255
53
- # @param [Integer] angle
54
- def angle_to_span(angle)
55
- (angle * 255 / 180).to_i
56
- end
57
- end
58
- end
59
- end
@@ -1,105 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # The Sphero driver behaviors
6
- class Sphero < Driver
7
-
8
- RED = [255, 0, 0]
9
- GREEN = [0, 255, 0]
10
- YELLOW = [255, 255, 0]
11
- BLUE = [0, 0, 255]
12
- WHITE = [255, 255, 255]
13
-
14
- COMMANDS = [:detect_collisions, :clear_collisions, :collisions,
15
- :power_notifications, :sensor_data, :set_color, :color].freeze
16
-
17
- # Starts drives and required connections
18
- def start_driver
19
- begin
20
- detect_collisions
21
-
22
- every(interval) do
23
- handle_collision_events
24
- end
25
-
26
- super
27
- rescue Exception => e
28
- Logger.error "Error starting Sphero driver!"
29
- Logger.error e.message
30
- Logger.error e.backtrace.inspect
31
- end
32
- end
33
-
34
- def handle_collision_events
35
- while i = find_event(::Sphero::Response::CollisionDetected) do
36
- update_collision(messages.slice!(i))
37
- end
38
- end
39
-
40
- # Publish collision events
41
- def update_collision(data)
42
- publish(event_topic_name("collision"), data)
43
- end
44
-
45
- # Detects collisions
46
- # @param [Hash] params
47
- def detect_collisions(params={})
48
- connection.configure_collision_detection 0x01, 0x20, 0x20, 0x20, 0x20, 0x50
49
- end
50
-
51
- # Clears collisions
52
- def clear_collisions
53
- messages.clear if responses = messages
54
- end
55
-
56
- # @return [CollisionDetected] collision
57
- def collisions
58
- matching_response_types messages, ::Sphero::Response::CollisionDetected
59
- end
60
-
61
- # @return [PowerNotification] power notification
62
- def power_notifications
63
- matching_response_types messages, ::Sphero::Response::PowerNotification
64
- end
65
-
66
- # @return [SensorData] sensor data
67
- def sensor_data
68
- matching_response_types messages, ::Sphero::Response::SensorData
69
- end
70
-
71
- # Set color
72
- # @param [Collection] colors
73
- def set_color(*colors)
74
- connection.rgb(*color(*colors))
75
- end
76
-
77
- # Retrieves color
78
- # @param [Collection] colors
79
- def color(*colors)
80
- case colors.first
81
- when :red then RED
82
- when :green then GREEN
83
- when :yellow then YELLOW
84
- when :blue then BLUE
85
- when :white then WHITE
86
- else colors
87
- end
88
- end
89
-
90
- private
91
-
92
- def find_event(response_klass)
93
- messages.index {|m| m.is_a? response_klass}
94
- end
95
-
96
- def matching_response_types(responses, respone_klass)
97
- responses.select { |m| m.is_a? respone_klass } if responses
98
- end
99
-
100
- def messages
101
- connection.async_messages
102
- end
103
- end
104
- end
105
- end
@@ -1,61 +0,0 @@
1
- require 'artoo/drivers/wiidriver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Wiichuck driver behaviors for Firmata
6
- class Wiichuck < Wiidriver
7
-
8
- # Update button and joystick values
9
- # @param [Object] value
10
- def update(value)
11
- begin
12
- super
13
-
14
- adjust_origins
15
- update_buttons
16
- update_joystick
17
-
18
- rescue Exception => e
19
- Logger.error "wiichuck update exception!"
20
- Logger.error e.message
21
- Logger.error e.backtrace.inspect
22
- end
23
- end
24
-
25
- # Adjust x, y origin values
26
- def adjust_origins
27
- set_joystick_default_value(:sy_origin, data[:sy])
28
- set_joystick_default_value(:sx_origin, data[:sx])
29
- end
30
-
31
- # Publishes events for c and z buttons
32
- def update_buttons
33
- publish(event_topic_name("c_button")) if data[:c] == true
34
- publish(event_topic_name("z_button")) if data[:z] == true
35
- end
36
-
37
- # Publishes event for joystick
38
- def update_joystick
39
- publish(event_topic_name("joystick"), {:x => calculate_joystick_value(:sx, :sx_origin), :y => calculate_joystick_value(:sy, :sy_origin)})
40
- end
41
-
42
- private
43
-
44
- def get_defaults
45
- {
46
- :sy_origin => nil,
47
- :sx_origin => nil
48
- }
49
- end
50
-
51
- def parse(value)
52
- return {
53
- :sx => decode_value(value, 0),
54
- :sy => decode_value(value, 1),
55
- :z => generate_bool(decode_value(value, 5) & 0x01),
56
- :c => generate_bool(decode_value(value, 5) & 0x02)
57
- }
58
- end
59
- end
60
- end
61
- end
@@ -1,139 +0,0 @@
1
- require 'artoo/drivers/wiidriver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Wiiclassic driver behaviors for Firmata
6
- class Wiiclassic < Wiidriver
7
-
8
- # Update buttons and joysticks values
9
- # @param [Object] value
10
- def update(value)
11
- begin
12
- super
13
-
14
- adjust_origins
15
- update_buttons
16
- update_left_joystick
17
- update_right_joystick
18
- update_triggers
19
-
20
- rescue Exception => e
21
- Logger.error "wiiclassic update exception!"
22
- Logger.error e.message
23
- Logger.error e.backtrace.inspect
24
- end
25
- end
26
-
27
- # Adjust all origins
28
- def adjust_origins
29
- set_joystick_default_value(:ly_origin, data[:ly])
30
- set_joystick_default_value(:lx_origin, data[:lx])
31
- set_joystick_default_value(:ry_origin, data[:ry])
32
- set_joystick_default_value(:rx_origin, data[:rx])
33
- set_joystick_default_value(:rt_origin, data[:rt])
34
- set_joystick_default_value(:lt_origin, data[:lt])
35
- end
36
-
37
- # Update button values
38
- def update_buttons
39
- update_button("a_button", :a)
40
- update_button("b_button", :b)
41
- update_button("x_button", :x)
42
- update_button("y_button", :y)
43
- update_button("home_button", :h)
44
- update_button("start_button", :+)
45
- update_button("select_button", :-)
46
- end
47
-
48
- # Publish button event
49
- def update_button(name, key)
50
- publish(event_topic_name(name)) if data[key] == true
51
- end
52
-
53
- # Publish left joystick event
54
- def update_left_joystick
55
- publish(event_topic_name("left_joystick"), {:x => calculate_joystick_value(:lx, :lx_origin), :y => calculate_joystick_value(:ly, :ly_origin)})
56
- end
57
-
58
- # Publish right joystick event
59
- def update_right_joystick
60
- publish(event_topic_name("right_joystick"), {:x => calculate_joystick_value(:rx, :rx_origin), :y => calculate_joystick_value(:ry, :ry_origin)})
61
- end
62
-
63
- # Publish triggers events
64
- def update_triggers
65
- publish(event_topic_name("right_trigger"), calculate_joystick_value(:rt, :rt_origin))
66
- publish(event_topic_name("left_trigger"), calculate_joystick_value(:lt, :lt_origin))
67
- end
68
-
69
- private
70
-
71
- def get_defaults
72
- {
73
- :ry_origin => nil,
74
- :rx_origin => nil,
75
- :ly_origin => nil,
76
- :lx_origin => nil,
77
- :rt_origin => nil,
78
- :lt_origin => nil
79
- }
80
- end
81
-
82
- def parse(value)
83
- return parse_joysticks(value).
84
- merge(parse_buttons(value)).
85
- merge(parse_triggers(value)).
86
- merge(parse_dpad(value)).
87
- merge(parse_zbuttons(value))
88
- end
89
-
90
- def parse_joysticks(value)
91
- {
92
- :lx => decode_value(value, 0) & 0x3f,
93
- :ly => decode_value(value, 1) & 0x3f,
94
- :rx => ((decode_value(value, 0) & 0xC0) >> 2) | ((decode_value(value, 1) & 0xC0) >> 4) | (decode_value(value, 2)[7]),
95
- :ry => decode_value(value, 2) & 0x1f
96
- }
97
- end
98
-
99
- def parse_buttons(value)
100
- {
101
- :a => get_bool_decoded_value(value, 5, 4),
102
- :b => get_bool_decoded_value(value, 5, 6),
103
- :x => get_bool_decoded_value(value, 5, 3),
104
- :y => get_bool_decoded_value(value, 5, 5),
105
- :+ => get_bool_decoded_value(value, 4, 2),
106
- :- => get_bool_decoded_value(value, 4, 4),
107
- :h => get_bool_decoded_value(value, 4, 3)
108
- }
109
- end
110
-
111
- def parse_triggers(value)
112
- {
113
- :lt => ((decode_value(value, 2) & 0x60) >> 3) | ((decode_value(value, 3) & 0xC0) >> 6),
114
- :rt => decode_value(value, 3) & 0x1f
115
- }
116
- end
117
-
118
- def parse_dpad(value)
119
- {
120
- :d_up => get_bool_decoded_value(value, 5, 0),
121
- :d_down => get_bool_decoded_value(value, 4, 6),
122
- :d_left => get_bool_decoded_value(value, 5, 1),
123
- :d_right => get_bool_decoded_value(value, 4, 7)
124
- }
125
- end
126
-
127
- def parse_zbuttons(value)
128
- {
129
- :zr => get_bool_decoded_value(value, 5, 2),
130
- :zl => get_bool_decoded_value(value, 5, 7)
131
- }
132
- end
133
-
134
- def get_bool_decoded_value(value, offset1, offset2)
135
- generate_bool(decode_value(value, offset1)[offset2])
136
- end
137
- end
138
- end
139
- end