From da0d91a79b1bf0fd1c4d4a568415073b70d17573 Mon Sep 17 00:00:00 2001 From: Wurstnase Date: Mon, 20 Apr 2015 23:28:46 +0200 Subject: [PATCH 1/7] max endstopp no user will home to 0 with a max endstopp --- Marlin/Marlin_main.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 64d3d1f350..22f037075d 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1947,12 +1947,18 @@ inline void gcode_G28() { if (home_all_axis || homeY) HOMEAXIS(Y); // Set the X position, if included - if (code_seen(axis_codes[X_AXIS]) && code_has_value()) - current_position[X_AXIS] = code_value(); + if (code_seen(axis_codes[X_AXIS]) && code_has_value()) { + float v = code_value(); + if (X_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps + current_position[X_AXIS] = v; + } // Set the Y position, if included - if (code_seen(axis_codes[Y_AXIS]) && code_has_value()) - current_position[Y_AXIS] = code_value(); + if (code_seen(axis_codes[Y_AXIS]) && code_has_value()) { + float v = code_value(); + if (Y_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps + current_position[Y_AXIS] = code_value(); + } // Home Z last if homing towards the bed #if Z_HOME_DIR < 0 @@ -2038,8 +2044,11 @@ inline void gcode_G28() { #endif // Z_HOME_DIR < 0 // Set the Z position, if included - if (code_seen(axis_codes[Z_AXIS]) && code_has_value()) + if (code_seen(axis_codes[Z_AXIS]) && code_has_value()) { + float v = code_value(); + if (Z_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps current_position[Z_AXIS] = code_value(); + } #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0) if (home_all_axis || homeZ) current_position[Z_AXIS] += zprobe_zoffset; // Add Z_Probe offset (the distance is negative) From 61ae43f35e8523ab9785a0d79a3c6f7e73407e4a Mon Sep 17 00:00:00 2001 From: Wurstnase Date: Mon, 20 Apr 2015 23:31:10 +0200 Subject: [PATCH 2/7] v <-> code_value --- Marlin/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 22f037075d..4987aaf1e2 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1957,7 +1957,7 @@ inline void gcode_G28() { if (code_seen(axis_codes[Y_AXIS]) && code_has_value()) { float v = code_value(); if (Y_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps - current_position[Y_AXIS] = code_value(); + current_position[Y_AXIS] = v; } // Home Z last if homing towards the bed @@ -2047,7 +2047,7 @@ inline void gcode_G28() { if (code_seen(axis_codes[Z_AXIS]) && code_has_value()) { float v = code_value(); if (Z_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps - current_position[Z_AXIS] = code_value(); + current_position[Z_AXIS] = v; } #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0) From c26d816839e556876522595e85c6aadd43c05844 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Apr 2015 12:09:57 +0200 Subject: [PATCH 3/7] filter any 0 --- Marlin/Marlin_main.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4987aaf1e2..952aa2fb3e 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1948,16 +1948,14 @@ inline void gcode_G28() { // Set the X position, if included if (code_seen(axis_codes[X_AXIS]) && code_has_value()) { - float v = code_value(); - if (X_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps - current_position[X_AXIS] = v; + if (code_value_long() != 0) // filter 0 + current_position[X_AXIS] = code_value(); } // Set the Y position, if included if (code_seen(axis_codes[Y_AXIS]) && code_has_value()) { - float v = code_value(); - if (Y_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps - current_position[Y_AXIS] = v; + if (code_value_long() != 0) // filter 0 + current_position[X_AXIS] = code_value(); } // Home Z last if homing towards the bed @@ -2045,9 +2043,8 @@ inline void gcode_G28() { // Set the Z position, if included if (code_seen(axis_codes[Z_AXIS]) && code_has_value()) { - float v = code_value(); - if (Z_HOME_DIR == -1 || v != 0) // filter 0 with max-endstopps - current_position[Z_AXIS] = v; + if (code_value_long() != 0) // filter 0 + current_position[X_AXIS] = code_value(); } #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0) From be9e4ceddcf02741c7042753d8c1276f9443bc67 Mon Sep 17 00:00:00 2001 From: Wurstnase Date: Thu, 23 Apr 2015 10:35:14 +0200 Subject: [PATCH 4/7] fix typo c'n'p ftw :/ --- Marlin/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 952aa2fb3e..d99b63b0b6 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1955,7 +1955,7 @@ inline void gcode_G28() { // Set the Y position, if included if (code_seen(axis_codes[Y_AXIS]) && code_has_value()) { if (code_value_long() != 0) // filter 0 - current_position[X_AXIS] = code_value(); + current_position[Y_AXIS] = code_value(); } // Home Z last if homing towards the bed @@ -2044,7 +2044,7 @@ inline void gcode_G28() { // Set the Z position, if included if (code_seen(axis_codes[Z_AXIS]) && code_has_value()) { if (code_value_long() != 0) // filter 0 - current_position[X_AXIS] = code_value(); + current_position[Z_AXIS] = code_value(); } #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0) From 79a44a9de37859b58a8de288341a54df42e26061 Mon Sep 17 00:00:00 2001 From: Wurstnase Date: Fri, 24 Apr 2015 08:03:17 +0200 Subject: [PATCH 5/7] stepper.cpp macros rework delete some tabs --- Marlin/stepper.cpp | 121 ++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 50 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index c8bcbbbf2b..ca17b3f9f2 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -46,7 +46,7 @@ block_t *current_block; // A pointer to the block currently being traced // Variables used by The Stepper Driver Interrupt static unsigned char out_bits; // The next stepping-bits to be output -static unsigned int cleaning_buffer_counter; +static unsigned int cleaning_buffer_counter; #ifdef Z_DUAL_ENDSTOPS static bool performing_homing = false, @@ -285,8 +285,8 @@ void checkHitEndstops() { } #ifdef Z_PROBE_ENDSTOP if (endstop_z_probe_hit) { - SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]); - LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP"); + SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]); + LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP"); } #endif SERIAL_EOL; @@ -411,7 +411,7 @@ ISR(TIMER1_COMPA_vect) { OCR1A = 200; return; } - + // If there is no current block, attempt to pop one from the buffer if (!current_block) { // Anything in the buffer? @@ -463,14 +463,22 @@ ISR(TIMER1_COMPA_vect) { count_direction[Y_AXIS] = 1; } + #define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop + #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN + #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING + #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop + #define _AXIS(AXIS) AXIS ##_AXIS + #define _ENDSTOP_HIT(axis) endstop_## axis ##_hit + #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \ - bool axis ##_## minmax ##_endstop = (READ(AXIS ##_## MINMAX ##_PIN) != AXIS ##_## MINMAX ##_ENDSTOP_INVERTING); \ - if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps[AXIS ##_AXIS] > 0)) { \ - endstops_trigsteps[AXIS ##_AXIS] = count_position[AXIS ##_AXIS]; \ - endstop_## axis ##_hit = true; \ + bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \ + if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \ + endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \ + _ENDSTOP_HIT(axis) = true; \ step_events_completed = current_block->step_event_count; \ } \ - old_## axis ##_## minmax ##_endstop = axis ##_## minmax ##_endstop; + _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax); + // Check X and Y endstops if (check_endstops) { @@ -486,7 +494,7 @@ ISR(TIMER1_COMPA_vect) { #ifdef DUAL_X_CARRIAGE // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1)) - #endif + #endif { #if HAS_X_MIN UPDATE_ENDSTOP(x, X, min, MIN); @@ -572,14 +580,14 @@ ISR(TIMER1_COMPA_vect) { z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING); if(z_probe_endstop && old_z_probe_endstop) { - endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_probe_hit=true; + endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; + endstop_z_probe_hit=true; -// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true"); +// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true"); } old_z_probe_endstop = z_probe_endstop; #endif - + } // check_endstops } @@ -625,15 +633,15 @@ ISR(TIMER1_COMPA_vect) { #endif // !Z_DUAL_ENDSTOPS #endif // Z_MAX_PIN - + #ifdef Z_PROBE_ENDSTOP UPDATE_ENDSTOP(z, Z, probe, PROBE); z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING); if(z_probe_endstop && old_z_probe_endstop) { - endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_probe_hit=true; -// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true"); + endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; + endstop_z_probe_hit=true; +// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true"); } old_z_probe_endstop = z_probe_endstop; #endif @@ -667,6 +675,11 @@ ISR(TIMER1_COMPA_vect) { } #endif //ADVANCE + #define _COUNTER(axis) counter_## axis + #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW) + #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP + #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN + #ifdef CONFIG_STEPPERS_TOSHIBA /** * The Toshiba stepper controller require much longer pulses. @@ -675,8 +688,8 @@ ISR(TIMER1_COMPA_vect) { * lag to allow it work with without needing NOPs */ #define STEP_ADD(axis, AXIS) \ - counter_## axis += current_block->steps[AXIS ##_AXIS]; \ - if (counter_## axis > 0) { AXIS ##_STEP_WRITE(HIGH); } + _COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \ + if (_COUNTER(axis) > 0) { _WRITE_STEP(AXIS, HIGH); } STEP_ADD(x,X); STEP_ADD(y,Y); STEP_ADD(z,Z); @@ -685,10 +698,10 @@ ISR(TIMER1_COMPA_vect) { #endif #define STEP_IF_COUNTER(axis, AXIS) \ - if (counter_## axis > 0) { \ - counter_## axis -= current_block->step_event_count; \ - count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \ - AXIS ##_STEP_WRITE(LOW); \ + if (_COUNTER(axis) > 0) { \ + _COUNTER(axis) -= current_block->step_event_count; \ + count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ + _WRITE_STEP(AXIS, LOW); \ } STEP_IF_COUNTER(x, X); @@ -701,12 +714,12 @@ ISR(TIMER1_COMPA_vect) { #else // !CONFIG_STEPPERS_TOSHIBA #define APPLY_MOVEMENT(axis, AXIS) \ - counter_## axis += current_block->steps[AXIS ##_AXIS]; \ - if (counter_## axis > 0) { \ - AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN,0); \ - counter_## axis -= current_block->step_event_count; \ - count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \ - AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN,0); \ + _COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \ + if (_COUNTER(axis) > 0) { \ + _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); \ + _COUNTER(axis) -= current_block->step_event_count; \ + count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ + _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \ } APPLY_MOVEMENT(x, X); @@ -874,7 +887,7 @@ void st_init() { #ifdef HAVE_L6470DRIVER L6470_init(); #endif - + // Initialize Dir Pins #if HAS_X_DIR X_DIR_INIT; @@ -920,11 +933,11 @@ void st_init() { #if HAS_Y_ENABLE Y_ENABLE_INIT; if (!Y_ENABLE_ON) Y_ENABLE_WRITE(HIGH); - - #if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE - Y2_ENABLE_INIT; - if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH); - #endif + + #if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE + Y2_ENABLE_INIT; + if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH); + #endif #endif #if HAS_Z_ENABLE Z_ENABLE_INIT; @@ -1001,8 +1014,8 @@ void st_init() { #ifdef ENDSTOPPULLUP_ZMAX WRITE(Z2_MAX_PIN,HIGH); #endif - #endif - + #endif + #if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used. SET_INPUT(Z_PROBE_PIN); #ifdef ENDSTOPPULLUP_ZPROBE @@ -1010,10 +1023,13 @@ void st_init() { #endif #endif + #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT + #define _DISABLE(axis) disable_## axis() + #define AXIS_INIT(axis, AXIS, PIN) \ - AXIS ##_STEP_INIT; \ - AXIS ##_STEP_WRITE(INVERT_## PIN ##_STEP_PIN); \ - disable_## axis() + _STEP_INIT(AXIS); \ + _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \ + _DISABLE(axis) #define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E) @@ -1146,14 +1162,19 @@ void quickStop() { // No other ISR should ever interrupt this! void babystep(const uint8_t axis, const bool direction) { + #define _ENABLE(axis) enable_## axis() + #define _READ_DIR(AXIS) AXIS ##_DIR_READ + #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR + #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true) + #define BABYSTEP_AXIS(axis, AXIS, INVERT) { \ - enable_## axis(); \ - uint8_t old_pin = AXIS ##_DIR_READ; \ - AXIS ##_APPLY_DIR(INVERT_## AXIS ##_DIR^direction^INVERT, true); \ - AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN, true); \ + _ENABLE(axis); \ + uint8_t old_pin = _READ_DIR(AXIS); \ + _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \ + _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \ delayMicroseconds(2); \ - AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN, true); \ - AXIS ##_APPLY_DIR(old_pin, true); \ + _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \ + _APPLY_DIR(AXIS, old_pin); \ } switch(axis) { @@ -1165,7 +1186,7 @@ void quickStop() { case Y_AXIS: BABYSTEP_AXIS(y, Y, false); break; - + case Z_AXIS: { #ifndef DELTA @@ -1202,7 +1223,7 @@ void quickStop() { #endif } break; - + default: break; } } @@ -1266,7 +1287,7 @@ void microstep_init() { #if HAS_MICROSTEPS pinMode(X_MS1_PIN,OUTPUT); - pinMode(X_MS2_PIN,OUTPUT); + pinMode(X_MS2_PIN,OUTPUT); pinMode(Y_MS1_PIN,OUTPUT); pinMode(Y_MS2_PIN,OUTPUT); pinMode(Z_MS1_PIN,OUTPUT); From 0fed46360c7b43ecb49f0fc404a46fa48ad3a4cc Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 24 Apr 2015 16:43:19 +0200 Subject: [PATCH 6/7] Add variant for MAX6675 in M104 Else will throw error: @:0 B@:0 Error:No thermistors - no temperature [ERROR] Error:No thermistors - no temperature when no bed is defined --- Marlin/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index a06bf78d0c..52b79c7dee 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3152,7 +3152,7 @@ inline void gcode_M104() { inline void gcode_M105() { if (setTargetedHotend(105)) return; - #if HAS_TEMP_0 || HAS_TEMP_BED + #if HAS_TEMP_0 || HAS_TEMP_BED || defined(HEATER_0_USES_MAX6675) SERIAL_PROTOCOLPGM("ok"); #if HAS_TEMP_0 SERIAL_PROTOCOLPGM(" T:"); From 35e79d56a5e5af903f310f28d92298bfc5bb5548 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 24 Apr 2015 19:23:12 -0700 Subject: [PATCH 7/7] Remove set-coordinate extension of G28 --- Marlin/Marlin_main.cpp | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7d417bd228..a09ef49070 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1790,12 +1790,6 @@ inline void gcode_G4() { * Y Home to the Y endstop * Z Home to the Z endstop * - * If numbers are included with XYZ set the position as with G92 - * Currently adds the home_offset, which may be wrong and removed soon. - * - * Xn Home X, setting X to n + home_offset[X_AXIS] - * Yn Home Y, setting Y to n + home_offset[Y_AXIS] - * Zn Home Z, setting Z to n + home_offset[Z_AXIS] */ inline void gcode_G28() { @@ -1855,7 +1849,7 @@ inline void gcode_G28() { homeY = code_seen(axis_codes[Y_AXIS]), homeZ = code_seen(axis_codes[Z_AXIS]); - home_all_axis = !(homeX || homeY || homeZ) || (homeX && homeY && homeZ); + home_all_axis = (!homeX && !homeY && !homeZ) || (homeX && homeY && homeZ); if (home_all_axis || homeZ) { @@ -1942,18 +1936,6 @@ inline void gcode_G28() { // Home Y if (home_all_axis || homeY) HOMEAXIS(Y); - // Set the X position, if included - if (code_seen(axis_codes[X_AXIS]) && code_has_value()) { - if (code_value_long() != 0) // filter 0 - current_position[X_AXIS] = code_value(); - } - - // Set the Y position, if included - if (code_seen(axis_codes[Y_AXIS]) && code_has_value()) { - if (code_value_long() != 0) // filter 0 - current_position[Y_AXIS] = code_value(); - } - // Home Z last if homing towards the bed #if Z_HOME_DIR < 0 @@ -2037,12 +2019,6 @@ inline void gcode_G28() { #endif // Z_HOME_DIR < 0 - // Set the Z position, if included - if (code_seen(axis_codes[Z_AXIS]) && code_has_value()) { - if (code_value_long() != 0) // filter 0 - current_position[Z_AXIS] = code_value(); - } - #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0) if (home_all_axis || homeZ) current_position[Z_AXIS] += zprobe_zoffset; // Add Z_Probe offset (the distance is negative) #endif