Analog Feedback Servos Created by Bill Earl Last updated on 2013-08-30 11:30:20 AM EDT
Guide Contents Guide Contents 2 About Servos and Feedback 3 What is a Servo? 3 Open and Closed Loops 3 Using Feedback 6 Reading the feedback 7 Calibrating the feedback 7 Using feedback in your code 8 Seeking to a position 8 Finding out where you are 9 Servos as Input Devices To run the Servo Record/Play Demo Sketch: © Adafruit Industries http://learn.adafruit.
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.
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.
The Feedback Servos allow you to close this outer loop by providing the feedback signal to the microcontroller too! © Adafruit Industries http://learn.adafruit.
Using Feedback If a servo mo to r do es what it is to ld 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.
Reading the feedback The feedback signal is tapped off the position pot attached to the servo shaft. You can connect the white feedback wire to any of the analog input pins and read the feedback value using analogRead(). int feedback = analogRead(feedbackPin); Calibrating the feedback The raw feedback signal is a voltage. In order to convert that voltage into a meaningful position, we need to calibrate it to the servo.
int maxFeedback; int tolerance = 2; // max feedback measurement error /* This function establishes the feedback values for 2 positions of the servo. With this information, we can interpolate feedback values for intermediate positions */ void calibrate(Servo servo, int analogPin, int minPos, int maxPos) { // Move to the minimum position and record the feedback value servo.
while(abs(analogRead(analogPin) - target) > tolerance){} // wait... } Finding out where you are Another great thing about feedback is: You don't need to write code to remember the last position command you sent to the servo (assuming it got there).
Servos as Input Devices Another neat feature of feedback servos is that they can be used as an input device too! The Servo Record/Play Demo lets you record a series of servo movements, then it will replay them back for you! The recorded positions are saved in EEPROM, so they will be remembered even after resetting or powering down the Arduino To run this demo, first wire up your Servo as in the Fritzing diagram below: Co mpo nents used: Arduino Uno (http://adafru.it/50) Feedback Servo (http://adafru.
Next, download the example sketch from Github using this button: Download Servo Record/Play Demo Sketch http://adafru.it/cCE To run the Servo Record/Play Demo Sketch: 1. 2. 3. 4. 5. 6. Upload servo_recordplay to the arduino press the top button to start recording. (The LED should light up.) Press the top button once more to stop recording. Press the bottom button to replay. You can press the green button as many times as you want. To record a new sequence, go back to step 2.
© Adafruit Industries Last Updated: 2013-08-30 11:30:22 AM EDT Page 12 of 12