LinuxCNC S-Curve Accelerations

More
13 Jun 2021 18:30 #211956 by rodw
Replied by rodw on topic LinuxCNC S-Curve Accelerations
Don't you just need to change the sign so values are negative to come back down? Could a direction pin to control that?
eg. Save the output first in an intermediate pin and then multiply by 1 or -1 before setting the out pin.

Please Log in or Create an account to join the conversation.

More
13 Jun 2021 18:51 #211957 by chris@cnc
Hi Rod,
Yes the reverse calculation is "out = 1 / ( 1+exp(counter));" But i am not able to set it in loop. I try it now since 6h but it doesn't work...
Attachments:

Please Log in or Create an account to join the conversation.

More
13 Jun 2021 19:01 #211960 by rodw
Replied by rodw on topic LinuxCNC S-Curve Accelerations

Hi Rod,
Yes the reverse calculation is "out = 1 / ( 1+exp(counter));" But i am not able to set it in loop. I try it now since 6h but it doesn't work...


If the intent was to always come down after you go up, you could go up for half the time then come down for the rest of the time by changing the sign

Please Log in or Create an account to join the conversation.

More
13 Jun 2021 19:32 #211962 by chris@cnc

If the intent was to always come down after you go up, you could go up for half the time then come down for the rest of the time by changing the sign

I tried that too, but as soon as I insert a 2nd "if", nonsense happens. My grammar is too bad.
But it may not even be necessary to go down. It is only necessary if the path is to be curved. If only the acceleration is to be curved, one way is enough. But there is the next problem. How can I bend the acceleration from the outside?

Please Log in or Create an account to join the conversation.

More
13 Jun 2021 21:31 - 13 Jun 2021 21:56 #211972 by Grotius
Hi Chris,

If you have troubles coding in c. Maybe try to to code in a header file.

I made a tiny example for you. Maybe it helps you.
In the tiny example there are some example functions that can help you.

The test.c is a preprocessed test.comp file. This can be done with halcompile --preprocess.
You can try to include the header direct into the comp file also. I did not test this.
Then in the test.c we #include scurve.h at line 10.
At line 103 we are using the header file.

Inside the scurve.h you can code in c style. You could also add function's inside the file.
This will keep it quite simple.
Writing header only library's is quite common and some header only library's are quite popular.

For the scurve implementation.
Using a sigmoid is not the best idea. With a sigmoid, how to check the distance at a certain timestamp?
If you use the orginal scurve mathematics you have the basic formula's on a paper. Scurves are first calculated
in classic lineair way. After that the scurve formula's are applied.

I am curious how do you implement the component? How does it interact with linuxcnc motion?

Here a example script how to test your app quickly. You have to edit your path's

Part of the message is hidden for the guests. Please log in or register to see it.


test.c shortened
Warning: Spoiler!


scurve.h
Warning: Spoiler!


Attached the qt halcompile example project.
Attachments:
Last edit: 13 Jun 2021 21:56 by Grotius.
The following user(s) said Thank You: chris@cnc

Please Log in or Create an account to join the conversation.

More
14 Jun 2021 06:21 - 14 Jun 2021 06:31 #212000 by arvidb

Hi arvidb,
You're right. It's a good idea to climb down the hill. :) But i can't do it.I can't do two calculations in a row. I can now control the length of the curve using a pin. My programming skills are not enough. I should leave it to people who know what they're doing. Try and error no longer leads to the goal.

I think you're approaching this from the wrong direction. Drawing a random s-shaped curve with a HAL component is neither very difficult nor useful.

I'd say: forget about the programming for now. Instead figure out: how would you calculate the distance that the tool moved while traversing one of these sigmoid curves? How would you *modify* the curve so that the tool moves exactly the distance you want? (So far you've only changed the duration of the curve, which doesn't say anything about the distance moved.) How can you affect the slope of the curve (i.e. the acceleration) so it doesn't violate machine limits?

To answer these questions you need to do math, not programming.

What do you thing about this way?

If it is easy to control the curve as described above, then the sigmoid function you suggested (the "logistic function") is a good idea. If it's difficult to get the answers to my questions above, then that function is probably not a good candidate. Once you've done the research and math required to answer these questions, you have the answer to your own question!
Last edit: 14 Jun 2021 06:31 by arvidb.
The following user(s) said Thank You: chris@cnc

Please Log in or Create an account to join the conversation.

