Hi guys
I'm working on controlling the orientation of an object using servo motors. I'm using 3 Tower pro micro servos to test my code before investing in some servos with some more torque. The problem I have is that not all of the servos power up and move to the commanded positions.
Tests I have completed to try and sort out the problem:
-I have checked that the servos are working and not damaged.
-I have checked enough current is being supplied to the servos from my power supply, it can turn all the servos without them being slow or lagging.
-I have checked all the wired connections between the Arduino, power supply and servos.
-I have checked that the values being given to the servos to position them fall between 0 and 180.
-I have tried my code and setup on a Mega 1280 and a Duemilanove 328, both are Seeeduino clones but I have never had any issues with them. I have tried to attach the servos to different PWM pins but no difference.
-Finally I have used the 'attached()' command in the servo library to test if the servos are attached (returns bool), the servos that move return true but the servo that doesn't move returns false.
The code for each servo is exactly the same so I can not understand why they would work differently. I've Included the parts of the code that the servos are affected by below.
void setup() {
myservo1.attach(3);
myservo2.attach(12);
myservo3.attach(11);
}
void loop() {
servocontrol()
}
void servocontrol() {
on = myservo1.attached();
if (on == true) {
digitalWrite(7, HIGH);
}
float pos1 = (ypr[2] * 180/M_PI) + 90; // Pitch
float pos2 = (ypr[0] * 180/M_PI) + 90; // Yaw
float pos3 = (ypr[1] * 180/M_PI) + 90; // Roll
myservo1.write(pos1); // Pitch
myservo2.write(pos2); // Yaw
myservo3.write(pos3); // Roll
delay(10);
}
Any suggestion of what could be wrong and how to solve it would be greatly appreciated.