artoo-sphero 1.0.0.pre → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 494f759984c5ab3cbb7ae3f7554d9d93bc521645
4
- data.tar.gz: 12e3f9a754de59708bd43a56d72eed6d959b5576
3
+ metadata.gz: 86d8416d37cd8b1e93c4f9c4155dd717d508cef0
4
+ data.tar.gz: 015fa75025d9ea248c04ee0bcad0bd750ced3e78
5
5
  SHA512:
6
- metadata.gz: ecf4f66c889eccc2b4d90b3350514d4d5c6de44cc0a20cffef0014d94d434c17e1826ef7e153dc3f12e07fb10a2de8931e3b7593ff548fabae55506d5b865024
7
- data.tar.gz: 49f47a74d5a628b1a5fa3acf5f448f60b43a34f7fbedec6065e8d180c79755de941899a213a96ab04b0c1228ea55de12b41903f7518f037ca8f3badd4d37066b
6
+ metadata.gz: 95b0541d27757b3fa1501c8fa69745a9ec5725096986bff6162d3e2e7b2018d1d5b09c5a99a134a1e67f8a1b1dedb089a8439199d8412ff3634f10bd96ce4822
7
+ data.tar.gz: 4684e5c04a729159ade002566c8799b12627a756a13dfa7b54f9105cefc9de86f5d62f22288985c06d1f7cccce51d2d4e77e2b87145631f12961d5b51b3c18a6
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .rvmrc
2
2
  .rbx
3
+ pkg
data/Gemfile.lock CHANGED
@@ -1,24 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo-sphero (1.0.0.pre)
5
- artoo (~> 1.0.0.pre)
6
- hybridgroup-sphero (~> 1.3.0)
4
+ artoo-sphero (1.0.0.rc1)
5
+ artoo (~> 1.0.0.rc)
6
+ sphero (~> 1.4.1)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- artoo (1.0.0.pre)
12
- celluloid (~> 0.14.0)
13
- celluloid-io (~> 0.14.0)
11
+ artoo (1.0.0.rc2)
12
+ celluloid (~> 0.14.1)
13
+ celluloid-io (~> 0.14.1)
14
14
  multi_json (~> 1.6)
15
15
  pry (~> 0.9)
16
16
  rake (~> 10.0)
17
- reel (~> 0.4.pre)
18
- celluloid (0.14.0)
17
+ reel (~> 0.4.0.pre)
18
+ thor (~> 0.18.1)
19
+ celluloid (0.14.1)
19
20
  timers (>= 1.0.0)
20
- celluloid-io (0.14.0)
21
- celluloid (>= 0.13.0)
21
+ celluloid-io (0.14.1)
22
+ celluloid (>= 0.14.1)
22
23
  nio4r (>= 0.4.5)
23
24
  certified (0.1.1)
24
25
  coderay (1.0.9)
@@ -26,28 +27,29 @@ GEM
26
27
  certified
27
28
  http_parser.rb
28
29
  http_parser.rb (0.5.3)
29
- hybridgroup-sphero (1.3.0)
30
30
  metaclass (0.0.1)
31
31
  method_source (0.8.1)
32
- minitest (5.0.1)
32
+ minitest (5.0.6)
33
33
  minitest-happy (1.0.0)
34
34
  mocha (0.14.0)
35
35
  metaclass (~> 0.0.1)
36
- multi_json (1.7.3)
37
- nio4r (0.4.5)
36
+ multi_json (1.7.7)
37
+ nio4r (0.4.6)
38
38
  pry (0.9.12.2)
39
39
  coderay (~> 1.0.5)
40
40
  method_source (~> 0.8)
41
41
  slop (~> 3.4)
42
42
  rack (1.5.2)
43
- rake (10.0.4)
43
+ rake (10.1.0)
44
44
  reel (0.4.0.pre)
45
45
  celluloid-io (>= 0.8.0)
46
46
  http (>= 0.2.0)
47
47
  http_parser.rb (>= 0.5.3)
48
48
  rack (>= 1.4.0)
49
49
  websocket_parser (>= 0.1.2)
50
- slop (3.4.5)
50
+ slop (3.4.6)
51
+ sphero (1.4.1)
52
+ thor (0.18.1)
51
53
  timers (1.1.0)
52
54
  websocket_parser (0.1.4)
53
55
  http
