# Problem Running Simultaneous Stepper Motors at Different speeds and acceleration

I am doing a project where a robot has to make it to 2 buckets and drop off a load. The course is in an L- shape so there are multiple turns and it is a test of speed. To do this I am using an Arduino Uno, 2 QMOT QSH4218 stepper motors with 2 G251 Step motor drivers. I have the task of accelerating both motors at the same time with different speeds and acceleration to provide a smooth S-shaped turn. While doing this I also need to operate 4 different DC motors which just uses digitalWrite to control. I have looked into the accelstepper library and many forum posts but can't seem to find the solution. I am reasonably new to Arduino and would like to know if anyone has any suggestions on how to do this task. Any advice would be much appreciated.

Thanks

It is quite easy to run stepping motors at different speeds. Take the number of steps you want the motors to make and divide the smallest one by the biggest one. This will give you an increment ( less than 1 ). Each time you step the motor with the biggest number, add to a variable this incremented value. When the variable exceeds a value of 1, then step the slower motor and subtract one from the variable.

The speed of both motors is controlled by how fast you step the motors. If this is constantly changing you get acceleration / deceleration.

jam4291:
I have the task of accelerating both motors at the same time with different speeds and acceleration to provide a smooth S-shaped turn.

Does that mean that you want separate speeds and separate accelerations for each motor? I believe the scheme proposed by @Grumpy_Mike would link the speeds and the accelerations.

OR, are you really asking a more general question "what do i need to do to get a smooth S-shaped turn"?

...R

I believe the scheme proposed by @Grumpy_Mike would link the speeds and the accelerations.

Yes it would.

But if they are not linked then just think what the searing would be like during acceleration.

I note you said:-

I have the task of accelerating both motors at the same time with different speeds and acceleration to provide a smooth S-shaped turn.

But think about it, that is not the way you get smooth movement.

Maybe you meant to say:-
I have the task of accelerating both motors at the same time with different speeds to provide a smooth S-shaped turn.

Grumpy_Mike:
Maybe you meant to say:-
I have the task of accelerating both motors at the same time with different speeds to provide a smooth S-shaped turn.

This is what I meant, Thanks for clarifying. I am currently trying to use accelstepper which allows me to set different speeds and run the two steppers at the same time. I am planning to change the speeds with multiple equations (which I have not got yet) and multiple if statements which change with respect to time. Here is an example of what I am trying to do.

`````` if (t<ta) {                                       // Acceleration
dly1 = equation1;
dly2 = =equation2;
}
else if (t>=ta && t<(ta+tconst)){                    // Constant velocity
dly1 = const_vel;
dly2 = const_vel;
}
else if (t>=(ta+tconst) && t<(ta+tconst+td)){          // Deceleration
dly = equation4;
dly2 = equation4;
}

t = t+2*dly; // update the current time

for (int n = 0 ; n < 12000; n++){
Left.setSpeed(dly1);
Right.setSpeed(dly2);
Right.runSpeed();
Left.runSpeed();
}
``````

What are your thoughts on this idea and do you think there is an easier way?

This is not how runSpeed() should be used

``````for (int n = 0 ; n < 12000; n++){
Left.setSpeed(dly1);
Right.setSpeed(dly2);
Right.runSpeed();
Left.runSpeed();
}
``````

Just completely remove the FOR code.

Also, runSpeed() does NOT use acceleration. You need to use run() if you want acceleration.

And you should only set the speed and acceleration at the start of the move, not during it.

…R

Robin2:
Also, runSpeed() does NOT use acceleration. You need to use run() if you want acceleration.

And you should only set the speed and acceleration at the start of the move, not during it.

Thanks for that, I had no idea. I have tried to use accelstepper by setting the acceleration and the max speed but the motors do not go as fast as I would like and I am not too sure why because when I used digitalWrite they went more than double the speed. Also, another approach to the problem would be of great help as everything I am trying at the moment is just turning to shambles.

Thanks

jam4291:
Thanks for that, I had no idea. I have tried to use accelstepper by setting the acceleration and the max speed but the motors do not go as fast as I would like and I am not too sure why because when I used digitalWrite they went more than double the speed. Also, another approach to the problem would be of great help as everything I am trying at the moment is just turning to shambles.

Start by learning how the AccelStepper library works with a single motor using some of the AccelStepper examples.

…R