Electronic – arduino – smooth a motor movement

arduinomovementstepper motor

i have a stepper motor (controlled by an arduino) that moves some gears and a pulley. the problem is that the pulley jerks a lot: the movement begin and stop too much suddenly. to make the movement more fluid i think i can use a kind of ramp: the first movement are slow, when the motors has reached the velocity it keep going on, then smoothly slow down.

i have tried to use a sine wave in this way:

// generate ramp
float t = 0;
float deltat = PI/(200+1)
for(int i=0; i<200; i++) {
    ramp[i] = 1000 - sin(t)*900;
    t += deltat;
}

now i have a ramp of 200 elements that goes from 1000 (very slow) to 100 (very fast) following a sinus wave. now i move the motor with this code:

for(int i=0; i<200; i++) {
    int delay_velocity = ramp[i];

    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(delay_velocity); 

    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(delay_velocity);
}

this works quite fine: the pulley does not jerk so much and i have control on how many steps to do.

but this work around has also problems:

  • i can't make ramps very long (due to overflow in atmega) – say an array no more longer than 400 elements more or less (it depends on how long is the arduino sketch)
  • i have control on how many steps but i have no idea on how many time it takes to get it completed (i think i can calculate it with some summation or integral but it is not so practical)

so i'm looking for some other way to smooth my movement. i think i can have a different curve instead of a sinewave. something more like this?

enter image description here

till now i don't have considered to generate the ramp in a computer and then pass it to arduino but could be a possibility.

some advice? thoughts?

Best Answer

What you're looking for is called a Trapezoidal velocity profile.

Trapezoidal velocity profile

There is no need to use sin waves. Smooth motion can be achieved by simply linearly ramping up the velocity to its maximum, holding it there, then letting it ramp down again. Many CNC milling machines and robots use this type of profile.

If you want super smooth motion, you can go for an S-Curve profile.

S-Curve profile

The maths for this is considerably harder, but the motion is beautiful. In this video they show how the two motion profiles affect a glass of water.