Nonlinear Acceleration

272 views
Skip to first unread message

Dan Bridavsky

unread,
Nov 4, 2020, 9:01:49 AM11/4/20
to accelstepper
Hello,

Can AccelStepper handle nonlinear accelerations? I need a sinusoidal speed profile for a project I'm working on. Here's the link to a Stack Exchange question I posted last week. I've read through the documentation multiple times and non-linear acceleration only appears in the context of an error, and only once at that. 

Thanks for you time in advance!

gjgsm...@gmail.com

unread,
Nov 4, 2020, 8:56:18 PM11/4/20
to accelstepper
Hi Dan,

Have a look at - my relevant previous posts... - which will hopefully assist with running steppers to their targets using accelstepper.

With regard to your desired 'sinusoidal speed profile' I don't have a definitive answer (someone else might) but I have a sorta 'workaround' which you may be able to play around with... 

Once the relevant stepper targets variables have been established, Accelstepper will run the stepper at the defined acceleration level until it reaches the ‘set’ maxSpeed and hold that 'speed' there until it calculates when to start deceleration to reach the target at zero speed.

If you increase the setMaxSpeed() to a higher, unattainable level, the stepper will then accelerate up to the 'target' halfway point and then immediately decelerate smoothly down to zero speed on reaching the target. It should be possible to then control the period of the sinusoidal movement by varying the ‘setAcceleration()’ variable. This would most likely need to be done prior to the move starting.

Of course, if the MCU and driver have the capacity, it is possible to increase the acceleration so that the maxSpeed is obtained. You will have to judge the max acceleration you can use before you hit the maxSpeed setting which you are trying to avoid.

Cheers

Geoff

Mike McCauley

unread,
Nov 4, 2020, 10:07:35 PM11/4/20
to accelstepper, Dan Bridavsky
Hi,

AccelStepper only supports linear acceleration, or no acceleration.

Cheers.

On Thursday, 5 November 2020 00:01:48 AEST Dan Bridavsky wrote:
> Hello,
>
> Can AccelStepper handle nonlinear accelerations? I need a sinusoidal speed
> profile for a project I'm working on. Here's the link
> <https://arduino.stackexchange.com/questions/78889/can-accelstepper-accelera
> te-non-linearly> to a Stack Exchange question I posted last week. I've read
> through the documentation multiple times and non-linear acceleration only
> appears in the context of an error, and only once at that.
>
> Thanks for you time in advance!


--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com 5R3MRFM2+X6
Phone +61 7 5598-7474



Dan Bridavsky

unread,
Nov 6, 2020, 9:20:50 AM11/6/20
to accelstepper
Thanks for the suggestion Geoff! It seems it'll be easier for me to just use AccelStepper to initialize the connection to the driver and from there use a simple on-off signal at varying time intervals, which I have gotten to work since posting this question. Regardless, I think I'll try your method just to see how it works!

Dan

Dan Bridavsky

unread,
Nov 6, 2020, 9:27:39 AM11/6/20
to accelstepper
Mike,

Thanks for your reply - I had my doubts that it was possible, but I figured you might be the only one who could give me a solid answer. As I said in my reply to Geoff, I've since made a program which calculates the time interval between pulses and simply uses on-off signals to move the stepper. Just in hopes that someone will later search for this same answer and find it of use, I'll post my code:

#include <AccelStepper.h>

/* Using a stepper motor,
  rotate a vibrational model using gears interconnected by springs
  in such a way as to induce torsional vibration, which should be visible by comparing
  movement of juxtaposed rotating gears with markers painted on. */

AccelStepper stepper(AccelStepper::DRIVER);
void setEnablePin(int enablePin = 8);



float spd;
float SPS = 25000;
float Amp = 24000;
int dirpin = 2;
int pulpin = 1;

void setup() {
//Serial.begin(9600);

pinMode(dirpin, OUTPUT);
pinMode(pulpin, OUTPUT);
}
void loop()
{
//float SPS = analogRead(0) * 20;
//float Amp = analogRead(1) * 10;
//float Freq = analogRead(2);

  spd = SPS + (Amp*sin(micros()*.00001));
  int t = 1000000/spd;

  digitalWrite(dirpin, LOW);     // Set the direction.
  delayMicroseconds(t);

//Serial.println(">>");
digitalWrite(pulpin, LOW);  
    delayMicroseconds(t);
digitalWrite(pulpin, HIGH); 
    delayMicroseconds(t);      

//Serial.print("t = ");
//Serial.println(t);
}

Cheers

Dan

Nilson Pour

unread,
Jan 7, 2021, 8:19:24 PMJan 7
to accelstepper
Hi Dan,

Thank you for sharing your code. I am quite new in programming and working with steppers, and I was hoping to find a code for non-linear acceleration. I need to modify the amplitude in my project but I don't know what is the unit for amplitude in your code. Is it in steps? And what is SPS in your code? I realized that if I remove it from spd equation, speed is not sinusoidal anymore. Could you please explain how did you calculate the value for SPS?

Thank you very much in advance for any help you can provide.

Nilson
Reply all
Reply to author
Forward
0 new messages