artoo 1.4.1 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57e4bd711ba505875140f81f9b2d469bad032770
4
- data.tar.gz: 45850c141125fe86cb4ac9eb5a6af5b958748e89
3
+ metadata.gz: a0431129b36962326980dd7276fd60800b83920a
4
+ data.tar.gz: aff806d943afefb360b34d6f4cb8eff004c432a7
5
5
  SHA512:
6
- metadata.gz: 696898f26fb1138d0cfbdef2e9975003c19024cc812b7e35e1cb2561f1abc8f1dd5515f56ad3917ce3ba3cbe46477971cb6b31e91b3af9ac0092ea8decf45f18
7
- data.tar.gz: 666ee74c17749ba33b3a124703cbbc459954b28c8a7608b9bc826b972a74c723cda49343e2837fe1a8f56b8bdaddedfdfc8f7001f4b9a2e2640e03c0f9632866
6
+ metadata.gz: ce7fca914d9a2ec16eb3ff84d8c933b4860d585d86574e7019e3fc9560b658790ce286a49ebb9a292c58063b6a5007707dc411e30ab1b15b9660c352a6d03b9c
7
+ data.tar.gz: aab84f30e836e8cd97ae429163374098680b38bb5424adef4687142e1caba8239ac9e359c93d7a7a0d214904e690c196bc61e2e3ac6de302f04ee5ec26e67668
data/.travis.yml CHANGED
@@ -7,3 +7,6 @@ rvm:
7
7
  matrix:
8
8
  allow_failures:
9
9
  - rvm: jruby-1.7.4
10
+ branches:
11
+ except:
12
+ - artoo.io
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo (1.4.1)
4
+ artoo (1.5.0)
5
5
  celluloid (~> 0.15.0)
6
6
  celluloid-io (~> 0.15.0)
7
7
  multi_json (~> 1.6)
@@ -15,7 +15,7 @@ GEM
15
15
  specs:
16
16
  bootstrap-sass (2.3.2.2)
17
17
  sass (~> 3.2)
18
- celluloid (0.15.1)
18
+ celluloid (0.15.2)
19
19
  timers (~> 1.1.0)
20
20
  celluloid-io (0.15.0)
21
21
  celluloid (>= 0.15.0)
@@ -60,6 +60,7 @@ GEM
60
60
  http (0.5.0)
61
61
  http_parser.rb
62
62
  http_parser.rb (0.6.0.beta.2)
63
+ http_parser.rb (0.6.0.beta.2-java)
63
64
  json (1.7.7)
64
65
  json (1.7.7-java)
65
66
  kramdown (1.2.0)
@@ -74,6 +75,7 @@ GEM
74
75
  metaclass (~> 0.0.1)
75
76
  multi_json (1.8.0)
76
77
  nio4r (0.5.0)
78
+ nio4r (0.5.0-java)
77
79
  pry (0.9.12.2)
78
80
  coderay (~> 1.0.5)
79
81
  method_source (~> 0.8)
data/README.md CHANGED
@@ -6,6 +6,8 @@ Artoo is a micro-framework for robotics using Ruby.
6
6
 
7
7
  Artoo provides a simple, yet powerful Domain-Specific Language (DSL) for robotics and physical computing.
8
8
 
