Go Down

Topic: Several motors simultaneously - what is the best strategy? (Read 4208 times) previous topic - next topic


Hi all.

I have to control 4 servo motor, simultanously.

The motors has to move in different speeds each one.

So, I don't know what would be the best strategy for deal with it... since the different speeds implies in different 'delay' values... but at the same time all the motors has to move together.

Any idea?

I've started an software to do serial communication (send position, what motor, etc) and the Arduino would be in charge only with the most basic job (evalutate the data and turn the motor). But I've realized that: if I have to send a single bunch of data to do a movement... I can't move several motors simultanously... or, maybe, I have to send a chain of data but each chunk should be so small (to make everything works like simultanously) that the overal speed (prepare data, send via USB cable, be interpreted, etc) probably would be too slow (and so my project ruined).

I thought using an single Arduino for each motor would be a better idea... but... 4 USB ports... 4 Arduinos, syncronize everything, etc... doesn't seem to be a good idea.

Brazil - Rio de Janeiro


You can't directly control the speed of servo motors. All you can do is give them repeated small position changes.
You can do this for many motors at the same time if you use the technique in the blink without delay example you find in your IDE.


Also read this page on the Rugged Motor Shield. He gives instructions on how to stack multiple shields as well as giving link to a library which allows the simultaneous control of multiple motors of varied speeds.


instructions on how to stack multiple shields

Yes but you don't need a motor shield for driving a servo, just a controlling pulse train. So no great current to drive, it can be connected directly to an I/O pin.


Well first you have to decide if you using modified 'continuous rotation' servos or standard servos. The first are easier if you just need to control the speed of your servos and require no precise position control.


Are you dealing with Hobby Servos, which use PWM for positioning control and do not have speed control, or Servos as in brushless DC motors with encoder feedback?

Since you talk about speed control, I'm pretty sure you can't be talking about Hobby servos - or, at least, hobby servos are a poor choice for your application whereas a standard DC brushed motor, stepper, or brushless servo is a better choice.  (A continuous rotation modified hobby servo might as well be a brushed DC motor optimized for torque->size.)

If you're using PWM drivers for dc brushed motors, you can simply analogWrite() the speeds to your PWM output pins, and they'll all move at different rates...  If you modify both the period and the duty cycle, you can achieve lower speeds (measured over a longer time) by increasing the period, with the resulting "rougher" movement than typical PWM, which never sees the motor come to a complete stop.  You can roll your own, or perhaps use one of the PWM libraries of late that let you control both the period and duty cycle.



I have to control 4 servo motor, simultanously.

The motors has to move in different speeds each one.

So, I don't know what would be the best strategy for deal with it... since the different speeds implies in different 'delay' values... but at the same time all the motors has to move together.

If you are talking about standard servos that only move ~180 deg, you will need to look at the "sweep" servo example as a way to change the rotation speed. Sometime back a person posted a library that allowed control of servo rotation speed. Operating several servos at the same time would probably not work with using any "delay" in the code.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Ok folks,

Thank you for the help!

Anyway, the motors are standard servor motors.

I have to control de speed -> and <- the forward/backward movement.

So, it will be 3 standard servo motors where sometimes one will do movements back and forth while another one will do a single forward slow movement, the third an slower backward movement, etc, in fact there isn't a predicted movement but a single bunch of "you three go and do this choreography".

I guess I have the solution:

Arduino software will receive a array with "positions", like (of course it's an simple example):

motor_1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
motor_2 = [ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10  ]
motor_3 = [ 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 ]

I don't know exactly how to deal with this idea, but seems fair that the slower motor has "more turns" to do.

Considering a small delay time, probably the gap will never be really noticed.

And I can use specific amount of positions and speeds, I mean, I can consider only 8 different end positions and 6 different speeds, so that I have the size of the loop and the array well defined.

I don't know, I have to try it.

It's more complex than I would like, but I guess moving 3 motors independently would be complex any way.

So, any different idea would be nice.

Rio de Janeiro


My code supports scripting for servos and steppers.  The format is the same for both.  They can even run simultaneously with little additional hardware just ULN2003.  See the long post in this category.  You fill an array with motor speeds.  Each element is active for 70ms by default.  Using Excel you can generate this script to move to your desired positions, at the speed you want.  Questions?


I'm a little confused. With a standard servo using the servo library you send it only position commands, not speed commands. If the servo is at one end of travel and you give it a single command to go to the other end position the servo will move at fastest it can move but not under any software command. Now you can slow a servo down by issuing smaller position steps and delay between issuing each new step to the final position desired. Just think the words position and speed may be getting mixed up, or maybe not. Time for pizza  ;)



I understand how the standard servo library works.  I wish I could make a video tonight to show you.  It works just how you described.  Each step is 70ms time by default.  My function tells the servo/stepper how 1/far to move each 70ms.  This is the 1/speed also.  It is easy to convert the standard servo library commands to my format using Excel.  Here is an example of the array (script) for servos.


This tells the servo to move at speed (distance too!) - 1/100 for 140ms, then 1/200 for 140ms, then 1/100 for 70ms.

In the case of a stepper in uses the "speed" as the delay between steps.  It's actually 1/speed.
The observed output appears exactly the same for a servo or stepper, you can't tell the difference.
Unless you try to move the servo too fast.


Go Up