Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accelerating / decelerating from current speed? #1

Open
philip100 opened this issue Mar 4, 2019 · 10 comments
Open

Accelerating / decelerating from current speed? #1

philip100 opened this issue Mar 4, 2019 · 10 comments
Labels
enhancement New feature or request

Comments

@philip100
Copy link

Hello.

First - a really good piece of math! It helped me a lot

I wonder if if there's any way to use your calculations for accelerating / decelerating from current speed? I cannot seem to find any logic to do that.

Any suggestions?

Kindly,
Artur.

@misan
Copy link
Owner

misan commented Mar 4, 2019

My assumption was to start from zero speed.

But you can change that. Motion command would need then the start speed and calculations would add that value too.

Same if you want the motion not to end at zero speed but at a higher speed.

@philip100
Copy link
Author

philip100 commented Mar 4, 2019

I was trying to do that with arduino, but a real time calculation is too expensive for its processor (so I cannot debug my code reliably). Using arrays is also impossible - 400 long array is not enough to store acceleration at 400 microseconds delay between steps. It would take hundred of thousands entries in the array to accelerate with smooth S-curve at higher stepping rate.

I'm waiting for ESP32 board, and I'll try to find some logic. I just thought you have it already :-)

PS. I'm controlling stepper motor speed via BLE module, and because of the bluetooth communication latency, I have to smooth (PWM-like) acceleration between received speed values.

PS 2. You can mark my question as an "enhancement request" or something, because there's no issue in your code at all :-)

Thanks for reply!

Kindly,
Artur.

@misan
Copy link
Owner

misan commented Mar 4, 2019 via email

@misan
Copy link
Owner

misan commented Mar 5, 2019

@philip100 One detail as I review the code is that using digitalWrite or digitalRead on an Arduino UNO or Mega is painfully slow and that will affect the timing of the operation. I got away using those because the ESP32 is a 240Mhz 32-bit processor that handles them much faster.

What are the max speed, max distance, and max acceleration values you want to achieve?

@misan misan added the enhancement New feature or request label Mar 5, 2019
@misan
Copy link
Owner

misan commented Mar 5, 2019 via email

@philip100
Copy link
Author

Thank you so much for spending your time on this

What are the max speed, max distance, and max acceleration values you want to achieve?

The basic idea is to run steps until "speed" value is above 0 (zero), so the distance is not important (at least to me) in this scenario. The maximum speed I'm looking for is about 100 microseconds delay between each step (I think it's optimum max speed, considering 16 microstepping).
As for the acceleration values - The only important thing is, that the time it takes to accelerate will be the same for any given initial and final speed value, and I think that something between 100-500 milliseconds would be perfect.

If you want to plan a move of L steps, with v0 initial and v1 final speed, vm as max speed and "a" acceleration values, then the calculation would be: accel_steps=abs(vm^2-v0^2)/(2a); decel_steps=abs(vm^2-v1^2)/(2a); N=L-accel_steps-decel_steps; // it might be zero or negative is there is not enough space to achieve the desired motion in the available number of steps !!! Please note I have coded it as if v1 or v0 could be larger than vm (that should not happen as vm is supposed to the be the max speed). Does that make sense?

In theory, yes it make sense :-D
I'm not that good in math, so I'll have to test it.
I got ESP32 today, and I'll play with it tomorrow. I already got rid of slow AccelStepper library by implementing your equations in my program!

Once again, thanks!

Kindly,
Artur.

@philip100
Copy link
Author

philip100 commented Mar 7, 2019

Hi misan.

Unfortunatelly I failed using your equations :-/
Well, I don't actually understand what kind of data you consider to be vm , v0 , v1 and a . Number of microseconds? a percentage of speed perhaps?

I've seen on youtube something exactly what I'm looking for: https://www.youtube.com/watch?v=vD_VCBO1lw4

Very sadly, it's written in micropython, so I'll have to search for the solution using Arduino IDE.

Thanks anyway.

Kindly,
Artur.

@misan
Copy link
Owner

misan commented Mar 7, 2019 via email

@philip100
Copy link
Author

I believe you're right (you're the master of the math here :-) ), I just can't get my head around this.

I'll try to figure this out. Thanks for help!

Kindly,
Artur.

@misan
Copy link
Owner

misan commented Mar 8, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants