Hi,

I am using the AccelStepper Library to control three motors. Now I want to synchronize the movement of these stepper motors.

All of the motors have a fixed acceleration and a maximum speed. The distance they have to travel is always different. Now I want to make sure that all the motors start and stop their movement at the same time. Therefor I want to calculate the time how long each of the motors would need to reach their destination. In the next step I want to increase / decrease the maximum speed of motor 2 and motor 3, so they need the same time to reach their destination as motor 1 does.

At the moment I am ignoring the acceleration and just assume that it moves with a constant velocity, but this is just a rough approximation and causes the motors to stop at a slightly different time.

My idea would be, that I need to calculate how long the motors take to reach their maximum speed, calculate how far they move during the acceleration process, then do the same with the deceleration. Now I can check how much distance is left, where the motor will move with a constant velocity, and calculate this time as well. Now I can compare the times and have a more precise time estimation. However, since this is no linear function, I can not simply use a multiplicator to increase / decrease the speed of the other axes. So this seems like a really inefficient solution with a lot of trial and error to get the desired result.

Is there another solution to my problem? A library or maybe a function I am not aware of?

Hi all, i'm Giacinto from Italy and congratulations for this forum.

I have created a similar project, a 3 axis slider with acceleration/deceleration with the AccelStepper library and i had the same problem as you.

I, however, have complicated my life by adding multiple keyframes and I have yet to finish it also because I have provided also a loop function.

However, if you use a start and an end point and (as AccelStepper works) the acceleration is the same as the deceleration, you have to manipulate the formulas of uniformly accelerated rectilinear motion. Even if it is an approximation (stepper motion is not exactly as uniformly accelerated rectilinear motion) I have tested it and it works very fine.

So, the

**total time** for a steppers with a maximum velocity

**v** (AccelStepper.setMaxSpeed(v)), an acceleration

**a** (AccelStepper.setAcceleration(a)) and a total space of

**s** steps (for example

*AccelStepper.targetPosition() - AccelStepper.currentPosition()* calculated before start the movement) is:

`t = (s/v) + (v/a)`

Now you want other steppers to have the same time of one stepper, for example the slider axis, so you use inverse formulas to find the maximum speed and acceleration.

I have simplified a lot using an acceleration twice the maximum speed:

`a = 2v`

So the total time become:

`t = (s/v) + (1/2)`

the maximum speed of other steppers become

`v = s / (t - 1/2)`

and the acceleration of other steppers

`a = 2v`

Note that obviously for other steppers you have to calculate the total travel space.