More
14 Jun 2021 09:03 - 14 Jun 2021 09:08 #212006 by chris@cnc
Hi Grotius Hi arvidb,
Thank you for the programming lesson.

Groitus wrote:
I am curious how do you implement the component? How does it interact with linuxcnc motion?

arvidb wrote:
How can you affect the slope of the curve (i.e. the acceleration) so it doesn't violate machine limits?

In the beginning it was just a simple test to try out how this algorithm works and how it can be controlled.
My math skills are not enough to perform complex calculations like you do. But I thought I don't have to because the work is already done. The machine is already moving from a to b. And someone has already calculated the acceleration, just linear. And my thought was when a 2nd timer is set, this curve is activated and the acceleration is output in one S curve gain. And existing accelerating is multiplying with the S-curve gain that is not higher 1. So i can not go over limit.
As an example, I have recalculated the analog spindle output with the component


I now try the same with the joint.0.acc-cmd. But that is beyond my knowledge and I was hoping you would like this simple solution and moving that forward.
Attachments:
Last edit: 14 Jun 2021 09:08 by chris@cnc.

Please Log in or Create an account to join the conversation.

More
14 Jun 2021 09:52 - 14 Jun 2021 10:12 #212011 by arvidb

My math skills are not enough to perform complex calculations like you do. But I thought I don't have to because the work is already done. The machine is already moving from a to b. And someone has already calculated the acceleration, just linear. And my thought was when a 2nd timer is set, this curve is activated and the acceleration is output in one S curve gain. And existing accelerating is multiplying with the S-curve gain that is not higher 1. So i can not go over limit.

Ok, that makes sure you don't violate the acceleration limit, so that's good!

But if you modify the calculated acceleration, then you also modify the speed of the tool in each instant in time, and thereby also its position at that time. If you multiply the preset (constant) acceleration value of the linear planner with a value < 1.0, then you will need to accelerate for a longer time to reach the target velocity. You need to calculate how much longer. Also, this will change the distance travelled over time in ways that are even more complex than the change to velocity, so to end up at the requested target coordinate, there's even more math to do! Also, since you cannot ask the LinuxCNC planner to "wait" while you insert more time for the modified acceleration, a HAL component is not the right place for creating jerk-limited motion. You need to modify LinuxCNC's motion planner(s) so that you get the correct trajectory from the start.

You could say that servo drives that have an internal jerk limiting function "refuse" to do what they are told to by the linear planner, and distorts the requested trajectory. They then rely on some external regulator (e.g. the PID in LinuxCNC) to correct the error they introduce. The jerk limiter in the drive and the PID controller in LinuxCNC will be fighting each other since it's simply physically impossible to make both happy.

Edit: On the other hand, a trajectory that has limited jerk from the start, with consistent acceleration, velocity and position output, will (at least in theory) be possible to follow exactly.
Last edit: 14 Jun 2021 10:12 by arvidb.

Please Log in or Create an account to join the conversation.

More
14 Jun 2021 10:16 #212013 by Becksvill
when your ready I have a 6 ton high speed cnc mill and can help out testing. really want to see jerk limited stuff come to linuxcnc!
The following user(s) said Thank You: arvidb

Please Log in or Create an account to join the conversation.

More
14 Jun 2021 11:21 #212022 by chris@cnc

arvidb wrote:
But if you modify the calculated acceleration, then you also modify the speed of the tool in each instant in time, and thereby also its position at that time. If you multiply the preset (constant) acceleration value of the linear planner with a value < 1.0, then you will need to accelerate for a longer time to reach the target velocity.

Yes, the machine will no longer be precise. She will always be lagging behind. This type of acceleration is often used on toolchanger, tailstock or turretaxis. Everywhere there when the position does not have to be interpolated with a 2nd axis. Now if that is needed you can always install a servo that already has the function and do not have to make linuxcnc imprecise.
Of course, modifying the LinuxCNC's motion planner is always the better solution. Practically an incredibly complex job outside of my mind. Well then I don't want to keep you from work any longer.


Becksvill wrote:when your ready I have a 6 ton high speed cnc mill and can help out testing. really want to see jerk limited stuff come to linuxcnc!

Take a look in your servodriver manual. Maybe you find some acceleration parameter including s-curve, jerk limit, bell-shaped acceleration/deceleratio. Maybe it's enough for smooth operation.

Please Log in or Create an account to join the conversation.

Time to create page: 0.286 seconds
Powered by Kunena Forum