more spindle servo tuning questions

Moderators: TomKerekes, dynomotion

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

more spindle servo tuning questions

Post by turbothis » Fri Jun 28, 2024 6:13 pm

i had the idea to run a load test on the spindle by ramming a large bolt head (in tailstock) into a large round bar in the spindle to see how it reacts
the spindle ramped up the DAC and it responded pretty nice
now i run a simple program with light cuts and the spindle will start running off and react terribly

what is the difference in the 2 tests?

Code: Select all

#include "KMotionDef.h"
#include "MySpindleDefs.h"
//#include "CSSJog.c"


int main() {

    // X axis
    
	ch0->InputMode=ENCODER_MODE;
	ch0->OutputMode=DAC_SERVO_MODE;
	ch0->Vel=80000;
	ch0->Accel=5e+06;
	ch0->Jerk=5e+06;
	ch0->P=5;
	ch0->I=0;
	ch0->D=20;
	ch0->FFAccel=0;
	ch0->FFVel=0;
	ch0->MaxI=200;
	ch0->MaxErr=200;
	ch0->MaxOutput=500;
	ch0->DeadBandGain=1;
	ch0->DeadBandRange=0;
	ch0->InputChan0=0;
	ch0->InputChan1=0;
	ch0->OutputChan0=0;
	ch0->OutputChan1=0;
	ch0->MasterAxis=-1;
	ch0->LimitSwitchOptions=0x100;
	ch0->LimitSwitchNegBit=0;
	ch0->LimitSwitchPosBit=0;
	ch0->SoftLimitPos=1e+09;
	ch0->SoftLimitNeg=-1e+09;
	ch0->InputGain0=1;
	ch0->InputGain1=1;
	ch0->InputOffset0=0;
	ch0->InputOffset1=0;
	ch0->OutputGain=1;
	ch0->OutputOffset=0;
	ch0->SlaveGain=1;
	ch0->BacklashMode=BACKLASH_OFF;
	ch0->BacklashAmount=0;
	ch0->BacklashRate=0;
	ch0->invDistPerCycle=1;
	ch0->Lead=0;
	ch0->MaxFollowingError=1000000000;
	ch0->StepperAmplitude=250;

	ch0->iir[0].B0=1;
	ch0->iir[0].B1=0;
	ch0->iir[0].B2=0;
	ch0->iir[0].A1=0;
	ch0->iir[0].A2=0;

	ch0->iir[1].B0=1;
	ch0->iir[1].B1=0;
	ch0->iir[1].B2=0;
	ch0->iir[1].A1=0;
	ch0->iir[1].A2=0;

	ch0->iir[2].B0=1;
	ch0->iir[2].B1=0;
	ch0->iir[2].B2=0;
	ch0->iir[2].A1=0;
	ch0->iir[2].A2=0;
    
    // Z axis
    
	ch1->InputMode=ENCODER_MODE;
	ch1->OutputMode=DAC_SERVO_MODE;
	ch1->Vel=130000;
	ch1->Accel=5e+06;
	ch1->Jerk=5e+06;
	ch1->P=10;
	ch1->I=0;
	ch1->D=20;
	ch1->FFAccel=0;
	ch1->FFVel=0;
	ch1->MaxI=200;
	ch1->MaxErr=200;
	ch1->MaxOutput=1000;
	ch1->DeadBandGain=1;
	ch1->DeadBandRange=0;
	ch1->InputChan0=1;
	ch1->InputChan1=0;
	ch1->OutputChan0=1;
	ch1->OutputChan1=0;
	ch1->MasterAxis=-1;
	ch1->LimitSwitchOptions=0x114;
	ch1->LimitSwitchNegBit=11;
	ch1->LimitSwitchPosBit=0;
	ch1->SoftLimitPos=1e+09;
	ch1->SoftLimitNeg=-1e+09;
	ch1->InputGain0=1;
	ch1->InputGain1=1;
	ch1->InputOffset0=0;
	ch1->InputOffset1=0;
	ch1->OutputGain=1;
	ch1->OutputOffset=0;
	ch1->SlaveGain=1;
	ch1->BacklashMode=BACKLASH_OFF;
	ch1->BacklashAmount=0;
	ch1->BacklashRate=0;
	ch1->invDistPerCycle=1;
	ch1->Lead=0;
	ch1->MaxFollowingError=5000;
	ch1->StepperAmplitude=250;

	ch1->iir[0].B0=1;
	ch1->iir[0].B1=0;
	ch1->iir[0].B2=0;
	ch1->iir[0].A1=0;
	ch1->iir[0].A2=0;

	ch1->iir[1].B0=1;
	ch1->iir[1].B1=0;
	ch1->iir[1].B2=0;
	ch1->iir[1].A1=0;
	ch1->iir[1].A2=0;

	ch1->iir[2].B0=1;
	ch1->iir[2].B1=0;
	ch1->iir[2].B2=0;
	ch1->iir[2].A1=0;
	ch1->iir[2].A2=0;
	
	
	    // SPINDLE  /  A axis

	ch2->InputMode=ENCODER_MODE;
	ch2->OutputMode=DAC_SERVO_MODE;
	ch2->Vel=  200000;   // 1500rpm = 200000 counts per second
	ch2->Accel=300000;   // 2 second to 1500 rpm = 100000 CPS
	ch2->Jerk= 300000;
	ch2->P=20;
	ch2->I=0;
	ch2->D=50;
	ch2->FFAccel=0;
	ch2->FFVel=0;
	ch2->MaxI=200;
	ch2->MaxErr=1e+06;
	ch2->MaxOutput=2000;
	ch2->DeadBandGain=1;
	ch2->DeadBandRange=0;
	ch2->InputChan0=2;
	ch2->InputChan1=0;
	ch2->OutputChan0=2;
	ch2->OutputChan1=0;
	ch2->MasterAxis=-1;
	ch2->LimitSwitchOptions=0x100;
	ch2->LimitSwitchNegBit=0;
	ch2->LimitSwitchPosBit=0;
	ch2->SoftLimitPos=1e+30;
	ch2->SoftLimitNeg=-1e+30;
	ch2->InputGain0=-1;
	ch2->InputGain1=1;
	ch2->InputOffset0=0;
	ch2->InputOffset1=0;
	ch2->OutputGain=1;
	ch2->OutputOffset=0;
	ch2->SlaveGain=1;
	ch2->BacklashMode=BACKLASH_OFF;
	ch2->BacklashAmount=0;
	ch2->BacklashRate=0;
	ch2->invDistPerCycle=1;
	ch2->Lead=0;
	ch2->MaxFollowingError=100000;
	ch2->StepperAmplitude=20;

	ch2->iir[0].B0=1;
	ch2->iir[0].B1=0;
	ch2->iir[0].B2=0;
	ch2->iir[0].A1=0;
	ch2->iir[0].A2=0;

	ch2->iir[1].B0=1;
	ch2->iir[1].B1=0;
	ch2->iir[1].B2=0;
	ch2->iir[1].A1=0;
	ch2->iir[1].A2=0;

	ch2->iir[2].B0=1;
	ch2->iir[2].B1=0;
	ch2->iir[2].B2=0;
	ch2->iir[2].A1=0;
	ch2->iir[2].A2=0;
	
	
	EnableAxis(0);
    EnableAxis(1);
    EnableAxis(2);
    
	DefineCoordSystem(0,-1,1,-1);
  }

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

