Simultaneous Servo Control Issues


#1

Hi, I’m driving two MG91 servo’s from a Makeblock RJ25 adapter off of a port on my Me Orion board. The servo’s work fine, however if I try to drive them simultaneously to the same position there seems to be unreliable results. About 50% of the time the servo’s act as expected and both rotate at the same time. The other 50% Slot 2 servo will stop… lag… then try to catch up.

Is this a limitation of running two servo’s off one port? Or are my Servo’s defective?

Here’s an example of my code.

void loop()
{
myservo1.write(168); // sets the servo position according to the scaled value
myservo2.write(168); // sets the servo position according to the scaled value
delay(3000); // waits for the servo to get there
myservo1.write(15);
myservo2.write(15);
delay(3000);
}


#2

IMHO you have to wait for the servo motor to travel to the requested point thus have to wait after you write the command to the servo before you change the next servo


#3

I think Dave-Dillon wants both servos to move at the same time. If you put a delay between them then one will move stop and then the other will move.
I haven’t tried this with the MakeBlock servos but my experience with other robotic platforms is that using time as a control is fraught with inaccuracies.
Would you be better to use a variable to set the position of your servos eg the 168 and then use a Pre-or post test loop While or Repeat Until structure to wait for the servos to reach your desired position.
This will also mean that you are getting your servos to the exact position you desire rather than the time related position which will vary depending on the power being supplied ie fully or partly charged batteries.

eg
set servo_pos = 168
While servo-pos < 300 //300 being the target servo position
myservo1.write(amount);
myservo2.write(amount);
endWhile

If you still get a difference in movement you may need to move each servo incrementally while testing for the desired end position to be met.


#4

I agree with the comment by Tards57. I haveave been modifying the drive of the mbot to use steppers (the cheap unipolar ones) for the drive motors. It’s critical that both motors run at the same time, and most stepper routines wait for one motor to get to its final position before moving on to the next stepper command to move the other motor.
There are great utube videos about running the two motors simultaneously. Basically you move each motor 1 step at a time, one right after the other, and then put that in a loop like Tards57 suggests and stay in the loop until the end position (168 in his example). You can use his myservo1.write(amount) command setting amount to 1, but its a faster loop if you find a command in the arduino software that moves a single step. onestep() does it in some software, but you probably need to look in the makeblock .cpp file for steppers to find what makeblock is using. Also, in the utube videos, it turns out to be important to put in a short delay in the loop so that the motors have a chance to make the one step before the next one. Something like this:
int servo_pos = 0;
While servo-pos<300 { //the final target position
myservo1.onestep()
myservo2.onestep()
servo_pos++ //increment by +1
delayMicroseconds (1000) //wait a ms for the steps to be made. Try to make this as small as possible
}
endWhile

It’s also possible there is a simpler solution, because Dave-Dillon says sometimes it works and sometimes only one servo runs. For my steppers, this occurs if the power is too low. The steppers need more voltage than the arduino often supplies. Can the stepper drivers be powered with Vin rather than +5V? I even run 8volts to my stepper drivers and only 3.7 or 5 to the arduino. Not sure how makeblock configures its stepper drivers. But at 8 volts, the action is very brisk - torque is betterI h


#5

Model airplane servos like the MG91 expect to receive a signal pulse ranging from 1.0 to 2.0 milliseconds long about 50 times per second. The length of the pulse tells the servo where its output shaft and wheel or arm should be. An internal potentiometer tells the servo where the output is. The internal electronics compares the “where I am” and “where I should be” signals and drives the motor and gear train in the right direction to bring the shaft to the desired position. They cannot move at infinite speed, so it may take a fraction of a second to move from one end of its travel to the other. You don’t have to wait for it to reach the previous position before changing to a new position. Model airplane flyers may be moving the servos almost constantly.

These are not stepper motors and require a different approach to controlling them.

For more information go to http://www.rcmodelreviews.com/howservoswork.shtml .


#6

I solved my issue. I had a couple of things going on. First off my Servo’s only have 150 degree rotation so they could not rotate to my 168 degree write angle.

Second, my power supply wasn’t delivering enough amperage. After I replaced it with a 12V 3A wall wart the servo’s are reacting as expected.

Thanks for everyone’s suggestions.


#7