pan_tilt 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/README.md +33 -1
- data/bin/pan_tilt +2 -1
- data/lib/pan_tilt/command_line.rb +49 -0
- data/lib/pan_tilt/rotor.rb +26 -0
- data/lib/pan_tilt/version.rb +1 -1
- data/lib/pan_tilt.rb +5 -38
- metadata +3 -1
data/README.md
CHANGED
@@ -1,3 +1,35 @@
|
|
1
1
|
# Pan and Tilt
|
2
2
|
|
3
|
-
Pan and tilt your Arduino connected
|
3
|
+
Pan and tilt your Arduino connected bracket
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* Arduino Uno
|
8
|
+
* USB cable
|
9
|
+
* Pan/Tilt Bracket from [sparkfun](https://www.sparkfun.com/products/10335)
|
10
|
+
* 2x Small Servos
|
11
|
+
* Breadboard
|
12
|
+
# Pinned wires
|
13
|
+
|
14
|
+
## Pan and Tilt bracket
|
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)
|
16
|
+
|
17
|
+
## Hardware Installation
|
18
|
+
|
19
|
+
* Connect the Pan servo's control wire to Pin 11 (configurable)
|
20
|
+
* Connect the Tilt servo's control wire to Pin 9 (configurable)
|
21
|
+
* Connect both servos' ground wires to GND
|
22
|
+
* Connect both servos' power wires to 5V
|
23
|
+
|
24
|
+
## Software Installation
|
25
|
+
|
26
|
+
* Connect the Arduino to your computer via USB
|
27
|
+
* Install the [Arduino IDE](http://arduino.cc/en/Main/Software)
|
28
|
+
* Install this gem
|
29
|
+
|
30
|
+
gem install pan_tilt
|
31
|
+
|
32
|
+
## Dino
|
33
|
+
|
34
|
+
The [Dino](https://github.com/austinbv/dino) bootstrapper will need to be instaled on the Arduino. You can follow the instructions in [here](https://github.com/austinbv/dino#upload-the-bootstrapper).
|
35
|
+
The .ino file referenced should be opened and not copied in.
|
data/bin/pan_tilt
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
module PanTilt
|
2
|
+
class CommandLine
|
3
|
+
def initialize(debug=false)
|
4
|
+
@debug = debug
|
5
|
+
@board = Dino::Board.new(Dino::TxRx::Serial.new)
|
6
|
+
@rotor = PanTilt::Rotor.new @board, @debug
|
7
|
+
@pan_angle = PanTilt::MIN_PAN_ANGLE
|
8
|
+
@tilt_angle = PanTilt::MIN_TILT_ANGLE
|
9
|
+
@led = Dino::Components::Led.new(pin: PanTilt::LIVE_LED, board: @board)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
print_instructions
|
14
|
+
@led.send :on
|
15
|
+
|
16
|
+
while key = STDIN.getch
|
17
|
+
case key
|
18
|
+
when PanTilt::ESCAPE
|
19
|
+
@led.send :off
|
20
|
+
break
|
21
|
+
when PanTilt::LEFT_ARROW
|
22
|
+
if @pan_angle > PanTilt::MIN_PAN_ANGLE
|
23
|
+
@pan_angle = @pan_angle - PanTilt::INCREMENT
|
24
|
+
end
|
25
|
+
when PanTilt::RIGHT_ARROW
|
26
|
+
if @pan_angle < PanTilt::MAX_PAN_ANGLE
|
27
|
+
@pan_angle = @pan_angle + PanTilt::INCREMENT
|
28
|
+
end
|
29
|
+
when PanTilt::DOWN_ARROW
|
30
|
+
if @tilt_angle > PanTilt::MIN_TILT_ANGLE
|
31
|
+
@tilt_angle = @tilt_angle - PanTilt::INCREMENT
|
32
|
+
end
|
33
|
+
when PanTilt::UP_ARROW
|
34
|
+
if @tilt_angle < PanTilt::MAX_TILT_ANGLE
|
35
|
+
@tilt_angle = @tilt_angle + PanTilt::INCREMENT
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@rotor.rotate @pan_angle, @tilt_angle
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def print_instructions
|
46
|
+
puts "Use 'h', 'j', 'k', and 'l' to pan and tilt. Use 'e' to exit"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PanTilt
|
2
|
+
class Rotor
|
3
|
+
attr_reader :board, :tilt_servo, :pan_servo
|
4
|
+
|
5
|
+
def initialize(board, debug=false)
|
6
|
+
@debug = debug
|
7
|
+
|
8
|
+
@board = board
|
9
|
+
@tilt_servo = Dino::Components::Servo.new(pin: PanTilt::TILT_PIN, board: @board)
|
10
|
+
@pan_servo = Dino::Components::Servo.new(pin: PanTilt::PAN_PIN, board: @board)
|
11
|
+
end
|
12
|
+
|
13
|
+
def rotate(pan_angle, tilt_angle)
|
14
|
+
pan_servo.position = pan_angle
|
15
|
+
tilt_servo.position = tilt_angle
|
16
|
+
|
17
|
+
print_debug "p: #{pan_angle}, t: #{tilt_angle}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def print_debug(string)
|
23
|
+
puts string if @debug
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/pan_tilt/version.rb
CHANGED
data/lib/pan_tilt.rb
CHANGED
@@ -3,53 +3,20 @@ require "pan_tilt/version"
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'dino'
|
5
5
|
require 'io/console'
|
6
|
+
require 'pan_tilt/rotor'
|
6
7
|
|
7
8
|
module PanTilt
|
9
|
+
TILT_PIN = 9
|
10
|
+
PAN_PIN = 11
|
11
|
+
LIVE_LED = 13
|
8
12
|
ESCAPE = 'e'
|
9
13
|
LEFT_ARROW = 'h'
|
10
14
|
RIGHT_ARROW = 'l'
|
11
15
|
UP_ARROW = 'k'
|
12
16
|
DOWN_ARROW = 'j'
|
13
17
|
MAX_TILT_ANGLE = 135
|
14
|
-
MAX_PAN_ANGLE =
|
18
|
+
MAX_PAN_ANGLE = 160
|
15
19
|
MIN_TILT_ANGLE = 15
|
16
20
|
MIN_PAN_ANGLE = 0
|
17
21
|
INCREMENT = 5
|
18
|
-
|
19
|
-
board = Dino::Board.new(Dino::TxRx::Serial.new)
|
20
|
-
tilt_servo = Dino::Components::Servo.new(pin: 9, board: board)
|
21
|
-
pan_servo = Dino::Components::Servo.new(pin: 11, board: board)
|
22
|
-
|
23
|
-
pan_angle = MIN_PAN_ANGLE
|
24
|
-
tilt_angle = MIN_TILT_ANGLE
|
25
|
-
|
26
|
-
def self.run
|
27
|
-
while key = STDIN.getch
|
28
|
-
case key
|
29
|
-
when ESCAPE
|
30
|
-
break
|
31
|
-
when LEFT_ARROW
|
32
|
-
if pan_angle > MIN_PAN_ANGLE
|
33
|
-
pan_angle = pan_angle - INCREMENT
|
34
|
-
pan_servo.position = pan_angle
|
35
|
-
end
|
36
|
-
when RIGHT_ARROW
|
37
|
-
if pan_angle < MAX_PAN_ANGLE
|
38
|
-
pan_angle = pan_angle + INCREMENT
|
39
|
-
pan_servo.position = pan_angle
|
40
|
-
end
|
41
|
-
when DOWN_ARROW
|
42
|
-
if tilt_angle > MIN_TILT_ANGLE
|
43
|
-
tilt_angle = tilt_angle - INCREMENT
|
44
|
-
tilt_servo.position = tilt_angle
|
45
|
-
end
|
46
|
-
when UP_ARROW
|
47
|
-
if tilt_angle < MAX_TILT_ANGLE
|
48
|
-
tilt_angle = tilt_angle + INCREMENT
|
49
|
-
tilt_servo.position = tilt_angle
|
50
|
-
end
|
51
|
-
end
|
52
|
-
puts "p: #{pan_angle}, t: #{tilt_angle}"
|
53
|
-
end
|
54
|
-
end
|
55
22
|
end
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -77,6 +77,8 @@ files:
|
|
77
77
|
- lib/du/Dino.h
|
78
78
|
- lib/du/du.ino
|
79
79
|
- lib/pan_tilt.rb
|
80
|
+
- lib/pan_tilt/command_line.rb
|
81
|
+
- lib/pan_tilt/rotor.rb
|
80
82
|
- lib/pan_tilt/version.rb
|
81
83
|
- pan_tilt.gemspec
|
82
84
|
homepage: https://github.com/wmernagh/pan_tilt
|