Analog Feedback Servos
Created by Bill Earl
Last updated on 2018-08-22 03:37:00 PM UTC
Guide Contents
Guide Contents
About Servos and Feedback
What is a Servo?
Open and Closed Loops
Using Feedback
Reading the feedback
Calibrating the feedback
Using feedback in your code
Seeking to a position
Finding out where you are
2
3
3
3
5
6
6
7
7
8
Servos as Input Devices
To run the Servo Record/Play Demo Sketch:
9
12
© Adafruit Industries
https://learn.adafruit.com/analog-feedback-servos
Page 2 of 12
About Servos and Feedback
What is a Servo?
The word 'servo' means more than just those little RC Servo Motors we usually think of. Servo is a general term for a
closed loop control system using negative feedback.
The cruise control in a car is one example of a servo system. It measures your speed and feeds that back into a control
circuit which adjusts the accelerator to maintain speed.
For the familiar RC Servo motor, the position of the output shaft is measured and fed back to the internal control circuit
which adjusts current to the motor to maintain position.
Open and Closed Loops
An "Open Loop" system has no feedback, so there is no way to verify that it is performing as expected. A common
expression among control engineers is "You can't control what you can't measure.".
A "Closed Loop" system can use the feedback signal to adjust the speed and direction of the motor to achieve the
desired result. In the case of an RC servo motor, the feedback is in the form of a potentiometer (pot) connected to the
output shaft of the motor. The output of the pot is proportional to the position of the servo shaft.
© Adafruit Industries
https://learn.adafruit.com/analog-feedback-servos
Page 3 of 12
The problem with controlling a standard RC servo motor from a microcontroller is that it is 'closed loop' inside the
servo motor case, but 'open loop' with respect to your microcontroller. You can tell the servo control circuit how you
want the shaft positioned, but you have no way to confirm if or when this actually happens.
The Feedback Servos allow you to close this outer loop by providing the feedback signal to the microcontroller too!
© Adafruit Industries
https://learn.adafruit.com/analog-feedback-servos
Page 4 of 12
Using Feedback
If a servo motor does what it is told to do, why do we need feedback?
RC servos
usually
do what they are told to do, but there are many cases where a servo motor
might not
. These can
include:
Insufficient motor size
Insufficient power supply
Physical interference
Electrical interference
loose connection
In these cases, feedback could alert you to the problem.
But even if the servo is adequately sized and functioning normally, it still takes some time to respond to a position
command, and in many applications it is just as important to know
when
the position is reached.
This following code snippet is from the "Sweep" example in the Servo library. Note the arbitrary 15 millisecond delay
after
"myservo.write(val)".
void loop()
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
myservo.write(val);
delay(15);
}
//
//
//
//
reads the value of the potentiometer (value between 0 and 1023)
scale it to use it with the servo (value between 0 and 180)
sets the servo position according to the scaled value
waits for the servo to get there
Without feedback, most servo programming has to make some assumptions about how long a particular move will
take. Adding fixed-time delays to servo code works OK for simple applications, but can result in slow and/or jerky
performance when trying to coordinate multiple servo motions or interactions between servos and other sensors or
actuators.
Or worse: If the delays are not long enough, your servos may not reach the desired position in time. This can cause
malfunctions and/or damage to your project. Timing problems are a big problem in battery-powered projects because
the motors will run slower as the battery power fades.
© Adafruit Industries
https://learn.adafruit.com/analog-feedback-servos
Page 5 of 12