Welcome! Log In Create A New Profile

Advanced

SOLVED Marlin and GCODE processing sequence v1.1.8

Posted by n9jcv 
SOLVED Marlin and GCODE processing sequence v1.1.8
April 27, 2019 01:47PM
I am having a bit of difficulty with something new I am working on. I am trying to add some new functionality for a robot and I am sure there are things I do not understand about Marlin. I have literally been up every night this week til early morning trying to get this to work and just need a bit of assistance please.

Here is a sample of a series of gcodes I execute from pronterface
where it says switch would be hit that is an endstop I have set up as E (i added new gcode to steppers.cpp to check this, that code is below as well, the code works fine when running from pronterface)
Anyway, I want to home E thus the G1 e-300 f100
then it hits the switch, then I disable endstops, set the home position for E to zero, reverse E just a bit to back off the endstop, enable the endstops, and reset the new position as E0 - this all works perfectly in pronterface when I type commands one at a time.

However, I then put the code in a gcode file and run from an SD card and BAM it does not work at all. The endstop no longer stops the motor at home. I am pretty sure this is due to queuing and processing commands out of order/or at least 2nd, 3rd,4th, etc before the 1st is completed.

G21			;METRIC
G90		     ;ABSOLUTE POS
M82			;M82 EXTRUDER ABSOLUTE

G1 E-300 F100	;HOME E
;SWITCH WOULD BE HIT
M121			;DISABLE ENDSTOPS TO MOVE AWAY
G92 E0		;SET POSITION TO ZERO
G1 E2 F50
M120			;ENABLE ENDSTOPS
G92 E0			;RESET POSITION AWAY FROM ENDSTOP AS ZERO

So I tried to deal with this in marlinmain.cpp. I wrote a new MCODE routine(below). I then had a gcode file with just a single M442 in it. It still does not process the way I want. I thought that my enqueuing a command and issuing a stepper.synchronize, it would do that command and wait for completion before the next.

So if you have ideas for how to process the original gcodes above, sequentially, I would be much appreciative. Or perhaps my M442 coding is missing something else to make it process properly.

inline void gcode_M442() {
  
  safe_delay(100);
    SERIAL_ECHO_START();
    SERIAL_ECHOLNPAIR("M442 START ", parser.value_byte());
    lcd_setstatus("M442 START");
enqueue_and_echo_commands_P(PSTR("G21"));
stepper.synchronize();
enqueue_and_echo_commands_P(PSTR("G90"));
stepper.synchronize();
enqueue_and_echo_commands_P(PSTR("M82"));
stepper.synchronize();
enqueue_and_echo_commands_P(PSTR("G1 E-300 F100"));
stepper.synchronize();
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR("AFTER G1 300 ", parser.value_byte());
lcd_setstatus("AFTER G1 300 ");
enqueue_and_echo_commands_P(PSTR("M121"));
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR("AFTER M121 ", parser.value_byte());
lcd_setstatus("AFTER M121 ");
stepper.synchronize();
enqueue_and_echo_commands_P(PSTR("G92 E0"));
stepper.synchronize();
enqueue_and_echo_commands_P(PSTR("G1 E2 F50"));
stepper.synchronize();
enqueue_and_echo_commands_P(PSTR("M120"));
stepper.synchronize();
enqueue_and_echo_commands_P(PSTR("G92 E0"));
stepper.synchronize();
}

Pronterface output from m442 command
echo:enqueueing "M23 test9~1.gco"
echo:enqueueing "M24"
echo:Now fresh file: test9~1.gco
File opened: test9~1.gco Size: 156
File selected
Done printing fiecho:enqueueing "M84 X Y Z E"
le
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing
echo:busy: processing

gcode from steppers.cpp
  if((READ(E_MIN_PIN) == 0) && (ENDSTOPS_ENABLED))
        {SERIAL_PROTOCOLPGM("reademin");
          stepper.endstop_triggered(E_AXIS);
          all_steps_done = true;
          current_block = NULL;
          planner.discard_current_block();
                 }

Edited 2 time(s). Last edit at 04/27/2019 04:29PM by n9jcv.
Re: Marlin and GCODE processing sequence
April 27, 2019 03:07PM
I have made some changes and have different results, still not exactly what I need though.

I am trying this from SD card
G21			;METRIC
G90		     ;ABSOLUTE POS
M82			;M82 EXTRUDER ABSOLUTE

G1 E-300 F100	;HOME E SWITCH WOULD BE HIT
M400			;WAIT FOR PLANNER MOVES
M121			;DISABLE ENDSTOPS TO MOVE AWAY
G92 E0		;SET POSITION TO ZERO
G1 E2 F500
M400			;WAIT FOR PLANNER MOVES
M120			;ENABLE ENDSTOPS
G92 E0			;RESET POSITION AWAY FROM ENDSTOP AS ZERO

M117 JOB FINISHED

I put the M400 in to ensure my g1's execute before continuing now that appears to work. The issue I see now is the second G1, is supposed to move for 2mm but it turns for what seems to be the remaining portion of the 300 when it encountered the endstop. The first g1 turns at f100 and I see this. The second g1 turns at f500 and I see it turn fast, but way farther than 2mm.

I have code in steppers.cpp, that I thought would kill the remaining
G1 E-300 F100 ;HOME E SWITCH WOULD BE HIT

here is my stepper code
I thought the following would eliminate anything for the above command that was left over;
all_steps_done = true;
current_block = NULL;
planner.discard_current_block();

if((READ(E_MIN_PIN) == 0) && (ENDSTOPS_ENABLED))
        {SERIAL_PROTOCOLPGM("reademin");
          //stepper.endstop_triggered(E_AXIS);
          all_steps_done = true;
          current_block = NULL;
          planner.discard_current_block();
                           }

        PULSE_STOP(E);
        #endif


Any help would be greatly appreciated
Thank You

Edited 2 time(s). Last edit at 04/27/2019 04:24PM by n9jcv.
Re: SOLVED Marlin and GCODE processing sequence v1.1.8
April 27, 2019 04:34PM
Not exactly sure how I solved this, making so many changes and testing, but I now have it working;

Gcode looks like this;

G21			;METRIC
G90		     ;ABSOLUTE POS
M82			;M82 EXTRUDER ABSOLUTE

G1 E-200 F100	;HOME E SWITCH WOULD BE HIT
M400			;WAIT FOR PLANNER MOVES
M121			;DISABLE ENDSTOPS TO MOVE AWAY
G92 E0		;SET POSITION TO ZERO
G1 E2 F500
M400			;WAIT FOR PLANNER MOVES
M120			;ENABLE ENDSTOPS
G92 E0		;RESET POSITION AWAY FROM ENDSTOP AS ZERO

steppers.cpp has this code

if((READ(E_MIN_PIN) == 0) && (ENDSTOPS_ENABLED))
        {SERIAL_PROTOCOLPGM("reademin");
          SERIAL_EOL();
          //stepper.endstop_triggered(E_AXIS);
          all_steps_done = true;
          current_block = NULL;
          planner.discard_current_block();
                  }

I also have this in configuration_adv
#define ENDSTOPS_ALWAYS_ON_DEFAULT

and I have many other changes for the pins for E_MIN_PIN

I realize this is not the "Correct" way to get another endstop working, but for me it was the easiest, and I really had limited requirements
Marlin is very complex and very Good. The developers did an excellent job with documentation and readability, but when you are new to C++ and Marlin, it can be very challenging.
Thanks to the Marlin Developers for making this open source for everyone!!!!
Sorry, only registered users may post in this forum.

Click here to login