So, after the last attempt (without acceleration) worked, I realized that the accelerations are hard to compute for two handles in parallel for an ATMEGA328 with the accelstepper library. The square root calculation takes a lot of time. So I have two solutions:
A) one MCU per handle (this will be expensive and a pure Overkill, but it has proven to work well)
B) change the way to calculate the acceleration
So obviously I have chosen B...
The approach for the following discussion is always, to have a certain frequency at which the programm is run (at the moment at 0.6ms) and it checks every time if there is a move to be run. Means, a speed of "2" makes a step every seccond tick. A speed of "4" makes a step every 4th tick...
As first, I calculated with a simple formula the acceleration and deceleration. Formula for deceleration:
amountOfTicksToAccelerate)*accelerationSpeed/(targetTick-actualTick).
This Formula works very well for acceleration, but at deceleration it is highly risky that the computed values will not match exactly and it ends up in non-matching position vs. timing.
So I made it the "easy" - and for programmers horrible - way. I saved an array for the acceleration. After how many ticks, shall the next step be made. The array is 50 items long:
accelArray[50] = { 12,11,10,10,9,9,8,7,7,6,6,6,5,5,4,4,4,3,3,3,3,3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,0,0,0,1 }
The first move is after 12 ticks. Tick timing is 0.6ms, so after 7.2ms the first move is done. The seccond step is after 11 ticks (6.6ms) etc. To decelerate I run the array backward. The main curve was calculated and then tested with different speed/acceleration combinations until it looked smooth.
So the acceleration phase with acceleration value of "1" ist always 50 steps. If you choose acceleration of "3", then it runs the array 3 times. Means, 3 times after 12 ticks, then 3 times after 11 ticks…
It's not nice, I know, but at least I was able to make it work smooth and reliable.
Here is the video: https://youtu.be/93-9P3XuW-w
The code and library is uploaded in the document section.
Any input/suggestion is highly welcome! :-)
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.