added firmware retract. disabled by default

This commit is contained in:
Bernhard 2012-06-02 20:32:28 +02:00
parent 88d2a671cc
commit bf077125b9
5 changed files with 722 additions and 317 deletions

View File

@ -179,6 +179,16 @@ const int dropsegments=5; //everything with less than this number of steps will
#define MAX_CMD_SIZE 96 #define MAX_CMD_SIZE 96
#define BUFSIZE 4 #define BUFSIZE 4
// Firmware based and LCD controled retract
// M207 and M208 can be used to define parameters for the retraction.
// The retraction can be called by the slicer using G10 and G11
// until then, intended retractions can be detected by moves that only extrude and the direction.
// 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
//=========================================================================== //===========================================================================
//============================= Define Defines ============================ //============================= Define Defines ============================
//=========================================================================== //===========================================================================

View File

@ -50,6 +50,8 @@
// G2 - CW ARC // G2 - CW ARC
// G3 - CCW ARC // G3 - CCW ARC
// G4 - Dwell S<seconds> or P<milliseconds> // G4 - Dwell S<seconds> or P<milliseconds>
// G10 - retract filament according to settings of M207
// G11 - retract recover filament according to settings of M208
// G28 - Home all Axis // G28 - Home all Axis
// G90 - Use Absolute Coordinates // G90 - Use Absolute Coordinates
// G91 - Use Relative Coordinates // G91 - Use Relative Coordinates
@ -102,6 +104,9 @@
// M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate // M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate
// M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk, E=maximum E jerk // M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk, E=maximum E jerk
// M206 - set additional homeing offset // M206 - set additional homeing offset
// M207 - set retract length S[positive mm] F[feedrate mm/sec] Z[additional zlift/hop]
// M208 - set recover=unretract length S[positive mm surplus to the M207 S*] F[feedrate mm/sec]
// M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction.
// M220 S<factor in percent>- set speed factor override percentage // M220 S<factor in percent>- set speed factor override percentage
// M221 S<factor in percent>- set extrude factor override percentage // M221 S<factor in percent>- set extrude factor override percentage
// M240 - Trigger a camera to take a photograph // M240 - Trigger a camera to take a photograph
@ -139,6 +144,12 @@ float add_homeing[3]={0,0,0};
uint8_t active_extruder = 0; uint8_t active_extruder = 0;
unsigned char FanSpeed=0; unsigned char FanSpeed=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;
#endif
//=========================================================================== //===========================================================================
//=============================private variables============================= //=============================private variables=============================
@ -179,6 +190,7 @@ static unsigned long stoptime=0;
static uint8_t tmp_extruder; static uint8_t tmp_extruder;
bool Stopped=false; bool Stopped=false;
//=========================================================================== //===========================================================================
@ -601,6 +613,36 @@ void process_commands()
LCD_STATUS; LCD_STATUS;
} }
break; 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];
current_position[Z_AXIS]+=-retract_zlift;
destination[E_AXIS]=current_position[E_AXIS]-retract_length;
feedrate=retract_feedrate;
retracted=true;
prepare_move();
}
break;
case 11: // G10 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];
current_position[Z_AXIS]+=retract_zlift;
current_position[E_AXIS]+=-retract_recover_length;
feedrate=retract_recover_feedrate;
retracted=false;
prepare_move();
}
break;
#endif //FWRETRACT
case 28: //G28 Home all Axis one at a time case 28: //G28 Home all Axis one at a time
saved_feedrate = feedrate; saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply; saved_feedmultiply = feedmultiply;
@ -1212,6 +1254,53 @@ void process_commands()
if(code_seen(axis_codes[i])) add_homeing[i] = code_value(); if(code_seen(axis_codes[i])) add_homeing[i] = code_value();
} }
break; break;
#ifdef FWRETRACT
case 207: //M207 - set retract length S[positive mm] F[feedrate mm/sec] Z[additional zlift/hop]
{
if(code_seen('S'))
{
retract_length = code_value() ;
}
if(code_seen('F'))
{
retract_feedrate = code_value() ;
}
if(code_seen('Z'))
{
retract_zlift = code_value() ;
}
}break;
case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/sec]
{
if(code_seen('S'))
{
retract_recover_length = code_value() ;
}
if(code_seen('F'))
{
retract_recover_feedrate = code_value() ;
}
}break;
case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction.
{
if(code_seen('S'))
{
int t= code_value() ;
switch(t)
{
case 0: autoretract_enabled=false;retracted=false;break;
case 1: autoretract_enabled=true;retracted=false;break;
default:
SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_UNKNOWN_COMMAND);
SERIAL_ECHO(cmdbuffer[bufindr]);
SERIAL_ECHOLNPGM("\"");
}
}
}break;
#endif
case 220: // M220 S<factor in percent>- set speed factor override percentage case 220: // M220 S<factor in percent>- set speed factor override percentage
{ {
if(code_seen('S')) if(code_seen('S'))
@ -1373,14 +1462,55 @@ void ClearToSend()
void get_coordinates() void get_coordinates()
{ {
bool seen[4]={false,false,false,false};
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i]; if(code_seen(axis_codes[i]))
{
destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
seen[i]=true;
}
else destination[i] = current_position[i]; //Are these else lines really needed? else destination[i] = current_position[i]; //Are these else lines really needed?
} }
if(code_seen('F')) { if(code_seen('F')) {
next_feedrate = code_value(); next_feedrate = code_value();
if(next_feedrate > 0.0) feedrate = next_feedrate; 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
destination[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+0*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() void get_arc_coordinates()

View File

@ -73,6 +73,7 @@
#define MSG_ZSTEPS " Zsteps/mm:" #define MSG_ZSTEPS " Zsteps/mm:"
#define MSG_ESTEPS " Esteps/mm:" #define MSG_ESTEPS " Esteps/mm:"
#define MSG_MAIN_WIDE " Main \003" #define MSG_MAIN_WIDE " Main \003"
#define MSG_RECTRACT_WIDE " Rectract \x7E"
#define MSG_TEMPERATURE_WIDE " Temperature \x7E" #define MSG_TEMPERATURE_WIDE " Temperature \x7E"
#define MSG_MOTION_WIDE " Motion \x7E" #define MSG_MOTION_WIDE " Motion \x7E"
#define MSG_STORE_EPROM " Store memory" #define MSG_STORE_EPROM " Store memory"
@ -83,6 +84,7 @@
#define MSG_PREPARE " Prepare \x7E" #define MSG_PREPARE " Prepare \x7E"
#define MSG_PREPARE_ALT " Prepare \003" #define MSG_PREPARE_ALT " Prepare \003"
#define MSG_CONTROL_ARROW " Control \x7E" #define MSG_CONTROL_ARROW " Control \x7E"
#define MSG_RETRACT_ARROW " Control \x7E"
#define MSG_TUNE " Tune \x7E" #define MSG_TUNE " Tune \x7E"
#define MSG_STOP_PRINT " Stop Print \x7E" #define MSG_STOP_PRINT " Stop Print \x7E"
#define MSG_CARD_MENU " Card Menu \x7E" #define MSG_CARD_MENU " Card Menu \x7E"
@ -97,7 +99,12 @@
#define MSG_PREHEAT_PLA " Preheat PLA" #define MSG_PREHEAT_PLA " Preheat PLA"
#define MSG_PREHEAT_ABS " Preheat ABS" #define MSG_PREHEAT_ABS " Preheat ABS"
#define MSG_STEPPER_RELEASED "Released." #define MSG_STEPPER_RELEASED "Released."
#define MSG_CONTROL_RETRACT " Retract mm:"
#define MSG_CONTROL_RETRACTF " Retract F:"
#define MSG_CONTROL_RETRACT_ZLIFT " Hop mm:"
#define MSG_CONTROL_RETRACT_RECOVER " UnRet +mm:"
#define MSG_CONTROL_RETRACT_RECOVERF " UnRet F:"
#define MSG_AUTORETRACT " AutoRetr.:"
// Serial Console Messages // Serial Console Messages
@ -231,6 +238,7 @@
#define MSG_PREPARE " Prepare \x7E" #define MSG_PREPARE " Prepare \x7E"
#define MSG_PREPARE_ALT " Prepare \003" #define MSG_PREPARE_ALT " Prepare \003"
#define MSG_CONTROL_ARROW " Control \x7E" #define MSG_CONTROL_ARROW " Control \x7E"
#define MSG_TUNE " Tune \x7E" #define MSG_TUNE " Tune \x7E"
#define MSG_STOP_PRINT " Druck stoppen \x7E" #define MSG_STOP_PRINT " Druck stoppen \x7E"
#define MSG_CARD_MENU " SDKarten Menue \x7E" #define MSG_CARD_MENU " SDKarten Menue \x7E"
@ -246,6 +254,7 @@
#define MSG_STEPPER_RELEASED "Released." #define MSG_STEPPER_RELEASED "Released."
// Serial Console Messages // Serial Console Messages
#define MSG_Enqueing "enqueing \"" #define MSG_Enqueing "enqueing \""

View File

@ -51,7 +51,7 @@
#define blocktime 500 #define blocktime 500
#define lcdslow 5 #define lcdslow 5
enum MainStatus{Main_Status, Main_Menu, Main_Prepare,Sub_PrepareMove, Main_Control, Main_SD,Sub_TempControl,Sub_MotionControl}; enum MainStatus{Main_Status, Main_Menu, Main_Prepare,Sub_PrepareMove, Main_Control, Main_SD,Sub_TempControl,Sub_MotionControl,Sub_RetractControl};
class MainMenu{ class MainMenu{
public: public:
@ -68,6 +68,7 @@
void showControl(); void showControl();
void showControlMotion(); void showControlMotion();
void showControlTemp(); void showControlTemp();
void showControlRetract();
void showAxisMove(); void showAxisMove();
void showSD(); void showSD();
bool force_lcd_update; bool force_lcd_update;

View File

@ -1688,6 +1688,8 @@ void MainMenu::showControlMotion()
} }
}break; }break;
case ItemCM_aret://float retract_acceleration = 7000; case ItemCM_aret://float retract_acceleration = 7000;
{ {
if(force_lcd_update) if(force_lcd_update)
@ -1884,8 +1886,252 @@ void MainMenu::showControlMotion()
} }
enum {
ItemR_exit,
ItemR_autoretract,
ItemR_retract_length,ItemR_retract_feedrate,ItemR_retract_zlift,
ItemR_unretract_length,ItemR_unretract_feedrate,
};
void MainMenu::showControlRetract()
{
#ifdef FWRETRACT
uint8_t line=0;
clearIfNecessary();
for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
{
switch(i)
{
case ItemR_exit:
MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
break;
//float retract_length=2, retract_feedrate=1200, retract_zlift=0.4;
//float retract_recover_length=0, retract_recover_feedrate=500;
case ItemR_autoretract:
{
if(force_lcd_update)
{
lcd.setCursor(0,line);lcdprintPGM(MSG_AUTORETRACT);
lcd.setCursor(13,line);
if(autoretract_enabled)
lcdprintPGM(MSG_ON);
else
lcdprintPGM(MSG_OFF);
}
if((activeline!=line) )
break;
if(CLICKED)
{
autoretract_enabled=!autoretract_enabled;
lcd.setCursor(13,line);
if(autoretract_enabled)
lcdprintPGM(MSG_ON);
else
lcdprintPGM(MSG_OFF);
BLOCK;
}
}break;
case ItemR_retract_length:
{
if(force_lcd_update)
{
lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT);
lcd.setCursor(13,line);lcd.print(ftostr52(retract_length));
}
if((activeline!=line) )
break;
if(CLICKED)
{
linechanging=!linechanging;
if(linechanging)
{
encoderpos=(long)(retract_length*100);
}
else
{
retract_length= encoderpos/100.;
encoderpos=activeline*lcdslow;
}
BLOCK;
beepshort();
}
if(linechanging)
{
if(encoderpos<1) encoderpos=1;
if(encoderpos>990) encoderpos=990;
lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
}
}break;
case ItemR_retract_feedrate:
{
if(force_lcd_update)
{
lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACTF);
lcd.setCursor(13,line);lcd.print(itostr4(retract_feedrate));
}
if((activeline!=line) )
break;
if(CLICKED)
{
linechanging=!linechanging;
if(linechanging)
{
encoderpos=(long)(retract_feedrate/5);
}
else
{
retract_feedrate= encoderpos*5.;
encoderpos=activeline*lcdslow;
}
BLOCK;
beepshort();
}
if(linechanging)
{
if(encoderpos<1) encoderpos=1;
if(encoderpos>990) encoderpos=990;
lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
}
}break;
case ItemR_retract_zlift://float retract_acceleration = 7000;
{
if(force_lcd_update)
{
lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_ZLIFT);
lcd.setCursor(13,line);lcd.print(ftostr52(retract_zlift));;
}
if((activeline!=line) )
break;
if(CLICKED)
{
linechanging=!linechanging;
if(linechanging)
{
encoderpos=(long)(retract_zlift*10);
}
else
{
retract_zlift= encoderpos/10.;
encoderpos=activeline*lcdslow;
}
BLOCK;
beepshort();
}
if(linechanging)
{
if(encoderpos<0) encoderpos=0;
if(encoderpos>990) encoderpos=990;
lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/10.));
}
}break;
case ItemR_unretract_length:
{
if(force_lcd_update)
{
lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVER);
lcd.setCursor(13,line);lcd.print(ftostr52(retract_recover_length));;
}
if((activeline!=line) )
break;
if(CLICKED)
{
linechanging=!linechanging;
if(linechanging)
{
encoderpos=(long)(retract_recover_length*100);
}
else
{
retract_recover_length= encoderpos/100.;
encoderpos=activeline*lcdslow;
}
BLOCK;
beepshort();
}
if(linechanging)
{
if(encoderpos<0) encoderpos=0;
if(encoderpos>990) encoderpos=990;
lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
}
}break;
case ItemR_unretract_feedrate:
{
if(force_lcd_update)
{
lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVERF);
lcd.setCursor(13,line);lcd.print(itostr4(retract_recover_feedrate));
}
if((activeline!=line) )
break;
if(CLICKED)
{
linechanging=!linechanging;
if(linechanging)
{
encoderpos=(long)retract_recover_feedrate/5;
}
else
{
retract_recover_feedrate= encoderpos*5.;
encoderpos=activeline*lcdslow;
}
BLOCK;
beepshort();
}
if(linechanging)
{
if(encoderpos<1) encoderpos=1;
if(encoderpos>990) encoderpos=990;
lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
}
}break;
default:
break;
}
line++;
}
updateActiveLines(ItemR_unretract_feedrate,encoderpos);
#endif
}
enum { enum {
ItemC_exit,ItemC_temp,ItemC_move, ItemC_exit,ItemC_temp,ItemC_move,
#ifdef FWRETRACT
ItemC_rectract,
#endif
ItemC_store, ItemC_load,ItemC_failsafe ItemC_store, ItemC_load,ItemC_failsafe
}; };
@ -1906,6 +2152,11 @@ void MainMenu::showControl()
case ItemC_move: case ItemC_move:
MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ; MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
break; break;
#ifdef FWRETRACT
case ItemC_rectract:
MENUITEM( lcdprintPGM(MSG_RECTRACT_WIDE) , BLOCK;status=Sub_RetractControl;beepshort(); ) ;
break;
#endif
case ItemC_store: case ItemC_store:
{ {
if(force_lcd_update) if(force_lcd_update)
@ -2250,6 +2501,10 @@ void MainMenu::update()
{ {
showControlMotion(); showControlMotion();
}break; }break;
case Sub_RetractControl:
{
showControlRetract();
}break;
case Sub_TempControl: case Sub_TempControl:
{ {
showControlTemp(); showControlTemp();