• Non ci sono risultati.

30- SERVOS WITH ARDUINO SLIDES

N/A
N/A
Protected

Academic year: 2021

Condividi "30- SERVOS WITH ARDUINO SLIDES"

Copied!
13
0
0

Testo completo

(1)

Using servos with an Arduino

(2)

Learning Objectives

•  Be able to identify characteristics that distinguish

a servo and a DC motor

•  Be able to describe the difference a conventional

servo and a continuous rotation servo

•  Be able to use the Arduino Servo library to

control servo position

(3)

References

Information on Arduino Servo library:

http://www.arduino.cc/en/Reference/Servo

http://www.arduino.cc/playground/Learning/SingleServoExample

Additional descriptions of servos

http://makeprojects.com/Wiki/Servos

(4)

What is a servo?

A servo-motor is an actuator with a built-in

feedback mechanism that responds to a control

signal by moving to and holding a position, or by

moving at a continuous speed.

(5)

DC Motors and Servos

DC Motor

•  Motion is continuous

•  Speed controlled by

applied voltage

Servo

•  Capable of holding a

position

•  Speed controlled by delay

between position updates

•  Hybrid of motor, gears

(6)

Conventional and Continuous Rotation

Two types of servos

continuous rotation

pulse tells servo

which way to spin & how fast to spin

pulse tells servo

which position to hold

standard

can only rotate 180 degrees

can rotate all the way around in either direction

(7)

Control signal is a pulse train

20 ms constant pulse timing

1 ms = pulse width

1 ms

1.5 ms

2 ms

Pulse frequency is fixed

Typical: 20 ms

Pulse width determines position

Typical: 1ms to 2 ms

(8)

Servo components

1.

Small

DC motor

2.

Gearbox

with small plastic gears to reduce the RPM and increase output torque

(9)

Servo from the Sparkfun kit

The micro servo from the Sparkfun Inventor’s kit is a

conventional servo, i.e. the control signal results in moving

the shaft to an angular position.

Red: Power (5V)

Black: Ground

White: Control signal

(Arduino pin 9 or 10)

(10)

Arduino Servo library handles the details

•  Must connect servos on pin 9 or pin 10

•  From the Aduino web site:

“…use of the library disables analogWrite()

(PWM) functionality on pins 9 and 10, whether

or not there is a Servo on those pins”

(11)

•  Three components of the Servo Library

–  Create the servo object

Servo my_servo_object;!

–  Attach the object

my_servo_object.attach(servo_pin);!

–  Send control signal

my_servo_object.write(pos);!

Arduino Servo library handles the details

Name of the object is like

a variable name.

attach

and

write

are

pre-defined methods that

act on the servo object.

(12)

Modified version of the sweep function

// File: sweep_variable_wait!

// !

// Modified version of Sweep by BARRAGAN <http://barraganstudio.com> ! // Use variable dtwait to make the speed of sweep aparent!

!

#include <Servo.h> // Make code in Servo.h available to this sketch ! !

Servo myservo; // Create servo object called "myservo" !

int servo_pin=9; // The servo must be attached to pin 9 or pin 10 ! !

void setup() ! { !

myservo.attach(servo_pin); // attaches the servo pin to myservo object ! } !

!

void loop() ! { !

int pos = 0; // variable to store the servo position ! int dtwait=15; // duration of wait at the end of each step! !

for(pos = 0; pos < 180; pos += 1) { !

myservo.write(pos); // Move to position in variable 'pos' !

delay(dtwait); // wait dtwait for the servo to reach the position ! } !

for(pos = 180; pos>=1; pos -= 1) { !

myservo.write(pos); // Move to position in variable 'pos' !

delay(dtwait); // wait dtwait for the servo to reach the position ! } !

(13)

Experiment

•  What happens when you adjust dtwait?

•  Can adjust the sweep angle?

–  Make new variable to define end angle of the loop

•  Open the Knob demo from the Arduino IDE

–  Connect a potentiometer to an analog input

Riferimenti

Documenti correlati

At both developmental stages, morphants showed abnormalities in the brain region, presence of hydrocephalus (*) and heart edema (≠) (D), severe perturbation of main vessels

La valutazione terr` a conto sia della correttezza che della completezza delle argomentazioni esposte a sostegno del risultato riportato. Il solo risultato numerico otterr` a

Starting from these data and with the aim of designing a continuous process addressing the most quantitatively relevant water flows, the target recovery and purification plant flow

“Transrectal doppler sonography of uterine blood flow during early pregnancy in mares“, Theriogenology 60:597-605, 2003a.. “Transrectal doppler sonography of uterine blood flow in

Due rette parallele ad un medesimo piano possono essere parallele (se esiste un piano che le contiene e non hanno punti in comune), oppure incidenti (se hanno un punto in comune),

La condizione che il punto in cui si calcola il limite di una funzione sia un punto di accumulazione è necessaria perché il limite esista, ma non è sufficiente.. Ad esempio, per x0,

Il grafico della funzione inversa è il simmetrico di quello di f rispetto alla bisettrice del primo e terzo quadrante: essendo f simmetrica rispetto a tale retta il grafico della sua

Il romanzo ha un impianto interessante, un narratore estraneo alla vicenda racconta i fatti, offrendo prima di tutto una visione generale della storia, per poi passare a evidenziare