how to implement a security switch launching a program / gcode

Moderators: TomKerekes, dynomotion

Jojo
Posts: 8
Joined: Fri Apr 27, 2018 6:34 am

how to implement a security switch launching a program / gcode

Post by Jojo » Sat Apr 28, 2018 9:53 pm

Dear Tom,

I transfer my question and your reply to it from yahoo group to here (below), I guess and hope it will be much more convenient for you !
So... Thanks for the quick reply! Indeed, I did not really consdier all the possible events you mentioned, all very good questions..
To keep it as simple and safe as possible, I will try to program the most basic case:

stop motion, turn off spindle and dont do anything when closing the door again, thus, the user has to resume the job onscreen (KmotionCNC-button) if(!) the door is again closed.

For this, I suppose it might be sufficient to start with the first part of your suggested code and use

StopCoordinatedMotion();
ClearBit(SPINDLEBIT)

solely?

I will try asap to modify my ini-file and post it here for the pros to have a look at;)
Thanks again, talk to you soon, and kind regards,

Johannes










****************************************
****************************************
INITIAL QUESTION
****************************************
****************************************

Dear all,

I have a 4-axis-milling machine with NEMA-steppers, run by a KFLOP and KSTEP.
For security reasons we have to install a security switch in the door of the machine housing.

It should to the following:
When opening the door to the milling machine, a switch in the door is triggered that should pause (!) the gcode-program: pause the axis movement and stop the spindle (like hitting F5 and stopping the spindle).

When closing the door (and thus the switch), the spindle should start spinning again and after e.g. 5 seconds continue with the milling process.

What would you suggest is the best way to achieve this? I would like to connect the switch to one of the io of KFLOP/KSEP, since I was able to do something similar with the tool-length sensor that Iuckily turned out to work pretty well:)

In g-code language, the door switch should do something like this

open door:
M05 (stop spindle)
M0 (stop program)

close door:
M3 (start spindle CW)
G4 P5.0 (pause for spindle to catch up speed)
G1 x .....

But apart from how this would interfer with the currently running g-code, I think a little C-Program thats launched with the switch might be more appropriate or safe or intelligent. What do you think? How would a program doiing the above look like?
Really looking forward to your opinions, solutions, suggestions!

Thanks a lot in advance,
Kind regards,

Johannes




****************************************
****************************************
YOUR REPLY
****************************************
****************************************

Hi Johannes,

Sorry for the delay we've been having problems with the Yahoo Group. Please use our forum in the future:
...

You might debounce the Door switch to detect a change in the door switch to open, then issue a FeedHold, Stop Spindle, then command KMotionCNC to Halt. By issuing the Feedhold and spindle stop from within KFLOP should allow that to occur whether or not the PC is responsive.

Disclaimer: Safety is entirely your responsibility and software monitors may not be reliable enough for proper protection.

Depending on your system you may want to wait until the Feedhold completes and the system stops before turning off the Spindle.

I tried to code something like that up as a state machine. See Attached example.

You would need to modify it for your system - Spindle Control, Door Input, etc...

It turned out to be more complicated than I thought as I soon realized there are a number of special cases. Such as:

#1 - if the door is closed should the Job be started in all cases even if one wasn't active before?

#2 - what to do if the Operator starts a Job with the Door Open?

#3 - what if the Operator opens the door which pauses a job, then loads a different job, then closes the door. Should the new Job automatically start?

#4 - what if the spindle is off when the Job is halted? Should it still be turned on when re-started

#5 - How to tell KFLOP you no longer wish to resume when the door is closed?

It might be a lot safer to never resume a paused Job automatically.

You might try the attached program. But again as always it is your responsibility to fully guarantee it meets all safety requirements.

Regards
TK




#include "KMotionDef.h"

// Defines axis 0, 1, 2 as simple step dir TTL outputs for KSTEP
// enables them
// sets them as an xyz coordinate system for GCode

