GCODE Paused, can I jog and/or issue manual entry, then resume?

Moderators: TomKerekes, dynomotion

Post Reply
greg9504
Posts: 20
Joined: Fri Mar 23, 2018 1:01 pm

GCODE Paused, can I jog and/or issue manual entry, then resume?

Post by greg9504 » Fri Nov 06, 2020 6:51 pm

Hi,

KmotionCNC question:
I have a custom M code that is used to pause and wait for user input. The machine is running a GCode file and is currently paused waiting for user input. Ideally I would like to jog or use the manual entry line to move the machine to remove stock, then jog/manual entry it back to the location it stopped at, then resume the GCode file. Can I do that?

Thanks.

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

Re: GCODE Paused, can I jog and/or issue manual entry, then resume?

Post by TomKerekes » Sat Nov 07, 2020 3:57 pm

Hi Greg,

To Jog you will need to Halt the execution of GCode. You might use the PC_COMM_HALT_NEXT_LINE command to Halt and advance the GCode to the next line so Cycle Start will then resume from there. Configure as Exec/wait/Sync

HaltNextLineKMotionCNC.c

Code: Select all

#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"

main()
{
	DoPC(PC_COMM_HALT_NEXT_LINE);
}
HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

greg9504
Posts: 20
Joined: Fri Mar 23, 2018 1:01 pm

Re: GCODE Paused, can I jog and/or issue manual entry, then resume?

Post by greg9504 » Sun Nov 08, 2020 2:40 am

Thanks.
Yes that's what I have my custom MCode do (if I remember correctly). After each cut it pauses so I can remove the wire, then I press a button to continue execution to the next contour. In this case while KMotionCNC is waiting for me to press the continue (physical) button, I pressed the pause button. Then used the step buttons to move the X axis over so I could get the forklift in to remove the waste. Then I step back to where it stopped. Then press the start button. I do get a warning window pop up that the machine needs to move to last known location (which it is at), I leave the options in that dialog set and continue. Seems to work fine.

I'm still working on the rotary table, actually started cutting metal. Will hopefully have it together before end of year but probably not before winter sets in so I wont get a chance to test it.
wasteremove.PNG
stonelight4.PNG

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

Re: GCODE Paused, can I jog and/or issue manual entry, then resume?

Post by TomKerekes » Sun Nov 08, 2020 3:41 pm

Hi Greg,

Its not clear if your issue is resolved.

If the axes are all exactly where they were when stopped you shouldn't get the warning dialog. 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.

Also its not clear why you need to hit a pause button. The MCode should halt execution and then all that should be needed is Cycle Start to continue.

That is cool. Can't wait to see what you can do with a rotary table.
Regards,

Tom Kerekes
Dynomotion, Inc.

greg9504
Posts: 20
Joined: Fri Mar 23, 2018 1:01 pm

Re: GCODE Paused, can I jog and/or issue manual entry, then resume?

Post by greg9504 » Mon Nov 09, 2020 2:57 am

Sorry I was going on memory. I double checked and this is how I have my custom M code configured:
kmotioncnc_mcode.PNG
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!

Post Reply