Re: more spindle servo tuning questions

Post by TomKerekes » Fri Jun 28, 2024 7:57 pm

What kind of spindle Drive do you have? Torque? Velocity?
the spindle ramped up the DAC and it responded pretty nice
to what DAC values?
now i run a simple program with light cuts and the spindle will start running off and react terribly
Could you be more specific?
now i run a simple program with light cuts and the spindle will start running off and react terribly
Maybe this requires higher torque and/or more sudden torque demands?

One possibility is the Servo is tuned in a way to not to be cable to keep up, so lags behind, then overshoots when it is able to catch up. A simple way to check for this is to set the max following error to a smaller value (ie. 500) then if it lags behind the axis will trigger a following error and disable so you will be aware the axis isn't able to keep up. Its a good idea to have a small max following error on all axes anyways so if anything unusual happens the axis will disable.

Otherwise you might use a data capture program like shown below to observe exactly what is happening. Afterwards the data file can be inspected or plotted with some application like Excel. This Program can be assigned to an MCode (Execute - no wait) to be triggered in the GCode where interested to observe.



Code: Select all

#include "KMotionDef.h"

#define N 5000

main()
{
    int i=0,k;
    double T0,*p=gather_buffer;
    
    T0 = Time_sec();

    // Capture Data
    
    for (i=0; i<N; i++)
    {
        for (k=0; k<5; k++)    WaitNextTimeSlice();  // 5 * 180us = 900us x 5000 = 4.5sec
        
        *p++ = Time_sec() - T0;
        *p++ = ch2->Dest;
        *p++ = ch2->Position;
        *p++ = ch2->Output;
    }
    
    printf("Capture Complete - writing...\n");
    
    FILE *f=fopen("C:\\temp\\kflopdata.txt","wt");

    fprintf(f,"Time,Dest,Pos,Out\n");

    p=gather_buffer;
    for (i=0; i<N; i++)
    {
        // round times to neaarest servo tick
        p[0] = ((int)(p[0]/TIMEBASE + 0.5))*TIMEBASE;
        fprintf(f,"%16.9f,%16.6f,%16.6f,%16.6f\n",p[0],p[1],p[2],p[3]);
        p += 4;
    }

    fclose(f);
}
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: more spindle servo tuning questions

