Very simply, I am controlling servos (9g micro servos) based on some data read in from elsewhere. Everything works fine except that the servos will constantly "shake." That is, they vibrate back with very subtle movements (with intermittent movements of 1/2 -> 1cm or so).
I tried correcting this issue in software by doing something like:
do{
delay(DTIME);
positionServo();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("X position: ");
lcd.print(xRead);
lcd.setCursor(0,1);
lcd.print("Y position: ");
lcd.print(yRead);
}while( readChange() ); //while there has been change
Where the do-while is necessary initialize the variables that store the mapped servo value (using the arduino servo library.)
The readChange() function is defined as:
int readChange(){
int x_Temp, y_Temp;
x_Temp = map(analogRead(x_axisReadPin), 0, 1023, 0, 179);
y_Temp = map(analogRead(y_axisReadPin), 0, 1023, 0, 179);
if( abs(x_Temp - xRead) < DEG && abs(y_Temp - yRead) < DEG ) return 0; // no change
else return 1; //change
}
Where xRead is the value that was initialized (the first, mapped servo output.)
This really is not a good approach. It requires that BOTH values must not have changed by a factor of DEG (~10 degrees, or ~0.28V in my case.) If I write the function such that either OR be less than DEG, then what if I was only changing one servo at a time? So there is a delimma.
Is this simply a property of servos (perhaps cheap ones?) or is there a workaround?
It would be much simpler to include a pastie link. Here is the full code.
I have attached two servos together with a laser pointer to allow for two degrees of freedom (X, Y.) There are options, based on the state of several buttons, to control the servos in various ways. The first is "Motion" where I have two photoresistors that, based on the amount of light exposure, affect the position of the servos. I have not yet implemented the code to control the servos by an Xbox controller. The third option is just randomized movement.