Bypassing the Marlin G-Code queue
March 10, 2022 07:15AM
Hello,
I am working on the Marlin-firmware of an Marlin-Robin-Nano-v3 board with an STM32F4.
I want to include a safety-feature which is called directly and does not have to wait for its turn in the queue.
Specificially, I am detecting when an applied force is too large and want to instantaniously lower the force without waiting for the queue.

Alternatively, is there a way to write directly to the front of the queue?
Re: Bypassing the Marlin G-Code queue
March 10, 2022 07:56AM
This is what EMERGENCY_PARSER is for
Is processed as soon as the code is loaded

But your probably needing monitoring as well not just gcode execution

Edited 1 time(s). Last edit at 03/10/2022 07:57AM by Dust.
Re: Bypassing the Marlin G-Code queue
March 10, 2022 08:43AM
That's a good idea, thank you. Do you know how I can parse directly from code? Do you know the function_x to call like function_x("M108"); , so that M108 gets executed?
Re: Bypassing the Marlin G-Code queue
March 10, 2022 06:40PM
There are a bunch

inject_P
inject
enqueue_one_now

depending on needs

Edited 1 time(s). Last edit at 03/10/2022 08:45PM by Dust.
Re: Bypassing the Marlin G-Code queue
March 14, 2022 03:59AM
With inject_P and inject I had no luck unfortunately. It adds the stop at the end of the queue. enqueue_one_now does not work at all.
Right now, my setup is: "Is a force detected that is too high?"(DMA and ADC, so the detection itself is really fast) --> Interrupt. Here I call queue.inject("M0 S5\n"); The M0 command only starts at the end of the queue, which is too late for a force overprotection. The EMERGENCY_PARSER is definitely activated. Does the EMERGENCY_PARSER only work on code sent by UART?

Maybe it is an option to move the steppers directly? Such as: too much pushing force detected. Move in z direction for as long as it needs to reduce the force

Edited 1 time(s). Last edit at 03/14/2022 04:29AM by alex939.
Re: Bypassing the Marlin G-Code queue
March 14, 2022 04:51AM
EMERGENCY_PARSER only works with particular gcodes, not all, and definitely not M0

Yes Emergency passer scans the incommoding serial stream for certain gcode, this is how it jumps the main gcode queue, so i not usable in this instance

use
void kill(FSTR_P const lcd_error=nullptr, FSTR_P const lcd_component=nullptr, const bool steppers_off=false);
or
void minkill(const bool steppers_off=false);

Edited 1 time(s). Last edit at 03/14/2022 04:56AM by Dust.
Re: Bypassing the Marlin G-Code queue
March 14, 2022 06:24AM
Ah alright, thank you.
Sadly, kill is not appropriate to use with my application. My idea was to stop the current G-Code from executing and move on to the next G-Code in queue.
In my interrupt, what I tried is to do:
queue.inject("M0 S5\n");
queue.advance();

My idea was to advance the queue to instantly perform the injected M0-task. At the top of "GCodeQueue::advance()
is the following code:
// Process immediate commands
if (process_injected_command_P() || process_injected_command()) return;
so I would have expected the M0-task to run an then the printer returns to the rest of the original queue
Sorry, only registered users may post in this forum.

Click here to login