wall_e 0.0.1 → 0.0.2
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.
- data/cookbook/Led/blink.rb +1 -1
- data/cookbook/Led/pulse.rb +1 -1
- data/cookbook/Piezo/morse_code.rb +1 -1
- data/cookbook/Servo/sweep.rb +8 -2
- data/lib/wall_e/components/claw.rb +46 -0
- data/lib/wall_e/components/servo.rb +1 -1
- data/lib/wall_e/version.rb +1 -1
- data/lib/wall_e.rb +24 -14
- data/test/claw_test.rb +47 -0
- data/test/servo_test.rb +6 -8
- data/test/test_helper.rb +2 -1
- metadata +5 -2
data/cookbook/Led/blink.rb
CHANGED
data/cookbook/Led/pulse.rb
CHANGED
data/cookbook/Servo/sweep.rb
CHANGED
@@ -2,8 +2,14 @@ require 'bundler/setup'
|
|
2
2
|
require 'wall_e'
|
3
3
|
|
4
4
|
WallE::Assembler.build do
|
5
|
-
|
6
|
-
|
5
|
+
# This example uses a Sparkfun's "Medium" servo.
|
6
|
+
# (DGServo S05NF STD http://www.sparkfun.com/products/10333)
|
7
|
+
# Using the range 15..170 appears to be the sweet spot for this servo.
|
8
|
+
#
|
9
|
+
# YMMV especially if you are using a different servo.
|
10
|
+
#
|
11
|
+
# The Hitec HS-322 (http://amzn.com/B0006O3XEA) has a range of 2..180.
|
12
|
+
servo = Servo(9, range: 15..170)
|
7
13
|
servo.min
|
8
14
|
|
9
15
|
repeat do
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module WallE
|
4
|
+
class Claw
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :@pan_servo, :min, :max, :center
|
8
|
+
|
9
|
+
# Public: Initialize a Claw
|
10
|
+
#
|
11
|
+
# claw_servo - the Servo controlling the claw.
|
12
|
+
# pan_servo - the Servo controlling the pan/tilt bracket.
|
13
|
+
def initialize(claw_servo, pan_servo)
|
14
|
+
@claw_servo = claw_servo
|
15
|
+
@pan_servo = pan_servo
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: open the claw.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def let_go
|
22
|
+
@claw_servo.min
|
23
|
+
end
|
24
|
+
|
25
|
+
# Public: close the claw.
|
26
|
+
#
|
27
|
+
# Returns nothing.
|
28
|
+
def grab
|
29
|
+
@claw_servo.max
|
30
|
+
end
|
31
|
+
|
32
|
+
# Public: Indicates if the claw currently open.
|
33
|
+
#
|
34
|
+
# Returns truthy/falsy value.
|
35
|
+
def open?
|
36
|
+
!closed?
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Indicates if the claw is currently closed.
|
40
|
+
#
|
41
|
+
# Returns truthy/falsy value.
|
42
|
+
def closed?
|
43
|
+
@claw_servo.maxed?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/wall_e/version.rb
CHANGED
data/lib/wall_e.rb
CHANGED
@@ -3,11 +3,11 @@ require 'wall_e/serial_snoop'
|
|
3
3
|
require 'wall_e/pin'
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
+
# TODO everything in components should be required automagically.
|
6
7
|
require 'wall_e/components/led'
|
7
8
|
require 'wall_e/components/servo'
|
8
9
|
require 'wall_e/components/piezo'
|
9
|
-
|
10
|
-
|
10
|
+
require 'wall_e/components/claw'
|
11
11
|
|
12
12
|
module WallE
|
13
13
|
class Assembler
|
@@ -15,14 +15,17 @@ module WallE
|
|
15
15
|
attr_reader :board
|
16
16
|
|
17
17
|
def self.build(&block)
|
18
|
+
wall_e = create
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
wall_e = new(arduino)
|
20
|
+
wall_e.instance_eval(&block) if block_given?
|
22
21
|
|
23
|
-
|
22
|
+
Pry.start(wall_e, :prompt => [ proc { |obj, *| "wall_e > " },
|
23
|
+
proc { |obj, *| "wall_e* "} ])
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
def self.create
|
27
|
+
arduino = SerialSnoop.locate_ports
|
28
|
+
new(arduino)
|
26
29
|
end
|
27
30
|
|
28
31
|
def initialize(arduino)
|
@@ -45,6 +48,7 @@ module WallE
|
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
51
|
+
# TODO some metaprogramming sauce to reduce the component helper code.
|
48
52
|
def Led(pin_number)
|
49
53
|
pin = Pin.new(pin_number, @board)
|
50
54
|
Led.new(pin)
|
@@ -60,6 +64,12 @@ module WallE
|
|
60
64
|
Piezo.new(pin)
|
61
65
|
end
|
62
66
|
|
67
|
+
def Claw(claw_pin_number, pan_pin_number)
|
68
|
+
claw_servo = Servo(claw_pin_number, range: 60..144)
|
69
|
+
pan_servo = Servo(pan_pin_number)
|
70
|
+
Claw.new(claw_servo, pan_servo)
|
71
|
+
end
|
72
|
+
|
63
73
|
def delay(seconds)
|
64
74
|
@board.delay seconds
|
65
75
|
end
|
@@ -81,13 +91,13 @@ module WallE
|
|
81
91
|
t = Thread.new do
|
82
92
|
loop do
|
83
93
|
Thread.stop unless @running
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
94
|
+
begin
|
95
|
+
block.call
|
96
|
+
rescue Exception => e
|
97
|
+
puts e.message
|
98
|
+
puts e.backtrace.inspect
|
99
|
+
Thread.kill
|
100
|
+
end
|
91
101
|
end
|
92
102
|
end
|
93
103
|
|
data/test/claw_test.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require_relative '../lib/wall_e/components/claw'
|
3
|
+
|
4
|
+
class ClawTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
DummyServo = Class.new
|
7
|
+
|
8
|
+
def test_let_go
|
9
|
+
claw_servo = MiniTest::Mock.new
|
10
|
+
claw_servo.expect :min, 1
|
11
|
+
pan_servo = DummyServo.new
|
12
|
+
|
13
|
+
claw = WallE::Claw.new(claw_servo, pan_servo)
|
14
|
+
|
15
|
+
claw.let_go
|
16
|
+
|
17
|
+
claw_servo.verify
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_grab
|
21
|
+
claw_servo = MiniTest::Mock.new
|
22
|
+
claw_servo.expect :max, 1
|
23
|
+
pan_servo = DummyServo.new
|
24
|
+
|
25
|
+
claw = WallE::Claw.new(claw_servo, pan_servo)
|
26
|
+
|
27
|
+
claw.grab
|
28
|
+
|
29
|
+
claw_servo.verify
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_tilting
|
33
|
+
pan_servo = MiniTest::Mock.new
|
34
|
+
pan_servo.expect :min, 1
|
35
|
+
pan_servo.expect :max, 1
|
36
|
+
pan_servo.expect :center, 1
|
37
|
+
claw_servo = DummyServo.new
|
38
|
+
|
39
|
+
claw = WallE::Claw.new(claw_servo, pan_servo)
|
40
|
+
|
41
|
+
claw.min
|
42
|
+
claw.max
|
43
|
+
claw.center
|
44
|
+
|
45
|
+
pan_servo.verify
|
46
|
+
end
|
47
|
+
end
|
data/test/servo_test.rb
CHANGED
@@ -56,16 +56,14 @@ class ServoTest < MiniTest::Unit::TestCase
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_moving_to_center
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
pin.expect(:servo_write, 1, [90])
|
59
|
+
pin = MiniTest::Mock.new
|
60
|
+
pin.expect(:set_mode, 1, [WallE::Pin::SERVO])
|
61
|
+
pin.expect(:servo_write, 1, [90])
|
63
62
|
|
64
|
-
|
65
|
-
|
63
|
+
servo = WallE::Servo.new(pin)
|
64
|
+
servo.center
|
66
65
|
|
67
|
-
|
68
|
-
end
|
66
|
+
pin.verify
|
69
67
|
end
|
70
68
|
|
71
69
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wall_e
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- cookbook/Piezo/morse_code.rb
|
95
95
|
- cookbook/Servo/sweep.rb
|
96
96
|
- lib/wall_e.rb
|
97
|
+
- lib/wall_e/components/claw.rb
|
97
98
|
- lib/wall_e/components/led.rb
|
98
99
|
- lib/wall_e/components/piezo.rb
|
99
100
|
- lib/wall_e/components/servo.rb
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- lib/wall_e/pin.rb
|
102
103
|
- lib/wall_e/serial_snoop.rb
|
103
104
|
- lib/wall_e/version.rb
|
105
|
+
- test/claw_test.rb
|
104
106
|
- test/led_test.rb
|
105
107
|
- test/piezo_test.rb
|
106
108
|
- test/pin_test.rb
|
@@ -133,6 +135,7 @@ signing_key:
|
|
133
135
|
specification_version: 3
|
134
136
|
summary: ''
|
135
137
|
test_files:
|
138
|
+
- test/claw_test.rb
|
136
139
|
- test/led_test.rb
|
137
140
|
- test/piezo_test.rb
|
138
141
|
- test/pin_test.rb
|