artoo 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile.lock +10 -10
- data/README.md +3 -0
- data/artoo.gemspec +3 -2
- data/bin/sphero_linux_socat.sh +8 -0
- data/examples/christmas_roomba.rb +54 -9
- data/examples/conway_sphero.rb +1 -1
- data/examples/roomba.rb +12 -0
- data/examples/roomba_wiichuck.rb +56 -0
- data/examples/sphero_cycle.rb +15 -0
- data/lib/artoo/adaptors/adaptor.rb +3 -2
- data/lib/artoo/connection.rb +10 -7
- data/lib/artoo/delegator.rb +1 -1
- data/lib/artoo/drivers/roomba.rb +62 -86
- data/lib/artoo/drivers/sphero.rb +2 -2
- data/lib/artoo/robot.rb +5 -1
- data/lib/artoo/version.rb +1 -1
- data/test/device_test.rb +4 -4
- data/test/drivers/roomba_test.rb +87 -0
- data/test/robot_test.rb +19 -27
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18102ca867dce3a87d0d7a37e9a3815b7b3be8a2
|
4
|
+
data.tar.gz: 5410f7319fbee6fa07c76808e0cb766b7883cd84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26e56150e35df75a79560888fa419f4e768b9e8634e7824f2c60e1df6bd2c7f3c136599f893547b23cb090ebab7c5f07c37665b0aca23353e10d1a13b8727a4e
|
7
|
+
data.tar.gz: 3b22a157db5e7826021dc74872b7bab951e32c9c1e0204476e5809d7639347d2bc3ef37c64739ec6bc269b8ae46e5992aa26d43df3f471b9caa760c7253bbd4d
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
artoo (0.
|
4
|
+
artoo (0.4.0)
|
5
5
|
active_support (~> 3.0)
|
6
|
-
celluloid
|
6
|
+
celluloid (~> 0.14.0)
|
7
|
+
celluloid-io (~> 0.14.0)
|
7
8
|
multi_json (~> 1.6)
|
8
9
|
pry (~> 0.9)
|
9
10
|
rake (~> 10.0)
|
10
|
-
reel (~> 0.
|
11
|
+
reel (~> 0.4.pre)
|
11
12
|
|
12
13
|
GEM
|
13
14
|
remote: http://rubygems.org/
|
@@ -17,11 +18,11 @@ GEM
|
|
17
18
|
activesupport (3.0.0)
|
18
19
|
bootstrap-sass (2.2.2.0)
|
19
20
|
sass (~> 3.2)
|
20
|
-
celluloid (0.
|
21
|
+
celluloid (0.14.0)
|
21
22
|
timers (>= 1.0.0)
|
22
|
-
celluloid-io (0.
|
23
|
+
celluloid-io (0.14.0)
|
23
24
|
celluloid (>= 0.13.0)
|
24
|
-
nio4r (>= 0.4.
|
25
|
+
nio4r (>= 0.4.5)
|
25
26
|
certified (0.1.1)
|
26
27
|
chunky_png (1.2.7)
|
27
28
|
coderay (1.0.9)
|
@@ -77,8 +78,7 @@ GEM
|
|
77
78
|
mocha (0.13.2)
|
78
79
|
metaclass (~> 0.0.1)
|
79
80
|
multi_json (1.6.1)
|
80
|
-
nio4r (0.4.
|
81
|
-
nio4r (0.4.3-java)
|
81
|
+
nio4r (0.4.5)
|
82
82
|
pry (0.9.12)
|
83
83
|
coderay (~> 1.0.5)
|
84
84
|
method_source (~> 0.8)
|
@@ -90,12 +90,12 @@ GEM
|
|
90
90
|
spoon (~> 0.0)
|
91
91
|
rack (1.5.2)
|
92
92
|
rake (10.0.4)
|
93
|
-
reel (0.
|
93
|
+
reel (0.4.0.pre)
|
94
94
|
celluloid-io (>= 0.8.0)
|
95
95
|
http (>= 0.2.0)
|
96
96
|
http_parser.rb (>= 0.5.3)
|
97
97
|
rack (>= 1.4.0)
|
98
|
-
websocket_parser (>= 0.1.
|
98
|
+
websocket_parser (>= 0.1.2)
|
99
99
|
sass (3.2.5)
|
100
100
|
slop (3.4.3)
|
101
101
|
spoon (0.0.1)
|
data/README.md
CHANGED
data/artoo.gemspec
CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_runtime_dependency 'celluloid
|
23
|
-
s.add_runtime_dependency '
|
22
|
+
s.add_runtime_dependency 'celluloid', '~> 0.14.0'
|
23
|
+
s.add_runtime_dependency 'celluloid-io', '~> 0.14.0'
|
24
|
+
s.add_runtime_dependency 'reel', '~> 0.4.pre'
|
24
25
|
s.add_runtime_dependency 'multi_json', '~> 1.6'
|
25
26
|
s.add_runtime_dependency 'active_support', '~> 3.0'
|
26
27
|
s.add_runtime_dependency 'rake', '~> 10.0'
|
@@ -1,11 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
rescue LoadError
|
4
|
-
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..', 'lib')))
|
5
|
-
require "artoo"
|
6
|
-
end
|
1
|
+
require 'artoo'
|
2
|
+
require 'artoo/drivers/roomba'
|
7
3
|
|
8
|
-
connection :roomba, :adaptor => :roomba, :port => '/dev/
|
4
|
+
connection :roomba, :adaptor => :roomba, :port => '/dev/ttyUSB0'
|
9
5
|
device :roomba, :driver => :roomba, :connection => :roomba
|
10
6
|
|
11
7
|
work do
|
@@ -14,5 +10,54 @@ work do
|
|
14
10
|
roomba.nudge_right
|
15
11
|
roomba.nudge_right
|
16
12
|
roomba.nudge_left
|
17
|
-
|
18
|
-
end
|
13
|
+
play_jingle_bells
|
14
|
+
end
|
15
|
+
|
16
|
+
def play_jingle_bells
|
17
|
+
roomba.song(JingleBells.song0, 0)
|
18
|
+
roomba.song(JingleBells.song1, 1)
|
19
|
+
roomba.song(JingleBells.song2, 2)
|
20
|
+
roomba.song(JingleBells.song3, 3)
|
21
|
+
|
22
|
+
roomba.play(0)
|
23
|
+
sleep(7)
|
24
|
+
roomba.play(1)
|
25
|
+
sleep(7)
|
26
|
+
roomba.play(2)
|
27
|
+
sleep(7)
|
28
|
+
roomba.play(3)
|
29
|
+
end
|
30
|
+
|
31
|
+
class JingleBells
|
32
|
+
extend Artoo::Drivers::Roomba::Note
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def song0
|
36
|
+
[[B, QUARTER], [B, QUARTER], [B, HALF],
|
37
|
+
[B, QUARTER], [B, QUARTER], [B, HALF],
|
38
|
+
[B, QUARTER], [D, QUARTER], [G, QUARTER], [A, QUARTER],
|
39
|
+
[B, WHOLE]]
|
40
|
+
end
|
41
|
+
|
42
|
+
def song1
|
43
|
+
[[C, QUARTER], [C, QUARTER], [C, QUARTER], [C, QUARTER],
|
44
|
+
[C, QUARTER], [B, QUARTER], [B, HALF],
|
45
|
+
[B, QUARTER], [A, QUARTER], [A, QUARTER], [B, QUARTER],
|
46
|
+
[A, HALF], [D, HALF]]
|
47
|
+
end
|
48
|
+
|
49
|
+
def song2
|
50
|
+
[[B, QUARTER], [B, QUARTER], [B, HALF],
|
51
|
+
[B, QUARTER], [B, QUARTER], [B, HALF],
|
52
|
+
[B, QUARTER], [D, QUARTER], [G, QUARTER], [A, QUARTER],
|
53
|
+
[B, WHOLE]]
|
54
|
+
end
|
55
|
+
|
56
|
+
def song3
|
57
|
+
[[C, QUARTER], [C, QUARTER], [C, QUARTER], [C, QUARTER],
|
58
|
+
[C, QUARTER], [B, QUARTER], [B, QUARTER], [B, QUARTER],
|
59
|
+
[D, QUARTER], [D, QUARTER], [C, QUARTER], [A, QUARTER],
|
60
|
+
[G, WHOLE]]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/examples/conway_sphero.rb
CHANGED
data/examples/roomba.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :roomba, :adaptor => :roomba, :port => '/dev/ttyUSB0'
|
4
|
+
device :roomba, :driver => :roomba, :connection => :roomba
|
5
|
+
|
6
|
+
work do
|
7
|
+
roomba.safe_mode
|
8
|
+
roomba.nudge_left
|
9
|
+
roomba.nudge_right
|
10
|
+
roomba.nudge_right
|
11
|
+
roomba.nudge_left
|
12
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :roomba, :adaptor => :roomba, :port => '8023'
|
4
|
+
device :roomba, :driver => :roomba, :connection => :roomba
|
5
|
+
|
6
|
+
connection :arduino, :adaptor => :firmata, :port => '8024'
|
7
|
+
device :wiichuck, :driver => :wiichuck, :connection => :arduino, :interval => 0.1
|
8
|
+
|
9
|
+
work do
|
10
|
+
roomba.safe_mode
|
11
|
+
on wiichuck, :z_button => proc {
|
12
|
+
C1 = 66
|
13
|
+
D1 = 74
|
14
|
+
E1 = 83
|
15
|
+
F1 = 88
|
16
|
+
A2 = 100
|
17
|
+
QUARTER = 16
|
18
|
+
HALF = 57
|
19
|
+
la_cucaracha = []
|
20
|
+
la_cucaracha << [C1, QUARTER]
|
21
|
+
la_cucaracha << [C1, QUARTER]
|
22
|
+
la_cucaracha << [C1, QUARTER]
|
23
|
+
la_cucaracha << [F1, HALF]
|
24
|
+
la_cucaracha << [A2, QUARTER]
|
25
|
+
la_cucaracha << [C1, QUARTER]
|
26
|
+
la_cucaracha << [C1, QUARTER]
|
27
|
+
la_cucaracha << [C1, QUARTER]
|
28
|
+
la_cucaracha << [F1, HALF]
|
29
|
+
la_cucaracha << [A2, QUARTER]
|
30
|
+
la_cucaracha << [F1, QUARTER]
|
31
|
+
la_cucaracha << [F1, QUARTER]
|
32
|
+
la_cucaracha << [E1, QUARTER]
|
33
|
+
la_cucaracha << [E1, QUARTER]
|
34
|
+
la_cucaracha << [D1, QUARTER]
|
35
|
+
la_cucaracha << [D1, QUARTER]
|
36
|
+
la_cucaracha << [C1, QUARTER]
|
37
|
+
roomba.play_song(la_cucaracha)
|
38
|
+
}
|
39
|
+
on wiichuck, :joystick => proc { |*value|
|
40
|
+
|
41
|
+
pair = value[1]
|
42
|
+
|
43
|
+
if pair[:y] > 10
|
44
|
+
roomba.forward(1)
|
45
|
+
elsif pair[:y] < -10
|
46
|
+
roomba.backwards(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
if pair[:x] > 10
|
50
|
+
roomba.turn_right
|
51
|
+
elsif pair[:x] < -10
|
52
|
+
roomba.turn_left
|
53
|
+
end
|
54
|
+
|
55
|
+
}
|
56
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4560'
|
4
|
+
device :sphero, :driver => :sphero
|
5
|
+
|
6
|
+
work do
|
7
|
+
sphero.set_color(0, 0, 0)
|
8
|
+
sphero.set_color(:red)
|
9
|
+
sphero.set_color(:yellow)
|
10
|
+
sphero.set_color(:green)
|
11
|
+
sphero.set_color(0, 255, 255)
|
12
|
+
sphero.set_color(:blue)
|
13
|
+
sphero.set_color(255, 0, 255)
|
14
|
+
sphero.set_color(:white)
|
15
|
+
end
|
@@ -50,9 +50,10 @@ module Artoo
|
|
50
50
|
@udp_socket ||= UDPSocket.new
|
51
51
|
end
|
52
52
|
|
53
|
-
def connect_to_serial(speed=57600, data_bits=8, stop_bits=1, parity=
|
53
|
+
def connect_to_serial(speed=57600, data_bits=8, stop_bits=1, parity=nil)
|
54
54
|
require 'serialport'
|
55
|
-
|
55
|
+
parity = ::SerialPort::NONE unless parity
|
56
|
+
@sp = ::SerialPort.new(port.port, speed, data_bits, stop_bits, parity)
|
56
57
|
rescue LoadError
|
57
58
|
Logger.error "Please 'gem install hybridgroup-serialport' for serial port support."
|
58
59
|
end
|
data/lib/artoo/connection.rb
CHANGED
@@ -7,10 +7,12 @@ module Artoo
|
|
7
7
|
class Connection
|
8
8
|
include Celluloid
|
9
9
|
include Artoo::Utility
|
10
|
+
include Comparable
|
10
11
|
|
11
|
-
attr_reader :parent, :name, :port, :adaptor
|
12
|
+
attr_reader :parent, :name, :port, :adaptor, :connection_id
|
12
13
|
|
13
14
|
def initialize(params={})
|
15
|
+
@connection_id = rand(10000)
|
14
16
|
@name = params[:name].to_s
|
15
17
|
@port = Port.new(params[:port])
|
16
18
|
@parent = params[:parent]
|
@@ -35,10 +37,15 @@ module Artoo
|
|
35
37
|
adaptor.connected?
|
36
38
|
end
|
37
39
|
|
40
|
+
def adaptor_name
|
41
|
+
adaptor.class.name
|
42
|
+
end
|
43
|
+
|
38
44
|
def to_hash
|
39
45
|
{:name => name,
|
46
|
+
:connection_id => connection_id,
|
40
47
|
:port => port.to_s,
|
41
|
-
:adaptor =>
|
48
|
+
:adaptor => adaptor_name.demodulize,
|
42
49
|
:connected => connected?
|
43
50
|
}
|
44
51
|
end
|
@@ -47,12 +54,8 @@ module Artoo
|
|
47
54
|
MultiJson.dump(to_hash)
|
48
55
|
end
|
49
56
|
|
50
|
-
def to_s
|
51
|
-
"#{self.class}:0x#{self.object_id}"
|
52
|
-
end
|
53
|
-
|
54
57
|
def inspect
|
55
|
-
"
|
58
|
+
"#<Connection @id=#{object_id}, @name='#{name}', @adaptor=#{adaptor_name}>"
|
56
59
|
end
|
57
60
|
|
58
61
|
def method_missing(method_name, *arguments, &block)
|
data/lib/artoo/delegator.rb
CHANGED
data/lib/artoo/drivers/roomba.rb
CHANGED
@@ -4,63 +4,74 @@ module Artoo
|
|
4
4
|
module Drivers
|
5
5
|
# The Roomba driver behaviors
|
6
6
|
class Roomba < Driver
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
7
|
+
module Direction
|
8
|
+
STRAIGHT = 32768
|
9
|
+
CLOCKWISE = 65535
|
10
|
+
COUNTERCLOCKWISE = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
module Speed
|
14
|
+
MAX = 500
|
15
|
+
SLOW = 250
|
16
|
+
NEG = (65536 - 250)
|
17
|
+
ZERO = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
module Note
|
21
|
+
B = 95
|
22
|
+
D = 98
|
23
|
+
G = 91
|
24
|
+
C = 96
|
25
|
+
A = 93
|
26
|
+
QUARTER = 16
|
27
|
+
HALF = 57
|
28
|
+
WHOLE = 114
|
29
|
+
end
|
30
|
+
|
31
|
+
module Mode
|
27
32
|
FULL = 132
|
28
33
|
SAFE = 131
|
34
|
+
START = 128
|
29
35
|
end
|
30
36
|
|
37
|
+
module Song
|
38
|
+
SONG = 140
|
39
|
+
PLAY = 141
|
40
|
+
end
|
41
|
+
|
31
42
|
def start
|
32
|
-
send_bytes(START)
|
43
|
+
send_bytes(Mode::START)
|
33
44
|
sleep 0.2
|
34
45
|
end
|
35
46
|
|
36
47
|
def safe_mode
|
37
48
|
start
|
38
|
-
send_bytes(
|
49
|
+
send_bytes(Mode::SAFE)
|
39
50
|
sleep 0.1
|
40
51
|
end
|
41
52
|
|
42
53
|
def full_mode
|
43
54
|
start
|
44
|
-
send_bytes(
|
55
|
+
send_bytes(Mode::FULL)
|
45
56
|
sleep 0.1
|
46
57
|
end
|
47
58
|
|
48
|
-
def forward(seconds, velocity = SLOW)
|
49
|
-
drive(velocity,STRAIGHT,seconds)
|
59
|
+
def forward(seconds, velocity = Speed::SLOW)
|
60
|
+
drive(velocity, Direction::STRAIGHT, seconds)
|
50
61
|
stop if seconds > 0
|
51
62
|
end
|
52
63
|
|
53
64
|
def stop
|
54
|
-
drive(ZERO,STRAIGHT)
|
65
|
+
drive(Speed::ZERO, Direction::STRAIGHT)
|
55
66
|
end
|
56
67
|
|
57
68
|
def fast_forward(seconds)
|
58
|
-
drive(MAX,STRAIGHT,seconds)
|
69
|
+
drive(Speed::MAX, Direction::STRAIGHT, seconds)
|
59
70
|
stop if seconds > 0
|
60
71
|
end
|
61
72
|
|
62
73
|
def backwards(seconds)
|
63
|
-
drive(NEG,STRAIGHT,seconds)
|
74
|
+
drive(Speed::NEG, Direction::STRAIGHT, seconds)
|
64
75
|
stop if seconds > 0
|
65
76
|
end
|
66
77
|
|
@@ -69,12 +80,12 @@ module Artoo
|
|
69
80
|
end
|
70
81
|
|
71
82
|
def turn_left(seconds = 1)
|
72
|
-
drive(SLOW,COUNTERCLOCKWISE,seconds)
|
83
|
+
drive(Speed::SLOW, Direction::COUNTERCLOCKWISE, seconds)
|
73
84
|
stop if seconds > 0
|
74
85
|
end
|
75
86
|
|
76
87
|
def turn_right(seconds = 1)
|
77
|
-
drive(SLOW,CLOCKWISE,seconds)
|
88
|
+
drive(Speed::SLOW, Direction::CLOCKWISE, seconds)
|
78
89
|
stop if seconds > 0
|
79
90
|
end
|
80
91
|
|
@@ -85,71 +96,36 @@ module Artoo
|
|
85
96
|
def turn_around
|
86
97
|
turn_left(1.6)
|
87
98
|
end
|
88
|
-
|
89
|
-
def
|
90
|
-
notes = [140,0,1,G,WHOLE]
|
91
|
-
connection.send_bytes(notes)
|
92
|
-
connection.send_bytes([141,0])
|
93
|
-
end
|
94
|
-
|
95
|
-
def sing_jingle_bells
|
96
|
-
song0 = [[B,QUART],[B,QUART],[B,HALF],
|
97
|
-
[B,QUART],[B,QUART],[B,HALF],
|
98
|
-
[B,QUART],[D,QUART],[G,QUART],[A,QUART],
|
99
|
-
[B,WHOLE]]
|
100
|
-
song1 = [[C,QUART],[C,QUART],[C,QUART],[C,QUART],
|
101
|
-
[C,QUART],[B,QUART],[B,HALF],
|
102
|
-
[B,QUART],[A,QUART],[A,QUART],[B,QUART],
|
103
|
-
[A,HALF],[D,HALF]]
|
104
|
-
song2 = [[B,QUART],[B,QUART],[B,HALF],
|
105
|
-
[B,QUART],[B,QUART],[B,HALF],
|
106
|
-
[B,QUART],[D,QUART],[G,QUART],[A,QUART],
|
107
|
-
[B,WHOLE]]
|
108
|
-
song3 = [[C,QUART],[C,QUART],[C,QUART],[C,QUART],
|
109
|
-
[C,QUART],[B,QUART],[B,QUART],[B,QUART],
|
110
|
-
[D,QUART],[D,QUART],[C,QUART],[A,QUART],
|
111
|
-
[G,WHOLE]]
|
112
|
-
|
113
|
-
note_group = song0.flatten.compact
|
114
|
-
l = note_group.length / 2
|
115
|
-
notes = [140,0,l] + note_group
|
116
|
-
connection.send_bytes(notes)
|
117
|
-
|
118
|
-
note_group = song1.flatten.compact
|
119
|
-
l = note_group.length / 2
|
120
|
-
notes = [140,1,l] + note_group
|
121
|
-
connection.send_bytes(notes)
|
122
|
-
|
123
|
-
note_group = song2.flatten.compact
|
124
|
-
l = note_group.length / 2
|
125
|
-
notes = [140,2,l] + note_group
|
126
|
-
connection.send_bytes(notes)
|
127
|
-
|
128
|
-
note_group = song3.flatten.compact
|
129
|
-
l = note_group.length / 2
|
130
|
-
notes = [140,3,l] + note_group
|
131
|
-
connection.send_bytes(notes)
|
132
|
-
|
133
|
-
connection.send_bytes([141,0])
|
134
|
-
sleep(7)
|
135
|
-
connection.send_bytes([141,1])
|
136
|
-
sleep(7)
|
137
|
-
connection.send_bytes([141,2])
|
138
|
-
sleep(7)
|
139
|
-
connection.send_bytes([141,3])
|
140
|
-
end
|
141
|
-
|
142
|
-
def drive(v,r,s = 0)
|
99
|
+
|
100
|
+
def drive(v, r, s = 0)
|
143
101
|
vH,vL = split_bytes(v)
|
144
102
|
rH,rL = split_bytes(r)
|
145
|
-
|
103
|
+
send_bytes([137, vH, vL, rH, rL])
|
146
104
|
sleep(s) if s > 0
|
147
105
|
end
|
148
106
|
|
149
107
|
def split_bytes(num)
|
150
108
|
[num >> 8, num & 255]
|
151
109
|
end
|
110
|
+
|
111
|
+
def play(song_number = 0)
|
112
|
+
send_bytes([Song::PLAY, song_number])
|
113
|
+
end
|
114
|
+
|
115
|
+
def song(notes, song_number = 0)
|
116
|
+
note_group = notes.flatten.compact
|
117
|
+
l = note_group.length / 2
|
118
|
+
send_bytes([Song::SONG, song_number, l] + note_group)
|
119
|
+
end
|
152
120
|
|
121
|
+
def play_song(notes, song_number = 0)
|
122
|
+
song(notes, song_number)
|
123
|
+
play(song_number)
|
124
|
+
end
|
125
|
+
|
126
|
+
def beep
|
127
|
+
play_song([Note::G, Note::WHOLE])
|
128
|
+
end
|
153
129
|
end
|
154
130
|
end
|
155
131
|
end
|
data/lib/artoo/drivers/sphero.rb
CHANGED
@@ -15,7 +15,7 @@ module Artoo
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def clear_collisions
|
18
|
-
|
18
|
+
messages.clear if responses = messages
|
19
19
|
end
|
20
20
|
|
21
21
|
def collisions
|
@@ -31,7 +31,7 @@ module Artoo
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def set_color(*colors)
|
34
|
-
connection.rgb(*color(colors))
|
34
|
+
connection.rgb(*color(*colors))
|
35
35
|
end
|
36
36
|
|
37
37
|
def color(*colors)
|
data/lib/artoo/robot.rb
CHANGED
@@ -89,7 +89,7 @@ module Artoo
|
|
89
89
|
|
90
90
|
unless cli?
|
91
91
|
Celluloid::Actor[:api] = Api.new(self.api_host, self.api_port) if self.use_api
|
92
|
-
|
92
|
+
master.start_work
|
93
93
|
self.running = true
|
94
94
|
sleep # sleep main thread, and let the work commence!
|
95
95
|
end
|
@@ -107,6 +107,10 @@ module Artoo
|
|
107
107
|
Celluloid::Actor[:master] = Master.new(robots)
|
108
108
|
end
|
109
109
|
|
110
|
+
def master
|
111
|
+
Celluloid::Actor[:master]
|
112
|
+
end
|
113
|
+
|
110
114
|
def test?
|
111
115
|
ENV["ARTOO_TEST"] == 'true'
|
112
116
|
end
|
data/lib/artoo/version.rb
CHANGED
data/test/device_test.rb
CHANGED
@@ -19,14 +19,14 @@ describe Artoo::Device do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'Artoo::Device#default_connection' do
|
22
|
-
@robot.devices[:test_device_1].default_connection.must_equal @robot.default_connection
|
23
|
-
@robot.devices[:test_device_2].default_connection.must_equal @robot.default_connection
|
22
|
+
@robot.devices[:test_device_1].default_connection.wrapped_object.must_equal @robot.default_connection.wrapped_object
|
23
|
+
@robot.devices[:test_device_2].default_connection.wrapped_object.must_equal @robot.default_connection.wrapped_object
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'Artoo::Device#connect' do
|
27
27
|
@robot2 = MultipleDeviceConnectionTestRobot.new
|
28
|
-
@robot2.devices[:test_device_1].connection.must_equal @robot2.connections[:test_connection]
|
29
|
-
@robot2.devices[:test_device_2].connection.must_equal @robot2.connections[:test_connection2]
|
28
|
+
@robot2.devices[:test_device_1].connection.wrapped_object.must_equal @robot2.connections[:test_connection].wrapped_object
|
29
|
+
@robot2.devices[:test_device_2].connection.wrapped_object.must_equal @robot2.connections[:test_connection2].wrapped_object
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'Artoo::Device#event_topic_name' do
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'artoo/drivers/roomba'
|
3
|
+
|
4
|
+
describe Artoo::Drivers::Roomba do
|
5
|
+
before do
|
6
|
+
@connection = mock('connection')
|
7
|
+
@device = mock('device')
|
8
|
+
@device.stubs(:connection).returns(@connection)
|
9
|
+
@roomba = Artoo::Drivers::Roomba.new(:parent => @device)
|
10
|
+
@roomba.stubs(:sleep)
|
11
|
+
@roomba_proxy = @roomba.wrapped_object
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'Roomba#start' do
|
15
|
+
@connection.expects(:send_bytes).with(Artoo::Drivers::Roomba::Mode::START)
|
16
|
+
@roomba.start
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'Roomba#safe_mode' do
|
20
|
+
@roomba.stubs(:start)
|
21
|
+
@connection.expects(:send_bytes).with(Artoo::Drivers::Roomba::Mode::SAFE)
|
22
|
+
@roomba.safe_mode
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Roomba#full_mode' do
|
26
|
+
@roomba.stubs(:start)
|
27
|
+
@connection.expects(:send_bytes).with(Artoo::Drivers::Roomba::Mode::FULL)
|
28
|
+
@roomba.full_mode
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'Roomba#forward' do
|
32
|
+
@roomba_proxy.expects(:drive).with(250, Artoo::Drivers::Roomba::Direction::STRAIGHT, 10)
|
33
|
+
@roomba_proxy.expects(:stop)
|
34
|
+
@roomba.forward(10, 250)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'Roomba#stop' do
|
38
|
+
@roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::ZERO, Artoo::Drivers::Roomba::Direction::STRAIGHT)
|
39
|
+
@roomba.stop
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'Roomba#fast_forward' do
|
43
|
+
@roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::MAX, Artoo::Drivers::Roomba::Direction::STRAIGHT, 10)
|
44
|
+
@roomba_proxy.expects(:stop)
|
45
|
+
@roomba.fast_forward(10)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'Roomba#backwards' do
|
49
|
+
@roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::NEG, Artoo::Drivers::Roomba::Direction::STRAIGHT, 10)
|
50
|
+
@roomba_proxy.expects(:stop)
|
51
|
+
@roomba.backwards(10)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'Roomba#turn_left' do
|
55
|
+
@roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::COUNTERCLOCKWISE, 10)
|
56
|
+
@roomba_proxy.expects(:stop)
|
57
|
+
@roomba.turn_left(10)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'Roomba#nudge_left' do
|
61
|
+
@roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::COUNTERCLOCKWISE, 0.25)
|
62
|
+
@roomba_proxy.expects(:stop)
|
63
|
+
@roomba.nudge_left
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'Roomba#turn_right' do
|
67
|
+
@roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::CLOCKWISE, 10)
|
68
|
+
@roomba_proxy.expects(:stop)
|
69
|
+
@roomba.turn_right(10)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'Roomba#nudge_right' do
|
73
|
+
@roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::CLOCKWISE, 0.25)
|
74
|
+
@roomba_proxy.expects(:stop)
|
75
|
+
@roomba.nudge_right
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'Roomba#play' do
|
79
|
+
@connection.expects(:send_bytes).with([Artoo::Drivers::Roomba::Song::PLAY, 0])
|
80
|
+
@roomba.play(0)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'Roomba#song' do
|
84
|
+
@connection.expects(:send_bytes).with([Artoo::Drivers::Roomba::Song::SONG, 0, 3, Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER, Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER, Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::HALF])
|
85
|
+
@roomba.song([[Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER], [Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER], [Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::HALF]], 0)
|
86
|
+
end
|
87
|
+
end
|
data/test/robot_test.rb
CHANGED
@@ -60,37 +60,29 @@ describe Artoo::Robot do
|
|
60
60
|
@robot.default_connection.adaptor.must_be_kind_of Artoo::Adaptors::Loopback
|
61
61
|
end
|
62
62
|
|
63
|
-
it 'Artoo::Robot
|
64
|
-
|
65
|
-
|
66
|
-
@asm = mock("async_method")
|
67
|
-
@asm.expects(:work)
|
68
|
-
@robot.expects(:async).returns(@asm)
|
69
|
-
TestRobot.work!(@robot)
|
63
|
+
it 'Artoo::Robot#as_json' do
|
64
|
+
MultiJson.load(@robot.as_json, :symbolize_keys => true)[:name].must_equal "testme"
|
70
65
|
end
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
@robot2.expects(:async).returns(@asm)
|
80
|
-
TestRobot.work!([@robot, @robot2])
|
81
|
-
end
|
67
|
+
describe 'work' do
|
68
|
+
before do
|
69
|
+
TestRobot.stubs(:sleep)
|
70
|
+
@master = mock('master')
|
71
|
+
TestRobot.stubs(:master).returns(@master)
|
72
|
+
@master.expects(:start_work)
|
73
|
+
end
|
82
74
|
|
83
|
-
|
84
|
-
|
75
|
+
it 'Artoo::Robot.work! with single object' do
|
76
|
+
TestRobot.work!(@robot)
|
77
|
+
end
|
85
78
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
TestRobot.work!
|
91
|
-
end
|
79
|
+
it 'Artoo::Robot.work! with array of objects' do
|
80
|
+
@robot2 = TestRobot.new(:name => "too", :connections => {:test_connection => {:port => '1234'}})
|
81
|
+
TestRobot.work!([@robot, @robot2])
|
82
|
+
end
|
92
83
|
|
93
|
-
|
94
|
-
|
84
|
+
it 'Artoo::Robot.work! without object' do
|
85
|
+
TestRobot.work!
|
86
|
+
end
|
95
87
|
end
|
96
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ron Evans
|
@@ -12,36 +12,50 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: celluloid
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.14.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.14.0
|
17
31
|
- !ruby/object:Gem::Dependency
|
18
32
|
name: celluloid-io
|
19
33
|
requirement: !ruby/object:Gem::Requirement
|
20
34
|
requirements:
|
21
35
|
- - ~>
|
22
36
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
37
|
+
version: 0.14.0
|
24
38
|
type: :runtime
|
25
39
|
prerelease: false
|
26
40
|
version_requirements: !ruby/object:Gem::Requirement
|
27
41
|
requirements:
|
28
42
|
- - ~>
|
29
43
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
44
|
+
version: 0.14.0
|
31
45
|
- !ruby/object:Gem::Dependency
|
32
46
|
name: reel
|
33
47
|
requirement: !ruby/object:Gem::Requirement
|
34
48
|
requirements:
|
35
49
|
- - ~>
|
36
50
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
51
|
+
version: 0.4.pre
|
38
52
|
type: :runtime
|
39
53
|
prerelease: false
|
40
54
|
version_requirements: !ruby/object:Gem::Requirement
|
41
55
|
requirements:
|
42
56
|
- - ~>
|
43
57
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
58
|
+
version: 0.4.pre
|
45
59
|
- !ruby/object:Gem::Dependency
|
46
60
|
name: multi_json
|
47
61
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,6 +147,7 @@ executables:
|
|
133
147
|
- retry.sh
|
134
148
|
- robi
|
135
149
|
- sphero.sh
|
150
|
+
- sphero_linux_socat.sh
|
136
151
|
extensions: []
|
137
152
|
extra_rdoc_files: []
|
138
153
|
files:
|
@@ -177,6 +192,7 @@ files:
|
|
177
192
|
- bin/retry.sh
|
178
193
|
- bin/robi
|
179
194
|
- bin/sphero.sh
|
195
|
+
- bin/sphero_linux_socat.sh
|
180
196
|
- examples/ardrone.rb
|
181
197
|
- examples/ardrone_nav.rb
|
182
198
|
- examples/ardrone_nav_video.rb
|
@@ -194,9 +210,12 @@ files:
|
|
194
210
|
- examples/hello_modular.rb
|
195
211
|
- examples/hello_multiple.rb
|
196
212
|
- examples/notifications.rb
|
213
|
+
- examples/roomba.rb
|
214
|
+
- examples/roomba_wiichuck.rb
|
197
215
|
- examples/sphero.rb
|
198
216
|
- examples/sphero2.rb
|
199
217
|
- examples/sphero_color.rb
|
218
|
+
- examples/sphero_cycle.rb
|
200
219
|
- examples/sphero_firmata.rb
|
201
220
|
- examples/sphero_messages.rb
|
202
221
|
- examples/sphero_multiple.rb
|
@@ -260,6 +279,7 @@ files:
|
|
260
279
|
- test/drivers/driver_test.rb
|
261
280
|
- test/drivers/led_test.rb
|
262
281
|
- test/drivers/motor_test.rb
|
282
|
+
- test/drivers/roomba_test.rb
|
263
283
|
- test/drivers/servo_test.rb
|
264
284
|
- test/drivers/sphero_test.rb
|
265
285
|
- test/drivers/wiichuck_test.rb
|