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
@@ -0,0 +1,147 @@
1
+ module Artoo
2
+ # The most important class used by Artoo is Robot. This represents the primary
3
+ # interface for interacting with a collection of physical computing capabilities.
4
+ #
5
+ # This module contains the class-level methods used by Artoo::Robot
6
+ class Robot
7
+ module ClassMethods
8
+ attr_accessor :device_types, :working_code,
9
+ :use_api, :api_host, :api_port
10
+
11
+ def connection_types
12
+ @@connection_types ||= []
13
+ end
14
+
15
+ # Connection to some hardware that has one or more devices via some specific protocol
16
+ # @example connection :arduino, :adaptor => :firmata, :port => '/dev/tty.usbmodemxxxxx'
17
+ # @param [String] name
18
+ # @param [Hash] params
19
+ def connection(name, params = {})
20
+ Celluloid::Logger.info "Registering connection '#{name}'..."
21
+ self.connection_types << {:name => name}.merge(params)
22
+ end
23
+
24
+ # Device that uses a connection to communicate
25
+ # @example device :collision_detect, :driver => :switch, :pin => 3
26
+ # @param [String] name
27
+ # @param [Hash] params
28
+ def device(name, params = {})
29
+ Celluloid::Logger.info "Registering device '#{name}'..."
30
+ self.device_types ||= []
31
+ self.device_types << {:name => name}.merge(params)
32
+ end
33
+
34
+ # The work that needs to be performed
35
+ # @example
36
+ # work do
37
+ # every(10.seconds) do
38
+ # puts "hello, world"
39
+ # end
40
+ # end
41
+ # @param [block] work
42
+ def work(&block)
43
+ Celluloid::Logger.info "Preparing work..."
44
+ self.working_code = block if block_given?
45
+ end
46
+
47
+ # Activate RESTful api
48
+ # Example:
49
+ # api :host => '127.0.0.1', :port => '1234'
50
+ def api(params = {})
51
+ Celluloid::Logger.info "Registering api..."
52
+ self.use_api = true
53
+ self.api_host = params[:host] || '127.0.0.1'
54
+ self.api_port = params[:port] || '4321'
55
+ end
56
+
57
+ # Work can be performed by either:
58
+ # an existing instance
59
+ # an array of existing instances
60
+ # or, a new instance can be created
61
+ # @param [Robot] robot
62
+ def work!(robot=nil)
63
+ return if is_running?
64
+ prepare_robots(robot)
65
+
66
+ unless cli?
67
+ begin
68
+ start_api
69
+ master.start_work
70
+ begin_working
71
+ rescue Interrupt
72
+ Celluloid::Logger.info 'Shutting down...'
73
+ master.stop_work if master
74
+ # Explicitly exit so busy Processor threads can't block
75
+ # process shutdown... taken from Sidekiq, thanks!
76
+ exit(0)
77
+ end
78
+ end
79
+ end
80
+
81
+ # Prepare master robots for work
82
+ def prepare_robots(robot=nil)
83
+ if robot.respond_to?(:work)
84
+ robots = [robot]
85
+ elsif robot.kind_of?(Array)
86
+ robots = robot
87
+ else
88
+ robots = [self.new]
89
+ end
90
+
91
+ Celluloid::Actor[:master] = Master.new(robots)
92
+ end
93
+
94
+ def begin_working
95
+ self_read, self_write = IO.pipe
96
+ setup_interrupt(self_write)
97
+ handle_signals(self_read)
98
+ end
99
+
100
+ def setup_interrupt(self_write)
101
+ Signal.trap("INT") do
102
+ self_write.puts("INT")
103
+ end
104
+ end
105
+
106
+ def handle_signals(self_read)
107
+ while readable_io = IO.select([self_read])
108
+ signal = readable_io.first[0].gets.strip
109
+ raise Interrupt
110
+ end
111
+ end
112
+
113
+ def start_api
114
+ Celluloid::Actor[:api] = Api.new(self.api_host, self.api_port) if self.use_api
115
+ end
116
+
117
+ # Master actor
118
+ def master
119
+ Celluloid::Actor[:master]
120
+ end
121
+
122
+ # @return [Boolean] True if test env
123
+ def test?
124
+ ENV["ARTOO_TEST"] == 'true'
125
+ end
126
+
127
+ # @return [Boolean] True if cli env
128
+ def cli?
129
+ ENV["ARTOO_CLI"] == 'true'
130
+ end
131
+
132
+ # @return [Boolean] True if it's running
133
+ def is_running?
134
+ @@running ||= false
135
+ @@running == true
136
+ end
137
+
138
+ def running!
139
+ @@running = true
140
+ end
141
+
142
+ def stopped!
143
+ @@running = false
144
+ end
145
+ end
146
+ end
147
+ end
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.5.0"
3
+ VERSION = "1.0.0.pre"
4
4
  end