int main()
{
double T0, LastX=0, LastY=0, LastZ=0, Tau;

KStepPresent=TRUE; // enable KSTEP input multiplexing
FPGA(KAN_TRIG_REG)=4; // Mux PWM0 to JP7 Pin5 IO 44 for KSTEP

FPGA(STEP_PULSE_LENGTH_ADD) = 63 + 0x80; // set polarity and pulse length to 4us

ch0->InputMode=NO_INPUT_MODE;
ch0->OutputMode=STEP_DIR_MODE;
ch0->Vel=40000;
ch0->Accel=200000;
ch0->Jerk=4e+006;
ch0->P=0;
ch0->I=0.01;
ch0->D=0;
ch0->FFAccel=0;
ch0->FFVel=0;
ch0->MaxI=200;
ch0->MaxErr=1e+006;
ch0->MaxOutput=200;
ch0->DeadBandGain=1;
ch0->DeadBandRange=0;
ch0->InputChan0=0;
ch0->InputChan1=0;
ch0->OutputChan0=8;
ch0->OutputChan1=0;
ch0->MasterAxis=-1;
ch0->LimitSwitchOptions=0x0;
ch0->SoftLimitPos=1e+030;
ch0->SoftLimitNeg=-1e+030;
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=20;

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=0.000769;
ch0->iir[2].B1=0.001538;
ch0->iir[2].B2=0.000769;
ch0->iir[2].A1=1.92076;
ch0->iir[2].A2=-0.923833;
EnableAxisDest(0,0);

ch1->InputMode=NO_INPUT_MODE;
ch1->OutputMode=STEP_DIR_MODE;
ch1->Vel=40000;
ch1->Accel=200000;
ch1->Jerk=4e+006;
ch1->P=0;
ch1->I=0.01;
ch1->D=0;
ch1->FFAccel=0;
ch1->FFVel=0;
ch1->MaxI=200;
ch1->MaxErr=1e+006;
ch1->MaxOutput=200;
ch1->DeadBandGain=1;
ch1->DeadBandRange=0;
ch1->InputChan0=0;
ch1->InputChan1=0;
ch1->OutputChan0=9;
ch1->OutputChan1=0;
ch1->MasterAxis=-1;
ch1->LimitSwitchOptions=0x0;
ch1->SoftLimitPos=1e+030;
ch1->SoftLimitNeg=-1e+030;
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=1000000000;
ch1->StepperAmplitude=20;

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=0.000769;
ch1->iir[2].B1=0.001538;
ch1->iir[2].B2=0.000769;
ch1->iir[2].A1=1.92076;
ch1->iir[2].A2=-0.923833;
EnableAxisDest(1,0);

ch2->InputMode=NO_INPUT_MODE;
ch2->OutputMode=STEP_DIR_MODE;
ch2->Vel=40000;
ch2->Accel=200000;
ch2->Jerk=4e+006;
ch2->P=0;
ch2->I=0.01;
ch2->D=0;
ch2->FFAccel=0;
ch2->FFVel=0;
ch2->MaxI=200;
ch2->MaxErr=1e+006;
ch2->MaxOutput=200;
ch2->DeadBandGain=1;
ch2->DeadBandRange=0;
ch2->InputChan0=0;
ch2->InputChan1=0;
ch2->OutputChan0=10;
ch2->OutputChan1=0;
ch2->MasterAxis=-1;
ch2->LimitSwitchOptions=0x0;
ch2->SoftLimitPos=1e+009;
ch2->SoftLimitNeg=-1e+009;
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=1000000000;
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;
EnableAxisDest(2,0);

DefineCoordSystem(0,1,2,-1);

SetBitDirection(45,1); // set Enable Signal as Output
SetBit(45); // Enable the amplifiers

// Add a small amount of Coordinated Motion Path smoothing if desired
// Tau = 0.001; // seconds for Low Pass Filter Time Constant
// KLP = exp(-TIMEBASE/Tau);
KLP=0; // force to 0 to disable
// printf("Tau=%f KLP=%f\n",Tau,KLP);


for (;;) // loop forever
{
WaitNextTimeSlice();
ServiceDoorMonitor();

// Service Amplifier disable after no activity for a while
if (ch0->Dest != LastX || ch1->Dest != LastY || ch2->Dest != LastZ)
{
// we moved - enable KStep Amplifers
SetBit(45);
T0 = Time_sec(); // record the time and position of last motion
LastX=ch0->Dest;
LastY=ch1->Dest;
LastZ=ch2->Dest;
}
else
{
if (Time_sec() > T0 + 10.0) ClearBit(45);
}
}

return 0;
}

