Merge pull request #1713 from mkbel/fix_octoprint_mmu_load_failed

Fix octoprint mmu load failed
This commit is contained in:
PavelSindler 2019-04-10 18:21:06 +02:00 committed by GitHub
commit 7168c09eec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 124 additions and 55 deletions

View File

@ -469,7 +469,7 @@ extern uint8_t calc_percent_done();
#define KEEPALIVE_STATE(n) do { busy_state = n;} while (0) #define KEEPALIVE_STATE(n) do { busy_state = n;} while (0)
extern void host_keepalive(); extern void host_keepalive();
//extern MarlinBusyState busy_state; //extern MarlinBusyState busy_state;
extern int busy_state; extern int8_t busy_state;
#ifdef TMC2130 #ifdef TMC2130
@ -497,3 +497,4 @@ void M600_load_filament_movements();
void M600_wait_for_user(float HotendTempBckp); void M600_wait_for_user(float HotendTempBckp);
void M600_check_state(float nozzle_temp); void M600_check_state(float nozzle_temp);
void load_filament_final_feed(); void load_filament_final_feed();
void marlin_wait_for_click();

View File

@ -303,7 +303,7 @@ int fanSpeed=0;
bool cancel_heatup = false ; bool cancel_heatup = false ;
int busy_state = NOT_BUSY; int8_t busy_state = NOT_BUSY;
static long prev_busy_signal_ms = -1; static long prev_busy_signal_ms = -1;
uint8_t host_keepalive_interval = HOST_KEEPALIVE_INTERVAL; uint8_t host_keepalive_interval = HOST_KEEPALIVE_INTERVAL;
@ -4962,13 +4962,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
lcd_ignore_click(false); lcd_ignore_click(false);
}else{ }else{
KEEPALIVE_STATE(PAUSED_FOR_USER); marlin_wait_for_click();
while(!lcd_clicked()){
manage_heater();
manage_inactivity(true);
lcd_update(0);
}
KEEPALIVE_STATE(IN_HANDLER);
} }
if (IS_SD_PRINTING) if (IS_SD_PRINTING)
LCD_MESSAGERPGM(_T(MSG_RESUMING_PRINT)); LCD_MESSAGERPGM(_T(MSG_RESUMING_PRINT));
@ -7014,7 +7008,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
if (mmu_enabled) if (mmu_enabled)
{ {
st_synchronize(); st_synchronize();
mmu_continue_loading(); mmu_continue_loading(is_usb_printing);
mmu_extruder = tmp_extruder; //filament change is finished mmu_extruder = tmp_extruder; //filament change is finished
mmu_load_to_nozzle(); mmu_load_to_nozzle();
} }
@ -7052,7 +7046,8 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
mmu_command(MmuCmd::T0 + tmp_extruder); mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE); manage_response(true, true, MMU_TCODE_MOVE);
mmu_continue_loading(); mmu_continue_loading(is_usb_printing);
mmu_extruder = tmp_extruder; //filament change is finished mmu_extruder = tmp_extruder; //filament change is finished
if (load_to_nozzle)// for single material usage with mmu if (load_to_nozzle)// for single material usage with mmu
@ -9614,4 +9609,22 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
lcd_update_enable(false); lcd_update_enable(false);
} }
//! @brief Wait for click
//!
//! Set
void marlin_wait_for_click()
{
int8_t busy_state_backup = busy_state;
KEEPALIVE_STATE(PAUSED_FOR_USER);
lcd_consume_click();
while(!lcd_clicked())
{
manage_heater();
manage_inactivity(true);
lcd_update(0);
}
KEEPALIVE_STATE(busy_state);
}
#define FIL_LOAD_LENGTH 60 #define FIL_LOAD_LENGTH 60

View File

