LinuxCNC S-Curve Accelerations
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.
Attachments:
Please Log in or Create an account to join the conversation.
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.
I tried that too, but as soon as I insert a 2nd "if", nonsense happens. My grammar is too bad.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
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.
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
#include "rtapi.h"
#ifdef RTAPI
#include "rtapi_app.h"
#endif
#include "rtapi_string.h"
#include "rtapi_errno.h"
#include "hal.h"
#include "rtapi_math64.h"
#include "scurve.h" // <<-- Here it is.
FUNCTION(_) {
struct traject tr;
tr.Vo=value;
int k=myfirstapp();
// Do something with k.
float result;
myfirstvoid(10,10,&result);
value=result;
struct line l;
l.xs=0;
l.xe=100;
struct point p=myfirstreturn(l);
value=p.x;
}
scurve.h
#ifndef SCURVE_H
#define SCURVE_H
struct point {
double x,y,z;
};
struct line {
double xs,ys,zs;
double xe,ye,ze;
};
struct traject {
double Vo; //start velocity
double Ve; //end velocity
double Vm; //max velocity if atspeed can not be reached
double Vel; //feedrate
double Acc_lineair; //lineair acceleration, mm/sec^2
double Acc_inflation; //max acceleration at inflection point, acc_lin*2, mm/sec^2
double T1; //total Acc time.
double T2; //total atspeed time.
double T3; //total Dcc time.
double Ttot; //total traject time, T1+T2+T3
double T1h; //total half Acc time, time to inflection point.
double T3h; //total half Dcc time, time to inflection point.
double L1; //acceleration lenght
double L2; //atspeed lenght.
double L3; //deacceleration lenght
double Ltot; //total traject lenght, L1+L2+L3
double Li; //line-line intersection x-value
double Jm; //max jerk for profile, x*acc_infl/T1 or T3
};
struct traject TrajectCalculator(double Vel, double Acc, double Vo, double Ve, struct line line);
struct traject ScurveUp(struct traject tr);
struct traject ScurveSteady(struct traject tr);
struct traject ScurveDown(struct traject tr);
int myfirstapp(); // Decleration
int myfirstapp(){ // Function
int i=35;
return i;
}
void myfirstvoid(float a, float b, float *result);
void myfirstvoid(float a, float b, float *result){
*result=a+b;
}
struct point myfirstreturn(struct line l); // return midpoint coordinates
struct point myfirstreturn(struct line l){
struct point p;
p.x= (l.xs+l.xe)/2;
p.y= (l.ys+l.ye)/2;
p.z= (l.zs+l.ze)/2;
return p;
}
#endif // SCURVE_H
Attached the qt halcompile example project.
Please Log in or Create an account to join the conversation.
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.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'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.
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!What do you thing about this way?
Please Log in or Create an account to join the conversation.
Thank you for the programming lesson.
Groitus wrote:
I am curious how do you implement the component? How does it interact with linuxcnc motion?
In the beginning it was just a simple test to try out how this algorithm works and how it can be controlled.arvidb wrote:
How can you affect the slope of the curve (i.e. the acceleration) so it doesn't violate machine limits?
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:
Please Log in or Create an account to join the conversation.
Ok, that makes sure you don't violate the acceleration limit, so that's good!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.
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.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
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.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.
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.
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.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!
Please Log in or Create an account to join the conversation.