InterfacingServos-2

Download Report

Transcript InterfacingServos-2

Raspberry Pi
Hands-on Seminars
Interfacing to Servo Motors
1
Gregory
GregoryGriffes
Griffes
8/16/15
Overview

Types of servo motors and operation

Electronic connections to a servo

Python code to control a servo

Wiring and operating your own servo motor
2
Hardware
High power
charging hub
Custom
servo cable
RPi GPIO
Breakout
breadboard
Servo motor
3.3v to 5v
Level shifter
(I2C safe version)
3
Parts Needed
• Canakit Ultimate Starter kit with
breadboard, breakout board, ribbon cable,
jumper wires, and electronic parts
• one Tek Republic TUH-3700 USB 3.0 7
Port Hub charging hub ($30)
• one HiTec HS-5055MG digital servo motor
($18)
• one Parallax continuous rotation servo
motor ($10)
• one Adafruit 4-channel I2C-safe Bidirectional Logic Level Converter ($8)
4
Step 1: Avoid Damage
to your Rpi hardware
ESD – ElectroStatic Discharge
Use a wrist strap, mat,
& ESD bags
5
Step 2: Breadboard

Remove the Rpi from the static bag

Connect breadboard circuit (see video)

Make sure the connector is correctly aligned
6
DANGER!
+5V
Damage!
/ /-
Step 2: Hardware
Warnings


Rpi

Correct
+3.3V

Rpi
Voltage and current can damage Rpi
GPIOs are 3.3 volt and NOT
protected from other voltages
Applying 5 volts to a GPIO can cause
permanent damage to the Rpi
When wired correctly – no damage
occurs

Rpi GPIO max voltage = 3.3v

Rpi GPIO max current = 16ma (0.016)
GPIO

Rpi all GPIOs max current = 50ma
7
Pulse Width Modulator
PWM used for controlling the servo motor
8
Servo Motors
PID (Proportional Integral Differentiator)
9
Servo Motor Specs
Parameter
Tower Pro SG51r
Tower Pro SG-5010
Stall Torque
@4.8v, 8.3 oz-in1
@4.8v, 76.4 oz-in
Speed
@4.8v, 0.08sec/60°2
@4.8v, 0.19sec/60°
Price
$5
$5
Availability
good
good
Surge current3
660ma @ 5.2v
2.2 amps @ 5.2v
Voltage Droop4
3.9v
3.3v
Voltage Droop5
4.8v
4.6v
1. 1” away from center line 8.3 ounces of force. The closer to the shaft the
more force is applied but the travel distance is less.
2. Takes 80 milliseconds to move 60 degrees at 4.8v power source
3. Amps required to move to a new position
4. Long wires (>12”); small gauge (breadboard wires); no filter cap
10
5. Short wires (6”); large gauge (USB charging cable); 1000uf filter cap
180 degree servo
(aka. Standard Servo)
1. Type A:
1) Wire colors: Brown (GND), Orange (+5v
power), Yellow (PWM signal)
2) 500us -> 2500us = counter-clockwise
rotation
2. Type B:
1) Wire colors: Black (GND), Red (+5v
power), Yellow (PWM signal)
2) 500us -> 2500us = clockwise rotation
11
Continuous Rotation
servo
1. Wire colors: Black (GND), Red (+5v
power), White (PWM signal)
2. 1000us = maximum speed clockwise
rotation
3. 1500us = stopped
4. 2000us = maximum speed counterclockwise rotation
12
Custom Servo Motor
cable
PWM signal
connection
1000uf
capacitor
USB Charging
cable
Servo motor
13
Wiring up the servo
1. Power off the Raspberry Pi
2. Wire breadboard
3. Connect servo
4. Power on servo and Rpi
14
Three approaches to
controlling the servo
1. Direct from 3.3v GPIO
2. Using the Adafruit I2C safe level shifter
3. Using the Adafruit 8 channel level shifter
Advantage
3.3V GPIO
I2C Safe
8 Channel
1. Simple
2. Cheap
3. No soldering
1. Can be used for
both servo and
sensors
2. Fits on GPIO
breakout
breadboard
1. 8 channels
2. No pullups needed
3. Smaller footprint than
two I2C safe devices
1. Only 4 channels
2. Requires pull ups
1. Does not support I2C
interface
2. Additional breadboard
needed
15
Disadvantage 1. Unreliable long term
2. Does not protect the
RPi output from
higher voltages
Cost
$0.05
$4
$8
Servo Motor
Schematic (I2C safe)
Use a separate power source for the servo
Reason: when the motor moves, it causes a spike
on the +5v power line
16
Using 3.3 volt GPIO
output
Custom
Servo cable
Servo motor
GPIO 18
Series resistor
(3.9k approx)
RPi GPIO
Breakout
breadboard
17
Using Adafruit 8
channel level shifter
Servo cable
Servo motor
3.3v to 5v
Level shifter
(8ch version)
RPi GPIO
Breakout
breadboard
18
Verify

Have someone else verify your wiring to
make sure you don’t damage your Rpi when
you turn it on
19
Turn On Rpi

Connect monitor, mouse, and keyboard

Turn on power and boot the Rpi

Login and startx, open file mgr

Create a projects directory

Connect to internet or use thumb drive


Hover over the “projects” directory and
“open terminal window”
Enter “git clone
http://github.com/griffegg/servo_motors”
20
Run the program




Enter “cd servo_motors”
Enter “chmod +x servo-slider.py” to make it
executable.
Enter “sudo ./servo-slider.py”
Use mouse to move slider, observe servo
motor moving
21
DMA Controller
Direct Memory Access (DMA)
• Hardware used to perform memory
transfers to/from memory or peripherals
independent from CPU operation
• Very fast data transfers which are not
interrupted by the CPU
• 16 DMA channels
22
Using the DMA engine
to control the servo
joan2937 commented a day ago
@Vijayenthiran servoblaster and pi-blaster
(and my pigpio) have been updated to
work on the Pi2. The servoblaster github
repository has not been updated. You
can find a link to the updated software by
searching for servoblaster on the
rasperrypi.org forums.
23
Using the DMA engine

This program does not use the DMA engine

Observe how the servo motor jitters

Use Servoblaster, pi-blaster, or pigpio to
implement the DMA servo controller
24
Switch to Continuous
Rotation servo


Unplug the 180 degree servo and plug in the
continuous rotation servo
Observe the different behavior
25
Questions ?

Done!
26