Post by turbothis » Fri Jun 28, 2024 8:19 pm

1 should be torque drive i believe
"Advance Motion Controls 30-125VAC Brush Type PWM Servo Amplifier 16A20ACT"

2 when i give it a lot of bolt ramming load it will DAC up to about 7 volt output

3

Code: Select all

G18 G20 G80 G90 
G95 
S1000  M04
G04P1
 
 
G01  X3.0  Z0.5      F0.010 
G00  X1.605  Z0.2 
G01  X1.5851  Z0.2 
 X1.5851  Z-1.6 
G00  X1.9386  Z-1.2465 
 X1.9386  Z0.2 
G01  X1.5652  Z0.2 
 X1.5652  Z-1.6 
G00  X1.9187  Z-1.2465 
 X1.9187  Z0.2 
G01  X1.5453  Z0.2 
 X1.5453  Z-1.6 
G00  X1.8988  Z-1.2465 
 X1.8988  Z0.2 
G01  X1.5254  Z0.2 
 X1.5254  Z-1.6 
G00  X1.8789  Z-1.2465 
 X1.8789  Z0.2 
G01  X1.5055  Z0.2 
 X1.5055  Z-1.6 
G00  X1.859  Z-1.2465 
 X1.859  Z0.2 
G01  X1.4855  Z0.2 
 X1.4855  Z-1.6 
G00  X1.8391  Z-1.2465 
 X1.8391  Z0.2 
G01  X1.4656  Z0.2 
 X1.4656  Z-1.6 
G00  X1.8192  Z-1.2465 
 X1.8192  Z0.2 
G01  X1.4457  Z0.2 
 X1.4457  Z-1.6 
G00  X1.7993  Z-1.2465 
 X1.7993  Z0.2 
G01  X1.4258  Z0.2 
 X1.4258  Z-1.6 
G00  X1.7794  Z-1.2465 
 X1.7794  Z0.2 
G01  X1.4059  Z0.2 
 X1.4059  Z-1.6 
G00  X1.7595  Z-1.2465 
 X1.7595  Z0.2 
G01  X1.386  Z0.2 
 X1.386  Z-1.6 
G00  X1.7395  Z-1.2465 
 X1.7395  Z0.2 
G01  X1.3661  Z0.2 
 X1.3661  Z-1.6 
G00  X1.7196  Z-1.2465 
 X1.7196  Z0.2 