5
5
  end
@@ -64,12 +64,12 @@ describe Artoo::Robot do
64
64
  MultiJson.load(@robot.as_json, :symbolize_keys => true)[:name].must_equal "testme"
65
65
  end
66
66
 
67
- describe 'work' do
67
+ describe 'work!' do
68
68
  before do
69
- TestRobot.stubs(:sleep)
69
+ TestRobot.stubs(:begin_working)
70
70
  @master = mock('master')
71
- TestRobot.stubs(:master).returns(@master)
72
71
  @master.expects(:start_work)
72
+ TestRobot.stubs(:master).returns(@master)
73
73
  end
74
74
 
75
75
  it 'Artoo::Robot.work! with single object' do
@@ -1,7 +1,6 @@
1
- gem 'minitest'
2
1
  require 'minitest/autorun'
3
2
  require 'mocha/setup'
4
3
 
5
4
  require 'artoo/robot'
6
5
 
7
- Celluloid.logger = nil
6
+ Celluloid.logger = nil
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.5.0
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron Evans
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-05-16 00:00:00.000000000 Z
15
+ date: 2013-05-24 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: celluloid
@@ -146,15 +146,13 @@ email:
146
146
  executables:
147
147
  - retry.sh
148
148
  - robi
149
- - sphero.sh
150
- - sphero_linux_bind.sh
151
- - sphero_linux_socat.sh
152
149
  extensions: []
153
150
  extra_rdoc_files: []
154
151
  files:
155
152
  - .gitignore
156
153
  - .travis.yml
157
154
  - .yardopts
155
+ - CONTRIBUTORS.md
158
156
  - Gemfile
159
157
  - Gemfile.lock
160
158
  - Guardfile
@@ -193,9 +191,6 @@ files:
193
191
  - artoo.gemspec
194
192
  - bin/retry.sh
195
193
  - bin/robi
196
- - bin/sphero.sh
197
- - bin/sphero_linux_bind.sh
198
- - bin/sphero_linux_socat.sh
199
194
  - examples/ardrone.rb
200
195
  - examples/ardrone_nav.rb
201
196
  - examples/ardrone_nav_video.rb
@@ -217,7 +212,6 @@ files:
217
212
  - examples/roomba.rb
218
213
  - examples/roomba_wiichuck.rb
219
214
  - examples/sphero.rb
220
- - examples/sphero2.rb
221
215
  - examples/sphero_color.rb
222
216
  - examples/sphero_cycle.rb
223
217
  - examples/sphero_firmata.rb
@@ -228,13 +222,8 @@ files:
228
222
  - examples/wiiclassic.rb
229
223
  - lib/artoo.rb
230
224
  - lib/artoo/adaptors/adaptor.rb
231
- - lib/artoo/adaptors/ardrone.rb
232
- - lib/artoo/adaptors/ardrone_navigation.rb
233
- - lib/artoo/adaptors/ardrone_video.rb
234
- - lib/artoo/adaptors/firmata.rb
235
225
  - lib/artoo/adaptors/loopback.rb
236
- - lib/artoo/adaptors/roomba.rb
237
- - lib/artoo/adaptors/sphero.rb
226
+ - lib/artoo/adaptors/test.rb
238
227
  - lib/artoo/api.rb
239
228
  - lib/artoo/api_route_helpers.rb
240
229
  - lib/artoo/basic.rb
@@ -242,22 +231,12 @@ files:
242
231
  - lib/artoo/delegator.rb
243
232
  - lib/artoo/device.rb
244
233
  - lib/artoo/device_event_client.rb
245
- - lib/artoo/drivers/ardrone.rb
246
- - lib/artoo/drivers/ardrone_navigation.rb
247
- - lib/artoo/drivers/ardrone_video.rb
248
- - lib/artoo/drivers/button.rb
234
+ - lib/artoo/drivers/counter.rb
249
235
  - lib/artoo/drivers/driver.rb
