Skip to content

Commit

Permalink
Extend ABORT_ON_ENDSTOP_HIT to USB-printing
Browse files Browse the repository at this point in the history
Added configurable option ABORT_ON_ENDSTOP_HIT_INIT to activate the feature at boot time.
Changes some descriptive text.
Cleaned up the use of enable_endstops() in homeaxis().
Changed the initialisation of abort_on_endstop_hit to relate on ABORT_ON_ENDSTOP_HIT_INIT.
Changed checkHitEndstops() to
throw an ERROR instead of an ECHO when ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED.
Send "X=" instead of "X:" also for Y,Z and probe to make the output not readable by Repetier Host.

Abort all printing when ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED. Therefor the already existent feature for sd-printing was extended.

To come out of the look send M999.
  • Loading branch information
AnHardt committed Dec 8, 2015
1 parent ae4acc4 commit dcc190b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 46 deletions.
14 changes: 8 additions & 6 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,16 @@
// This allows hosts to request long names for files and folders with M33
//#define LONG_FILENAME_HOST_SUPPORT

// This option allows you to abort SD printing when any endstop is triggered.
// This feature must be enabled with "M540 S1" or from the LCD menu.
// To have any effect, endstops must be enabled during SD printing.
// With ENDSTOPS_ONLY_FOR_HOMING you must send "M120" to enable endstops.
//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED

#endif // SDSUPPORT

// This option allows you to abort printing when any endstop is triggered.
// This feature must be enabled with "M540 S1" or from the LCD menu
// or by #define ABORT_ON_ENDSTOP_HIT_INIT true.
// To have any effect, endstops must be enabled during printing.
// With ENDSTOPS_ONLY_FOR_HOMING you must send "M120" to enable endstops.
//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
//#define ABORT_ON_ENDSTOP_HIT_INIT true

// for dogm lcd displays you can choose some additional fonts:
#if ENABLED(DOGLCD)
// save 3120 bytes of PROGMEM by commenting out #define USE_BIG_EDIT_FONT
Expand Down
33 changes: 4 additions & 29 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
* M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
* M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
* M503 - Print the current settings (from memory not from EEPROM). Use S0 to leave off headings.
* M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
* M540 - Use S[0|1] to enable or disable the stop print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
* M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
* M665 - Set delta configurations: L<diagonal rod> R<delta radius> S<segments/s>
* M666 - Set delta endstop adjustment
Expand Down Expand Up @@ -246,7 +246,7 @@ float current_position[NUM_AXIS] = { 0.0 };
static float destination[NUM_AXIS] = { 0.0 };
bool axis_known_position[3] = { false };

static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;
static long gcode_N, gcode_LastN; //Stopped_gcode_LastN = 0; unused