data/README.md CHANGED
@@ -14,3 +14,76 @@ For more information abut Artoo, check out our repo at https://github.com/hybrid
14
14
  gem install artoo-sphero
15
15
  ```
16
16
 
17
+ ## Using
18
+
19
+ ```ruby
20
+ require 'artoo'
21
+
22
+ connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4567'
23
+ device :sphero, :driver => :sphero
24
+
25
+ work do
26
+ @rolling = false
27
+
28
+ every(3.seconds) do
29
+ puts "Rolling..."
30
+ sphero.roll 90, rand(360)
31
+ end
32
+ end
33
+ ```
34
+ ## Connecting to Sphero
35
+
36
+ ### OSX
37
+
38
+ The main steps are:
39
+ - Pair your computer and the Sphero
40
+ - Use a socket to serial connection to map a TCP socket to the local unix port
41
+ - Connect to the device via Artoo
42
+
43
+ First pair your computer and Sphero. You might be prompted for a passcode, but you do not need to enter it, sinec the Sphero does not check.
44
+
45
+ Once paired, use the `artoo connect scan` command to find out your connection info:
46
+
47
+ ```
48
+ $ artoo connect scan
49
+ ```
50
+
51
+ Now you are ready to connect to the Sphero using the socket, in this example port 4567:
52
+
53
+ ```
54
+ artoo connect socat 4567 Sphero-WRW
55
+ ```
56
+
57
+ ### Ubuntu
58
+
59
+ The main steps are:
60
+ - Pair your computer and the Sphero
61
+ - Map your device to a unix port
62
+ - Use a socket to serial connection to map a TCP socket to the local unix port
63
+ - Connect to the device via Artoo
64
+
65
+ First pair your computer and Sphero. You might be prompted for a passcode, but you do not need to enter it, sinec the Sphero does not check.
66
+
67
+ Once paired, use the `artoo connect scan` command to find out your connection info:
68
+
69
+ ```
70
+ $ artoo connect scan
71
+ Scanning ...
72
+ 00:06:66:4A:14:99 Sphero-WRW
73
+ ```
74
+
75
+ Next, you need to bind the Sphero to the system port. In the above example, /dev/Sphero-WRW. The easiest way to do this is to use the `artoo connect bind` command:
76
+
77
+ ```
78
+ artoo connect bind 00:06:66:4A:14:99 Sphero-WRW
79
+ ```
80
+
81
+ Now you are ready to connect to the Sphero using the socket, in this example port 4567:
82
+
83
+ ```
84
+ artoo connect socat 4567 Sphero-WRW
85
+ ```
86
+
87
+ ### Windows
88
+
89
+ Someone please fill in the blanks here...
data/artoo-sphero.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "artoo-sphero"
7
7
  s.version = Artoo::Sphero::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Ron Evans", "Adrian Zankich"]
9
+ s.authors = ["Ron Evans", "Adrian Zankich", "Mike Ford"]
10
10
  s.email = ["artoo@hybridgroup.com"]
11
11
  s.homepage = "https://github.com/hybridgroup/artoo-sphero"
12
12
  s.summary = %q{Artoo adaptor and driver for Sphero robot}
@@ -19,8 +19,8 @@ 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 'artoo', '~> 1.0.0.pre'
23
- s.add_runtime_dependency 'hybridgroup-sphero', '~> 1.3.0'
22
+ s.add_runtime_dependency 'artoo', '~> 1.0.0.rc'
23
+ s.add_runtime_dependency 'sphero', '~> 1.4.1'
24
24
  s.add_development_dependency 'minitest', '~> 5.0'
25
25
  s.add_development_dependency 'minitest-happy'
26
26
  s.add_development_dependency 'mocha', '~> 0.14.0'
data/examples/sphero.rb CHANGED
@@ -1,11 +1,19 @@
1
1
  require 'artoo'
2
2
 
3
- connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4560'
3
+ connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4567'
4
4
  device :sphero, :driver => :sphero
5
5
 
6
6
  work do
7
+ @rolling = false
8
+
7
9
  every(3.seconds) do
8
10
  puts "Rolling..."
9
- sphero.roll 90, rand(360)
11
+ unless @rolling
12
+ sphero.roll 90, rand(360)
13
+ @rolling = true
14
+ else
15
+ sphero.stop
16
+ @rolling = false
17
+ end
10
18
  end
11
19
  end
@@ -15,9 +15,7 @@ module Artoo
15
15
  # Closes connection with device if connected
16
16
  # @return [Boolean]
17
17
  def finalize
18
- if connected?
19
- sphero.close
20
- end
18
+ disconnect if connected?
21
19
  end
22
20
 
23
21
  # Creates a connection with Sphero object with retries
@@ -44,7 +42,8 @@ module Artoo
44
42
  # Closes connection with device
45
43
  # @return [Boolean]
46
44
  def disconnect
47
- sphero.close
45
+ sphero.close if connected?
46
+
48
47
  super
49
48
  end
50
49
 
@@ -11,8 +11,7 @@ module Artoo
11
11
  BLUE = [0, 0, 255]
12
12
  WHITE = [255, 255, 255]
13
13
 
14
- COMMANDS = [:detect_collisions, :clear_collisions, :collisions,
15
- :power_notifications, :sensor_data, :set_color, :color].freeze
14
+ COMMANDS = [:roll, :stop, :detect_collisions, :messages, :set_color, :color].freeze
16
15
 
17
16
  # Starts drives and required connections
18
17
  def start_driver
@@ -20,7 +19,7 @@ module Artoo
20
19
  detect_collisions
21
20
 
22
21
  every(interval) do
23
- handle_collision_events
22
+ handle_message_events
24
23
  end
25
24
 
26
25
  super
@@ -31,43 +30,26 @@ module Artoo
31
30
  end
32
31
  end
33
32
 
34
- def handle_collision_events
35
- while i = find_event(::Sphero::Response::CollisionDetected) do
36
- update_collision(messages.slice!(i))
33
+ def handle_message_events
34
+ while not connection.messages.empty? do
35
+ evt = connection.messages.pop
36
+ case
37
+ when evt.is_a?(::Sphero::Response::CollisionDetected)
38
+ handle_collision_detected(evt)
39
+ when evt.is_a?(::Sphero::Response::PowerNotification)
40
+ handle_power_notification(evt)
41
+ when evt.is_a?(::Sphero::Response::SensorData)
42
+ handle_sensor_data(evt)
43
+ end
37
44
  end
38
45
  end
39
46
 
40
- # Publish collision events
41
- def update_collision(data)
42
- publish(event_topic_name("collision"), data)
43
- end
44
-
45
47
  # Detects collisions
46
48
  # @param [Hash] params
47
49
  def detect_collisions(params={})
48
50
  connection.configure_collision_detection 0x01, 0x20, 0x20, 0x20, 0x20, 0x50
49
51
  end
50
52
 
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
53
  # Set color
72
54
  # @param [Collection] colors
73
55
  def set_color(*colors)
@@ -89,16 +71,19 @@ module Artoo
89
71
 
90
72
  private
91
73
 
92
- def find_event(response_klass)
93
- messages.index {|m| m.is_a? response_klass}
74
+ # Publish collision events
75
+ def handle_collision_detected(data)
76
+ publish(event_topic_name("collision"), data)
94
77
  end
95
78
 
96
- def matching_response_types(responses, respone_klass)
97
- responses.select { |m| m.is_a? respone_klass } if responses
79
+ # Publish collision events
80
+ def handle_power_notification(data)
81
+ publish(event_topic_name("power"), data)
98
82
  end
99
83
 
100
- def messages
101
- connection.async_messages
84
+ # Publish collision events
85
+ def handle_sensor_data(data)
86
+ publish(event_topic_name("sensor"), data)
102
87
  end
103
88
  end
104
89
  end
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  module Sphero
3
- VERSION = '1.0.0.pre'
3
+ VERSION = '1.0.0.rc1'
4
4
  end
5
5
  end
@@ -6,27 +6,30 @@ describe Artoo::Drivers::Sphero do
6
6
  @device = mock('device')
7
7
  @driver = Artoo::Drivers::Sphero.new(:parent => @device)
8
8
  @connection = mock('connection')
9
- @col1 = ::Sphero::Response::CollisionDetected.new("yo", "ho")
10
- @col2 = ::Sphero::Response::CollisionDetected.new("yo", "ho")
11
- @sen1 = ::Sphero::Response::SensorData.new("yo", "ho")
12
- @sen2 = ::Sphero::Response::SensorData.new("lo", "no")
13
- @sen3 = ::Sphero::Response::SensorData.new("jo", "jo")
14
- @pow1 = ::Sphero::Response::PowerNotification.new("yo", "ho")
15
- @pow2 = ::Sphero::Response::PowerNotification.new("yo", "ho")
16
- @connection.stubs(:async_messages).returns([@col1, @col2, @sen1, @sen2, @sen3, @pow1, @pow2])
9
+ @messages = Queue.new
10
+ @messages << ::Sphero::Response::CollisionDetected.new("yo", "ho")
11
+ @messages << ::Sphero::Response::CollisionDetected.new("yo", "ho")
12
+ @messages << ::Sphero::Response::SensorData.new("yo", "ho")
13
+ @messages << ::Sphero::Response::SensorData.new("lo", "no")
14
+ @messages << ::Sphero::Response::SensorData.new("jo", "jo")
15
+ @messages << ::Sphero::Response::PowerNotification.new("yo", "ho")
16
+ @messages << ::Sphero::Response::PowerNotification.new("yo", "ho")
17
+ @connection.stubs(:messages).returns(@messages)
17
18
  @device.stubs(:connection).returns(@connection)
18
19
  end
19
20
 
20
- it 'Sphero#collisions' do
21
- @driver.collisions.size.must_equal 2
22
- end
21
+ it 'Sphero#handle_message_events' do
22
+ @driver.stubs(:handle_collision_detected)
23
+ @driver.stubs(:handle_power_notification)
24
+ @driver.stubs(:handle_sensor_data)
23
25
 
24
- it 'Sphero#power_notifications' do
25
- @driver.power_notifications.size.must_equal 2
26
- end
26
+ @messages.empty?.must_equal false
27
+ @messages.size.must_equal 7
27
28
 
28
- it 'Sphero#sensor_data' do
29
- @driver.sensor_data.size.must_equal 3
29
+ @driver.handle_message_events
30
+
31
+ @messages.empty?.must_equal true
32
+ @messages.size.must_equal 0
30
33
  end
31
34
 
32
35
  describe 'color' do
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
+ require 'artoo/robot'
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'mocha/setup'
3
5
 
4
- require 'artoo/robot'
5
-
6
6
  Celluloid.logger = nil
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artoo-sphero
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron Evans
8
8
  - Adrian Zankich
9
+ - Mike Ford
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-05-24 00:00:00.000000000 Z
13
+ date: 2013-07-26 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: artoo
@@ -17,28 +18,28 @@ dependencies:
17
18
  requirements:
18
19
  - - ~>
19
20
  - !ruby/object:Gem::Version
20
- version: 1.0.0.pre
21
+ version: 1.0.0.rc
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
26
  - - ~>
26
27
  - !ruby/object:Gem::Version
27
- version: 1.0.0.pre
28
+ version: 1.0.0.rc
28
29
  - !ruby/object:Gem::Dependency
29
- name: hybridgroup-sphero
30
+ name: sphero
30
31
  requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
33
  - - ~>
33
34
  - !ruby/object:Gem::Version
34
- version: 1.3.0
35
+ version: 1.4.1
35
36
  type: :runtime
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
40
  - - ~>
40
41
  - !ruby/object:Gem::Version
41
- version: 1.3.0
42
+ version: 1.4.1
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: minitest
44
45
  requirement: !ruby/object:Gem::Requirement
@@ -84,10 +85,7 @@ dependencies:
84
85
  description: Artoo adaptor and driver for Sphero robot
85
86
  email:
86
87
  - artoo@hybridgroup.com
87
- executables:
88
- - sphero.sh
89
- - sphero_linux_bind.sh
90
- - sphero_linux_socat.sh
88
+ executables: []
91
89
  extensions: []
92
90
  extra_rdoc_files: []
93
91
  files:
@@ -100,9 +98,6 @@ files:
100
98
  - README.md
101
99
  - Rakefile
102
100
  - artoo-sphero.gemspec
103
- - bin/sphero.sh
104
- - bin/sphero_linux_bind.sh
105
- - bin/sphero_linux_socat.sh
106
101
  - examples/sphero.rb
107
102
  - examples/sphero2.rb
108
103
  - examples/sphero_color.rb
data/bin/sphero.sh DELETED
@@ -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