250
- - lib/artoo/drivers/led.rb
251
- - lib/artoo/drivers/motor.rb
252
236
  - lib/artoo/drivers/passthru.rb
253
237
  - lib/artoo/drivers/pinger.rb
254
- - lib/artoo/drivers/pinger2.rb
255
- - lib/artoo/drivers/roomba.rb
256
- - lib/artoo/drivers/servo.rb
257
- - lib/artoo/drivers/sphero.rb
258
- - lib/artoo/drivers/wiichuck.rb
259
- - lib/artoo/drivers/wiiclassic.rb
260
- - lib/artoo/drivers/wiidriver.rb
238
+ - lib/artoo/drivers/random.rb
239
+ - lib/artoo/drivers/test.rb
261
240
  - lib/artoo/events.rb
262
241
  - lib/artoo/ext/actor.rb
263
242
  - lib/artoo/ext/timers.rb
@@ -265,30 +244,17 @@ files:
265
244
  - lib/artoo/master.rb
266
245
  - lib/artoo/port.rb
267
246
  - lib/artoo/robot.rb
247
+ - lib/artoo/robot_class_methods.rb
268
248
  - lib/artoo/utility.rb
269
249
  - lib/artoo/version.rb
270
250
  - test/adaptors/adaptor_test.rb
271
- - test/adaptors/ardrone_test.rb
272
- - test/adaptors/firmata_test.rb
273
251
  - test/adaptors/loopback_test.rb
274
- - test/adaptors/sphero_test.rb
275
252
  - test/api_test.rb
276
253
  - test/artoo_test.rb
277
254
  - test/connection_test.rb
278
255
  - test/delegator_test.rb
279
256
  - test/device_test.rb
280
- - test/drivers/ardrone_navigation_test.rb
281
- - test/drivers/ardrone_test.rb
282
- - test/drivers/ardrone_video_test.rb
283
257
  - test/drivers/driver_test.rb
284
- - test/drivers/led_test.rb
285
- - test/drivers/motor_test.rb
286
- - test/drivers/roomba_test.rb
287
- - test/drivers/servo_test.rb
288
- - test/drivers/sphero_test.rb
289
- - test/drivers/wiichuck_test.rb
290
- - test/drivers/wiiclassic_test.rb
291
- - test/drivers/wiidriver_test.rb
292
258
  - test/master_test.rb
293
259
  - test/port_test.rb
294
260
  - test/robot_test.rb
@@ -309,9 +275,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
309
275
  version: '0'
310
276
  required_rubygems_version: !ruby/object:Gem::Requirement
311
277
  requirements:
312
- - - '>='
278
+ - - '>'
313
279
  - !ruby/object:Gem::Version
314
- version: '0'
280
+ version: 1.3.1
315
281
  requirements: []
316
282
  rubyforge_project: artoo
317
283
  rubygems_version: 2.0.3
