artoo-roomba 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08001779fc2a7bd65d66891a5f818bfc8325920d
4
+ data.tar.gz: b173c210fa6081aba29f9a6cd637c8a2fa9bcf69
5
+ SHA512:
6
+ metadata.gz: a4c6039adc339bc3f7173fbeeb274e4db1eea2ab5baa7a0d7e15dc6a4c2231d86f78452a56f381b03b1f6e809d5b07c30246053e213cd8c7607b8024b5c3d017
7
+ data.tar.gz: f79d2ea1af3a7b99aca4a295498a77536761dd5e555fa8bb42b9b37d7f9db96c49b88c3a2191acfa1f0e90add67744ebad171e6b0b6f226fa5f8ea11ea8442fb
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .rvmrc
2
+ .rbx
data/.rvmrc.example ADDED
@@ -0,0 +1 @@
1
+ rvm use rbx-2.0.0-rc1@artoo-roomba --create
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in artoo-sphero.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ artoo-roomba (1.0.0.pre)
5
+ artoo (~> 1.0.0.pre)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ artoo (1.0.0.pre)
11
+ celluloid (~> 0.14.0)
12
+ celluloid-io (~> 0.14.0)
13
+ multi_json (~> 1.6)
14
+ pry (~> 0.9)
15
+ rake (~> 10.0)
16
+ reel (~> 0.4.pre)
17
+ celluloid (0.14.0)
18
+ timers (>= 1.0.0)
19
+ celluloid-io (0.14.0)
20
+ celluloid (>= 0.13.0)
21
+ nio4r (>= 0.4.5)
22
+ certified (0.1.1)
23
+ coderay (1.0.9)
24
+ http (0.4.0)
25
+ certified
26
+ http_parser.rb
27
+ http_parser.rb (0.5.3)
28
+ metaclass (0.0.1)
29
+ method_source (0.8.1)
30
+ minitest (5.0.1)
31
+ minitest-happy (1.0.0)
32
+ mocha (0.14.0)
33
+ metaclass (~> 0.0.1)
34
+ multi_json (1.7.3)
35
+ nio4r (0.4.5)
36
+ pry (0.9.12.2)
37
+ coderay (~> 1.0.5)
38
+ method_source (~> 0.8)
39
+ slop (~> 3.4)
40
+ rack (1.5.2)
41
+ rake (10.0.4)
42
+ reel (0.4.0.pre)
43
+ celluloid-io (>= 0.8.0)
44
+ http (>= 0.2.0)
45
+ http_parser.rb (>= 0.5.3)
46
+ rack (>= 1.4.0)
47
+ websocket_parser (>= 0.1.2)
48
+ slop (3.4.5)
49
+ timers (1.1.0)
50
+ websocket_parser (0.1.4)
51
+ http
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ artoo-roomba!
58
+ minitest (~> 5.0)
59
+ minitest-happy
60
+ mocha (~> 0.14.0)
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012, 2013 The Hybrid Group
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Artoo Adaptor For Roomba
2
+
3
+ This repository contains the Artoo (http://artoo.io/) adaptor for the Roomba robot.
4
+
5
+ Artoo is a open source micro-framework for robotics using Ruby.
6
+
7
+ For more information abut Artoo, check out our repo at https://github.com/hybridgroup/artoo
8
+
9
+ [![Code Climate](https://codeclimate.com/github/hybridgroup/artoo-roomba.png)](https://codeclimate.com/github/hybridgroup/artoo-roomba) [![Build Status](https://travis-ci.org/hybridgroup/artoo-roomba.png?branch=master)](https://travis-ci.org/hybridgroup/artoo-roomba)
10
+
11
+ ## Installing
12
+
13
+ ```
14
+ gem install artoo-roomba
15
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "artoo-roomba/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "artoo-roomba"
7
+ s.version = Artoo::Roomba::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ron Evans", "Adrian Zankich"]
10
+ s.email = ["artoo@hybridgroup.com"]
11
+ s.homepage = "https://github.com/hybridgroup/artoo-roomba"
12
+ s.summary = %q{Artoo adaptor and driver for Roomba robot}
13
+ s.description = %q{Artoo adaptor and driver for Roomba robot}
14
+
15
+ s.rubyforge_project = "artoo-roomba"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency 'artoo', '~> 1.0.0.pre'
23
+ s.add_development_dependency 'minitest', '~> 5.0'
24
+ s.add_development_dependency 'minitest-happy'
25
+ s.add_development_dependency 'mocha', '~> 0.14.0'
26
+ end
@@ -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,51 @@
1
+ require 'artoo/adaptors/adaptor'
2
+
3
+ module Artoo
4
+ module Adaptors
5
+ # Connect to a Roomba
6
+ # @see http://www.irobot.com/en/us/robots/Educators/Create.aspx Roomba information
7
+ class Roomba < Adaptor
8
+ finalizer :finalize
9
+ attr_reader :sp
10
+
11
+ # Closes connection if already connected
12
+ # @return [Boolean]
13
+ def finalize
14
+ if connected?
15
+ @sp.close
16
+ end
17
+ end
18
+
19
+ # Creates serial or tcp connection
20
+ # @return [Boolean]
21
+ def connect
22
+ if port.is_serial?
23
+ @sp = connect_to_serial
24
+ @sp.dtr = 0
25
+ @sp.rts = 0
26
+ else
27
+ @sp = connect_to_tcp
28
+ end
29
+ super
30
+ end
31
+
32
+ # Send bytes to device
33
+ def send_bytes(bytes)
34
+ bytes = [bytes] unless bytes.respond_to?(:map)
35
+ bytes.map!(&:chr)
36
+ Logger.debug "sending: #{bytes.inspect}"
37
+ res = []
38
+ bytes.each{|b| res << @sp.write(b) }
39
+ Logger.debug "returned: #{res.inspect}"
40
+ end
41
+
42
+ # Closes connection to device
43
+ # @return [Boolean]
44
+ def disconnect
45
+ @sp.close
46
+ super
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,179 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # The Roomba driver behaviors
6
+ class Roomba < Driver
7
+
8
+ COMMANDS = [:start, :safe_mode, :full_mode, :forward, :stop, :fast_forward,
9
+ :backwards, :nudge_left, :nudge_right, :turn_left, :turn_right,
10
+ :turn_around, :drive, :play, :song, :beep].freeze
11
+
12
+ # Sets Direction constant values
13
+ module Direction
14
+ STRAIGHT = 32768
15
+ CLOCKWISE = 65535
16
+ COUNTERCLOCKWISE = 1
17
+ end
18
+
19
+ # Sets speed constant values
20
+ module Speed
21
+ MAX = 500
22
+ SLOW = 250
23
+ NEG = (65536 - 250)
24
+ ZERO = 0
25
+ end
26
+
27
+ # Sets notes constant values
28
+ module Note
29
+ B = 95
30
+ D = 98
31
+ G = 91
32
+ C = 96
33
+ A = 93
34
+ QUARTER = 16
35
+ HALF = 57
36
+ WHOLE = 114
37
+ end
38
+
39
+ # Sets mode constant values
40
+ module Mode
41
+ FULL = 132
42
+ SAFE = 131
43
+ START = 128
44
+ end
45
+
46
+ # Sets song constant values
47
+ module Song
48
+ SONG = 140
49
+ PLAY = 141
50
+ end
51
+
52
+ # Sends start mode
53
+ def start
54
+ send_bytes(Mode::START)
55
+ sleep 0.2
56
+ end
57
+
58
+ # Sends safe mode
59
+ def safe_mode
60
+ start
61
+ send_bytes(Mode::SAFE)
62
+ sleep 0.1
63
+ end
64
+
65
+ # Sends full mode
66
+ def full_mode
67
+ start
68
+ send_bytes(Mode::FULL)
69
+ sleep 0.1
70
+ end
71
+
72
+ # Move forward
73
+ # @param [Integer] seconds
74
+ # @param [Constant] velocity
75
+ # @see Speed
76
+ def forward(seconds, velocity = Speed::SLOW)
77
+ drive(velocity, Direction::STRAIGHT, seconds)
78
+ stop if seconds > 0
79
+ end
80
+
81
+ # Stop movement
82
+ def stop
83
+ drive(Speed::ZERO, Direction::STRAIGHT)
84
+ end
85
+
86
+ # Move forward with fast speed
87
+ # @param [Integer] seconds
88
+ def fast_forward(seconds)
89
+ drive(Speed::MAX, Direction::STRAIGHT, seconds)
90
+ stop if seconds > 0
91
+ end
92
+
93
+ # Move backward
94
+ # @param [Integer] seconds
95
+ def backwards(seconds)
96
+ drive(Speed::NEG, Direction::STRAIGHT, seconds)
97
+ stop if seconds > 0
98
+ end
99
+
100
+ # Nudge left
101
+ def nudge_left
102
+ turn_left(0.25)
103
+ end
104
+
105
+ # Turn left
106
+ # @param [Integer] seconds
107
+ def turn_left(seconds = 1)
108
+ drive(Speed::SLOW, Direction::COUNTERCLOCKWISE, seconds)
109
+ stop if seconds > 0
110
+ end
111
+
112
+ # Turn right
113
+ # @param [Integer] seconds
114
+ def turn_right(seconds = 1)
115
+ drive(Speed::SLOW, Direction::CLOCKWISE, seconds)
116
+ stop if seconds > 0
117
+ end
118
+
119
+ # Nudge right
120
+ def nudge_right
121
+ turn_right(0.25)
122
+ end
123
+
124
+ # Turn around
125
+ def turn_around
126
+ turn_left(1.6)
127
+ end
128
+
129
+ # Drive
130
+ # @param [Integer] v speed
131
+ # @param [Integer] r direction
132
+ # @param [Integer] s seconds (waiting time)
133
+ # @see Speed
134
+ # @see Direction
135
+ def drive(v, r, s = 0)
136
+ vH,vL = split_bytes(v)
137
+ rH,rL = split_bytes(r)
138
+ send_bytes([137, vH, vL, rH, rL])
139
+ sleep(s) if s > 0
140
+ end
141
+
142
+ # Split bytes (hex)
143
+ # @param [Integer] num
144
+ def split_bytes(num)
145
+ [num >> 8, num & 255]
146
+ end
147
+
148
+ # Play song
149
+ # @param [Integer] song_number
150
+ def play(song_number = 0)
151
+ send_bytes([Song::PLAY, song_number])
152
+ end
153
+
154
+ # Save song
155
+ # @param [Collection] notes
156
+ # @param [Integer] song_number
157
+ # @see Notes
158
+ def song(notes, song_number = 0)
159
+ note_group = notes.flatten.compact
160
+ l = note_group.length / 2
161
+ send_bytes([Song::SONG, song_number, l] + note_group)
162
+ end
163
+
164
+ # Play song
165
+ # @param [Collection] notes
166
+ # @param [Integer] song_number
167
+ # @see Notes
168
+ def play_song(notes, song_number = 0)
169
+ song(notes, song_number)
170
+ play(song_number)
171
+ end
172
+
173
+ # Beeps with a G note
174
+ def beep
175
+ play_song([Note::G, Note::WHOLE])
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,5 @@
1
+ module Artoo
2
+ module Roomba
3
+ VERSION = '1.0.0.pre'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'lib/artoo/adaptors/roomba'
2
+ require 'lib/artoo/drivers/roomba'
3
+ require 'lib/artoo-roomba/version'
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'artoo/adaptors/roomba'
3
+
4
+ describe Artoo::Adaptors::Roomba do
5
+ it 'needs tests'
6
+ end
@@ -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
@@ -0,0 +1,6 @@
1
+ require 'minitest/autorun'
2
+ require 'mocha/setup'
3
+
4
+ require 'artoo/robot'
5
+
6
+ Celluloid.logger = nil
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artoo-roomba
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Ron Evans
8
+ - Adrian Zankich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: artoo
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0.pre
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.0.pre
28
+ - !ruby/object:Gem::Dependency
29
+ name: minitest
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '5.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '5.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest-happy
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: mocha
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.14.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.14.0
70
+ description: Artoo adaptor and driver for Roomba robot
71
+ email:
72
+ - artoo@hybridgroup.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rvmrc.example
79
+ - .travis.yml
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - artoo-roomba.gemspec
86
+ - examples/roomba.rb
87
+ - lib/artoo-roomba.rb
88
+ - lib/artoo-roomba/version.rb
89
+ - lib/artoo/adaptors/roomba.rb
90
+ - lib/artoo/drivers/roomba.rb
91
+ - test/adaptors/roomba_test.rb
92
+ - test/drivers/roomba_test.rb
93
+ - test/test_helper.rb
94
+ homepage: https://github.com/hybridgroup/artoo-roomba
95
+ licenses: []
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>'
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.1
111
+ requirements: []
112
+ rubyforge_project: artoo-roomba
113
+ rubygems_version: 2.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Artoo adaptor and driver for Roomba robot
117
+ test_files: []