artoo 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/.yardopts +10 -0
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +10 -7
  6. data/README.md +2 -2
  7. data/api/assets/javascripts/artoo/controllers/robot.js.coffee +2 -1
  8. data/api/public/core.js +3 -1
  9. data/artoo.gemspec +0 -1
  10. data/lib/artoo/adaptors/adaptor.rb +27 -6
  11. data/lib/artoo/adaptors/ardrone.rb +10 -2
  12. data/lib/artoo/adaptors/ardrone_navigation.rb +9 -2
  13. data/lib/artoo/adaptors/ardrone_video.rb +13 -5
  14. data/lib/artoo/adaptors/firmata.rb +10 -2
  15. data/lib/artoo/adaptors/loopback.rb +2 -1
  16. data/lib/artoo/adaptors/roomba.rb +12 -4
  17. data/lib/artoo/adaptors/sphero.rb +15 -3
  18. data/lib/artoo/api.rb +48 -5
  19. data/lib/artoo/api_route_helpers.rb +22 -3
  20. data/lib/artoo/basic.rb +3 -7
  21. data/lib/artoo/connection.rb +25 -7
  22. data/lib/artoo/delegator.rb +6 -16
  23. data/lib/artoo/device.rb +39 -10
  24. data/lib/artoo/device_event_client.rb +6 -0
  25. data/lib/artoo/drivers/ardrone.rb +5 -1
  26. data/lib/artoo/drivers/ardrone_navigation.rb +5 -1
  27. data/lib/artoo/drivers/ardrone_video.rb +9 -4
  28. data/lib/artoo/drivers/button.rb +7 -1
  29. data/lib/artoo/drivers/driver.rb +44 -4
  30. data/lib/artoo/drivers/led.rb +12 -1
  31. data/lib/artoo/drivers/motor.rb +12 -1
  32. data/lib/artoo/drivers/pinger.rb +10 -1
  33. data/lib/artoo/drivers/pinger2.rb +10 -1
  34. data/lib/artoo/drivers/roomba.rb +65 -17
  35. data/lib/artoo/drivers/servo.rb +12 -2
  36. data/lib/artoo/drivers/sphero.rb +19 -5
  37. data/lib/artoo/drivers/wiichuck.rb +7 -1
  38. data/lib/artoo/drivers/wiiclassic.rb +14 -5
  39. data/lib/artoo/drivers/wiidriver.rb +4 -1
  40. data/lib/artoo/events.rb +11 -4
  41. data/lib/artoo/ext/actor.rb +1 -1
  42. data/lib/artoo/ext/timers.rb +1 -1
  43. data/lib/artoo/main.rb +2 -13
  44. data/lib/artoo/master.rb +20 -2
  45. data/lib/artoo/port.rb +8 -3
  46. data/lib/artoo/robot.rb +45 -17
  47. data/lib/artoo/utility.rb +53 -9
  48. data/lib/artoo/version.rb +1 -1
  49. data/test/drivers/driver_test.rb +15 -0
  50. data/test/drivers/led_test.rb +4 -0
  51. data/test/utility_test.rb +35 -18
  52. data/test/utility_test_cases.rb +56 -0
  53. metadata +5 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18102ca867dce3a87d0d7a37e9a3815b7b3be8a2
4
- data.tar.gz: 5410f7319fbee6fa07c76808e0cb766b7883cd84
3
+ metadata.gz: cca65df971ac15acb591d811d8664703046390a6
4
+ data.tar.gz: 78ce7b30d92c1ec9b111cfe23550e5067a8ea525
5
5
  SHA512:
6
- metadata.gz: 26e56150e35df75a79560888fa419f4e768b9e8634e7824f2c60e1df6bd2c7f3c136599f893547b23cb090ebab7c5f07c37665b0aca23353e10d1a13b8727a4e
7
- data.tar.gz: 3b22a157db5e7826021dc74872b7bab951e32c9c1e0204476e5809d7639347d2bc3ef37c64739ec6bc269b8ae46e5992aa26d43df3f471b9caa760c7253bbd4d
6
+ metadata.gz: 34a0ecc46495423973c52b345acb4fe7d99984c06bfc0b10b6741a35f4615caa4e89d5225b7119d3db504209e57a36245810f5052e61a5d21e9fe48cf5b00195
7
+ data.tar.gz: e2f70290fd6c9d2162a3bed8430f5741399f557c3c4b372c232313052da006e6e526f08c359afa80bf9a6d6a2e044e58967cbc6f81a54de519b8a46c3c5f0a7b
@@ -2,5 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 1.9.3
5
- #- jruby-19mode # JRuby in 1.9 mode commented until JRuby/Celluloid issues corrected
5
+ - jruby-19mode
6
6
  - rbx-19mode