#define StateDoorIsClosed 0
#define StateWaitingForFeedHoldComplete 1
#define StateDoorIsOpen 2
#define WaitingForSpindleSpinUp 3

#define DOOROPENBIT 46
#define SPINDLEBIT 47

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

// function prototypes for compiler
int Debounce(int n, int *cnt, int *last, int *lastsolid);

// state variables for switch debouncing
int dlast=0,dlastsolid=-1,dcount=0;

// Monitor Door called continuously
//
// Keeps track of what State we are in and watches for the appropriate event
// to perform some action and transition to a new state

void ServiceDoorMonitor(void)
{
static int JobWasActive, SpindleWasOn, PrevJobActive, State=StateDoorIsClosed;
static double SpinUpTime;


switch (State)
{
case StateDoorIsClosed:
// check if door was opened
if (Debounce(ReadBit(DOOROPENBIT),&dcount,&dlast,&dlastsolid)==1)
{
//Door was opened
printf("Door was opened\n");
StopCoordinatedMotion(); // command Feedhold
State++;
}
break;

case StateWaitingForFeedHoldComplete:
// Check if Feedhold has completed or not active
if (CS0_StoppingState == 0 || CS0_StoppingState > 2)
{
SpindleWasOn = ReadBit(SPINDLEBIT); // remember if Spindle was on
ClearBit(SPINDLEBIT); // StopSpindle
PrevJobActive = JobWasActive = JOB_ACTIVE;
printf("Door - Full Stop JobWasActive=%d SpindleWasOn=%d\n",JobWasActive,SpindleWasOn);
DoPC(PC_COMM_HALT); // Halt KMotionCNC
State++;
}
break;

case StateDoorIsOpen:
ClearBit(SPINDLEBIT); // Force Spindle Off in all cases
if (JOB_ACTIVE && !PrevJobActive) // did a Job suddenly start with door open?
{
printf("Job Started with Door Open\n");
StopCoordinatedMotion(); // command Feedhold
State=StateWaitingForFeedHoldComplete;
}
// check if door was closed
else if (Debounce(ReadBit(DOOROPENBIT),&dcount,&dlast,&dlastsolid)==0)
{
//Door was closed
printf("Door was closed\n");
if (JobWasActive && SpindleWasOn) // was Job running and Spindle on when door was opened??
{
printf("Door - Spindle Started - Time Delay Started\n");
SetBit(SPINDLEBIT); // Yes, StartSpindle
SpinUpTime = Time_sec() + 5.0; // Record Time Spindle should be up to speed
State++;
}
else
{
State=StateDoorIsClosed; //No, go directly to closed state
}
}
PrevJobActive = JOB_ACTIVE; // remember previous job state
break;

case WaitingForSpindleSpinUp:
// check if door was opened while still spinning up
if (Debounce(ReadBit(DOOROPENBIT),&dcount,&dlast,&dlastsolid)==1)
{
//Door was opened
printf("Door was opened while still spinning up\n");
State = StateWaitingForFeedHoldComplete;
}

// else, check if Time to resume Job
else if (Time_sec() > SpinUpTime)
{
printf("Door closed and Job Resumed\n");
DoPC(PC_COMM_EXECUTE);
State = StateDoorIsClosed;
}
break;
}
}


// Debounce a bit
//
// return 1 one time when first debounced high
// return 0 one time when first debounced low
// return -1 otherwise
#define DBTIME 300

