Axis commanded acceleration

Moderators: TomKerekes, dynomotion

Post Reply
gnrules
Posts: 19
Joined: Fri Jun 14, 2019 7:06 am

Axis commanded acceleration

Post by gnrules » Mon Feb 28, 2022 6:59 pm

Hi Tom,
is there any way to retrieve axis commanded acceleration during G-code execution (and in general in real time)?
As for my understanding it should be possible to derive it from the trip state.
Correct if I'm wrong, it should be pcoeff->b*2.0 during trapezoidal motion.
Unfortunately I was not able to access it during g-code execution: the pcoeff pointer of the axis is always null. I think that this structure is filled only during independent axis motion and not during coordinated motion.

I managed then to access CoordSystem0 strucure, where I found something similar for the global segment of motion, but I cannot acces to single axis data (also there is something strange during compilation because compiler gives error when accessing CoordSystem0->X stating that there is no such field even if in KmotionDef.h is declared).

Is there some sample code to get current commanded acceleration of each axis?

Thank you

Best regards

Giancarlo

User avatar
TomKerekes
Posts: 2527
Joined: Mon Dec 04, 2017 1:49 am

Re: Axis commanded acceleration

Post by TomKerekes » Mon Feb 28, 2022 11:39 pm

For linear coordinated motion there is a single parametric 3rd order function of time for all axes (p). Each axis is then a linear function of p.

See the example below. With 0 Jerk the acceleration should be the b coefficient of p multiplied by the c coefficient for the axis.

The units are all in counts for the axis and seconds. CS0_t (time) is relative to the beginning of the coordinated motion segment. Note there is a change of being interrupted, time changing or being reset, and possibly a switch to a new segment. You might want to add a WaitNextTimeSlice() before sampling things to avoid being interrupted.

Code: Select all

include "KMotionDef.h"

void main()
{
	double p,x,y;
	
	for (;;)
	{
		PARAMETRIC_COEFF *CS = CoordSystem0;

		if (CS)
		{
			p = ((CS->a * CS0_t + CS->b)*CS0_t + CS->c)*CS0_t + CS->d;
			x = CS->X.c * p + CS->X.d;
			y = CS->Y.c * p + CS->Y.d;
			
			printf("p=%f x=%f y=%f accelx=%f\n", p, x, y, CS->b * CS->X.c);
		}
		Delay_sec(0.5);
	}
}

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

gnrules
Posts: 19
Joined: Fri Jun 14, 2019 7:06 am

Re: Axis commanded acceleration

Post by gnrules » Tue Mar 01, 2022 8:06 am

Hi Tom,
thank you for your quick response.
Clear and precise as always.

I got the passage I was missing: the axis coefficients are interpolation coefficients of the global linear segment as function of parametric coordinate p.
For circular movements I suppose something similar, but data of the circle are stored in X and Y structures; it means I have to check active plane to calculate actual axis acceleration, is that correct?

I'll try your example and I'll check why the compiler complains about CS structure fields.

Thank you very much for your support.

Best regards

Giancarlo

User avatar
TomKerekes
Posts: 2527
Joined: Mon Dec 04, 2017 1:49 am

Re: Axis commanded acceleration

Post by TomKerekes » Tue Mar 01, 2022 5:40 pm

I suppose something similar, but data of the circle are stored in X and Y structures
Yes.

It would be helpful to know what you are trying to do.

Another possibly simpler approach would the to sample the Axis's ch->last_vel variable and after some time (N Time Slices) compute the change to determine acceleration.

There is an option to have KMotionCNC use only linear segments. If you switch that on you won't need to worry about circular motions.

Otherwise you can test for circular motions with:

if (CS->trajectory_mode == TRAJECTORY_CIRCULAR)

You shouldn't need to check the Plane. The "XY" axis will be the two KFLOP Axes that are doing the circular motion. Those two each axes use a linear function of p as an angle, where position is a linear function of the sin function of that angle. See below

Code: Select all

	chx = &chan[CS->x_axis];
	chy = &chan[CS->y_axis];
		
	x = CS->X.c * sin(p * CS->X.a + CS->X.b) + CS->X.d;
	y = CS->Y.c * sin(p * CS->Y.a + CS->Y.b) + CS->Y.d;
HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

gnrules
Posts: 19
Joined: Fri Jun 14, 2019 7:06 am

Re: Axis commanded acceleration

Post by gnrules » Tue Mar 01, 2022 6:35 pm

Hi Tom,
thanks again for the clarification.
It would be helpful to know what you are trying to do.
Sure... I'm so catched to solve the problem that I forgot to describe the application.
I wrote an interesting friction compensator that behaves very well with low speeds and accelerations.
Unfortunately I noticed that things changes significantly when acceleration increases. Searching in literature, it is a typical behaviour of the lubricated contact friction that exhibits a dependency from acceleration.

I managed to adapt my friction model (analytical, static and continuous) with a simple gain function dependent on acceleration; the best option I think is to correct my friction model by means of the theoretical acceleration. I know that I can derive it directly from last_vel but I need to filter the result in order to avoid spikes. I suppose also last_vel is filtered because has very smooth changes.
Maybe it is an option to try, but if the last_vel is the actual velocity than probably deriving acceleration could lead to some instable interaction with the friction compensation model.

Coming back to your example I tried it and it works well except that it seems to calculate half of the real acceleration. Looking at the formula the b coefficient should be 0.5*A because it multiplies t^2 (p=1/2*A*t^2+....)

I'm not sure to understand how to retrieve the axis in case of circular motion in a plane different from XY. In you example chx and chy are the actual axes making the circle? so if I select G18 they should return X and Z axes (meaning that if axes are x=0 y=1 z=2 CS->x_axis should be 0 and CS->y_axis should be 2)? If so it should be fairly simple to get the right acceleration even in case of circular motion.

I'll go on testing and keep you up to date on the results.

Thank you very much

Best regards

Giancarlo

User avatar
TomKerekes
Posts: 2527
Joined: Mon Dec 04, 2017 1:49 am

Re: Axis commanded acceleration

Post by TomKerekes » Tue Mar 01, 2022 7:41 pm

Interesting Giancarlo,

Not that I really understand :)
Looking at the formula the b coefficient should be 0.5*A because it multiplies t^2 (p=1/2*A*t^2+....)
Oops. Correct. I forgot the 1/2 was absorbed into the coefficient.
Maybe it is an option to try, but if the last_vel is the actual velocity than probably deriving acceleration could lead to some instable interaction with the friction compensation model.
No last_vel is the commanded velocity not measured.
so if I select G18 they should return X and Z axes (meaning that if axes are x=0 y=1 z=2 CS->x_axis should be 0 and CS->y_axis should be 2)? If so it should be fairly simple to get the right acceleration even in case of circular motion.
That is correct

Good luck
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply