robolove 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +11 -0
- data/lib/robolove.rb +5 -0
- data/lib/robolove/bot.rb +54 -0
- data/lib/robolove/version.rb +3 -0
- data/robolove.gemspec +26 -0
- data/test/bot_test.rb +88 -0
- data/test/test_helper.rb +8 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dde48212b4ca702cdd926b48cd775da56957bb02
|
4
|
+
data.tar.gz: b00a86a2332d545167344c176e206bbe53b74e7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e818f3fa458f2d95f0221005cab4b19baf99daee67a229cfe012f1af64d6adbcd403c744ab2a628bbf2f23149c8233b8cce574c92f8662ab180bf36cfcbcc2d3
|
7
|
+
data.tar.gz: 11d470b163fd937dd7dfff0f332a3d29f7254c5ed550e0959d0df025ed974f4fdfcb17b4d3f1ace746789682f56007d461e43f505718ea6a1217418e6acde9f8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Jonan Scheffler
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Robolove
|
2
|
+
|
3
|
+
A simple wrapper for lego_nxt to drive Lego robots.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'robolove'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install robolove
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Create a new robot:
|
24
|
+
|
25
|
+
```
|
26
|
+
@bot = Robolove::Bot.new
|
27
|
+
```
|
28
|
+
|
29
|
+
Drive!
|
30
|
+
|
31
|
+
```
|
32
|
+
@bot.forward
|
33
|
+
```
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/1337807/robolove/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/robolove.rb
ADDED
data/lib/robolove/bot.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'lego_nxt'
|
2
|
+
|
3
|
+
module Robolove
|
4
|
+
class Bot
|
5
|
+
DEFAULTS = {
|
6
|
+
:brick => nil,
|
7
|
+
:left_motor => :a,
|
8
|
+
:right_motor => :b,
|
9
|
+
:speed => 100
|
10
|
+
}
|
11
|
+
attr_reader :brick, :left_motor, :right_motor, :speed
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
options = DEFAULTS.merge options
|
15
|
+
|
16
|
+
@brick = options[:brick] || LegoNXT::LowLevel.connect
|
17
|
+
@left_motor = options[:left_motor] || DEFAULTS[:left_motor]
|
18
|
+
@right_motor = options[:right_motor] || DEFAULTS[:right_motor]
|
19
|
+
@speed = options[:speed] || DEFAULTS[:speed]
|
20
|
+
end
|
21
|
+
|
22
|
+
def forward(duration = 1)
|
23
|
+
self.brick.run_motor(self.left_motor, self.speed)
|
24
|
+
self.brick.run_motor(self.right_motor, self.speed)
|
25
|
+
sleep duration
|
26
|
+
self.brick.stop_motor(self.left_motor)
|
27
|
+
self.brick.stop_motor(self.right_motor)
|
28
|
+
end
|
29
|
+
|
30
|
+
def backward(duration = 1)
|
31
|
+
self.brick.run_motor(self.left_motor, -self.speed)
|
32
|
+
self.brick.run_motor(self.right_motor, -self.speed)
|
33
|
+
sleep duration
|
34
|
+
self.brick.stop_motor(self.left_motor)
|
35
|
+
self.brick.stop_motor(self.right_motor)
|
36
|
+
end
|
37
|
+
|
38
|
+
def right(duration = 0.5)
|
39
|
+
self.brick.run_motor(self.left_motor, self.speed)
|
40
|
+
self.brick.run_motor(self.right_motor, -self.speed)
|
41
|
+
sleep duration
|
42
|
+
self.brick.stop_motor(self.left_motor)
|
43
|
+
self.brick.stop_motor(self.right_motor)
|
44
|
+
end
|
45
|
+
|
46
|
+
def left(duration = 0.5)
|
47
|
+
self.brick.run_motor(self.right_motor, self.speed)
|
48
|
+
self.brick.run_motor(self.left_motor, -self.speed)
|
49
|
+
sleep duration
|
50
|
+
self.brick.stop_motor(self.right_motor)
|
51
|
+
self.brick.stop_motor(self.left_motor)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/robolove.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'robolove/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "robolove"
|
8
|
+
spec.version = Robolove::VERSION
|
9
|
+
spec.authors = ["Jonan Scheffler", "Zoe Kay"]
|
10
|
+
spec.email = ["jonanscheffler@gmail.com", "zoevkay@gmail.com"]
|
11
|
+
spec.summary = %q{A simple library to control LegoNXT robots.}
|
12
|
+
spec.description = %q{Robolove wraps the lego_nxt gem to make driving easier.}
|
13
|
+
spec.homepage = "https://github.com/1337807/robolove"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.4"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.10.1"
|
25
|
+
spec.add_development_dependency "mocha", "~> 1.1"
|
26
|
+
end
|
data/test/bot_test.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BotTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@brick = mock
|
6
|
+
@left = 'test_left'
|
7
|
+
@right = 'test_right'
|
8
|
+
@speed = 100
|
9
|
+
@bot = Robolove::Bot.new(
|
10
|
+
brick: @brick,
|
11
|
+
left_motor: @left,
|
12
|
+
right_motor: @right,
|
13
|
+
speed: @speed
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_bot_creates_a_brick
|
18
|
+
brick = 'fake brick'
|
19
|
+
::LegoNXT::LowLevel.stub(:connect, brick) {}
|
20
|
+
bot = Robolove::Bot.new(brick: brick)
|
21
|
+
assert_equal brick, bot.brick
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_forward_runs_both_motors
|
25
|
+
@brick.stubs(:stop_motor)
|
26
|
+
@brick.expects(:run_motor).with(@left, @speed)
|
27
|
+
@brick.expects(:run_motor).with(@right, @speed)
|
28
|
+
|
29
|
+
@bot.forward(0)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_forward_stops_motors_after_duration
|
33
|
+
@brick.stubs(:run_motor)
|
34
|
+
@brick.expects(:stop_motor).with(@left)
|
35
|
+
@brick.expects(:stop_motor).with(@right)
|
36
|
+
|
37
|
+
@bot.forward(0)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_right_runs_motors
|
41
|
+
@brick.stubs(:stop_motor)
|
42
|
+
@brick.expects(:run_motor).with(@left, @speed)
|
43
|
+
@brick.expects(:run_motor).with(@right, -@speed)
|
44
|
+
|
45
|
+
@bot.right(0)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_right_stops_motors_after_duration
|
49
|
+
@brick.stubs(:run_motor)
|
50
|
+
@brick.expects(:stop_motor).with(@left)
|
51
|
+
@brick.expects(:stop_motor).with(@right)
|
52
|
+
|
53
|
+
@bot.right(0)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_left_runs_motors
|
57
|
+
@brick.stubs(:stop_motor)
|
58
|
+
@brick.expects(:run_motor).with(@right, @speed)
|
59
|
+
@brick.expects(:run_motor).with(@left, -@speed)
|
60
|
+
|
61
|
+
@bot.left(0)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_left_stops_motors_after_duration
|
65
|
+
@brick.stubs(:run_motor)
|
66
|
+
@brick.expects(:stop_motor).with(@right)
|
67
|
+
@brick.expects(:stop_motor).with(@left)
|
68
|
+
|
69
|
+
@bot.left(0)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_backward_runs_both_motors
|
73
|
+
def @brick.stop_motor(port); true; end
|
74
|
+
@brick.stubs(:stop_motor)
|
75
|
+
@brick.expects(:run_motor).with(@left, -@speed)
|
76
|
+
@brick.expects(:run_motor).with(@right, -@speed)
|
77
|
+
|
78
|
+
@bot.backward(0)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_backward_stops_motors_after_duration
|
82
|
+
@brick.stubs(:run_motor)
|
83
|
+
@brick.expects(:stop_motor).with(@left)
|
84
|
+
@brick.expects(:stop_motor).with(@right)
|
85
|
+
|
86
|
+
@bot.backward(0)
|
87
|
+
end
|
88
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: robolove
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonan Scheffler
|
8
|
+
- Zoe Kay
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.4'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '5.4'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: pry
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.10.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.10.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: mocha
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.1'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.1'
|
84
|
+
description: Robolove wraps the lego_nxt gem to make driving easier.
|
85
|
+
email:
|
86
|
+
- jonanscheffler@gmail.com
|
87
|
+
- zoevkay@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/robolove.rb
|
98
|
+
- lib/robolove/bot.rb
|
99
|
+
- lib/robolove/version.rb
|
100
|
+
- robolove.gemspec
|
101
|
+
- test/bot_test.rb
|
102
|
+
- test/test_helper.rb
|
103
|
+
homepage: https://github.com/1337807/robolove
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.5
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A simple library to control LegoNXT robots.
|
127
|
+
test_files:
|
128
|
+
- test/bot_test.rb
|
129
|
+
- test/test_helper.rb
|
130
|
+
has_rdoc:
|