Axis tuning

Moderators: TomKerekes, dynomotion

RogerFroud
Posts: 78
Joined: Tue Mar 30, 2021 8:07 am

Re: Axis tuning

Post by RogerFroud » Mon Jul 12, 2021 8:17 pm

Ok, I'll chew over how I might make an assymetric response when the direction reverses.

I've spent the whole day trying to get to the bottom of the dithering. What's been happening is the SureServo has been cycling back and forth even when KMotion isn't calling for any movement. I've finally got an acceptable response for large steps, as well as the leadscrews holding position when they're supposed to be still.

It looks like the difference in performance between KMotion and KMotionCNC was that the tiny one count dithering was upsetting the SureServo with the parameters I'd got set in there.

I still wasn't completely happy, and I need to get a job out. So I implemented the Anti-Dithering to just affect the Integral part, since the P term is zero anyway. This has made it stand still, which I particularly need in the Z-axis since it's a Milling Machine.

So far this looks usable now, but I'll return to it when I have more time. The motion seems smooth, and the following error on the SureServo itself it only a count or two, so at least I know it's making a good attempt as following what KMotion is telling it to do. The feedrates are never going to be that high on this sort of machine, so slow speed performance is more important.

Anyway, many thanks for your patience and assistance, it's much appreciated.

This is what I did for the Anti-Dithering. Is there any sample code to see how the backlash compensation is done? Maybe I can use something as a starting point.

#define SMALL_ERR_XY 1
#define SMALL_ERR_Z 2
#define LONG_TIME 0.2

void DoDitherXY(CHAN *ch, float P_original, float P_low, float I_original, double *T0, double T1);
void DoDitherZ(CHAN *ch, float P_original, float P_low, float I_original, double *T0, double T1);


// save original gains and do anti-dither

double T1,T0_0=0,T0_1=0,T0_2=0;

float P_original_0 = 0.1; //ch0->P;
float P_low_0 = P_original_0 * 0.1;
float I_original_0 = ch0->I; //Use the value passed from Configuration dialog box

float P_original_1 = 0.1; //ch1->P;
float P_low_1 = P_original_1 * 0.1;
float I_original_1 = ch1->I; //ch1->I;

float P_original_2 = 0.1;//ch2->P;
float P_low_2 = P_original_2 * 0.1;
float I_original_2 = ch2->I; //ch2->I;


for (;;) // loop forever
{
T1=WaitNextTimeSlice();


if ((ch0->Enable)&& ReadBit(143)) //Make common enable bit follow the enable button
SetBit(151); //but only if the E-Stop input OP7 is high
else
ClearBit(151);


DoDitherXY(ch0, P_original_0, P_low_0, I_original_0, &T0_0, T1);
DoDitherXY(ch1, P_original_1, P_low_1, I_original_1, &T0_1, T1);
DoDitherZ(ch2, P_original_2, P_low_2, I_original_2, &T0_2, T1);

}

return 0;
}


void DoDitherXY(CHAN *ch, float P_original, float P_low, float I_original, double *T0, double T1)
{
if (fast_fabs(ch->LastFollowingError) > SMALL_ERR_XY) *T0=T1;

if (T1 - *T0 > LONG_TIME)// error for a long time
{
ch->I = 0.0; // no integrator
}
else
{
ch->I = I_original; // normal integrator
}
}

void DoDitherZ(CHAN *ch, float P_original, float P_low, float I_original, double *T0, double T1)
{
if (fast_fabs(ch->LastFollowingError) > SMALL_ERR_Z) *T0=T1;

if (T1 - *T0 > LONG_TIME)// error for a long time
{
ch->I = 0.0; // no integrator
}
else
{
ch->I = I_original; // normal integrator
}
}

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

Re: Axis tuning

Post by TomKerekes » Tue Jul 13, 2021 12:30 am

Hi Roger,

Here is the way backlash is implemented:

Code: Select all

void DoBacklash(CHAN *chx)
{
	if (chx->Dest > chx->PrevBacklashDest + chx->BacklashAmount*0.005)// moving forward?
	{
		chx->PrevBacklashDest = chx->Dest;
		chx->BacklashDirection = 1;
	}
	else if (chx->Dest < chx->PrevBacklashDest - chx->BacklashAmount*0.005)// moving backward?
	{
		chx->PrevBacklashDest = chx->Dest;
		chx->BacklashDirection = -1;
	}

	chx->Backlash += chx->BacklashRate * chx->BacklashDirection * TIMEBASE;
	
	if (chx->Backlash > chx->BacklashAmount)
		chx->Backlash = chx->BacklashAmount;
	else if (chx->Backlash < 0.0f)
		chx->Backlash = 0.0f;
}
Regards,

Tom Kerekes
Dynomotion, Inc.

RogerFroud
Posts: 78
Joined: Tue Mar 30, 2021 8:07 am

Re: Axis tuning

Post by RogerFroud » Tue Jul 13, 2021 3:58 pm

Thanks Tom,
Do you have the portion of the code that initialises the variables?

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

Re: Axis tuning

Post by TomKerekes » Tue Jul 13, 2021 4:10 pm

Code: Select all

	p->PrevBacklashDest = Dest;
	p->Backlash=p->BacklashDirection=0.0f;
Regards,

Tom Kerekes
Dynomotion, Inc.

RogerFroud
Posts: 78
Joined: Tue Mar 30, 2021 8:07 am

Re: Axis tuning

Post by RogerFroud » Thu Aug 19, 2021 12:09 pm

I'm just starting to look into this with a view to effectively implementing something very much like this. However, the code you've provided doesn't show how the final position is being modified by the backlash value. Could you share the code that shows that?

I'll need to keep the final position that planner wants to go to unchanged, because I want to compare that with the Linear Scales. What I need to do is to modify the Servo Output position to take up the backlash. I don't think this is how it's currently done, but I can't be sure without seeing what the code is doing.

Maybe this is just another backlash mode that you could implement? You have everything at your fingertips, so it ought to be easy to do. Basically, it's backlack compensation, while checking the final position against the Linear scales.

Any help would be much appreciated.

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

Re: Axis tuning

Post by TomKerekes » Fri Aug 20, 2021 4:54 pm

Hi Roger,

In that case I think you might try manipulating the Integrator (ch->integrator). Normally the Integrator compensates for backlash. When the trajectory reverses an error will develop which will basically cause the Integrator to ramp up to correct for backlash. So you could add/subtract some amount to the integrator to achieve this more quickly. You probably can't add it all at once without causing a motor stall or even exceeding the step rate of the driver unless there is sufficient low pass filtering for the output. See here.

Again whenever I've tried such things it resulted in either an unstable system or no real benefit.
Regards,

Tom Kerekes
Dynomotion, Inc.

RogerFroud
Posts: 78
Joined: Tue Mar 30, 2021 8:07 am

Re: Axis tuning

Post by RogerFroud » Fri Aug 20, 2021 8:07 pm

Ok, thanks for that, I can start with that. I can see that you have to apply any modifiers progressively else it will certainly be unstable. It just seemed to me that there is always lost motion, however small, and that's predictable. If it's predictable, I thought that a position offset could be inserted to correct for that. Obviously if the correction is too big, it will overshoot, but something a little less than that amount ought to take up the slack without moving the axis at all.

It's an interesting problem, and one that everyone with feedback has, even if it's not obvious.

Post Reply