static char* current_command, *current_command_args;
static int cmd_queue_index_r = 0;
Expand Down Expand Up @@ -1872,32 +1872,19 @@ static void homeaxis(AxisEnum axis) {
current_position[axis] = 0;
sync_plan_position();

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (marlin_debug_flags & DEBUG_LEVELING) {
SERIAL_ECHOLNPGM("> enable_endstops(false)");
}
#endif
enable_endstops(false); // Disable endstops while moving away

// Move away from the endstop by the axis HOME_BUMP_MM
destination[axis] = -home_bump_mm(axis) * axis_home_dir;
line_to_destination();
st_synchronize();

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (marlin_debug_flags & DEBUG_LEVELING) {
SERIAL_ECHOLNPGM("> enable_endstops(true)");
}
#endif
enable_endstops(true); // Enable endstops for next homing move

// Slow down the feedrate for the next move
set_homing_bump_feedrate(axis);

// Move slowly towards the endstop until triggered
destination[axis] = 2 * home_bump_mm(axis) * axis_home_dir;
line_to_destination();
st_synchronize();
endstops_hit_on_purpose(); // clear endstop hit flags

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (marlin_debug_flags & DEBUG_LEVELING) {
Expand Down Expand Up @@ -1933,12 +1920,6 @@ static void homeaxis(AxisEnum axis) {
#if ENABLED(DELTA)
// retrace by the amount specified in endstop_adj
if (endstop_adj[axis] * axis_home_dir < 0) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (marlin_debug_flags & DEBUG_LEVELING) {
SERIAL_ECHOLNPGM("> enable_endstops(false)");
}
#endif
enable_endstops(false); // Disable endstops while moving away
sync_plan_position();
destination[axis] = endstop_adj[axis];
#if ENABLED(DEBUG_LEVELING_FEATURE)
Expand All @@ -1949,12 +1930,6 @@ static void homeaxis(AxisEnum axis) {
#endif
line_to_destination();
st_synchronize();
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (marlin_debug_flags & DEBUG_LEVELING) {
SERIAL_ECHOLNPGM("> enable_endstops(true)");
}
#endif
enable_endstops(true); // Enable endstops for next homing move
}
#if ENABLED(DEBUG_LEVELING_FEATURE)
else {
Expand Down Expand Up @@ -7191,7 +7166,7 @@ void Stop() {
disable_all_heaters();
if (IsRunning()) {
Running = false;
Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart
//Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
LCD_MESSAGEPGM(MSG_STOPPED);
Expand Down
36 changes: 25 additions & 11 deletions Marlin/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_
old_endstop_bits = 0; // use X_MIN, X_MAX... Z_MAX, Z_MIN_PROBE, Z2_MIN, Z2_MAX

#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
bool abort_on_endstop_hit = false;
#if ENABLED(ABORT_ON_ENDSTOP_HIT_INIT)
bool abort_on_endstop_hit = ABORT_ON_ENDSTOP_HIT_INIT;
#else
bool abort_on_endstop_hit = false;
#endif
#endif

#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
Expand Down Expand Up @@ -251,36 +255,46 @@ void endstops_hit_on_purpose() {

void checkHitEndstops() {
if (endstop_hit_bits) {
SERIAL_ECHO_START;
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
if (abort_on_endstop_hit)
SERIAL_ERROR_START;
else
SERIAL_ECHO_START;
#else
SERIAL_ECHO_START;
#endif
SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
if (endstop_hit_bits & BIT(X_MIN)) {
SERIAL_ECHOPAIR(" X:", (float)endstops_trigsteps[X_AXIS] / axis_steps_per_unit[X_AXIS]);
SERIAL_ECHOPAIR(" X=", (float)endstops_trigsteps[X_AXIS] / axis_steps_per_unit[X_AXIS]);
LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "X");
}
if (endstop_hit_bits & BIT(Y_MIN)) {
SERIAL_ECHOPAIR(" Y:", (float)endstops_trigsteps[Y_AXIS] / axis_steps_per_unit[Y_AXIS]);
SERIAL_ECHOPAIR(" Y=", (float)endstops_trigsteps[Y_AXIS] / axis_steps_per_unit[Y_AXIS]);
LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Y");
}
if (endstop_hit_bits & BIT(Z_MIN)) {
SERIAL_ECHOPAIR(" Z:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
SERIAL_ECHOPAIR(" Z=", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Z");
}
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
if (endstop_hit_bits & BIT(Z_MIN_PROBE)) {
SERIAL_ECHOPAIR(" Z_MIN_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
SERIAL_ECHOPAIR(" Z_MIN_PROBE=", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
}
#endif
SERIAL_EOL;

endstops_hit_on_purpose();

#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
if (abort_on_endstop_hit) {
card.sdprinting = false;
card.closefile();
quickStop();
disable_all_heaters(); // switch off all heaters.
#if ENABLED(SDSUPPORT)
card.sdprinting = false;
card.closefile();
#endif
axis_known_position[3] = { false }; // not homed anymore
quickStop(); // kill the planner buffer
Stop(); // restart by M999
}
#endif
}
Expand Down

0 comments on commit dcc190b

Please sign in to comment.