@@ -1,8 +0,0 @@
1
- #!/bin/bash
2
-
3
- NEXT_WAIT_TIME=0
4
- COMMAND="socat PIPE:/dev/tty.Sphero-$1-RN-SPP,nonblock TCP-LISTEN:$2,fork"
5
- until $COMMAND || [ $NEXT_WAIT_TIME -eq 4 ]; do
6
- echo "retry..."
7
- sleep $(( NEXT_WAIT_TIME++ ))
8
- done
@@ -1,25 +0,0 @@
1
- #!/bin/bash
2
- #
3
- # This will create a sphero connection bound to /dev/Sphero-XXX
4
- #
5
- # Requires sudo or ran as root
6
- #
7
- # $1 = unbound /dev/rfcommXX
8
- # $2 = sphero hardware address from hcitool scan
9
- # $3 = sphero three letter color code
10
- #
11
- # Optional parameter
12
- # $4 = bluetooth radio hcix
13
- #
14
- # Example
15
- #
16
- # sudo ./sphero_linux_bind.sh 1 00:06:66:4A:43:23 PYG hci1
17
- #
18
- #
19
- if [ -z "$4" ]; then
20
- addr="hci0"
21
- else
22
- addr=$4
23
- fi
24
- rfcomm -i $addr bind /dev/rfcomm$1 $2 1
25
- ln -s /dev/rfcomm$1 /dev/Sphero-$3
@@ -1,8 +0,0 @@
1
- #!/bin/bash
2
-
3
- NEXT_WAIT_TIME=0
4
- COMMAND="socat FILE:/dev/$2,nonblock,raw,b115200,echo=0 TCP-LISTEN:$1,fork"
5
- until $COMMAND || [ $NEXT_WAIT_TIME -eq 4 ]; do
6
- echo "retry..."
7
- sleep $(( NEXT_WAIT_TIME++ ))
8
- done
@@ -1,26 +0,0 @@
1
- require 'artoo/robot'
2
-
3
- class DoubleSpheroRobot < Artoo::Robot
4
- connection :sphero, :adaptor => :sphero
5
- device :sphero, :driver => :sphero
6
-
7
- work do
8
- @count = 1
9
- every(3.seconds) do
10
- sphero.set_color(@count % 2 == 0 ? :green : :blue)
11
- @count += 1
12
- sphero.roll 90, rand(360)
13
- end
14
- end
15
- end
16
-
17
- SPHEROS = {"127.0.0.1:4560" => "/dev/tty.Sphero-BRG-RN-SPP",
18
- "127.0.0.1:4561" => "/dev/tty.Sphero-YBW-RN-SPP"}
19
- robots = []
20
- SPHEROS.each_key {|p|
21
- robots << DoubleSpheroRobot.new(:connections =>
22
- {:sphero =>
23
- {:port => p}})
24
- }
25
-
26
- DoubleSpheroRobot.work!(robots)
@@ -1,41 +0,0 @@
1
- require 'artoo/adaptors/adaptor'
2
-
3
- module Artoo
4
- module Adaptors
5
- # This class connects to a ARDrone 2.0
6
- # @see http://rubydoc.info/gems/hybridgroup-argus/0.2.0/Argus/Drone Argus Drone Documentation
7
- class Ardrone < Adaptor
8
- finalizer :finalize
9
- attr_reader :ardrone
10
-
11
- # Finalizes connection with ARDrone by landing and stopping the device
12
- def finalize
13
- if connected?
14
- ardrone.land
15
- ardrone.stop
16
- end
17
- end
18
-
19
- # Creates Argus Drone connection with device
20
- # @return [Boolean]
21
- def connect
22
- require 'argus' unless defined?(::Argus)
23
- @ardrone = Argus::Drone.new(connect_to_udp, port.host, port.port)
24
- super
25
- end
26
-
27
- # Disconnects device by stopping it and ending connection
28
- # @return [Boolean]
29
- def disconnect
30
- ardrone.stop
31
- super
32
- end
33
-
34
- # Calls ardrone actions using method missing
35
- # @see https://github.com/hybridgroup/argus/blob/master/lib/argus/drone.rb hybridgroup-argus Drone
36
- def method_missing(method_name, *arguments, &block)
37
- ardrone.send(method_name, *arguments, &block)
38
- end
39
- end
40
- end
41
- end
@@ -1,33 +0,0 @@
1
- require 'artoo/adaptors/adaptor'
2
-
3
- module Artoo
4
- module Adaptors
5
- # Connect to a ARDrone 2.0 navigation data stream
6
- # @see http://rubydoc.info/gems/hybridgroup-argus/0.2.0/Argus/NavStreamer Argus NavStremer Documentation
7
- class ArdroneNavigation < Adaptor
8
- attr_reader :ardrone
9
-
10
- # Creates connection with Argus NavStreamer and starts ardrone device
11
- # @return [Boolean]
12
- def connect
13
- require 'argus' unless defined?(::Argus)
14
- @ardrone = Argus::NavStreamer.new(connect_to_udp, port.host, port.port.to_i)
15
- @ardrone.start
16
- super
17
- end
18
-
19
- # Closes connection with ardrone device
20
- # @return [Boolean]
21
- def disconnect
22
- ardrone.close
23
- super
24
- end
25
-
26
- # Calls ardrone actions using method missing
27
- # @see http://rubydoc.info/gems/hybridgroup-argus/0.2.0/Argus/Drone Argus Drone Documentation
28
- def method_missing(method_name, *arguments, &block)
29
- ardrone.send(method_name, *arguments, &block)
30
- end
31
- end
32
- end
33
- end