Control LED lights with conditional code
-
Hiya - I'm trying to write a short piece of conditional code to change some LED colours and their behaviour depending on the status on the duet 2 wifi (RRF 3.1.1). I'm using the controller for a CNC machine and want a white light while idle, red while cutting and yellow during pause.
My conditional2.g file contains the following:
M42 P4 S0 ; Turn LED off (Warm White)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0 ; Turn LED off (Red)
M42 P7 S0 ; Turn LED off (Yellow)if state.status == "paused"
M42 P7 S0.1
elif state.status == "resume" || state.status == "printing"
M42 P6 S0.1
else
M42 P4 S0.1I have placed an M98 P"condition2.g in my start.g, pause.g, resume.g and cancel.g files. The pause and cancel files are executing the code but it's not working with start or resume. Can anyone tell me if I've written that part of the code incorrectly, or if the status of the machine is still in the previous state while resume.g and start.g happen?
Thanks in advance.
-
Have you considered putting that code in daemon.g ?
While resume.g is running, the state will be "resuming", not "resume".
-
This post is deleted! -
Thanks - I've combined that and another piece of conditonal g-code into the deomon.g file in this way:
if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed || !move.axes[3].homed ; if axes are 0,1,2 and 3 are not homed do...
M42 P4 S0 ; Turn LED off (Warm White)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0 ; Turn LED off (Red)
M42 P7 S0.1 ; Turn LED on (Yellow)elif state.status == "paused"
M42 P4 S0 ; Turn LED off (WW)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0 ; Turn LED off (Red)
M42 P7 S0.1 ; Turn LED on (Yellow)elif state.status == "processing"
M42 P4 S0 ; Turn LED off (WW)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0.1 ; Turn LED on (Red)
M42 P7 S0 ; Turn LED off (Yellow)else
M42 P4 S0.1 ; Turn LED on (WW)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0 ; Turn LED off (Red)
M42 P7 S0 ; Turn LED off (Yellow)I'm finding state.status == "resuming" doesn't work - I'm not sure if it is happening too quickly so I'm about to try put a dwell command in the resume.g file. Otherwise the lights remains yellow from the pause while the machine has already resumed the cutting procedure.
I've also had another idea - therefore a question about oscillating the PWM signal from the fan headers to differentiate between a solid yellow for axis being un-homed and a diming to bright looping yellow for paused. Do you have any advice on where I can find information to help me do that? Thanks again.
-
Just to add to the above - it seems that the resuming state happens after the resume.g file occurs - which is why I can't refer to state.status == "resume" in the resume.g file.
As it stands it can take up to 10 seconds before the red warming lights turns on after resuming form a pause with the above code in the daemon.g file by which time the machine has already started cutting. The pause.g and pause state occur more simultaneously.
Where this could become a bigger problem is if I were to write additional M42 commands in the daemon.g file to trigger relay modules to operate a dust extractor and air filter for a CNC router machine - up to 10 seconds is too long to wait for the extraction to turn on - especially if a cnc machine is already cutting and producing dust.
-
you could "cheat" the system I suppose and use a work place co-ordinate as a trigger that resume has been called.
I.e. something likeG10 L9 X1
Then check if its set to one in the daemon file.
if move.axes[0].workplaceOffsets[8]==1 do x G10 L9 X0
So running the code and then setting it back to 0.
This will be easier once variables come in
-
@jay_s_uk just had a thought that I could call the daemon.g file using the m98 command in resume.g - but I'll have to wait to test that next time I can get in.
-
@EducatingSavvas daemon.g is ran roughly every second on its own thread i believe so theres no need to call it
-
I will investigate whether or not the Resuming state is being reported correctly.
-
I confirm that the Resuming state is not reported correctly. I will try to get this fixed in time for 3.2beta3.
-
@dc42 The resume state is behaving properly now. I though there was a problem with the pause but had change my conditional code to the following to include the pausing state. Really happy with how this works now.
if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed || !move.axes[3].homed ; if axes are 0,1,2 and 3 are not homed do...
M42 P4 S0 ; Turn LED off (Warm White)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0 ; Turn LED off (Red)
M42 P7 S0.1 ; Turn LED on (Yellow)elif state.status == "paused" | state.status == "pausing"
M42 P4 S0 ; Turn LED off (WW)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0 ; Turn LED off (Red)
M42 P7 S0.1 ; Turn LED on (Yellow)elif state.status == "resuming" | state.status == "processing" | state.status == "halted"
M42 P4 S0 ; Turn LED off (WW)
M42 P5 S0 ; Turn LED on (Blue)
M42 P6 S0.1 ; Turn LED off (Red)
M42 P7 S0 ; Turn LED off (Yellow)else
M42 P4 S0.1 ; Turn LED on (WW)
M42 P5 S0 ; Turn LED off (Blue)
M42 P6 S0 ; Turn LED off (Red)
M42 P7 S0 ; Turn LED off (Yellow) -
Thanks for confirming.