@@ -0,0 +1,10 @@
1
+ -M github-markup
2
+
3
+ --no-private
4
+ --hide-void-return
5
+
6
+ --markup=markdown
7
+ --markup-provider=redcarpet
8
+
9
+ --exclude lib/artoo/ext
10
+ --plugin yard-sinatra
data/Gemfile CHANGED
@@ -18,3 +18,12 @@ gem 'guard'
18
18
  gem 'guard-livereload'
19
19
  gem 'guard-sprockets'
20
20
  gem 'guard-compass'
21
+
22
+ # For documentation
23
+ gem 'yard'
24
+ gem 'yard-sinatra'
25
+ gem 'redcarpet'
26
+
27
+ # For tests
28
+ gem 'minitest'
29
+ gem 'mocha'
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo (0.4.0)
5
- active_support (~> 3.0)
4
+ artoo (0.4.1)
6
5
  celluloid (~> 0.14.0)
7
6
  celluloid-io (~> 0.14.0)
8
7
  multi_json (~> 1.6)
@@ -13,9 +12,6 @@ PATH
13
12
  GEM
14
13
  remote: http://rubygems.org/
15
14
  specs:
16
- active_support (3.0.0)
17
- activesupport (= 3.0.0)
18
- activesupport (3.0.0)
19
15
  bootstrap-sass (2.2.2.0)
20
16
  sass (~> 3.2)
21
17
  celluloid (0.14.0)
@@ -90,6 +86,7 @@ GEM
90
86
  spoon (~> 0.0)
91
87
  rack (1.5.2)
92
88
  rake (10.0.4)
89
+ redcarpet (2.2.2)
93
90
  reel (0.4.0.pre)
94
91
  celluloid-io (>= 0.8.0)
95
92
  http (>= 0.2.0)
@@ -110,6 +107,9 @@ GEM
110
107
  timers (1.1.0)
111
108
  websocket_parser (0.1.2)
112
109
  http
110
+ yard (0.8.6.1)
111
+ yard-sinatra (1.0.0)
112
+ yard (~> 0.7)
113
113
 
114
114
  PLATFORMS
115
115
  java
@@ -127,7 +127,10 @@ DEPENDENCIES
127
127
  hybridgroup-argus
128
128
  hybridgroup-firmata
129
129
  hybridgroup-sphero
130
- minitest (~> 4.6)
131
- mocha (~> 0.13)
130
+ minitest
131
+ mocha
132
+ redcarpet
132
133
  sass
133
134
  sprockets
135
+ yard
136
+ yard-sinatra
data/README.md CHANGED
@@ -100,9 +100,9 @@ end
100
100
 
101
101
  Once the robot or group is working, you can view the main API page at the host and port specified.
102
102
 
103
- ## CLI:
103
+ ## Console:
104
104
 
