Sorry I was going on memory. I double checked and this is how I have my custom M code configured:
I wanted a physical button to press because I'm physically within the working envelope of the machine while paused. Right now the spindle is manually turned on/off but at some point I'd like to have that handled within KmotionCNC too. This is what I have the Sheetcam post do:
Code: Select all
G02 X17.0285 Y31.2744 I1.1431 J15.0199
F1
(Pause to remove Wire)
M5
M100
G00
X17.4966 Y19.4421
(Pause to load Wire)
M5
M100
M3
G01 X17.6605 Y19.9145
F0.5
X17.9881 Y20.8593
Right now the M5 M3 don't actually do anything with the spindle. I manually turn it off/on. When the end of the 'inner' contour is reached the M5 M100 is executed and the GCode processing halts waiting for me to press the physical button. This is when I turn off the spindle, then remove the wire so the machine can move to the next 'inner' contour. Once the wire is removed I press the button, the machine moves to the next start point, where I feed the wire through a hole. Then turn on the spindle, press the button and it starts cutting. Hope that is clear. It's at the stop point where I remove the wire that I pressed the pause button within KmotionCNC, and used the step button to move the x axis to allow removal of the waste.
There is also some "snap" code to account for infinitesimal round off errors. So with the same number of "steps" away and same number back it shouldn't occur.
I think this is why I get the warning: Not sure if you remember but I'm using linear encoders for closed loop feedback, but the machine is moved by AC induction motors with VFDs. It was necessary to add +/- 8 counts (1142 counts/inch) of 'dead band' to prevent hunting. I'm guessing that the +/- 8 counts while 'infinitesimal' to my stone cutting, isn't to KmotionCNC

, and that is why I get the warning dialog since the machine isn't returning to the "exact" position.
This code runs in my forever loop for each axis for the dither/hunting (DoVFDEnable()):
Code: Select all
// bits used to enable axis VFD
#define CHAN0VFDENABLEBIT 152
#define CHAN1VFDENABLEBIT 153
// constants for vfd dither calcs
#define SMALL_X_ERR 8
#define SMALL_Y_ERR 8
#define LONG_TIME 0.5
P_original_0 = ch0->P;
P_low_0 = P_original_0 * 0.1;
I_original_0 = ch0->I;
printf("P original ch0 %g, P low %g, I original %g\n", P_original_0,P_low_0,I_original_0);
P_original_1 = ch1->P;
P_low_1 = P_original_1 * 0.1;
I_original_1 = ch1->I;
printf("P original ch1 %g, P low %g, I original %g\n", P_original_1,P_low_1,I_original_1);
//setting to low so first error doesn't cause wild swing
ch1->P = P_low_1;
ch1->I = 0.0;
for (;;)
{
T1=WaitNextTimeSlice(); // waits and returns current time
DoVFDEnable(ch0,CHAN0VFDENABLEBIT, SMALL_X_ERR, P_original_0, P_low_0, I_original_0, &T0_0, T1);
DoVFDEnable(ch1,CHAN1VFDENABLEBIT, SMALL_Y_ERR, P_original_1, P_low_1, I_original_1, &T0_1, T1);
result = Debounce(ReadBit(RPM_OP_IN_BIT),&rpmcount,&rpmlast,&rpmlastsolid);
if (result == 1)
{
rpmcounter_current++;
}
if (T1 - TimeLastAnalogInVarsUpdated >= TIMEBETWEENANALOGINUPDATES)
{
int updaterpm = (rpm_update_counter % RPM_UPDATE_MULTIPLIER == 0);
// printf("rpm_update_counter value %d, updaterpm value %d\n", rpm_update_counter, updaterpm);
ReadADCSendToKMotionCNC((rpmcounter_current - rpmcounter_last)/PULSE_PER_REVOLUTION, updaterpm);
TimeLastAnalogInVarsUpdated = T1;
rpm_update_counter++;
if (updaterpm)
{
rpmcounter_last = rpmcounter_current;
rpm_update_counter = 1;
}
}
}
void DoVFDEnable(CHAN *ch, int vfdenablebit, int error, float P_original, float P_low, float I_original, double *T0, double T1)
{
if (fast_fabs(ch->LastFollowingError) > error)
{
*T0=T1;
}
int currState = ReadBit(vfdenablebit);
if (ch->Enable)
{
if (ch->last_vel == 0 &&
(T1 - *T0 > LONG_TIME))
{
if (currState == 1) //don't keep resetting the same state
{
ch->P = P_low; // reduced gain
ch->I = 0.0; // no integrator
ClearBit(vfdenablebit);//disable vfd
printf("P low %g, P original %g, I original %g\n", P_low, P_original, I_original);
printf("VFD %d disabled, output %g, last velocity %g, error %g, ch->P %g, ch->I %g, current state %d\n", ch->ChanNumber, ch->Output,ch->last_vel, ch->LastFollowingError, ch->P, ch->I,currState);
}
}
else
{
if (currState == 0) //don't keep resetting the same state
{
ch->P = P_original; // normal gain
ch->I = I_original; // normal integrator
SetBit(vfdenablebit); // enable VFD
printf("P original %g, I original %g\n", P_original, I_original);
printf("VFD %d enabled, output %g, last velocity %g, error %g, ch->P %g, ch->I %g, current state %d\n", ch->ChanNumber, ch->Output,ch->last_vel, ch->LastFollowingError, ch->P, ch->I,currState);
}
}
}
else
{
if (currState == 1)
{
ClearBit(vfdenablebit);
}
}
}
So I think the issue is resolved.
Thanks!