MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.25k stars 19.23k forks source link

Order of operations for planner when using solenoids #23391

Open FormenSul opened 2 years ago

FormenSul commented 2 years ago

Is your feature request related to a problem? Please describe.

I have made a printhead that uses a solenoid. I added a command to turn on the solenoid in G10, and turn off the solenoid in G11, and I want the solenoid to turn on at the beginning of the retraction and turn off after. Instead, the solenoid is turned on as soon as it hits Planner :: block_buffer, with all other parts of the retract being executed on time. If both commands G10 and G11 fall into the buffer, the solenoid turns on and off immediately, after which printing continues. I found this peculiarity by changing the buffer size, when it = 2, the solenoids work almost correctly. I also tried adding these commands to fwretract.cpp, the result does not change

Are you looking for hardware support?

printer flying bear ghost 5, with significant changes mks_robin_nano35 marlin 2.0.9.1

Describe the feature you want

Is it possible to change the priority in the Planner so that the solenoids opens and closes on time?

Additional context

these are my changes in G10 and G11

void GcodeSuite::G10() {
  #if HAS_MULTI_EXTRUDER
    const bool rs = parser.boolval('S');
  #endif
  fwretract.retract(true
    #if HAS_MULTI_EXTRUDER
      , rs
    #endif
  );
    #ifdef epoxy
      enable_solenoid(1);
      disable_solenoid(0);
    #endif
}

/**
 * G11 - Recover filament according to settings of M208
 */
void GcodeSuite::G11() { 
  fwretract.retract(false);     
  #ifdef epoxy
      enable_solenoid(0);
      disable_solenoid(1);
  #endif
  }

FWRETRACT settings:

#define FWRETRACT
#if ENABLED(FWRETRACT)
  //#define FWRETRACT_AUTORETRACT             // Override slicer retractions
  #if ENABLED(FWRETRACT_AUTORETRACT)
    #define MIN_AUTORETRACT             0 // (mm) Don't convert E moves under this length
    #define MAX_AUTORETRACT             0 // (mm) Don't convert E moves over this length
  #endif
  #define RETRACT_LENGTH                0   // (mm) Default retract length (positive value)
  #define RETRACT_LENGTH_SWAP           0   // (mm) Default swap retract length (positive value)
  #define RETRACT_FEEDRATE              0   // (mm/s) Default feedrate for retracting
  #define RETRACT_ZRAISE                1   // (mm) Default retract Z-raise
  #define RETRACT_RECOVER_LENGTH        0   // (mm) Default additional recover length (added to retract length on recover)
  #define RETRACT_RECOVER_LENGTH_SWAP   0   // (mm) Default additional swap recover length (added to retract length on recover from toolchange)
  #define RETRACT_RECOVER_FEEDRATE      0   // (mm/s) Default feedrate for recovering from retraction
  #define RETRACT_RECOVER_FEEDRATE_SWAP 0   // (mm/s) Default feedrate for recovering from swap retraction
  #if ENABLED(MIXING_EXTRUDER)
    //#define RETRACT_SYNC_MIXING           // Retract and restore all mixing steppers simultaneously
  #endif
#endif

part of g-code, as a sample, if BLOCK_BUFFER_SIZE = 16

G1 X19.953 Y144.455 E40.28643 G1 X19.845 Y143.727 E40.33900 solenoid open solenoid close G1 X19.794 Y143.203 E40.37654 G1 X19.643 Y140.000 E40.60557 G1 X19.643 Y37.000 E47.96141 G1 X19.669 Y36.475 E47.99895 G1 X19.803 Y35.109 E48.09695 G1 X20.008 Y34.079 E48.17195 G1 X20.406 Y32.766 E48.26996 G1 X20.808 Y31.796 E48.34495 G1 X21.455 Y30.586 E48.44295 G1 X22.039 Y29.712 E48.51795 G1 X22.909 Y28.652 E48.61595 G1 X23.588 Y27.973 E48.68452 G10 (z-hope on time) G92 E0 G1 X25.200 Y37.010 F12000.000 G11

thinkyhead commented 2 years ago

Marlin relies on these commands only involving planner moves, and thus executing in proper sequence with other queued moves. Therefore G10 / G11 do not call planner.synchronize at any point.

So see if it helps to insert some M400 commands in strategic places, such as just before G10 and just before G11.