105
- Artoo includes Robi, a Command Line Interface (CLI) based on Pry (http://pryrepl.org/) to allow you to interactively control your robot.
105
+ Artoo includes Robi, a console based on Pry (http://pryrepl.org/) to allow you to interactively debug and control your robot.
106
106
 
107
107
  ```
108
108
  robi ./examples/hello.rb
@@ -20,7 +20,8 @@ window.driversWithOutput = ["Pinger", "Pinger2", "ardrone_navigation", "wiiclass
20
20
 
21
21
  device = console: ->
22
22
  window.ws.close() if window.ws
23
- window.ws = new WebSocket("ws://localhost:4321/robots/" + $scope.robot.name + "/devices/" + $scope.deviceDetail.name + "/events")
23
+ wspath = "ws://" + location.host + "/robots/"
24
+ window.ws = new WebSocket(wspath + $scope.robot.name + "/devices/" + $scope.deviceDetail.name + "/events")
24
25
  $(".console code").empty()
25
26
  ws.onmessage = (evt)->
26
27
  $(".console code").prepend(evt.data + "\n")
@@ -241,10 +241,12 @@ ngChange:rd,required:dc,ngRequired:dc,ngValue:ud}).directive(lb).directive(ec);a
241
241
  };
242
242
  device = {
243
243
  console: function() {
244
+ var wspath;
244
245
  if (window.ws) {
245
246
  window.ws.close();
246
247
  }
247
- window.ws = new WebSocket("ws://localhost:4321/robots/" + $scope.robot.name + "/devices/" + $scope.deviceDetail.name + "/events");
248
+ wspath = "ws://" + location.host + "/robots/";
249
+ window.ws = new WebSocket(wspath + $scope.robot.name + "/devices/" + $scope.deviceDetail.name + "/events");
248
250
  $(".console code").empty();
249
251
  return ws.onmessage = function(evt) {
250
252
  return $(".console code").prepend(evt.data + "\n");
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency 'celluloid-io', '~> 0.14.0'
24
24
  s.add_runtime_dependency 'reel', '~> 0.4.pre'
25
25
  s.add_runtime_dependency 'multi_json', '~> 1.6'
26
- s.add_runtime_dependency 'active_support', '~> 3.0'
27
26
  s.add_runtime_dependency 'rake', '~> 10.0'
28
27
  s.add_runtime_dependency 'pry', '~> 0.9'
29
28
  s.add_development_dependency 'minitest', '~> 4.6'
@@ -1,39 +1,53 @@
1
1
  module Artoo
2
2
  module Adaptors
3
- # The Adaptor class is the base class used to
4
- # connect to a specific group of hardware devices. Examples
5
- # would be an Arduino, a Sphero, or an ARDrone.
3
+ # The Adaptor class is the base class used to connect to a specific group
4
+ # of hardware devices. Examples would be an Arduino, a Sphero, or an ARDrone.
6
5
  #
7
6
  # Derive a class from this class, in order to implement communication
8
7
  # with a new type of hardware device.
8
+ # @see https://github.com/celluloid/celluloid-io Celluloid::IO Documentation
9
9
  class Adaptor
10
10
  include Celluloid::IO
11
11
 
12
12
  attr_reader :parent, :port
13
13
 
14
+ # Initialize an adaptor
15
+ # @param params [hash]
16
+ # @option params [String] :parent
17
+ # @option params [String] :port
14
18
  def initialize(params={})
15
19
  @parent = params[:parent]
16
20
  @port = params[:port]
17
21
  @connected = false
18
22
  end
19
23
 
24
+ # Makes connected flag true
25
+ # @return [Boolean]
20
26
  def connect
21
27
  @connected = true
22
28
  end
23
29
 
30
+ # Makes connected flag false
31
+ # @return [Boolean]
24
32
  def disconnect
25
33
  @connected = false
26
34
  true
27
35
  end
28
36
 
37
+ # Makes connected flag true
38
+ # @return [Boolean] true unless connected
29
39
  def reconnect
30
40
  connect unless connected?
31
41
  end
32
42
 
43
+ # @return [Boolean] connected flag status
33
44
  def connected?
34
45
  @connected == true
35
46
  end
36
47
 
48
+ # Connects to configured port
49
+ # @return [TCPSocket] tcp socket of tcp port
50
+ # @return [String] port configured
37
51
  def connect_to
38
52
  if port.is_tcp?
39
53
  connect_to_tcp
@@ -42,15 +56,22 @@ module Artoo
42
56
  end
43
57
  end
44
58
 
59
+ # @return [TCPSocket] TCP socket connection
45
60
  def connect_to_tcp
46
61
  @socket ||= TCPSocket.new(port.host, port.port)
47
62
  end
48
-
63
+ # @return [UDPSocket] UDP socket connection
49
64
  def connect_to_udp
50
65
  @udp_socket ||= UDPSocket.new
51
66
  end
52
67
 
53
- def connect_to_serial(speed=57600, data_bits=8, stop_bits=1, parity=nil)
68
+ # Creates serial connection
69
+ # @param speed [int]
70
+ # @param data_bits [int]
71
+ # @param stop_bits [int]
72
+ # @param parity
73
+ # @return [SerialPort] new connection
74
+ def connect_to_serial(speed=57600, data_bits=8, stop_bits=1, parity=::SerialPort::NONE)
54
75
  require 'serialport'
55
76
  parity = ::SerialPort::NONE unless parity
56
77
  @sp = ::SerialPort.new(port.port, speed, data_bits, stop_bits, parity)
@@ -59,4 +80,4 @@ module Artoo
59
80
  end
60
81
  end
61
82
  end
62
- end
83
+ end
@@ -2,11 +2,13 @@ require 'artoo/adaptors/adaptor'
2
2
 
3
3
  module Artoo
4
4
  module Adaptors
5
- # Connect to a ARDrone 2.0 (http://ardrone2.parrot.com/)
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
6
7
  class Ardrone < Adaptor
7
8
  finalizer :finalize
8
9
  attr_reader :ardrone
9
10
 
11
+ # Finalizes connection with ARDrone by landing and stopping the device
10
12
  def finalize
11
13
  if connected?
12
14
  ardrone.land
@@ -14,20 +16,26 @@ module Artoo
14
16
  end
15
17
  end
16
18
 
19
+ # Creates Argus Drone connection with device
20
+ # @return [Boolean]
17
21
  def connect
18
22
  require 'argus' unless defined?(::Argus)
19
23
  @ardrone = Argus::Drone.new(connect_to_udp, port.host, port.port)
20
24
  super
21
25
  end
22
26
 
27
+ # Disconnects device by stopping it and ending connection
28
+ # @return [Boolean]
23
29
  def disconnect
24
30
  ardrone.stop
25
31
  super
26
32
  end
27
33
 
34
+ # Calls ardrone actions using method missing
35
+ # @see https://github.com/hybridgroup/argus/blob/master/lib/argus/drone.rb hybridgroup-argus Drone
28
36
  def method_missing(method_name, *arguments, &block)
29
37
  ardrone.send(method_name, *arguments, &block)
30
38
  end
31
39
  end
32
40
  end
33
- end
41
+ end
@@ -2,10 +2,13 @@ require 'artoo/adaptors/adaptor'
2
2
 
3
3
  module Artoo
4
4
  module Adaptors
5
- # Connect to a ARDrone 2.0 (http://ardrone2.parrot.com/) navigation data stream
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
6
7
  class ArdroneNavigation < Adaptor
7
8
  attr_reader :ardrone
8
9
 
10
+ # Creates connection with Argus NavStreamer and starts ardrone device
11
+ # @return [Boolean]
9
12
  def connect
10
13
  require 'argus' unless defined?(::Argus)
11
14
  @ardrone = Argus::NavStreamer.new(connect_to_udp, port.host, port.port.to_i)
@@ -13,14 +16,18 @@ module Artoo
13
16
  super
14
17
  end
15
18
 
19
+ # Closes connection with ardrone device
20
+ # @return [Boolean]
16
21
  def disconnect
17
22
  ardrone.close
18
23
  super
19
24
  end
20
25
 
26
+ # Calls ardrone actions using method missing
27
+ # @see http://rubydoc.info/gems/hybridgroup-argus/0.2.0/Argus/Drone Argus Drone Documentation
21
28
  def method_missing(method_name, *arguments, &block)
22
29
  ardrone.send(method_name, *arguments, &block)
23
30
  end
24
31
  end
25
32
  end
26
- end
33
+ end
@@ -2,26 +2,34 @@ require 'artoo/adaptors/adaptor'
2
2
 
3
3
  module Artoo
4
4
  module Adaptors
5
- # Connect to a ARDrone 2.0 (http://ardrone2.parrot.com/) video data stream
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
6
8
  class ArdroneVideo < Adaptor
7
9
  attr_reader :ardrone, :video_parser
8
10
 
11
+ # Creates connection to Argus TCP Video Streamer and
12
+ # Argus PaVE Parser starting a stream with ardrone device
13
+ # @return [Boolean]
9
14
  def connect
10
15
  require 'argus' unless defined?(::Argus)
11
- @ardrone = Argus::TcpVideoStreamer.new(connect_to_tcp, port.host, port.port)
12
- @video_parser = Argus::PaVEParser.new(@ardrone)
13
- @ardrone.start_stream(connect_to_udp)
16
+ @ardrone = Argus::VideoStreamer.new(connect_to_tcp, port.host, port.port)
17
+ @ardrone.start(connect_to_udp)
14
18
  super
15
19
  end
16
20
 
21
+ # Closes ardrone connection
22
+ # @return [Boolean]
17
23
  def disconnect
18
24
  ardrone.close
19
25
  super
20
26
  end
21
27
 
28
+ # Calls ardrone actions using method missing
29
+ # @see https://github.com/hybridgroup/argus/blob/master/lib/argus/drone.rb hybridgroup-argus Drone
22
30
  def method_missing(method_name, *arguments, &block)
23
31
  ardrone.send(method_name, *arguments, &block)
24
32
  end
25
33
  end
26
34
  end
27
- end
35
+ end
@@ -2,9 +2,13 @@ require 'artoo/adaptors/adaptor'
2
2
 
3
3
  module Artoo
4
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
5
7
  class Firmata < Adaptor
6
8
  attr_reader :firmata
7
9
 
10
+ # Creates connection with firmata board
11
+ # @return [Boolean]
8
12
  def connect
9
13
  require 'firmata' unless defined?(::Firmata)
10
14
  @firmata = ::Firmata::Board.new(connect_to)
@@ -13,13 +17,17 @@ module Artoo
13
17
  return true
14
18
  end
15
19
 
20
+ # Closes connection with firmata board
21
+ # @return [Boolean]
16
22
  def disconnect
17
23
  super
18
- end
24
+ end
19
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
20
28
  def method_missing(method_name, *arguments, &block)
21
29
  firmata.send(method_name, *arguments, &block)
22
30
  end
23
- end
31
+ end
24
32
  end
25
33
  end
@@ -2,7 +2,8 @@ require 'artoo/adaptors/adaptor'
2
2
 
3
3
  module Artoo
4
4
  module Adaptors
5
+ # This class is used for testing
5
6
  class Loopback < Adaptor
6
7
  end
7
8
  end
8
- end
9
+ end
@@ -2,17 +2,22 @@ require 'artoo/adaptors/adaptor'
2
2
 
3
3
  module Artoo
4
4
  module Adaptors
5
- # Connect to a Roomba (http://www.irobot.com/en/us/robots/Educators/Create.aspx)
5
+ # Connect to a Roomba
6
+ # @see http://www.irobot.com/en/us/robots/Educators/Create.aspx Roomba information
6
7
  class Roomba < Adaptor
7
8
  finalizer :finalize
8
9
  attr_reader :sp
9
10
 
11
+ # Closes connection if already connected
12
+ # @return [Boolean]
10
13
  def finalize
11
14
  if connected?
12
15
  @sp.close
13
16
  end
14
17
  end
15
18
 
19
+ # Creates serial or tcp connection
20
+ # @return [Boolean]
16
21
  def connect
17
22
  if port.is_serial?
18
23
  @sp = connect_to_serial
@@ -23,7 +28,8 @@ module Artoo
23
28
  end
24
29
  super
25
30
  end
26
-
31
+
32
+ # Send bytes to device
27
33
  def send_bytes(bytes)
28
34
  bytes = [bytes] unless bytes.respond_to?(:map)
29
35
  bytes.map!(&:chr)
@@ -33,11 +39,13 @@ module Artoo
33
39
  Logger.debug "returned: #{res.inspect}"
34
40
  end
35
41
 
42
+ # Closes connection to device
43
+ # @return [Boolean]
36
44
  def disconnect
37
45
  @sp.close
38
46
  super
39
47
  end
40
-
48
+
41
49
  end
42
50
  end
43
- end
51
+ end
@@ -2,18 +2,26 @@ require 'artoo/adaptors/adaptor'
2
2
 
3
3
  module Artoo
4
4
  module Adaptors
5
- # Connect to a Sphero (http://gosphero.com)
5
+ # Connect to a Sphero device
6
+ # @see http://gosphero.com Sphero information
7
+ # @see http://rubydoc.info/gems/hybridgroup-sphero HybridGroup Sphero Documentation
6
8
  class Sphero < Adaptor
7
9
  finalizer :finalize
8
- RETRY_COUNT = 5
9
10
  attr_reader :sphero
10
11
 
12
+ # Number of retries when connecting
13
+ RETRY_COUNT = 5
14
+
15
+ # Closes connection with device if connected
16
+ # @return [Boolean]
11
17
  def finalize
12
18
  if connected?
13
19
  sphero.close
14
20
  end
15
21
  end
16
22
 
23
+ # Creates a connection with Sphero object with retries
24
+ # @return [Boolean]
17
25
  def connect
18
26
  @retries_left = RETRY_COUNT
19
27
  require 'sphero' unless defined?(::Sphero)
@@ -33,14 +41,18 @@ module Artoo
33
41
  end
34
42
  end
35
43
 
44
+ # Closes connection with device
45
+ # @return [Boolean]
36
46
  def disconnect
37
47
  sphero.close
38
48
  super
39
49
  end
40
50
 
51
+ # Uses method missing to call sphero actions
52
+ # @see http://rubydoc.info/gems/hybridgroup-sphero/Sphero Sphero documentation
41
53
  def method_missing(method_name, *arguments, &block)
42
54
  sphero.send(method_name, *arguments, &block)
43
55
  end
44
56
  end
45
57
  end
46
- end
58
+ end