G01  X1.3462  Z0.2 
 X1.3462  Z-1.6 
G00  X1.6997  Z-1.2465 
 X1.6997  Z0.2 
G01  X1.3263  Z0.2 
 X1.3263  Z-1.6 
G00  X1.6798  Z-1.2465 
 X1.6798  Z0.2 
G01  X1.3063  Z0.2 
 X1.3063  Z-1.6 
G00  X1.6599  Z-1.2465 
 X1.6599  Z0.2 
G01  X1.2864  Z0.2 
 X1.2864  Z-1.6 
G00  X1.64  Z-1.2465 
 X1.64  Z0.2 
G01  X1.2665  Z0.2 
 X1.2665  Z-1.6 
G00  X1.6201  Z-1.2465 
 X1.6201  Z0.2 
G01  X1.2466  Z0.2 
 X1.2466  Z-1.6 
G00  X1.6002  Z-1.2465 
 X1.6002  Z0.2 
G01  X1.2267  Z0.2 
 X1.2267  Z-1.6 
G00  X1.5803  Z-1.2465 
 X1.5803  Z0.2 
G01  X1.2068  Z0.2 
 X1.2068  Z-1.6 
G00  X1.5603  Z-1.2465 
 X1.5603  Z0.2 
G01  X1.1869  Z0.2 
 X1.1869  Z-1.6 
G00  X1.5404  Z-1.2465 
 X1.5404  Z0.2 
G01  X1.167  Z0.2 
 X1.167  Z-1.6 
G00  X1.5205  Z-1.2465 
 X1.5205  Z0.2 
G01  X1.1471  Z0.2 
 X1.1471  Z-1.6 
G00  X1.5006  Z-1.2465 
 X1.5006  Z0.2 
G01  X1.1271  Z0.2 
 X1.1271  Z-1.6 
G00  X1.4807  Z-1.2465 
 X1.4807  Z0.2 
G01  X1.1072  Z0.2 
 X1.1072  Z-1.6 
G00  X1.4608  Z-1.2465 
 X1.4608  Z0.2 
G01  X1.0873  Z0.2 
 X1.0873  Z-1.6 
G00  X1.4409  Z-1.2465 
 X1.4409  Z0.2 
G01  X1.0674  Z0.2 
 X1.0674  Z-1.6 
G00  X1.421  Z-1.2465 
 X1.421  Z0.2 
G01  X1.0475  Z0.2 
 X1.0475  Z-1.6 
G00  X1.4011  Z-1.2465 
 X1.4011  Z0.2 
G01  X1.0276  Z0.2 
 X1.0276  Z-1.6 
G00  X1.3811  Z-1.2465 
 X1.3811  Z0.2 
G01  X1.0077  Z0.2 
 X1.0077  Z-1.6 
G00  X1.3612  Z-1.2465 
 X1.3612  Z0.2 
G01  X0.9878  Z0.2 
 X0.9878  Z-1.6 
G00  X1.3413  Z-1.2465 
 X1.3413  Z0.2 
G01  X0.9679  Z0.2 
 X0.9679  Z-1.6 
G00  X1.3214  Z-1.2465 
 X1.3214  Z0.2 
G01  X0.948  Z0.2 
 X0.948  Z-1.6 
G00  X1.3015  Z-1.2465 
 X1.3015  Z0.2 
G01  X0.928  Z0.2 
 X0.928  Z-1.6 
G00  X1.2816  Z-1.2465 
 X1.2816  Z0.2 
G01  X0.9081  Z0.2 
 X0.9081  Z-1.6 
G00  X1.2617  Z-1.2465 
 X1.2617  Z0.2 
G01  X0.8882  Z0.2 
 X0.8882  Z-1.6 
G00  X1.2418  Z-1.2465 
 X1.2418  Z0.2 
G01  X0.8683  Z0.2 
 X0.8683  Z-1.6 
G00  X1.2219  Z-1.2465 
 X1.2219  Z0.2 
G01  X0.8484  Z0.2 
 X0.8484  Z-1.6 
G00  X1.202  Z-1.2465 
 X1.202  Z0.2 