@ -679,6 +679,7 @@ void manage_response(bool move_axes, bool turn_off_nozzle, uint8_t move)
st_synchronize(); st_synchronize();
mmu_print_saved = true; mmu_print_saved = true;
printf_P(PSTR("MMU not responding\n")); printf_P(PSTR("MMU not responding\n"));
KEEPALIVE_STATE(PAUSED_FOR_USER);
hotend_temp_bckp = degTargetHotend(active_extruder); hotend_temp_bckp = degTargetHotend(active_extruder);
if (move_axes) { if (move_axes) {
z_position_bckp = current_position[Z_AXIS]; z_position_bckp = current_position[Z_AXIS];
@ -735,6 +736,7 @@ void manage_response(bool move_axes, bool turn_off_nozzle, uint8_t move)
} }
else if (mmu_print_saved) { else if (mmu_print_saved) {
printf_P(PSTR("MMU starts responding\n")); printf_P(PSTR("MMU starts responding\n"));
KEEPALIVE_STATE(IN_HANDLER);
mmu_loading_flag = false; mmu_loading_flag = false;
if (turn_off_nozzle) if (turn_off_nozzle)
{ {
@ -878,7 +880,7 @@ void mmu_M600_load_filament(bool automatic, float nozzle_temp)
mmu_command(MmuCmd::T0 + tmp_extruder); mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(false, true, MMU_LOAD_MOVE); manage_response(false, true, MMU_LOAD_MOVE);
mmu_continue_loading(); mmu_continue_loading(is_usb_printing);
mmu_extruder = tmp_extruder; //filament change is finished mmu_extruder = tmp_extruder; //filament change is finished
mmu_load_to_nozzle(); mmu_load_to_nozzle();
@ -1363,7 +1365,7 @@ bFilamentAction=false; // NOT in "mmu_load_to_nozzle_
lcd_print(tmp_extruder + 1); lcd_print(tmp_extruder + 1);
mmu_command(MmuCmd::T0 + tmp_extruder); mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE); manage_response(true, true, MMU_TCODE_MOVE);
mmu_continue_loading(); mmu_continue_loading(false);
mmu_extruder = tmp_extruder; //filament change is finished mmu_extruder = tmp_extruder; //filament change is finished
mmu_load_to_nozzle(); mmu_load_to_nozzle();
load_filament_final_feed(); load_filament_final_feed();
@ -1464,59 +1466,109 @@ static void load_more()
st_synchronize(); st_synchronize();
} }
void mmu_continue_loading() static void increment_load_fail()
{ {
if (ir_sensor_detected) uint8_t mmu_load_fail = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL);
uint16_t mmu_load_fail_tot = eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT);
if(mmu_load_fail < 255) eeprom_update_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL, mmu_load_fail + 1);
if(mmu_load_fail_tot < 65535) eeprom_update_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT, mmu_load_fail_tot + 1);
}
//! @brief continue loading filament
//! @par blocking
//! * true blocking - do not return until successful load
//! * false non-blocking - pause print and return on load failure
//!
//! @startuml
//! [*] --> [*] : !ir_sensor_detected /\n send MmuCmd::C0
//! [*] --> LoadMore
//! LoadMore --> [*] : filament \ndetected
//! LoadMore --> Retry : !filament detected /\n increment load fail
//! Retry --> [*] : filament \ndetected
//! Retry --> Unload : !filament \ndetected
//! Unload --> [*] : non-blocking
//! Unload --> Retry : button \nclicked
//!
//! Retry : Cut filament if enabled
//! Retry : repeat last T-code
//! Unload : unload filament
//! Unload : pause print
//! Unload : show error message
//!
//! @enduml
void mmu_continue_loading(bool blocking)
{
if (!ir_sensor_detected)
{ {
load_more(); mmu_command(MmuCmd::C0);
return;
}
if (PIN_GET(IR_SENSOR_PIN) != 0) { load_more();
uint8_t mmu_load_fail = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL);
uint16_t mmu_load_fail_tot = eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT);
if(mmu_load_fail < 255) eeprom_update_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL, mmu_load_fail + 1);
if(mmu_load_fail_tot < 65535) eeprom_update_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT, mmu_load_fail_tot + 1);
enum class Ls : uint_least8_t
{
enter,
retry,
unload,
};
Ls state = Ls::enter;
while (PIN_GET(IR_SENSOR_PIN) != 0)
{
switch (state)
{
case Ls::enter:
increment_load_fail();
// no break
case Ls::retry:
#ifdef MMU_HAS_CUTTER #ifdef MMU_HAS_CUTTER
if (1 == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED)) if (1 == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
{ {
mmu_command(MmuCmd::K0 + tmp_extruder); mmu_command(MmuCmd::K0 + tmp_extruder);
manage_response(true, true, MMU_UNLOAD_MOVE); manage_response(true, true, MMU_UNLOAD_MOVE);
} }
#endif //MMU_HAS_CUTTER #endif //MMU_HAS_CUTTER
mmu_command(MmuCmd::T0 + tmp_extruder); mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE); manage_response(true, true, MMU_TCODE_MOVE);
load_more(); load_more();
state = Ls::unload;
break;
case Ls::unload:
stop_and_save_print_to_ram(0, 0);
if (PIN_GET(IR_SENSOR_PIN) != 0) //lift z
current_position[Z_AXIS] += Z_PAUSE_LIFT;
if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder);
st_synchronize();
//Move XY to side
current_position[X_AXIS] = X_PAUSE_POS;
current_position[Y_AXIS] = Y_PAUSE_POS;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder);
st_synchronize();
mmu_command(MmuCmd::U0);
manage_response(false, true, MMU_UNLOAD_MOVE);
setAllTargetHotends(0);
lcd_setstatuspgm(_i("MMU load failed "));////c=20 r=1
if (blocking)
{
marlin_wait_for_click();
restore_print_from_ram_and_continue(0);
state = Ls::retry;
}
else
{ {
//pause print, show error message and then repeat last T-code
stop_and_save_print_to_ram(0, 0);
//lift z
current_position[Z_AXIS] += Z_PAUSE_LIFT;
if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder);
st_synchronize();
//Move XY to side
current_position[X_AXIS] = X_PAUSE_POS;
current_position[Y_AXIS] = Y_PAUSE_POS;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder);
st_synchronize();
mmu_command(MmuCmd::U0);
manage_response(false, true, MMU_UNLOAD_MOVE);
setAllTargetHotends(0);
lcd_setstatuspgm(_i("MMU load failed "));////MSG_RECOVERING_PRINT c=20 r=1
mmu_fil_loaded = false; //so we can retry same T-code again mmu_fil_loaded = false; //so we can retry same T-code again
isPrintPaused = true; isPrintPaused = true;
mmu_command(MmuCmd::W0); mmu_command(MmuCmd::W0);
return;
} }
} break;
} }
else { //mmu_ir_sensor_detected == false }
mmu_command(MmuCmd::C0);
}
} }

