Door-switch check conditional code
-
(using RRF3.2beta3)
Hi, I am using the duex.e2temp terminal to operate a door switch on a CNC machine as an external trigger. I want to also have some conditional code available to check the state of the pins before a job can start or while resuming after a pause. This is to prevent gcode being processed if the door is left open for safety reasons.
I've created and assigned the pin as such, with an R1 setting on M581 so it’ll only trigger while processing gcode:
M950 J6 C"!duex.e2temp" ; duex.e2temp M581 P6 S0 T5 R1 ; T5 only while processing gcode.
I've tried to write the conditions, but I don't think I'm using the correct terms. Value 1 = door closed while 0 is door open. I am using a normally closed switch with the idea being that if the cables were to come lose it should identify as the door being left ajar and files cannot be sent.
My resume and start files refer to the following with an M98 P”Condition2.g”:
if state.status == "resuming" | state.status == "processing" & sensors.gpIn[6].value=0 M25 ; Pause elif state.status == "paused" | state.status == "pausing" & sensors.gpIn[6].value=0 M291 P"Shut enclosure door before commencing" R"Warming" ; M292 P1 ; else
and the door switch trigger refers to:
if state.status == "resuming" | state.status == "processing" & sensors.gpIn[6].value=0 M25 ; Pause else state.status == "paused" | state.status == "pausing" & sensors.gpIn[6].value=0 M291 P"Shut enclosure door before commencing" R"Warming" ; M292 P1 ;
What I’m finding it that if I test the code by leaving the door open before starting some gcode I cannot resume, and if I try to cancel I get an “M0 H1 – M0: Pause the print before attempting to cancel it” message. I’m wondering if I should persist with this or if there’s plans to add a new machine state based on enclosure door being opened? Any advice welcomed.
-
-
Please confirm that you have indented the commands within the if- and else-block in your files. The command blocks you have posted show no indentation.
-
M25 will not work before the print has started.
-
If you use M25 within resume.g, I think it will schedule a pause for when the print is about to resume (i.e. resume.g has completed and the tool has moved back to the resume position), however I have not tested this. It might be better to use something like this in resume.g instead:
while sensors.gpIn[6].value=0 M291 S2 R"Door open" P"Close the door and press OK to continue, or Cancel to cancel the job"
Caution: I have not tested this.
-
-
@EducatingSavvas if that's a straight copy and paste you don't have the code indented correctly.
Should look something like thisif state.status == "resuming" | state.status == "processing" & sensors.gpIn[6].value=0 M25 ; Pause else state.status == "paused" | state.status == "pausing" & sensors.gpIn[6].value=0 M291 P"Shut enclosure door before commencing" R"Warming" ; M292 P1
-
@dc42 @jay_s_uk Apologies, the indentation were correct in the actual files. I think I may have looped the conditions somehow - and over complicated them. I'll also try using what was suggest and also while sensors.gpIn[6].value=1 and M291, before the start code to see if the prevents a job starting before the door is closed. Will have to do this when I'm next in and report back. Cheers.
-
@dc42 I can confirm this works with one exception.
The start.g and resume.g refer to a file I've named conditional2.g with the following:
while sensors.gpIn[6].value=0
M291 S2 R"Enclosure Door Open" P"Close the door and press OK to continue"while the door switch itself uses external trigger5.g with the following:
if state.status == "processing" & sensors.gpIn[6].value=0
M25 ; Pause
M291 S1 R"Enclosure Door Open" P"Close the door before resuming"The exception is if I change the M291 in conditional2.g to an S3 which includes cancel - pressing cancel results it the job running while the door is open. It would be good to link that cancel option to cancelling the job. Is there a way of instructing the cancel in M291 to do something specific?