9
+ Want to use JavaScript on robots? Check out our sister project Cylon.js (http://cylonjs.com)
10
+
9
11
  [![Code Climate](https://codeclimate.com/github/hybridgroup/artoo.png)](https://codeclimate.com/github/hybridgroup/artoo) [![Build Status](https://travis-ci.org/hybridgroup/artoo.png?branch=master)](https://travis-ci.org/hybridgroup/artoo)
10
12
 
11
13
  ## Examples:
@@ -96,8 +98,9 @@ Artoo has a extensible system for connecting to hardware devices. The following
96
98
  - [BeagleBone](http://beagleboard.org/) <=> [Adaptor](https://github.com/hybridgroup/artoo-beaglebone)
97
99
  - [Crazyflie](http://www.bitcraze.se/) <=> [Adaptor](https://github.com/hybridgroup/artoo-crazyflie)
98
100
  - [Digispark](http://digistump.com/products/1) <=> [Adaptor](https://github.com/hybridgroup/artoo-digispark)
99
- - [Leap Motion](https://www.leapmotion.com/) <=> [Adaptor](https://github.com/hybridgroup/artoo-leapmotion)
100
101
  - [Joystick](http://www.libsdl.org/) <=> [Adaptor](https://github.com/hybridgroup/artoo-joystick)
102
+ - [Leap Motion](https://www.leapmotion.com/) <=> [Adaptor](https://github.com/hybridgroup/artoo-leapmotion)
103
+ - [OpenCV](http://opencv.org/) <=> [Adaptor](https://github.com/hybridgroup/artoo-opencv)
101
104
  - [Pebble](http://getpebble.com/) <=> [Adaptor](https://github.com/hybridgroup/artoo-pebble)
102
105
  - [Raspberry Pi](http://www.raspberrypi.org/) <=> [Adaptor](https://github.com/hybridgroup/artoo-raspi)
103
106
  - [Roomba](http://www.irobot.com/us/robots/Educators/Create.aspx) <=> [Adaptor](https://github.com/hybridgroup/artoo-roomba)
@@ -168,31 +171,44 @@ Once the robot or group is working, you can view the main API page at the host a
168
171
 
169
172
  Artoo makes it easy to do Test Driven Development (TDD) of your robotic devices using your favorite Ruby test and mocking frameworks.
170
173
 
171
- Here is an example that uses Minitest and Mocha:
174
+ Here is an example that uses Minitest, Mocha, and Timecop:
172
175
 
173
176
  ```ruby
177
+ require './test_helper'
178
+ require './test_robot'
179
+
174
180
  describe 'sphero' do
175
181
  let(:robot) { Artoo::MainRobot.new }
176
-
177
- it 'has work to do every 3 seconds' do
182
+ let (:start) { Time.now }
183
+
184
+ before :each do
185
+ Timecop.travel(start)
178
186
  robot.work
179
-
180
- robot.has_work?(:every, 3.seconds).wont_be_nil
181
187
  end
182
-
183
- it 'must roll every 3 seconds' do
184
- robot.sphero.expects(:roll).twice
185
-
186
- robot.work
187
- sleep 6.1
188
+
189
+ after :each do
190
+ Timecop.return
188
191
  end
189
-
192
+
193
+ it 'has work to do every 3 seconds' do
194
+ robot.has_work?(:every, 3.seconds).wont_be_nil
195
+ end
196
+
190
197
  it 'receives collision event' do
191
198
  robot.expects(:contact)
192
-
193
- robot.work
194
199
  robot.sphero.publish("collision", "clunk")
195
- sleep 0.1
200
+ sleep 0.05
201
+ end
202
+
203
+ it 'must roll every 3 seconds' do
204
+ Timecop.travel(start + 3.seconds) do
205
+ robot.sphero.expects(:roll)
206
+ sleep 0.05
207
+ end
208
+ Timecop.travel(start + 6.seconds) do
209
+ robot.sphero.expects(:roll)
210
+ sleep 0.05
211
+ end
196
212
  end
197
213
  end
198
214
  ```
@@ -214,12 +230,13 @@ work do
214
230
  on sphero, :collision => :contact
215
231
 
216
232
  every(3.seconds) do
217
- puts "Rolling..."
218
233
  sphero.roll 90, rand(360)
219
234
  end
220
235
  end
221
236
  ```
222
237
 
238
+ The repo with full example of using Artoo for test driven robotics is located at [https://github.com/hybridgroup/artoo-test-example](https://github.com/hybridgroup/artoo-test-example)
239
+
223
240
  ## CLI
224
241
 
225
242
  Artoo has a Command Line Interface (CLI) so you can access important features right from the command line.
@@ -305,6 +322,8 @@ Done!
305
322
 
306
323
  Check out our [documentation](http://artoo.io/documentation/) for lots of information about how to use Artoo.
307
324
 
325
+ If you want to help us with some documentation on the site, you can go to [artoo.io branch](https://github.com/hybridgroup/artoo/tree/artoo.io) and then, follow the instructions.
326
+
308
327
  ## IRC
309
328
 
310
329
  Need more help? Just want to say "Hello"? Come visit us on IRC freenode #artoo
@@ -1,9 +1,20 @@
1
- require 'artoo'
1
+ require 'artoo/robot'
2
2
 
3
- connection :loop
4
- device :passthru
5
- api :host => '127.0.0.1', :port => '4321'
3
+ class HelloRobot < Artoo::Robot
4
+ connection :loop
5
+ device :passthru
6
6
 
7
- work do
8
- puts "Hello from the API running at #{api_host}:#{api_port}..."
9
- end
7
+ api :host => '127.0.0.1', :port => '4321'
8
+
9
+ work do
10
+ puts "Hello from the API running at #{api_host}:#{api_port}..."
11
+ end
12
+
13
+ def hello name
14
+ "hi #{name}!"
15
+ end
16
+ end
17
+
18
+ robots = []
19
+ robots << HelloRobot.new(:name => "hello", :commands => [:hello])
20
+ HelloRobot.work!(robots)
data/lib/artoo/api/api.rb CHANGED
@@ -36,6 +36,19 @@ module Artoo
36
36
  master.robot(@params['robotid']).as_json
37
37
  end
38
38
 
39
+ # Retrieve robot commands
40
+ # @return [JSON] commands
41
+ get '/robots/:robotid/commands' do
42
+ MultiJson.dump(master.robot(@params['robotid']).commands)
43
+ end
44
+
45
+ # Execute robot command
46
+ # @return [JSON] command
47
+ any '/robots/:robotid/commands/:commandid' do
48
+ result = master.robot(@params['robotid']).command(@params['commandid'], *command_params)
49
+ return MultiJson.dump({'result' => result})
50
+ end
51
+
39
52
  # Retrieve robot devices
40
53
  # @return [JSON] devices
41
54
  get '/robots/:robotid/devices' do
@@ -56,7 +69,7 @@ module Artoo
56
69
 
57
70
  # Execute robot command
58
71
  # @return [JSON] command
59
- post '/robots/:robotid/devices/:deviceid/commands/:commandid' do
72
+ any '/robots/:robotid/devices/:deviceid/commands/:commandid' do
60
73
  result = device(@params['robotid'], @params['deviceid']).command(@params['commandid'], *command_params)
61
74
  return MultiJson.dump({'result' => result})
62
75
  end
@@ -91,11 +104,17 @@ module Artoo
91
104
  end
92
105
 
93
106
  def command_params
94
- data = MultiJson.load(@req.body, :symbolize_keys => true)
95
- if data && params = data[:params]
96
- params.size == 1 ? params.first : params
97
- else
98
- nil
107
+ if @req.body.to_s != ""
108
+ data = MultiJson.load(@req.body.to_s, :symbolize_keys => true)
109
+ if data
110
+ params = []
111
+ data.each {|key, value|
112
+ params << value
113
+ }
114
+ params
115
+ else
116
+ nil
117
+ end
99
118
  end
100
119
  end
101
120
  end
@@ -124,6 +124,12 @@ module Artoo
124
124
  def put(path, &block)
125
125
  route 'PUT', path, &block
126
126
  end
127
+
128
+ # Route function for put
129
+ def any(path, &block)
130
+ route 'GET', path, &block
131
+ route 'POST', path, &block
132
+ end
127
133
  end
128
134
 
129
135
  module InstanceMethods
@@ -0,0 +1,41 @@
1
+ # Monkeypatches for Timers & Timer classes used by Celluloid
2
+ class Timers
3
+ def initialize
4
+ @timers = SortedSet.new
5
+ @paused_timers = SortedSet.new
6
+ end
7
+
8
+ def pause(timer = nil)
9
+ return pause_all if timer.nil?
10
+ raise TypeError, "not a Timers::Timer" unless timer.is_a? Timers::Timer
11
+ @timers.delete timer
12
+ @paused_timers.add timer
13
+ end
14
+
15
+ def pause_all
16
+ @timers.each {|timer| timer.pause}
17
+ end
18
+
19
+ def continue(timer = nil)
20
+ return continue_all if timer.nil?
21
+ raise TypeError, "not a Timers::Timer" unless timer.is_a? Timers::Timer
22
+ @paused_timers.delete timer
23
+ @timers.add timer
24
+ end
25
+
26
+ def continue_all
27
+ @paused_timers.each {|timer| timer.continue}
28
+ end
29
+
30
+ class Timer
31
+ # Pause this timer
32
+ def pause
33
+ @timers.pause self
34
+ end
35
+
36
+ # Continue this timer
37
+ def continue
38
+ @timers.continue self
39
+ end
40
+ end
41
+ end
data/lib/artoo/robot.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'celluloid/autostart'
2
2
  require 'celluloid/io'
3
3
  require 'multi_json'
4
-
4
+ require 'artoo/ext/timers'
5
5
  require 'artoo/ext/actor'
6
+
6
7
  require 'artoo/robot_class_methods'
7
8
  require 'artoo/basic'
8
9
  require 'artoo/connection'
@@ -29,7 +30,7 @@ module Artoo
29
30
  include Artoo::Utility
30
31
  include Artoo::Events
31
32
 
32
- attr_reader :connections, :devices, :name
33
+ attr_reader :connections, :devices, :name, :commands
33
34
 
34
35
  exclusive :execute_startup
35
36
 
@@ -40,6 +41,7 @@ module Artoo
40
41
  # @option params [Collection] :devices
41
42
  def initialize(params={})
42
43
  @name = params[:name] || "Robot #{random_string}"
44
+ @commands = params[:commands] || []
43
45
  initialize_connections(params[:connections] || {})
44
46
  initialize_devices(params[:devices] || {})
45
47
  end
@@ -117,7 +119,8 @@ module Artoo
117
119
  {
118
120
  :name => name,
119
121
  :connections => connections.each_value.collect {|c|c.to_hash},
120
- :devices => devices.each_value.collect {|d|d.to_hash}
122
+ :devices => devices.each_value.collect {|d|d.to_hash},
123
+ :commands => commands
121
124
  }
122
125
  end
123
126
 
@@ -131,8 +134,31 @@ module Artoo
131
134
  "#<Robot #{object_id}>"
132
135
  end
133
136
 
137
+ def command(method_name, *arguments)
138
+ if known_command?(method_name)
139
+ if arguments.first
140
+ self.send(method_name, *arguments)
141
+ else
142
+ self.send(method_name)
143
+ end
144
+ else
145
+ "Unknown Command"
146
+ end
147
+ rescue Exception => e
148
+ Logger.error e.message
149
+ Logger.error e.backtrace.inspect
150
+ return nil
151
+ end
152
+
153
+ # @return [Boolean] True if command exists
154
+ def known_command?(method_name)
155
+ return commands.include?(method_name.intern)
156
+ end
157
+
158
+
134
159
  private
135
160
 
161
+
136
162
  def initialize_connections(params={})
137
163
  @connections = {}
138
164
  connection_types.each {|ct|
@@ -147,7 +173,8 @@ module Artoo
147
173
  @devices = {}
148
174
  device_types.each {|d|
149
175
  Logger.info "Initializing device #{d[:name].to_s}..."
150
- d = Device.new(d.merge(:parent => current_instance))
176
+ dp = params[d[:name]] || {}
177
+ d = Device.new(d.merge(dp).merge(:parent => current_instance))
151
178
  instance_eval("def #{d.name}; return devices[:#{d.name}]; end")
152
179
  @devices[d.name.intern] = d
153
180
  }
data/lib/artoo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  unless const_defined?('VERSION')
3
- VERSION = "1.4.1"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  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: 1.4.1
4
+ version: 1.5.0
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-10-18 00:00:00.000000000 Z
15
+ date: 2013-12-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: celluloid
@@ -226,6 +226,7 @@ files:
226
226
  - lib/artoo/exceptions.rb
227
227
  - lib/artoo/ext/actor.rb
228
228
  - lib/artoo/ext/numeric.rb
229
+ - lib/artoo/ext/timers.rb
229
230
  - lib/artoo/generators/adaptor.rb
230
231
  - lib/artoo/generators/adaptor/Gemfile.tt
231
232
  - lib/artoo/generators/adaptor/LICENSE