pan_tilt 0.0.2 → 0.0.3
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/README.md +1 -1
- data/lib/pan_tilt/command_line.rb +8 -20
- data/lib/pan_tilt/rotor.rb +33 -3
- data/lib/pan_tilt/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Pan and tilt your Arduino connected bracket
|
|
9
9
|
* Pan/Tilt Bracket from [sparkfun](https://www.sparkfun.com/products/10335)
|
10
10
|
* 2x Small Servos
|
11
11
|
* Breadboard
|
12
|
-
|
12
|
+
* Pinned wires
|
13
13
|
|
14
14
|
## Pan and Tilt bracket
|
15
15
|
To create the bracket you can order the parts from [sparkfun](https://www.sparkfun.com/products/10335) and follow their [assembly instructions.](https://www.sparkfun.com/datasheets/Robotics/Other/sensor%20pan%20tilt%20manual.jpg)
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module PanTilt
|
2
2
|
class CommandLine
|
3
3
|
def initialize(debug=false)
|
4
|
-
@debug
|
5
|
-
@board
|
6
|
-
@rotor
|
7
|
-
@
|
8
|
-
@tilt_angle = PanTilt::MIN_TILT_ANGLE
|
9
|
-
@led = Dino::Components::Led.new(pin: PanTilt::LIVE_LED, board: @board)
|
4
|
+
@debug = debug
|
5
|
+
@board = Dino::Board.new(Dino::TxRx::Serial.new)
|
6
|
+
@rotor = PanTilt::Rotor.new @board, @debug
|
7
|
+
@led = Dino::Components::Led.new(pin: PanTilt::LIVE_LED, board: @board)
|
10
8
|
end
|
11
9
|
|
12
10
|
def run
|
@@ -19,24 +17,14 @@ module PanTilt
|
|
19
17
|
@led.send :off
|
20
18
|
break
|
21
19
|
when PanTilt::LEFT_ARROW
|
22
|
-
|
23
|
-
@pan_angle = @pan_angle - PanTilt::INCREMENT
|
24
|
-
end
|
20
|
+
@rotor.rotate_by (- PanTilt::INCREMENT), 0
|
25
21
|
when PanTilt::RIGHT_ARROW
|
26
|
-
|
27
|
-
@pan_angle = @pan_angle + PanTilt::INCREMENT
|
28
|
-
end
|
22
|
+
@rotor.rotate_by PanTilt::INCREMENT, 0
|
29
23
|
when PanTilt::DOWN_ARROW
|
30
|
-
|
31
|
-
@tilt_angle = @tilt_angle - PanTilt::INCREMENT
|
32
|
-
end
|
24
|
+
@rotor.rotate_by 0, (- PanTilt::INCREMENT)
|
33
25
|
when PanTilt::UP_ARROW
|
34
|
-
|
35
|
-
@tilt_angle = @tilt_angle + PanTilt::INCREMENT
|
36
|
-
end
|
26
|
+
@rotor.rotate_by 0, PanTilt::INCREMENT
|
37
27
|
end
|
38
|
-
|
39
|
-
@rotor.rotate @pan_angle, @tilt_angle
|
40
28
|
end
|
41
29
|
end
|
42
30
|
|
data/lib/pan_tilt/rotor.rb
CHANGED
@@ -6,10 +6,42 @@ module PanTilt
|
|
6
6
|
@debug = debug
|
7
7
|
|
8
8
|
@board = board
|
9
|
-
@tilt_servo = Dino::Components::Servo.new(pin: PanTilt::TILT_PIN,
|
9
|
+
@tilt_servo = Dino::Components::Servo.new(pin: PanTilt::TILT_PIN, board: @board)
|
10
10
|
@pan_servo = Dino::Components::Servo.new(pin: PanTilt::PAN_PIN, board: @board)
|
11
11
|
end
|
12
12
|
|
13
|
+
def rotate_by(pan_offset, tilt_offset)
|
14
|
+
rotate new_pan_position(pan_offset), new_tilt_position(tilt_offset)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def new_pan_position(offset)
|
20
|
+
current_position = @pan_servo.position
|
21
|
+
new_position = @pan_servo.position + offset
|
22
|
+
|
23
|
+
if new_position.between? PanTilt::MIN_PAN_ANGLE, PanTilt::MAX_PAN_ANGLE
|
24
|
+
return new_position
|
25
|
+
elsif PanTilt::MIN_PAN_ANGLE.between? new_position, PanTilt::MAX_PAN_ANGLE
|
26
|
+
PanTilt::MIN_PAN_ANGLE
|
27
|
+
elsif PanTilt::MAX_PAN_ANGLE.between? PanTilt::MIN_PAN_ANGLE, new_position
|
28
|
+
PanTilt::MAX_PAN_ANGLE
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def new_tilt_position(offset)
|
33
|
+
current_position = @tilt_servo.position
|
34
|
+
new_position = @tilt_servo.position + offset
|
35
|
+
|
36
|
+
if new_position.between? PanTilt::MIN_TILT_ANGLE, PanTilt::MAX_TILT_ANGLE
|
37
|
+
return new_position
|
38
|
+
elsif PanTilt::MIN_TILT_ANGLE.between? new_position, PanTilt::MAX_TILT_ANGLE
|
39
|
+
PanTilt::MIN_TILT_ANGLE
|
40
|
+
elsif PanTilt::MAX_TILT_ANGLE.between? PanTilt::MIN_TILT_ANGLE, new_position
|
41
|
+
PanTilt::MAX_TILT_ANGLE
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
13
45
|
def rotate(pan_angle, tilt_angle)
|
14
46
|
pan_servo.position = pan_angle
|
15
47
|
tilt_servo.position = tilt_angle
|
@@ -17,8 +49,6 @@ module PanTilt
|
|
17
49
|
print_debug "p: #{pan_angle}, t: #{tilt_angle}"
|
18
50
|
end
|
19
51
|
|
20
|
-
private
|
21
|
-
|
22
52
|
def print_debug(string)
|
23
53
|
puts string if @debug
|
24
54
|
end
|
data/lib/pan_tilt/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pan_tilt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2013-07-
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dino
|