int Debounce(int n, int *cnt, int *last, int *lastsolid)
{
int v = -1;

if (n == *last) // same as last time?
{
if (*cnt == DBTIME-1)
{
if (n != *lastsolid)
{
v = *lastsolid = n; // return debounced value
}
}
if (*cnt < DBTIME) (*cnt)++;
}
else
{
*cnt = 0; // reset count
}
*last = n;
return v;
}

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

Re: how to implement a security switch launching a program / gcode

Post by TomKerekes » Sat Apr 28, 2018 10:28 pm

Hi Johannes,
To keep it as simple and safe as possible, I will try to program the most basic case:

stop motion, turn off spindle and dont do anything when closing the door again, thus, the user has to resume the job onscreen (KmotionCNC-button) if(!) the door is again closed.
That will simplify things greatly
For this, I suppose it might be sufficient to start with the first part of your suggested code and use

StopCoordinatedMotion();
ClearBit(SPINDLEBIT)
Do you think it will be ok to start stopping motion and turn off the Spindle at the same time?

StopCoordinatedMotion(); will be like hitting Feedhold. So you probably want to send a Halt to KMotionCNC so it doesn't resume if the Feedhold is released.

It isn't clear what you want to permit while the door is open? Jogging? CycleStart?

Regards
Regards,

Tom Kerekes
Dynomotion, Inc.

Jojo
Posts: 8
Joined: Fri Apr 27, 2018 6:34 am

Re: how to implement a security switch launching a program / gcode

Post by Jojo » Sun Apr 29, 2018 8:56 pm

Dear Tom,

thanks again for the reply!
You are right, I mixed up Feedhold and Halt..

Currently I think the following might be a good starting point for a first setup:
When opening the door, perform:

1) Halt G Code (like F5)
can you tell me whats the corresponding C-Code for that?

2) once halted, turn off spindle (like F11, or corresponding M5, spindle off)
can you tell me whats the corresponding C-Code for that?

3) possibly: stop program (like M0)
can you tell me whats the corresponding C-Code for that?

4) possibily: Feedhold (like F3)
StopCoordinatedMotion();

From then on, the user should resume the currently running G-Code-program from KmotionCNC-screen (if (!) the door is closed again). So:
a) start spindle (M3, F9)
b) possibly deactivate Feedhold (F3)
c) continue job (F5)

Could you give me some hints on the missing C-Code for 1) to 3) in the above list?

Thanks a lot!
Kind regards

Johannes

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

Re: how to implement a security switch launching a program / gcode

Post by TomKerekes » Sun Apr 29, 2018 9:42 pm

Hi Johannes,
1) Halt G Code (like F5)
can you tell me whats the corresponding C-Code for that?
DoPC(PC_COMM_HALT); // Halt KMotionCNC
2) once halted, turn off spindle (like F11, or corresponding M5, spindle off)
can you tell me whats the corresponding C-Code for that?
Rather than telling KMotionCNC to do an M5 it would faster and safer to turn off the Spindle Directly. How does your Spindle work? Is it just turning on/off a bit?
3) possibly: stop program (like M0)
can you tell me whats the corresponding C-Code for that?
This would be the same as Halt above. You can't really Insert an M0 into running GCode and if you could it could be a while before things stop.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

Jojo
Posts: 8
Joined: Fri Apr 27, 2018 6:34 am

Re: how to implement a security switch launching a program / gcode

Post by Jojo » Mon Apr 30, 2018 10:07 pm

Dear Tom,

again, thanks a lot. So my ini-file would curretly look like the one below (removed the "standard parts").
Does this seem somehow reasonable?

I dont know though how to run the

if(ReadBit(180)); ...
...

only if the door is really closed; currently the if loop will be executed every timeslice as long as the door is open I suppose, which might be very stressy for Kmotion..



Another question:
Its not yet clear to me what the additional Feedhold at the end will lead to (machine and controller currently not accessible, so cannot yet test it).
Maybe I should first do the Feedhold and then halt?
Since I am working with steppers (not servos), and since I want to continue the job manually via KmotionCNC-screen after closing the door again, it would be very important that the Feddhold command does not lead to "uncoordinated step losses".