G01  X0.8285  Z0.2 
 X0.8285  Z-1.6 
G00  X1.182  Z-1.2465 
 X1.182  Z0.2 
G01  X0.8086  Z0.2 
 X0.8086  Z-1.6 
G00  X1.1621  Z-1.2465 
 X1.1621  Z0.2 
G01  X0.7887  Z0.2 
 X0.7887  Z-1.6 
G00  X1.1422  Z-1.2465 
 X1.1422  Z0.2 
G01  X0.7688  Z0.2 
 X0.7688  Z-1.6 
G00  X1.1223  Z-1.2465 
 X1.1223  Z0.2 
G01  X0.7488  Z0.2 
 X0.7488  Z-1.6 
G00  X1.1024  Z-1.2465 
 X1.1024  Z0.2 
G01  X0.7289  Z0.2 
 X0.7289  Z-1.6 
G00  X1.0825  Z-1.2465 
 X1.0825  Z0.2 
G01  X0.709  Z0.2 
 X0.709  Z-1.6 
G00  X1.0626  Z-1.2465 
 X1.0626  Z0.2 
G01  X0.6891  Z0.2 
 X0.6891  Z-1.6 
G00  X1.0427  Z-1.2465 
 X1.0427  Z0.2 
G01  X0.6692  Z0.2 
 X0.6692  Z-1.6 
G00  X1.0228  Z-1.2465 
 X1.0228  Z0.2 
G01  X0.6493  Z0.2 
 X0.6493  Z-1.6 
G00  X1.0028  Z-1.2465 
 X1.0028  Z0.2 
G01  X0.6294  Z0.2 
 X0.6294  Z-1.6 
G00  X0.9829  Z-1.2465 
 X0.9829  Z0.2 
G01  X0.6095  Z0.2 
 X0.6095  Z-1.6 
G00  X0.963  Z-1.2465 
 X0.963  Z0.2 
G01  X0.5896  Z0.2 
 X0.5896  Z-1.6 
G00  X0.9431  Z-1.2465 
 X0.9431  Z0.2 
G01  X0.5696  Z0.2 
 X0.5696  Z-1.6 
G00  X0.9232  Z-1.2465 
 X0.9232  Z0.2 
G01  X0.5497  Z0.2 
 X0.5497  Z-1.6 
G00  X0.9033  Z-1.2465 
 X0.9033  Z0.2 
G01  X0.5298  Z0.2 
 X0.5298  Z-1.6 
G00  X0.8834  Z-1.2465 
 X0.8834  Z0.2 
G01  X0.5099  Z0.2 
 X0.5099  Z-1.6 
G00  X0.8635  Z-1.2465 
 X0.8635  Z0.2 
G01  X0.49  Z0.2 
 X0.49  Z-1.6 
G00  X0.8436  Z-1.2465 
 X0.8436  Z0.2 
 X1.605  Z0.2 
 X3.0  Z1.0 
 M05 M09
 M30
 

4 the program for the cuts is very gentle. way less impact as bolt ramming demo

"One possibility is the Servo is tuned in a way to not to be cable to keep up, so lags behind, then overshoots when it is able to catch up."

this describes it pretty good
i think ill try crazy slow acc and jerk to see if that calms it down
Attachments
drive.JPG

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: more spindle servo tuning questions

Post by turbothis » Fri Jun 28, 2024 8:29 pm

is there any difference in the spindle performance between the G code program and just turning on the spindle by the CCW button?

my spindle jog below

Code: Select all

#include "KMotionDef.h"

#include "MySpindleDefs.h"

int   *css_mode = &persist.UserData[PC_COMM_CSS_MODE];			// Mode 1=Normal RPM mode. 2=CSS

// desired speed is passed from KMotionCNC in variable KMVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed

