I have found the repeatability is good but the accuracy is a bit variable and the second unit seems better than the first although the first I did not test as well.
I have a setup with two Adafruit V2.2 motor shields stacked on a Uno and am using the servo outputs built into the top shield - pin 9 and feedback A1. I suppose I should check the other output and see what result I get.
Results from 2 tests angles programed = 5 30 60 90 120 175 using code based on the servo example on your site attached below.
Calibrated between 5 and 175
5 32 62 91 118 168
5 32 62 91 118 168
Variation
0 +2 +2 +1 -2 -7
As I understand it the code should freeze if the position is out by 2 deg on the wait line but that is not working.
For some reason I am not getting any return from the serial monitor at the moment and may have altered something incorrectly in the code.
Code: Select all
// https://learn.adafruit.com/analog-feedback-servos/using-feedback
// This code runs a calibration function on startup and has a angle hardcoded.
// Using PWM pin 9 and feedback on pin A1
// The two servo outputs on the UNO board are wired to pins 9 & 10 so they can not be used for anything else.
// The servo is using the power supply from the arduino without an external supply.
#include <Servo.h>
Servo myservo;
// Control and feedback pins
int servoPin = 9;
int feedbackPin = A1;
// Calibration values
int minDegrees;
int maxDegrees;
int minFeedback;
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.write(minPos);
minDegrees = minPos;
delay(2000); // make sure it has time to get there and settle
minFeedback = analogRead(analogPin);
// Move to the maximum position and record the feedback value
servo.write(maxPos);
maxDegrees = maxPos;
delay(2000); // make sure it has time to get there and settle
maxFeedback = analogRead(analogPin);
}
void setup()
{
Serial.begin(9600);
myservo.attach(servoPin);
Serial.println("Claibrating");
calibrate(myservo, feedbackPin, 5, 175); // calibrate for the 5-175 degree range
Serial.println("Claibrated");
}
void loop()
{
// Seeking to a position
Serial.println();
Seek(myservo, feedbackPin, 5);
Serial.println("Servo seek angle = 5");
delay(1000);
// Display servo position
Serial.print("Servo angle = ");
Serial.println(getPos(feedbackPin));
delay(10000);
// Seeking to a position
Serial.println();
Seek(myservo, feedbackPin, 30);
Serial.println("Servo seek angle = 30");
delay(1000);
// Display servo position
Serial.print("Servo angle = ");
Serial.println(getPos(feedbackPin));
delay(10000);
// Seeking to a position
Serial.println();
Seek(myservo, feedbackPin, 60);
Serial.println("Servo seek angle = 60");
delay(1000);
// Display servo position
Serial.print("Servo angle = ");
Serial.println(getPos(feedbackPin));
delay(10000);
// Seeking to a position
Serial.println();
Seek(myservo, feedbackPin, 90);
Serial.println("Servo seek angle = 90");
delay(1000);
// Display servo position
Serial.print("Servo angle = ");
Serial.println(getPos(feedbackPin));
delay(10000);
// Seeking to a position
Serial.println();
Seek(myservo, feedbackPin, 120);
Serial.println("Servo seek angle = 120");
delay(1000);
// Display servo position
Serial.print("Servo angle = ");
Serial.println(getPos(feedbackPin));
delay(10000);
// Seeking to a position
Serial.println();
Seek(myservo, feedbackPin, 175);
Serial.println("Servo seek angle = 175");
delay(1000);
// Display servo position
Serial.print("Servo angle = ");
Serial.println(getPos(feedbackPin));
delay(10000);
}
int getPos(int analogPin)
{
return map(analogRead(analogPin), minFeedback, maxFeedback, minDegrees, maxDegrees);
}
void Seek(Servo servo, int analogPin, int pos)
{
// Start the move...
servo.write(pos);
// Calculate the target feedback value for the final position
int target = map(pos, minDegrees, maxDegrees, minFeedback, maxFeedback);
// Wait until it reaches the target
while(abs(analogRead(analogPin) - target) > tolerance){} // wait...
}