As usual, thanks a lot again:)
Kind regards,

Johannes


int main()
{
// variables for amplifyer activation/deactivation
double T0, LastX=0, LastY=0, LastZ=0, LastA=0, Tau;

KStepPresent=TRUE; // enable KSTEP input multiplexing
FPGA(KAN_TRIG_REG)=4; // Mux PWM0 to JP7 Pin5 IO 44 for KSTEP

FPGA(STEP_PULSE_LENGTH_ADD) = 63 + 0x80; // set polarity and pulse length to 4us

ch0->InputMode=NO_INPUT_MODE;
...

DefineCoordSystem(0,1,2,3);
...


// http://dynomotion.com/Help/SchematicsKS ... gKStep.htm
SetBitDirection(45,1); // Amplifier bit, set Enable Signal as Output
SetBit(45); // Enable the amplifiers

SetBitDirection(1,1); // JP33 Pin 3,4: KFLOP Bit 1: KFLOP Relais schaltet Relais für untere Steckdose (zB Spindel)
// set Enable Signal as Output (means: activate!)
// see also help on KMOTION digital I/O screen
SetBitDirection(0,1); // JP33 Pin 1,2: KFLOP Bit 0: KFLOP Relais, schaltet zB WJ200 logischen Input
// set Enable Signal as Output (means: activate!)
// see also help on KMOTION digital I/O screen

for (;;) // loop forever
{
WaitNextTimeSlice();
ServiceDoorMonitor();
}

return 0;
}


void ServiceDoorMonitor(void)
{
if(ReadBit(180)); // door was opened
{
DoPC(PC_COMM_HALT); // Halt KMotionCNC
ClearBit(1); // stop spindle: bit 1 is the bit that turns the 220V-socket,
// to which FU is connected, on and off
StopCoordinatedMotion(); // Feedhold
}

}

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

Re: how to implement a security switch launching a program / gcode

Post by TomKerekes » Mon Apr 30, 2018 10:42 pm

Hi Johannes
I dont know though how to run the

if(ReadBit(180)); ...
...

only if the door is really closed; currently the if loop will be executed every timeslice as long as the door is open I suppose, which might be very stressy for Kmotion..
Yes sending infinite Halts while the door is open to KMotionCNC wouldn't be nice.

The simplest method might be to use the standard Debounce function. That will eliminate possible rapid glitches caused by switch bouncing and it also will return 1 only once when the door transitions to open. It returns 0 when the door transitions to closed and -1 otherwise. So you can just check for 1 to do one Halt every time the door opens.

You had a bug in your code. An "if" statement executes the next statement (or block) before the next semicolon ';'. So you should remove the ';' after the "if" otherwise it would not do the block. It would always do nothing.
Another question:
Its not yet clear to me what the additional Feedhold at the end will lead to (machine and controller currently not accessible, so cannot yet test it).
Maybe I should first do the Feedhold and then halt?
Yes. I recommend doing the Feedhold first. That should stop things quicker and without the PC being involved. When KMotionCNC Halts it does a Feedhold first but it shoudn't matter if Feehold is already in progress.
Since I am working with steppers (not servos), and since I want to continue the job manually via KmotionCNC-screen after closing the door again, it would be very important that the Feddhold command does not lead to "uncoordinated step losses".
Feedhold should bring the motion to a stop in a controlled manner such that there should be no steps lost.

So you might try this:

Code: Select all

// function prototypes for compiler
int Debounce(int n, int *cnt, int *last, int *lastsolid);

// state variables for switch debouncing
int dlast=0,dlastsolid=-1,dcount=0;

void ServiceDoorMonitor(void)
{
    if(Debounce(ReadBit(180),&dcount,&dlast,&dlastsolid)==1) // door was opened
    {
        ClearBit(1); // stop spindle: bit 1 is the bit that turns the 220V-socket,
        // to which FU is connected, on and off
        StopCoordinatedMotion(); // Feedhold
        DoPC(PC_COMM_HALT); // Halt KMotionCNC
    }
}
You will need to include the Debounce function included in the previous example.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