View File

@ -58,7 +58,7 @@ enum class MmuCmd : uint_least8_t
K4, K4,
R0, R0,
S3, S3,
W0, W0, //!< Wait and signal load error
}; };
inline MmuCmd operator+ (MmuCmd cmd, uint8_t filament) inline MmuCmd operator+ (MmuCmd cmd, uint8_t filament)
@ -134,7 +134,7 @@ extern void mmu_eject_filament(uint8_t filament, bool recover);
#ifdef MMU_HAS_CUTTER #ifdef MMU_HAS_CUTTER
extern void mmu_cut_filament(uint8_t filament_nr); extern void mmu_cut_filament(uint8_t filament_nr);
#endif //MMU_HAS_CUTTER #endif //MMU_HAS_CUTTER
extern void mmu_continue_loading(); extern void mmu_continue_loading(bool blocking);
extern void mmu_filament_ramming(); extern void mmu_filament_ramming();
extern void mmu_wait_for_heater_blocking(); extern void mmu_wait_for_heater_blocking();
extern void mmu_load_step(bool synchronize = true); extern void mmu_load_step(bool synchronize = true);

View File

@ -715,6 +715,9 @@ uint8_t tmc2130_get_pwr(uint8_t axis)
return 0; return 0;
} }
//! @par pwr motor power
//! * 0 disabled
//! * non-zero enabled
void tmc2130_set_pwr(uint8_t axis, uint8_t pwr) void tmc2130_set_pwr(uint8_t axis, uint8_t pwr)
{ {
switch (axis) switch (axis)