main()
{
	float speed = *(float *)&persist.UserData[KMVAR];  // value stored is actually a float 
	int  LastState = persist.UserData[STATEVAR];  // get last state 
	
	persist.UserData[SPEEDVAR] = persist.UserData[KMVAR];  // Always save the last desired speed 
	
	if (LastState==0 || *css_mode == 2)  
	{
		// if spindle is off (or CSS mode) and User Changes the speed 
		// just save the desired speed
		
		return 0;
	}
	
	// spindle is already on, so ramp to new speed
	if (USE_POS_NEG_VOLTAGE)
		Jog(SPINDLEAXIS,speed * FACTOR * LastState);
	else
		Jog(SPINDLEAXIS,speed * FACTOR);
		
	printf("Jogging Spindle %f counts/sec\n",speed * FACTOR);
}

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

Re: more spindle servo tuning questions

Post by TomKerekes » Fri Jun 28, 2024 8:45 pm

i think ill try crazy slow acc and jerk to see if that calms it down
That should have no effect as the speed should be constant with no acceleration or Jerk needed.

is there any difference in the spindle performance between the G code program and just turning on the spindle by the CCW button?
There shouldn't be any difference. Unless you are in CSS mode (G96). In that case the speed will vary dependent on radius (X). But I don't see any G96 in the GCode. You might add a G97 to be sure the Spindle is in RPM mode.

You might also try running the GCode without any stock present (Air run) so there will be no load on the Spindle to see what happens.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: more spindle servo tuning questions

Post by turbothis » Fri Jun 28, 2024 9:09 pm

boy it did have trouble just cutting air!
what to look at now?

i lowered the following error to 5000 and it ...
"Following Error Disabled Axis:2"

this is a brushed DC motor so its not slipping or phasing out right? like a brushless could?

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

Re: more spindle servo tuning questions

Post by TomKerekes » Fri Jun 28, 2024 11:13 pm

boy it did have trouble just cutting air!
That simplifies things as it has nothing to do with load.
i lowered the following error to 5000 and it ...
"Following Error Disabled Axis:2"
That's a large error to be having. With an error of 100-150 the output should be saturated at 10V (with P Gain of 20). When does the error happen?

What gets printed to the console? The speed should only be set once at the beginning of the GCode.

You might single step through the GCode.

Maybe you have some wiring error such as a missing GND such that the X Z DACs have an effect on the Spindle?
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: more spindle servo tuning questions

Post by turbothis » Sat Jun 29, 2024 12:16 am

ok, i lowered the error to 150 and slowed the accel and jerk to

Code: Select all

ch2->Vel=  200000;   // 1500rpm = 200000 counts per second
	ch2->Accel=50000;   // 2 second to 1500 rpm = 100000 CPS
	ch2->Jerk= 100000;
	ch2->P=20;
	ch2->I=0;
	ch2->D=50;
and runs stable but is kinda wimpy spindle performance

the spindle will power up to 1500 rpm in about a second with some larger accel and jerk values. seems very powerful to me! :o
it will also not over shoot any rpm revving up, just the deceleration has mega trouble
how fast would be reasonable to slow it back to zero?

can i run that logging program to see how fast in kill mode the spindle can get up to speed and see how far behind the position gets at this?

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

Re: more spindle servo tuning questions

Post by TomKerekes » Sat Jun 29, 2024 8:30 pm

Hi Turbothis,

Your responses seem to jump around from one post to the next without any closure on things so I'm having a hard time following. It seems the original problem was starting up the spindle and not while running GCode.

You might start over and tune the axis using the Step Response Screen to see what ranges the Spindle is capable of.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: more spindle servo tuning questions

Post by turbothis » Sun Jun 30, 2024 7:39 pm

ya i am a mess on this
at one point i had it tuned to spin up and down on the RPM slider very aggressively, i mean respect! :shock:
made some cuts and threaded some stuff no problem
then the event where it all kind of went sideways on me

working back up to useful performance since then....
i even posted the settings which i have revisited a bunch and i cant get the spindle stable anywhere :(

i am feeling like one of my CW/CCW, spindle jog or something like that is off, but i dont know.
in all my other axis i can tune them in a couple minutes.

so on the step/response screen, a small 3 second move is accurate up to 1500rpm and 100 pounds of rotational mass?

Post Reply