Jojo
Posts: 8
Joined: Fri Apr 27, 2018 6:34 am

Re: how to implement a security switch launching a program / gcode

Post by Jojo » Wed May 02, 2018 8:40 pm

Hi Tom,

great, removed the semicolon and included the debounce function. Really looking forward to test it on the machine soon..

I have two more questions if you dont mind..

After opening the door: if I remove Feedhold, the machine is still on Halt. Then I close the door. Then I move the axis in KmotionCNC (they should be free to move I suppose?). If I now continue illingby releasing halt (with F5for exaple) will the milling process continue with the latest saved position that was active when the "halt" command was issued? So will it travel from the altered position to the one it left off after halt and then continue?

After switching of the relais the FU is hooked up to with

ClearBit(1); // stop spindle: bit 1 is the bit that turns the 220V-socket,
// to which FU is connected, on and off

I think it would be great to "arm" it again, but before that turn off the spindle in KmotionCNC. If I understand correctly, the following command should be equivalent to the gcode-command "M5"

DoPCInt(PC_COMM_MCODE,5); // stop spindle

Is this correct? If so, Iwould do the followingin the ServiceDoorMonitor-function

ClearBit(1);
DoPCInt(PC_COMM_MCODE,5); // command M5
SetBit(1); //turn FU on again

Then the user does not have to remember to again switch on the FU..

As usual, thanks a lot in advance!
Kind regards,

Johannes

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

Re: how to implement a security switch launching a program / gcode

Post by TomKerekes » Thu May 03, 2018 1:14 am

Hi Johannes,
After opening the door: if I remove Feedhold, the machine is still on Halt.
Halt is not really a state. A Halt causes the execution to stop gracefully with the exact stopping point recorded internally. The system is then basically idle. To resume you can push Cycle Start. Note the point that was stopped might well be within the middle of a GCode Block. If within a GCode Block the remaining portion of the block will be executed. If nothing has moved then the motion will simply continue from where it came to a stop. However if the system was Jogged or otherwise moved at all, and the GCode was not Restarted, then the system will prompt the Operator for a resume sequence to get back to where it was.
SafeResume.png
SafeResume.png (11.02 KiB) Viewed 10928 times
I don't really understand your questions. What is an FU? Spindle? I don't see how commanding an M5 would help.

I think you should test what you have so far. But there are probably several other cases that need to be handled.

Regards
Regards,

Tom Kerekes
Dynomotion, Inc.

Jojo
Posts: 8
Joined: Fri Apr 27, 2018 6:34 am

Re: how to implement a security switch launching a program / gcode

Post by Jojo » Thu May 03, 2018 5:20 am

Hi Tom,

thanks! Ok, understood. The halt might (most likely) be issued within a GCode Block and I will be prompted in case I move away from the current location, perfect!

Concerning spindle:
yes, "FU" is the controller driving my spindle (sorry, I guess the abbreviation "FU" is german for "Frequenz-Umrichter"...).
In the current C-program I completely switch it off via relais on bit "1":

ClearBit(1);

However, it would be nice to also change the GCode-state and switch off the spindle with an M5 command:

DoPCInt(PC_COMM_MCODE,5); // command M5

and then again switch on the FU:

SetBit(1);

This way, the spindle will be "armed" and can be restarted with "M3" or the corresponding KmotionCNC-button (without having to remember to also activate the FU again).

As you suggest, I will just start testing with the current state of the code and come back once I have more info or question..
Thanks again!
Kind regards,

Johannes

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

Re: how to implement a security switch launching a program / gcode

Post by TomKerekes » Thu May 03, 2018 7:02 am

Hi Johannes,

Well in English FU represents something very insulting and vulgar :D

But I'm afraid I'm still confused. Wouldn't M5 be configured to turn off Bit 1 and therefore do nothing? And then wouldn't SetBit(1); turn the Spindle back on and start spinning? Do you have two IO bits controlling the Spindle? How do you have M3 and M5 configured?

Regards
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply