From 2f2459c0db59bb9cf009101c57a0c65550f41b7d Mon Sep 17 00:00:00 2001 From: whosawhatsis Date: Sun, 16 Feb 2014 15:53:01 -0800 Subject: [PATCH 1/6] Fix G10/G11 Z-lift --- Marlin/Marlin_main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 903271375..1681c88b7 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1134,7 +1134,6 @@ void process_commands() destination[X_AXIS]=current_position[X_AXIS]; destination[Y_AXIS]=current_position[Y_AXIS]; destination[Z_AXIS]=current_position[Z_AXIS]; - current_position[Z_AXIS]-=retract_zlift; destination[E_AXIS]=current_position[E_AXIS]; current_position[E_AXIS]+=retract_length/volumetric_multiplier[active_extruder]; plan_set_e_position(current_position[E_AXIS]); @@ -1142,6 +1141,9 @@ void process_commands() feedrate=retract_feedrate; retracted=true; prepare_move(); + current_position[Z_AXIS]-=retract_zlift; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + prepare_move(); feedrate = oldFeedrate; } @@ -1152,8 +1154,10 @@ void process_commands() destination[X_AXIS]=current_position[X_AXIS]; destination[Y_AXIS]=current_position[Y_AXIS]; destination[Z_AXIS]=current_position[Z_AXIS]; - current_position[Z_AXIS]+=retract_zlift; destination[E_AXIS]=current_position[E_AXIS]; + current_position[Z_AXIS]+=retract_zlift; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + //prepare_move(); current_position[E_AXIS]-=(retract_length+retract_recover_length)/volumetric_multiplier[active_extruder]; plan_set_e_position(current_position[E_AXIS]); float oldFeedrate = feedrate; From 66e386913897d9f45762e227161d53e8323b1c5b Mon Sep 17 00:00:00 2001 From: whosawhatsis Date: Sun, 16 Feb 2014 18:59:04 -0800 Subject: [PATCH 2/6] Fix autoretract This takes the (now working) G10/G11 code and moves it to a function, which is called by G10 and G11, and also called by G1 if autoretract is enabled and a retract/recover move is detected. --- Marlin/Marlin_main.cpp | 120 +++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 71 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1681c88b7..c07cbc427 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1080,6 +1080,41 @@ static void homeaxis(int axis) { } #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS) +#ifdef FWRETRACT + void retract(bool retracting) { + if(retracting && !retracted) { + destination[X_AXIS]=current_position[X_AXIS]; + destination[Y_AXIS]=current_position[Y_AXIS]; + destination[Z_AXIS]=current_position[Z_AXIS]; + destination[E_AXIS]=current_position[E_AXIS]; + current_position[E_AXIS]+=retract_length/volumetric_multiplier[active_extruder]; + plan_set_e_position(current_position[E_AXIS]); + float oldFeedrate = feedrate; + feedrate=retract_feedrate; + retracted=true; + prepare_move(); + current_position[Z_AXIS]-=retract_zlift; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + prepare_move(); + feedrate = oldFeedrate; + } else if(!retracting && retracted) { + destination[X_AXIS]=current_position[X_AXIS]; + destination[Y_AXIS]=current_position[Y_AXIS]; + destination[Z_AXIS]=current_position[Z_AXIS]; + destination[E_AXIS]=current_position[E_AXIS]; + current_position[Z_AXIS]+=retract_zlift; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + //prepare_move(); + current_position[E_AXIS]-=(retract_length+retract_recover_length)/volumetric_multiplier[active_extruder]; + plan_set_e_position(current_position[E_AXIS]); + float oldFeedrate = feedrate; + feedrate=retract_recover_feedrate; + retracted=false; + prepare_move(); + feedrate = oldFeedrate; + } + } //retract +#endif //FWRETRACT void process_commands() { unsigned long codenum; //throw away variable @@ -1095,6 +1130,18 @@ void process_commands() case 1: // G1 if(Stopped == false) { get_coordinates(); // For X Y Z E F + #ifdef FWRETRACT + if(autoretract_enabled) + if( !(code_seen(X_AXIS) || code_seen(Y_AXIS) || code_seen(Z_AXIS)) && code_seen(E_AXIS)) { + float echange=destination[E_AXIS]-current_position[E_AXIS]; + if((echange<-MIN_RETRACT && !retracted) || (echange>MIN_RETRACT && retracted)) { //move appears to be an attempt to attract or recover + current_position[E_AXIS] = destination[E_AXIS]; //hide the slicer-generated retract/recover from calculations + plan_set_e_position(current_position[E_AXIS]); //AND from the planner + retract(!retracted); + return; + } + } + #endif //FWRETRACT prepare_move(); //ClearToSend(); return; @@ -1129,43 +1176,10 @@ void process_commands() break; #ifdef FWRETRACT case 10: // G10 retract - if(!retracted) - { - destination[X_AXIS]=current_position[X_AXIS]; - destination[Y_AXIS]=current_position[Y_AXIS]; - destination[Z_AXIS]=current_position[Z_AXIS]; - destination[E_AXIS]=current_position[E_AXIS]; - current_position[E_AXIS]+=retract_length/volumetric_multiplier[active_extruder]; - plan_set_e_position(current_position[E_AXIS]); - float oldFeedrate = feedrate; - feedrate=retract_feedrate; - retracted=true; - prepare_move(); - current_position[Z_AXIS]-=retract_zlift; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - prepare_move(); - feedrate = oldFeedrate; - } - + retract(true); break; case 11: // G11 retract_recover - if(retracted) - { - destination[X_AXIS]=current_position[X_AXIS]; - destination[Y_AXIS]=current_position[Y_AXIS]; - destination[Z_AXIS]=current_position[Z_AXIS]; - destination[E_AXIS]=current_position[E_AXIS]; - current_position[Z_AXIS]+=retract_zlift; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - //prepare_move(); - current_position[E_AXIS]-=(retract_length+retract_recover_length)/volumetric_multiplier[active_extruder]; - plan_set_e_position(current_position[E_AXIS]); - float oldFeedrate = feedrate; - feedrate=retract_recover_feedrate; - retracted=false; - prepare_move(); - feedrate = oldFeedrate; - } + retract(false); break; #endif //FWRETRACT case 28: //G28 Home all Axis one at a time @@ -3020,42 +3034,6 @@ void get_coordinates() next_feedrate = code_value(); if(next_feedrate > 0.0) feedrate = next_feedrate; } - #ifdef FWRETRACT - if(autoretract_enabled) - if( !(seen[X_AXIS] || seen[Y_AXIS] || seen[Z_AXIS]) && seen[E_AXIS]) - { - float echange=destination[E_AXIS]-current_position[E_AXIS]; - if(echange<-MIN_RETRACT) //retract - { - if(!retracted) - { - - destination[Z_AXIS]+=retract_zlift; //not sure why chaninging current_position negatively does not work. - //if slicer retracted by echange=-1mm and you want to retract 3mm, corrrectede=-2mm additionally - float correctede=-echange-retract_length; - //to generate the additional steps, not the destination is changed, but inversely the current position - current_position[E_AXIS]+=-correctede; - feedrate=retract_feedrate; - retracted=true; - } - - } - else - if(echange>MIN_RETRACT) //retract_recover - { - if(retracted) - { - //current_position[Z_AXIS]+=-retract_zlift; - //if slicer retracted_recovered by echange=+1mm and you want to retract_recover 3mm, corrrectede=2mm additionally - float correctede=-echange+1*retract_length+retract_recover_length; //total unretract=retract_length+retract_recover_length[surplus] - current_position[E_AXIS]+=correctede; //to generate the additional steps, not the destination is changed, but inversely the current position - feedrate=retract_recover_feedrate; - retracted=false; - } - } - - } - #endif //FWRETRACT } void get_arc_coordinates() From 99f0e44864a248e3487a4e3d9aad5a5f07f3d447 Mon Sep 17 00:00:00 2001 From: whosawhatsis Date: Sun, 16 Feb 2014 19:00:28 -0800 Subject: [PATCH 3/6] Move FWRETRACT defaults to configuration_adv.h --- Marlin/Configuration_adv.h | 10 ++++++++-- Marlin/Marlin_main.cpp | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index dc986fae4..aed27c079 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -399,8 +399,14 @@ const unsigned int dropsegments=5; //everything with less than this number of st // the moves are than replaced by the firmware controlled ones. // #define FWRETRACT //ONLY PARTIALLY TESTED -#define MIN_RETRACT 0.1 //minimum extruded mm to accept a automatic gcode retraction attempt - +#ifdef FWRETRACT + #define MIN_RETRACT 0.1 //minimum extruded mm to accept a automatic gcode retraction attempt + #define RETRACT_LENGTH 3 //default retract length (positive mm) + #define RETRACT_FEEDRATE 80*60 //default feedrate for retracting + #define RETRACT_ZLIFT 0 //default retract Z-lift + #define RETRACT_RECOVER_LENGTH 0 //default additional recover length (mm, added to retract length when recovering) + #define RETRACT_RECOVER_FEEDRATE 8*60 //default feedrate for recovering from retraction +#endif //adds support for experimental filament exchange support M600; requires display #ifdef ULTIPANEL diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index c07cbc427..e860d7d25 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -233,8 +233,11 @@ int EtoPPressure=0; #ifdef FWRETRACT bool autoretract_enabled=true; bool retracted=false; - float retract_length=3, retract_feedrate=17*60, retract_zlift=0.8; - float retract_recover_length=0, retract_recover_feedrate=8*60; + float retract_length = RETRACT_LENGTH; + float retract_feedrate = RETRACT_FEEDRATE; + float retract_zlift = RETRACT_ZLIFT; + float retract_recover_length = RETRACT_RECOVER_LENGTH; + float retract_recover_feedrate = RETRACT_RECOVER_FEEDRATE; #endif #ifdef ULTIPANEL @@ -1115,6 +1118,7 @@ static void homeaxis(int axis) { } } //retract #endif //FWRETRACT + void process_commands() { unsigned long codenum; //throw away variable From c43838bb1ee4f787c637f4fc0b91aa4b78e4f56a Mon Sep 17 00:00:00 2001 From: whosawhatsis Date: Sun, 16 Feb 2014 19:04:54 -0800 Subject: [PATCH 4/6] disable auto retract by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should make it safe to enable FWRETRACT by default, with autoretract (which should now be fixed) only enabled by M209. FWRETRACT should probably now default to enabled (to make G10/G11 and M207-209 available, without changing functionality when they are not used), but I’ll save that for another pull request/discussion. --- 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 e860d7d25..4e9fed10e 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -231,7 +231,7 @@ int EtoPPressure=0; #endif #ifdef FWRETRACT - bool autoretract_enabled=true; + bool autoretract_enabled=false; bool retracted=false; float retract_length = RETRACT_LENGTH; float retract_feedrate = RETRACT_FEEDRATE; From 306588925df929d843bb25fbfb93695e5a1f4afe Mon Sep 17 00:00:00 2001 From: Paul Telford Date: Sun, 16 Feb 2014 21:01:19 -0800 Subject: [PATCH 5/6] Add whitespace to M114 output --- Marlin/Marlin_main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 903271375..2ae569828 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2122,18 +2122,18 @@ void process_commands() case 114: // M114 SERIAL_PROTOCOLPGM("X:"); SERIAL_PROTOCOL(current_position[X_AXIS]); - SERIAL_PROTOCOLPGM("Y:"); + SERIAL_PROTOCOLPGM(" Y:"); SERIAL_PROTOCOL(current_position[Y_AXIS]); - SERIAL_PROTOCOLPGM("Z:"); + SERIAL_PROTOCOLPGM(" Z:"); SERIAL_PROTOCOL(current_position[Z_AXIS]); - SERIAL_PROTOCOLPGM("E:"); + SERIAL_PROTOCOLPGM(" E:"); SERIAL_PROTOCOL(current_position[E_AXIS]); SERIAL_PROTOCOLPGM(MSG_COUNT_X); SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]); - SERIAL_PROTOCOLPGM("Y:"); + SERIAL_PROTOCOLPGM(" Y:"); SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]); - SERIAL_PROTOCOLPGM("Z:"); + SERIAL_PROTOCOLPGM(" Z:"); SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]); SERIAL_PROTOCOLLN(""); From d1c64b9dc4104eee87574f11ac24693870791426 Mon Sep 17 00:00:00 2001 From: Gabe Rosenhouse Date: Mon, 17 Feb 2014 07:53:45 -0800 Subject: [PATCH 6/6] Fix syntax error introduced in 477b6fa1d --- 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 498adfdb9..952ac5847 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1080,7 +1080,7 @@ static void homeaxis(int axis) { } } #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS) -+void refresh_cmd_timeout(void) +void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); }