From fd9b9acf4e5c256dd0d6b30830c77d74e4e240e9 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Jul 2018 14:03:22 +0200 Subject: [PATCH 01/12] FSensor, code cleaning + optical quality meassurement --- Firmware/Marlin_main.cpp | 50 ++++------------------- Firmware/fsensor.cpp | 88 +++++++++++++++++++++++++++------------- Firmware/fsensor.h | 22 +++++----- Firmware/ultralcd.cpp | 10 ++--- 4 files changed, 86 insertions(+), 84 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 74719f72..227f69bd 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -638,7 +638,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move); void restore_print_from_ram_and_continue(float e_move); bool fans_check_enabled = true; -bool filament_autoload_enabled = true; +bool fsensor_autoload_enabled = true; #ifdef TMC2130 @@ -1187,7 +1187,7 @@ void setup() tmc2130_current_r[E_AXIS] = 36; #endif //TMC2130 //disabled filament autoload (PFW360) - filament_autoload_enabled = false; + fsensor_autoload_enabled = false; eeprom_update_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED, 0); } MYSERIAL.begin(BAUDRATE); @@ -1766,38 +1766,6 @@ void setup() #endif //WATCHDOG } -#ifdef PAT9125 -void fsensor_init() { - int pat9125 = pat9125_init(); - printf_P(_N("PAT9125_init:%d\n"), pat9125); - uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); - filament_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); - if (!pat9125) - { - fsensor = 0; //disable sensor - fsensor_not_responding = true; - } - else { - fsensor_not_responding = false; - } - puts_P(PSTR("FSensor ")); - if (fsensor) - { - puts_P(PSTR("ENABLED\n")); - fsensor_enable(); - } - else - { - puts_P(PSTR("DISABLED\n")); - fsensor_disable(); - } -#ifdef DEBUG_DISABLE_FSENSORCHECK - filament_autoload_enabled = false; - fsensor_disable(); -#endif //DEBUG_DISABLE_FSENSORCHECK -} - -#endif //PAT9125 void trace(); @@ -3121,7 +3089,7 @@ void gcode_M701() fsensor_st_sum = 0; fsensor_yd_sum = 0; fsensor_er_sum = 0; - fsensor_yd_min = 255; + fsensor_yd_min = 65535; fsensor_yd_max = 0; lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT)); @@ -6556,14 +6524,14 @@ Sigma_Exit: KEEPALIVE_STATE(PAUSED_FOR_USER); #ifdef PAT9125 - if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_start(); + if (fsensor_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_start(); #endif //PAT9125 while(!lcd_clicked()) { manage_heater(); manage_inactivity(true); #ifdef PAT9125 - if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout) && fsensor_check_autoload()) + if (fsensor_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout) && fsensor_check_autoload()) { tone(BEEPER, 1000); delay_keep_alive(50); @@ -6579,7 +6547,7 @@ Sigma_Exit: } #ifdef PAT9125 - if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_stop(); + if (fsensor_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_stop(); #endif //PAT9125 //WRITE(BEEPER, LOW); KEEPALIVE_STATE(IN_HANDLER); @@ -7673,9 +7641,9 @@ static void handleSafetyTimer() void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h { #ifdef PAT9125 - if (fsensor_enabled && filament_autoload_enabled && fsensor_watch_runout && !moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + if (fsensor_enabled && fsensor_autoload_enabled && fsensor_watch_runout && !moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) { - if (fsensor_autoload_enabled) + if (fsensor_watch_autoload) { if (fsensor_check_autoload()) { @@ -7708,7 +7676,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s fsensor_autoload_check_start(); } else - if (fsensor_autoload_enabled) + if (fsensor_watch_autoload) fsensor_autoload_check_stop(); #endif //PAT9125 diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index c2291235..9ba2fbf2 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -21,12 +21,43 @@ extern void stop_and_save_print_to_ram(float z_move, float e_move); extern void restore_print_from_ram_and_continue(float e_move); extern int8_t FSensorStateMenu; -void fsensor_stop_and_save_print() +void fsensor_init(void) +{ + int pat9125 = pat9125_init(); + printf_P(_N("PAT9125_init:%d\n"), pat9125); + uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); + fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); + if (!pat9125) + { + fsensor = 0; //disable sensor + fsensor_not_responding = true; + } + else { + fsensor_not_responding = false; + } + puts_P(PSTR("FSensor ")); + if (fsensor) + { + puts_P(PSTR("ENABLED\n")); + fsensor_enable(); + } + else + { + puts_P(PSTR("DISABLED\n")); + fsensor_disable(); + } +#ifdef DEBUG_DISABLE_FSENSORCHECK + fsensor_autoload_enabled = false; + fsensor_disable(); +#endif //DEBUG_DISABLE_FSENSORCHECK +} + +void fsensor_stop_and_save_print(void) { stop_and_save_print_to_ram(0, 0); //XYZE - no change } -void fsensor_restore_print_and_continue() +void fsensor_restore_print_and_continue(void) { restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change } @@ -46,7 +77,7 @@ int16_t fsensor_st_cnt = 0; uint8_t fsensor_log = 1; //autoload enable/disable flag -bool fsensor_autoload_enabled = false; +bool fsensor_watch_autoload = false; uint16_t fsensor_autoload_y = 0; uint8_t fsensor_autoload_c = 0; uint32_t fsensor_autoload_last_millis = 0; @@ -55,10 +86,10 @@ uint8_t fsensor_autoload_sum = 0; uint32_t fsensor_st_sum = 0; uint32_t fsensor_yd_sum = 0; uint32_t fsensor_er_sum = 0; -uint8_t fsensor_yd_min = 255; -uint8_t fsensor_yd_max = 0; +uint16_t fsensor_yd_min = 65535; +uint16_t fsensor_yd_max = 0; -bool fsensor_enable() +bool fsensor_enable(void) { // puts_P(PSTR("fsensor_enable\n")); int pat9125 = pat9125_init(); @@ -81,7 +112,7 @@ bool fsensor_enable() return fsensor_enabled; } -void fsensor_disable() +void fsensor_disable(void) { // puts_P(PSTR("fsensor_disable\n")); fsensor_enabled = false; @@ -91,8 +122,8 @@ void fsensor_disable() void fsensor_autoload_set(bool State) { - filament_autoload_enabled = State; - eeprom_update_byte((unsigned char *)EEPROM_FSENS_AUTOLOAD_ENABLED, filament_autoload_enabled); + fsensor_autoload_enabled = State; + eeprom_update_byte((unsigned char *)EEPROM_FSENS_AUTOLOAD_ENABLED, fsensor_autoload_enabled); } void pciSetup(byte pin) @@ -102,19 +133,6 @@ void pciSetup(byte pin) PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group } -void fsensor_setup_interrupt() -{ -// uint8_t fsensor_int_pin = FSENSOR_INT_PIN; -// uint8_t fsensor_int_pcmsk = digitalPinToPCMSKbit(pin); -// uint8_t fsensor_int_pcicr = digitalPinToPCICRbit(pin); - - pinMode(FSENSOR_INT_PIN, OUTPUT); - digitalWrite(FSENSOR_INT_PIN, LOW); - fsensor_int_pin_old = 0; - - pciSetup(FSENSOR_INT_PIN); -} - void fsensor_autoload_check_start(void) { // puts_P(PSTR("fsensor_autoload_check_start\n")); @@ -123,14 +141,14 @@ void fsensor_autoload_check_start(void) printf_P(ERRMSG_PAT9125_NOT_RESP, 3); fsensor_disable(); fsensor_not_responding = true; - fsensor_autoload_enabled = false; + fsensor_watch_autoload = false; return; } fsensor_autoload_y = pat9125_y; //save current y value fsensor_autoload_c = 0; //reset number of changes counter fsensor_autoload_sum = 0; fsensor_autoload_last_millis = millis(); - fsensor_autoload_enabled = true; + fsensor_watch_autoload = true; fsensor_err_cnt = 0; } @@ -138,7 +156,7 @@ void fsensor_autoload_check_stop(void) { // puts_P(PSTR("fsensor_autoload_check_stop\n")); fsensor_autoload_sum = 0; - fsensor_autoload_enabled = false; + fsensor_watch_autoload = false; fsensor_err_cnt = 0; } @@ -208,8 +226,8 @@ ISR(PCINT2_vect) fsensor_err_cnt--; if (st_cnt == FSENSOR_CHUNK_LEN) { - if (fsensor_yd_min > pat9125_y) fsensor_yd_min = pat9125_y; - if (fsensor_yd_max < pat9125_y) fsensor_yd_max = pat9125_y; + if (fsensor_yd_min > pat9125_y) fsensor_yd_min = (fsensor_yd_min + pat9125_y) / 2; + if (fsensor_yd_max < pat9125_y) fsensor_yd_max = (fsensor_yd_max + pat9125_y) / 2; } } fsensor_st_sum += st_cnt; @@ -262,7 +280,7 @@ void fsensor_st_block_chunk(block_t* bl, int cnt) // _WRITE(fsensor_int_pin, LOW); } -void fsensor_update() +void fsensor_update(void) { if (fsensor_enabled && fsensor_watch_runout) if (fsensor_err_cnt > FSENSOR_ERR_MAX) @@ -295,4 +313,18 @@ void fsensor_update() } } +void fsensor_setup_interrupt(void) +{ +// uint8_t fsensor_int_pin = FSENSOR_INT_PIN; +// uint8_t fsensor_int_pcmsk = digitalPinToPCMSKbit(pin); +// uint8_t fsensor_int_pcicr = digitalPinToPCICRbit(pin); + + pinMode(FSENSOR_INT_PIN, OUTPUT); + digitalWrite(FSENSOR_INT_PIN, LOW); + fsensor_int_pin_old = 0; + + pciSetup(FSENSOR_INT_PIN); +} + + #endif //PAT9125 diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index eda8d43f..70534b39 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -7,21 +7,23 @@ #define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm //save restore printing -extern void fsensor_stop_and_save_print(); -extern void fsensor_restore_print_and_continue(); +extern void fsensor_stop_and_save_print(void); +extern void fsensor_restore_print_and_continue(void); + +extern void fsensor_init(void); //enable/disable -extern bool fsensor_enable(); -extern void fsensor_disable(); +extern bool fsensor_enable(void); +extern void fsensor_disable(void); -extern bool filament_autoload_enabled; +extern bool fsensor_autoload_enabled; extern void fsensor_autoload_set(bool State); //update (perform M600 on filament runout) -extern void fsensor_update(); +extern void fsensor_update(void); //setup pin-change interrupt -extern void fsensor_setup_interrupt(); +extern void fsensor_setup_interrupt(void); // extern void fsensor_autoload_check_start(void); @@ -48,13 +50,13 @@ extern bool fsensor_not_responding; extern uint8_t fsensor_err_cnt; //autoload enable/disable flag -extern bool fsensor_autoload_enabled; +extern bool fsensor_watch_autoload; extern uint32_t fsensor_st_sum; extern uint32_t fsensor_yd_sum; extern uint32_t fsensor_er_sum; -extern uint8_t fsensor_yd_min; -extern uint8_t fsensor_yd_max; +extern uint16_t fsensor_yd_min; +extern uint16_t fsensor_yd_max; #endif //FSENSOR_H diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 6ea1b5f1..45ea2288 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -38,7 +38,7 @@ extern int lcd_change_fil_state; extern bool fans_check_enabled; -extern bool filament_autoload_enabled; +extern bool fsensor_autoload_enabled; #ifdef PAT9125 extern bool fsensor_not_responding; @@ -2280,7 +2280,7 @@ void lcd_set_fan_check() { } void lcd_set_filament_autoload() { - fsensor_autoload_set(!filament_autoload_enabled); + fsensor_autoload_set(!fsensor_autoload_enabled); } void lcd_unLoadFilament() @@ -4102,7 +4102,7 @@ static void lcd_fsensor_state_set() FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable() if (!FSensorStateMenu) { fsensor_disable(); - if (filament_autoload_enabled) + if (fsensor_autoload_enabled) menu_submenu(lcd_filament_autoload_info); }else{ fsensor_enable(); @@ -4609,7 +4609,7 @@ static void lcd_settings_menu() MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set); - if (filament_autoload_enabled) { + if (fsensor_autoload_enabled) { MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1 } else { @@ -5948,7 +5948,7 @@ static void lcd_main_menu() #else #ifdef PAT9125 - if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true))) + if ( ((fsensor_autoload_enabled == true) && (fsensor_enabled == true))) MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0 else #endif //PAT9125 From 0f91bf9527eb2d20631ae23e48a504e47e3092ee Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Jul 2018 20:30:08 +0200 Subject: [PATCH 02/12] FSensor - optical quality meassurement durring load filament --- Firmware/Marlin_main.cpp | 25 ++++++++---- Firmware/fsensor.cpp | 83 +++++++++++++++++++++++++++++++--------- Firmware/fsensor.h | 36 +++++++++++------ 3 files changed, 105 insertions(+), 39 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 227f69bd..eb0146ed 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3085,12 +3085,7 @@ void gcode_M701() custom_message_type = 2; bool old_watch_runout = fsensor_watch_runout; - fsensor_watch_runout = false; - fsensor_st_sum = 0; - fsensor_yd_sum = 0; - fsensor_er_sum = 0; - fsensor_yd_min = 65535; - fsensor_yd_max = 0; + fsensor_oq_meassure_start(); lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT)); current_position[E_AXIS] += 40; @@ -3132,11 +3127,25 @@ void gcode_M701() custom_message_type = 0; #endif + fsensor_oq_meassure_stop(); + fsensor_err_cnt = 0; fsensor_watch_runout = old_watch_runout; - printf_P(_N("\nFSENSOR st_sum=%lu yd_sum=%lu er_sum=%lu\n"), fsensor_st_sum, fsensor_yd_sum, fsensor_er_sum); - printf_P(_N("\nFSENSOR yd_min=%hhu yd_max=%hhu yd_avg=%hhu\n"), fsensor_yd_min, fsensor_yd_max, fsensor_yd_sum * FSENSOR_CHUNK_LEN / fsensor_st_sum); + + printf_P(_N("\nFSENSOR st_sum=%lu yd_sum=%lu er_sum=%u er_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); + printf_P(_N("\nFSENSOR yd_min=%hhu yd_max=%hhu yd_avg=%hhu\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum); printf_P(PSTR("gcode_M701 end\n")); + + + if (!fsensor_oq_result()) + { + bool disable = lcd_show_fullscreen_message_yes_no_and_wait_P( + _i("Filament sensor low response, disable it?"), false, true); + lcd_update_enable(true); + lcd_update(2); + if (disable) + fsensor_disable(); + } } /** * @brief Get serial number from 32U2 processor diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 9ba2fbf2..f2161fc0 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -12,8 +12,6 @@ const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n"; -//#define FSENSOR_ERR_MAX 5 //filament sensor max error count -#define FSENSOR_ERR_MAX 10 //filament sensor max error count #define FSENSOR_INT_PIN 63 //filament sensor interrupt pin PK1 #define FSENSOR_INT_PIN_MSK 0x02 //filament sensor interrupt pin mask (bit1) @@ -83,15 +81,19 @@ uint8_t fsensor_autoload_c = 0; uint32_t fsensor_autoload_last_millis = 0; uint8_t fsensor_autoload_sum = 0; -uint32_t fsensor_st_sum = 0; -uint32_t fsensor_yd_sum = 0; -uint32_t fsensor_er_sum = 0; -uint16_t fsensor_yd_min = 65535; -uint16_t fsensor_yd_max = 0; +//filament optical quality meassurement +bool fsensor_oq_meassure = false; +uint8_t fsensor_oq_skipchunk; +uint32_t fsensor_oq_st_sum; +uint32_t fsensor_oq_yd_sum; +uint16_t fsensor_oq_er_sum; +uint8_t fsensor_oq_er_max; +uint16_t fsensor_oq_yd_min; +uint16_t fsensor_oq_yd_max; + bool fsensor_enable(void) { -// puts_P(PSTR("fsensor_enable\n")); int pat9125 = pat9125_init(); printf_P(PSTR("PAT9125_init:%d\n"), pat9125); if (pat9125) @@ -100,14 +102,11 @@ bool fsensor_enable(void) fsensor_not_responding = true; fsensor_enabled = pat9125?true:false; fsensor_watch_runout = true; + fsensor_oq_meassure = false; fsensor_err_cnt = 0; eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled?0x01:0x00); FSensorStateMenu = fsensor_enabled?1:0; -// printf_P(PSTR("fsensor_enable - end %d\n"), fsensor_enabled?1:0); - fsensor_st_sum = 0; - fsensor_yd_sum = 0; - fsensor_er_sum = 0; return fsensor_enabled; } @@ -194,6 +193,41 @@ bool fsensor_check_autoload(void) return false; } +void fsensor_oq_meassure_start(void) +{ + fsensor_oq_skipchunk = 1; + fsensor_oq_st_sum = 0; + fsensor_oq_yd_sum = 0; + fsensor_oq_er_sum = 0; + fsensor_oq_er_max = 0; + fsensor_oq_yd_min = FSENSOR_OQ_MAX_YD; + fsensor_oq_yd_max = 0; + pat9125_update_y(); + pat9125_y = 0; + fsensor_watch_runout = false; + fsensor_oq_meassure = true; +} + +void fsensor_oq_meassure_stop(void) +{ + fsensor_oq_meassure = false; +} + +bool fsensor_oq_result(void) +{ + printf(_N("fsensor_oq_result\n")); + if (fsensor_oq_er_sum > FSENSOR_OQ_MAX_ER) return false; + printf(_N(" er_sum OK\n")); + uint8_t yd_avg = fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum; + if ((yd_avg < FSENSOR_OQ_MIN_YD) || (yd_avg > FSENSOR_OQ_MAX_YD)) return false; + printf(_N(" yd_avg OK\n")); + if (fsensor_oq_yd_max > (yd_avg * FSENSOR_OQ_MAX_PD)) return false; + printf(_N(" yd_max OK\n")); + if (fsensor_oq_yd_min < (yd_avg / FSENSOR_OQ_MAX_ND)) return false; + printf(_N(" yd_min OK\n")); + return true; +} + ISR(PCINT2_vect) { if (!((fsensor_int_pin_old ^ PINK) & FSENSOR_INT_PIN_MSK)) return; @@ -218,20 +252,31 @@ ISR(PCINT2_vect) if (pat9125_y <= 0) { fsensor_err_cnt++; - fsensor_er_sum++; } else { if (fsensor_err_cnt) fsensor_err_cnt--; - if (st_cnt == FSENSOR_CHUNK_LEN) + } + if (fsensor_oq_meassure) + { + if (fsensor_oq_skipchunk) + fsensor_oq_skipchunk--; + else { - if (fsensor_yd_min > pat9125_y) fsensor_yd_min = (fsensor_yd_min + pat9125_y) / 2; - if (fsensor_yd_max < pat9125_y) fsensor_yd_max = (fsensor_yd_max + pat9125_y) / 2; + if (st_cnt == FSENSOR_CHUNK_LEN) + { + if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2; + if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2; + } + fsensor_oq_st_sum += st_cnt; + fsensor_oq_yd_sum += pat9125_y; + if (fsensor_err_cnt > old_err_cnt) + fsensor_oq_er_sum += (fsensor_err_cnt - old_err_cnt); + if (fsensor_oq_er_max < fsensor_err_cnt) + fsensor_oq_er_max = fsensor_err_cnt; } } - fsensor_st_sum += st_cnt; - fsensor_yd_sum += pat9125_y; } else //negative movement { @@ -245,7 +290,7 @@ ISR(PCINT2_vect) if (fsensor_log) { printf_P(_N("FSENSOR cnt=%d dy=%d err=%d %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); - printf_P(_N("FSENSOR st_sum=%lu yd_sum=%lu er_sum=%lu\n"), fsensor_st_sum, fsensor_yd_sum, fsensor_er_sum); + printf_P(_N("FSENSOR st_sum=%lu yd_sum=%lu er_sum=%u er_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); } #endif //DEBUG_FSENSOR_LOG diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 70534b39..99f30e8a 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -3,8 +3,16 @@ #include "planner.h" -//#define FSENSOR_CHUNK_LEN 280 //filament sensor chunk length in steps - 1mm #define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm +#define FSENSOR_ERR_MAX 10 //filament sensor maximum error count for runout detection + +//Optical quality meassurement params +#define FSENSOR_OQ_MAX_ER 5 //maximum error count for loading (~150mm) +#define FSENSOR_OQ_MIN_YD 2 //minimum yd per chunk +#define FSENSOR_OQ_MAX_YD 200 //maximum yd per chunk +#define FSENSOR_OQ_MAX_PD 3 //maximum positive deviation (= yd_max/yd_avg) +#define FSENSOR_OQ_MAX_ND 5 //maximum negative deviation (= yd_avg/yd_min) + //save restore printing extern void fsensor_stop_and_save_print(void); @@ -25,15 +33,16 @@ extern void fsensor_update(void); //setup pin-change interrupt extern void fsensor_setup_interrupt(void); -// +//autoload support extern void fsensor_autoload_check_start(void); - -// extern void fsensor_autoload_check_stop(void); - -// extern bool fsensor_check_autoload(void); +//optical quality meassurement support +extern void fsensor_oq_meassure_start(void); +extern void fsensor_oq_meassure_stop(void); +extern bool fsensor_oq_result(void); + //callbacks from stepper extern void fsensor_st_block_begin(block_t* bl); extern void fsensor_st_block_chunk(block_t* bl, int cnt); @@ -52,11 +61,14 @@ extern uint8_t fsensor_err_cnt; //autoload enable/disable flag extern bool fsensor_watch_autoload; - -extern uint32_t fsensor_st_sum; -extern uint32_t fsensor_yd_sum; -extern uint32_t fsensor_er_sum; -extern uint16_t fsensor_yd_min; -extern uint16_t fsensor_yd_max; +//filament optical quality meassurement +extern bool fsensor_oq_meassure; +extern uint8_t fsensor_oq_skipchunk; +extern uint32_t fsensor_oq_st_sum; +extern uint32_t fsensor_oq_yd_sum; +extern uint16_t fsensor_oq_er_sum; +extern uint8_t fsensor_oq_er_max; +extern uint16_t fsensor_oq_yd_min; +extern uint16_t fsensor_oq_yd_max; #endif //FSENSOR_H From ca2d69271ccab30f47a117de74beef40e0ff76c5 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Jul 2018 20:37:50 +0200 Subject: [PATCH 03/12] filament_autoload_enabled renamed to fsensor_watch_autoload --- Firmware/Marlin_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 68661a49..a8eb3b42 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9128,14 +9128,14 @@ void M600_load_filament(bool fsensor_enabled) { KEEPALIVE_STATE(PAUSED_FOR_USER); #ifdef PAT9125 - if (filament_autoload_enabled && (fsensor_enabled || fsensor_watch_runout)) fsensor_autoload_check_start(); + if (fsensor_watch_autoload && (fsensor_enabled || fsensor_watch_runout)) fsensor_autoload_check_start(); #endif //PAT9125 while(!lcd_clicked()) { manage_heater(); manage_inactivity(true); #ifdef PAT9125 - if (filament_autoload_enabled && (fsensor_enabled || fsensor_watch_runout) && fsensor_check_autoload()) + if (fsensor_watch_autoload && (fsensor_enabled || fsensor_watch_runout) && fsensor_check_autoload()) { tone(BEEPER, 1000); delay_keep_alive(50); @@ -9146,7 +9146,7 @@ void M600_load_filament(bool fsensor_enabled) { } #ifdef PAT9125 - if (filament_autoload_enabled && (fsensor_enabled || fsensor_watch_runout)) fsensor_autoload_check_stop(); + if (fsensor_watch_autoload && (fsensor_enabled || fsensor_watch_runout)) fsensor_autoload_check_stop(); #endif //PAT9125 KEEPALIVE_STATE(IN_HANDLER); From 1309c52bcfa78f14f30d3de1887f04c126469e14 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 20 Jul 2018 23:48:00 +0200 Subject: [PATCH 04/12] FSensor - code cleaning + simplification + removed DEBUG_DISABLE_FSENSORCHECK + added FILAMENT_SENSOR --- Firmware/Marlin_main.cpp | 74 +++--- Firmware/fsensor.cpp | 131 ++++++---- Firmware/fsensor.h | 12 +- Firmware/ultralcd.cpp | 226 +++++++++--------- Firmware/ultralcd.h | 2 +- .../variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h | 3 +- .../variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h | 3 +- .../variants/1_75mm_MK3-EINSy10a-E3Dv6full.h | 1 + 8 files changed, 225 insertions(+), 227 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a8eb3b42..5bf0c74b 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -638,7 +638,6 @@ void stop_and_save_print_to_ram(float z_move, float e_move); void restore_print_from_ram_and_continue(float e_move); bool fans_check_enabled = true; -bool fsensor_autoload_enabled = true; #ifdef TMC2130 @@ -1187,8 +1186,7 @@ void setup() tmc2130_current_r[E_AXIS] = 36; #endif //TMC2130 //disabled filament autoload (PFW360) - fsensor_autoload_enabled = false; - eeprom_update_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED, 0); + fsensor_autoload_set(false); } MYSERIAL.begin(BAUDRATE); fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream @@ -1625,9 +1623,7 @@ void setup() #endif //DEBUG_DISABLE_FANCHECK #ifdef PAT9125 -#ifndef DEBUG_DISABLE_FSENSORCHECK fsensor_setup_interrupt(); -#endif //DEBUG_DISABLE_FSENSORCHECK #endif //PAT9125 for (int i = 0; i<4; i++) EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]); @@ -3084,7 +3080,6 @@ void gcode_M701() custom_message = true; custom_message_type = 2; - bool old_watch_runout = fsensor_watch_runout; fsensor_oq_meassure_start(); lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT)); @@ -3129,12 +3124,7 @@ void gcode_M701() fsensor_oq_meassure_stop(); - fsensor_err_cnt = 0; - fsensor_watch_runout = old_watch_runout; - printf_P(_N("\nFSENSOR st_sum=%lu yd_sum=%lu er_sum=%u er_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); - printf_P(_N("\nFSENSOR yd_min=%hhu yd_max=%hhu yd_avg=%hhu\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum); - printf_P(PSTR("gcode_M701 end\n")); if (!fsensor_oq_result()) @@ -7501,43 +7491,35 @@ static void handleSafetyTimer() void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h { #ifdef PAT9125 - if (fsensor_enabled && fsensor_autoload_enabled && fsensor_watch_runout && !moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) { - if (fsensor_watch_autoload) + if (fsensor_check_autoload()) { - if (fsensor_check_autoload()) - { - - if (degHotend0() > EXTRUDE_MINTEMP) - { - fsensor_autoload_check_stop(); - tone(BEEPER, 1000); - delay_keep_alive(50); - noTone(BEEPER); - loading_flag = true; - enquecommand_front_P((PSTR("M701"))); - } - else - { - lcd_update_enable(false); - lcd_clear(); - lcd_set_cursor(0, 0); - lcd_puts_P(_T(MSG_ERROR)); - lcd_set_cursor(0, 2); - lcd_puts_P(_T(MSG_PREHEAT_NOZZLE)); - delay(2000); - lcd_clear(); - lcd_update_enable(true); - } - - } + if (degHotend0() > EXTRUDE_MINTEMP) + { + fsensor_autoload_check_stop(); + tone(BEEPER, 1000); + delay_keep_alive(50); + noTone(BEEPER); + loading_flag = true; + enquecommand_front_P((PSTR("M701"))); + } + else + { + lcd_update_enable(false); + lcd_clear(); + lcd_set_cursor(0, 0); + lcd_puts_P(_T(MSG_ERROR)); + lcd_set_cursor(0, 2); + lcd_puts_P(_T(MSG_PREHEAT_NOZZLE)); + delay(2000); + lcd_clear(); + lcd_update_enable(true); + } } - else - fsensor_autoload_check_start(); } else - if (fsensor_watch_autoload) - fsensor_autoload_check_stop(); + fsensor_autoload_check_stop(); #endif //PAT9125 #ifdef SAFETYTIMER @@ -9128,14 +9110,14 @@ void M600_load_filament(bool fsensor_enabled) { KEEPALIVE_STATE(PAUSED_FOR_USER); #ifdef PAT9125 - if (fsensor_watch_autoload && (fsensor_enabled || fsensor_watch_runout)) fsensor_autoload_check_start(); + fsensor_autoload_check_start(); #endif //PAT9125 while(!lcd_clicked()) { manage_heater(); manage_inactivity(true); #ifdef PAT9125 - if (fsensor_watch_autoload && (fsensor_enabled || fsensor_watch_runout) && fsensor_check_autoload()) + if (fsensor_check_autoload()) { tone(BEEPER, 1000); delay_keep_alive(50); @@ -9146,7 +9128,7 @@ void M600_load_filament(bool fsensor_enabled) { } #ifdef PAT9125 - if (fsensor_watch_autoload && (fsensor_enabled || fsensor_watch_runout)) fsensor_autoload_check_stop(); + fsensor_autoload_check_stop(); #endif //PAT9125 KEEPALIVE_STATE(IN_HANDLER); diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index f2161fc0..609e9244 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -19,37 +19,6 @@ extern void stop_and_save_print_to_ram(float z_move, float e_move); extern void restore_print_from_ram_and_continue(float e_move); extern int8_t FSensorStateMenu; -void fsensor_init(void) -{ - int pat9125 = pat9125_init(); - printf_P(_N("PAT9125_init:%d\n"), pat9125); - uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); - fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); - if (!pat9125) - { - fsensor = 0; //disable sensor - fsensor_not_responding = true; - } - else { - fsensor_not_responding = false; - } - puts_P(PSTR("FSensor ")); - if (fsensor) - { - puts_P(PSTR("ENABLED\n")); - fsensor_enable(); - } - else - { - puts_P(PSTR("DISABLED\n")); - fsensor_disable(); - } -#ifdef DEBUG_DISABLE_FSENSORCHECK - fsensor_autoload_enabled = false; - fsensor_disable(); -#endif //DEBUG_DISABLE_FSENSORCHECK -} - void fsensor_stop_and_save_print(void) { stop_and_save_print_to_ram(0, 0); //XYZE - no change @@ -64,38 +33,91 @@ void fsensor_restore_print_and_continue(void) uint8_t fsensor_int_pin_old = 0; int16_t fsensor_chunk_len = FSENSOR_CHUNK_LEN; +//enabled = initialized and sampled every chunk event bool fsensor_enabled = true; +//runout watching is done in fsensor_update (called from main loop) bool fsensor_watch_runout = true; +//not responding - is set if any communication error occured durring initialization or readout bool fsensor_not_responding = false; +//number of errors, updated in ISR uint8_t fsensor_err_cnt = 0; +//variable for accumolating step count int16_t fsensor_st_cnt = 0; - +//log flag: 0=log disabled, 1=log enabled uint8_t fsensor_log = 1; -//autoload enable/disable flag +//////////////////////////////////////////////////////////////////////////////// +//filament autoload variables + +//autoload feature enabled +bool fsensor_autoload_enabled = true; + +//autoload watching enable/disable flag bool fsensor_watch_autoload = false; +// uint16_t fsensor_autoload_y = 0; +// uint8_t fsensor_autoload_c = 0; +// uint32_t fsensor_autoload_last_millis = 0; +// uint8_t fsensor_autoload_sum = 0; -//filament optical quality meassurement +//////////////////////////////////////////////////////////////////////////////// +//filament optical quality meassurement variables + +//meassurement enable/disable flag bool fsensor_oq_meassure = false; +//skip-chunk counter, for accurate meassurement is necesary to skip first chunk... uint8_t fsensor_oq_skipchunk; -uint32_t fsensor_oq_st_sum; -uint32_t fsensor_oq_yd_sum; +//sum of steps in positive direction movements +uint16_t fsensor_oq_st_sum; +//sum of deltas in positive direction movements +uint16_t fsensor_oq_yd_sum; +//sum of errors durring meassurement uint16_t fsensor_oq_er_sum; +//max error counter value durring meassurement uint8_t fsensor_oq_er_max; +//minimum delta value uint16_t fsensor_oq_yd_min; +//maximum delta value uint16_t fsensor_oq_yd_max; -bool fsensor_enable(void) +void fsensor_init(void) { int pat9125 = pat9125_init(); - printf_P(PSTR("PAT9125_init:%d\n"), pat9125); + printf_P(_N("PAT9125_init:%d\n"), pat9125); + uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); + fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); + if (!pat9125) + { + fsensor = 0; //disable sensor + fsensor_not_responding = true; + } + else + { + fsensor_not_responding = false; + } + puts_P(PSTR("FSensor ")); + if (fsensor) + { + fsensor_enable(); + puts_P(PSTR("ENABLED\n")); + } + else + { + fsensor_disable(); + puts_P(PSTR("DISABLED\n")); + } +} + +bool fsensor_enable(void) +{ + uint8_t pat9125 = pat9125_init(); + printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125); if (pat9125) fsensor_not_responding = false; else @@ -113,7 +135,6 @@ bool fsensor_enable(void) void fsensor_disable(void) { -// puts_P(PSTR("fsensor_disable\n")); fsensor_enabled = false; eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, 0x00); FSensorStateMenu = 0; @@ -134,41 +155,54 @@ void pciSetup(byte pin) void fsensor_autoload_check_start(void) { -// puts_P(PSTR("fsensor_autoload_check_start\n")); + if (!fsensor_enabled) return; + if (!fsensor_autoload_enabled) return; + if (fsensor_watch_autoload) return; if (!pat9125_update_y()) //update sensor { - printf_P(ERRMSG_PAT9125_NOT_RESP, 3); fsensor_disable(); fsensor_not_responding = true; fsensor_watch_autoload = false; + printf_P(ERRMSG_PAT9125_NOT_RESP, 3); return; } fsensor_autoload_y = pat9125_y; //save current y value fsensor_autoload_c = 0; //reset number of changes counter fsensor_autoload_sum = 0; fsensor_autoload_last_millis = millis(); + fsensor_watch_runout = false; fsensor_watch_autoload = true; fsensor_err_cnt = 0; } void fsensor_autoload_check_stop(void) { -// puts_P(PSTR("fsensor_autoload_check_stop\n")); + if (!fsensor_enabled) return; + if (!fsensor_autoload_enabled) return; + if (!fsensor_watch_autoload) return; fsensor_autoload_sum = 0; fsensor_watch_autoload = false; + fsensor_watch_runout = true; fsensor_err_cnt = 0; } bool fsensor_check_autoload(void) { + if (!fsensor_enabled) return false; + if (!fsensor_autoload_enabled) return false; + if (!fsensor_watch_autoload) + { + fsensor_autoload_check_start(); + return false; + } uint8_t fsensor_autoload_c_old = fsensor_autoload_c; if ((millis() - fsensor_autoload_last_millis) < 25) return false; fsensor_autoload_last_millis = millis(); if (!pat9125_update_y()) { - printf_P(ERRMSG_PAT9125_NOT_RESP, 2); fsensor_disable(); fsensor_not_responding = true; + printf_P(ERRMSG_PAT9125_NOT_RESP, 2); return false; //update sensor } int16_t dy = fsensor_autoload_y - pat9125_y; @@ -210,7 +244,12 @@ void fsensor_oq_meassure_start(void) void fsensor_oq_meassure_stop(void) { + printf_P(PSTR("fsensor_oq_meassure_stop\n")); + printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); + printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum); fsensor_oq_meassure = false; + fsensor_err_cnt = 0; + fsensor_watch_runout = true; } bool fsensor_oq_result(void) @@ -241,9 +280,9 @@ ISR(PCINT2_vect) uint8_t old_err_cnt = fsensor_err_cnt; if (!pat9125_update_y()) { - printf_P(ERRMSG_PAT9125_NOT_RESP, 1); fsensor_disable(); fsensor_not_responding = true; + printf_P(ERRMSG_PAT9125_NOT_RESP, 1); } if (st_cnt != 0) { //movement @@ -308,8 +347,6 @@ void fsensor_st_block_begin(block_t* bl) if (_READ(63)) _WRITE(63, LOW); else _WRITE(63, HIGH); } -// PINK |= FSENSOR_INT_PIN_MSK; //toggle pin -// _WRITE(fsensor_int_pin, LOW); } void fsensor_st_block_chunk(block_t* bl, int cnt) @@ -321,8 +358,6 @@ void fsensor_st_block_chunk(block_t* bl, int cnt) if (_READ(63)) _WRITE(63, LOW); else _WRITE(63, HIGH); } -// PINK |= FSENSOR_INT_PIN_MSK; //toggle pin -// _WRITE(fsensor_int_pin, LOW); } void fsensor_update(void) diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 99f30e8a..2b22633a 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -18,12 +18,14 @@ extern void fsensor_stop_and_save_print(void); extern void fsensor_restore_print_and_continue(void); +//initialize extern void fsensor_init(void); //enable/disable extern bool fsensor_enable(void); extern void fsensor_disable(void); +//autoload feature enabled extern bool fsensor_autoload_enabled; extern void fsensor_autoload_set(bool State); @@ -56,19 +58,11 @@ extern bool fsensor_watch_runout; //not responding flag extern bool fsensor_not_responding; +//error counter extern uint8_t fsensor_err_cnt; //autoload enable/disable flag extern bool fsensor_watch_autoload; -//filament optical quality meassurement -extern bool fsensor_oq_meassure; -extern uint8_t fsensor_oq_skipchunk; -extern uint32_t fsensor_oq_st_sum; -extern uint32_t fsensor_oq_yd_sum; -extern uint16_t fsensor_oq_er_sum; -extern uint8_t fsensor_oq_er_max; -extern uint16_t fsensor_oq_yd_min; -extern uint16_t fsensor_oq_yd_max; #endif //FSENSOR_H diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 8d869aa8..da618570 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -27,6 +27,10 @@ #include "pat9125.h" #endif //PAT9125 +#ifdef FILAMENT_SENSOR +#include "fsensor.h" +#endif //FILAMENT_SENSOR + #ifdef TMC2130 #include "tmc2130.h" #endif //TMC2130 @@ -38,12 +42,7 @@ extern int lcd_change_fil_state; extern bool fans_check_enabled; -extern bool fsensor_autoload_enabled; -#ifdef PAT9125 -extern bool fsensor_not_responding; -extern bool fsensor_enabled; -#endif //PAT9125 int scrollstuff = 0; char longFilenameOLD[LONG_FILENAME_LENGTH]; @@ -2506,7 +2505,7 @@ void lcd_alright() { } -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR static void lcd_menu_AutoLoadFilament() { if (degHotend0() > EXTRUDE_MINTEMP) @@ -2526,7 +2525,7 @@ static void lcd_menu_AutoLoadFilament() } menu_back_if_clicked(); } -#endif //PAT9125 +#endif //FILAMENT_SENSOR static void lcd_LoadFilament() { @@ -4024,7 +4023,7 @@ static void lcd_crash_mode_info2() } #endif //TMC2130 -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR static void lcd_filament_autoload_info() { uint8_t nlines; @@ -4050,7 +4049,7 @@ uint8_t nlines; } menu_back_if_clicked(); } -#endif //PAT9125 +#endif //FILAMENT_SENSOR static void lcd_silent_mode_set() { @@ -4107,7 +4106,7 @@ static void lcd_crash_mode_set() #endif //TMC2130 -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR static void lcd_fsensor_state_set() { FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable() @@ -4121,7 +4120,7 @@ static void lcd_fsensor_state_set() menu_submenu(lcd_fsensor_fail); } } -#endif //PAT9125 +#endif //FILAMENT_SENSOR #if !SDSORT_USES_RAM @@ -4581,130 +4580,120 @@ void lcd_settings_linearity_correction_menu(void) */ static void lcd_settings_menu() { - EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu)); - MENU_BEGIN(); - MENU_ITEM_BACK_P(_T(MSG_MAIN)); + EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu)); + MENU_BEGIN(); + MENU_ITEM_BACK_P(_T(MSG_MAIN)); + MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0 + if (!homing_flag) + MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0 + if (!isPrintPaused) + MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0 - MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0 - if (!homing_flag) - { - MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0 - } - if (!isPrintPaused) - { - MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0 - } #ifndef TMC2130 - if (!farm_mode) { //dont show in menu if we are in farm mode - switch (SilentModeMenu) { - case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; - case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break; - case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break; - default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed - } - } + if (!farm_mode) + { //dont show in menu if we are in farm mode + switch (SilentModeMenu) + { + case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; + case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break; + case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break; + default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed + } + } #endif //TMC2130 -#ifdef PAT9125 -#ifndef DEBUG_DISABLE_FSENSORCHECK - if (FSensorStateMenu == 0) { - if (fsensor_not_responding){ - // Filament sensor not working - MENU_ITEM_FUNCTION_P(_i("Fil. sensor [N/A]"), lcd_fsensor_state_set);////MSG_FSENSOR_NA c=0 r=0 - MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail); - } - else{ - // Filament sensor turned off, working, no problems - MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set); - MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info); - } - } else { - // Filament sensor turned on, working, no problems - MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set); - +#ifdef FILAMENT_SENSOR + if (FSensorStateMenu == 0) + { + if (fsensor_not_responding) + { + // Filament sensor not working + MENU_ITEM_FUNCTION_P(_i("Fil. sensor [N/A]"), lcd_fsensor_state_set);////MSG_FSENSOR_NA c=0 r=0 + MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail); + } + else + { + // Filament sensor turned off, working, no problems + MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set); + MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info); + } + } + else + { + // Filament sensor turned on, working, no problems + MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set); + if (fsensor_autoload_enabled) + MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1 + else + MENU_ITEM_FUNCTION_P(_i("F. autoload [off]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_OFF c=17 r=1 + } +#endif //FILAMENT_SENSOR - if (fsensor_autoload_enabled) { - MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1 - } - else { - MENU_ITEM_FUNCTION_P(_i("F. autoload [off]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_OFF c=17 r=1 - } - - } -#endif //DEBUG_DISABLE_FSENSORCHECK -#endif //PAT9125 - - if (fans_check_enabled == true) { - MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1 - } - else { - MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1 - } + if (fans_check_enabled == true) + MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1 + else + MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1 #ifdef TMC2130 - if(!farm_mode) - { - if (SilentModeMenu == SILENT_MODE_NORMAL) { MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set); } - else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set); - if (SilentModeMenu == SILENT_MODE_NORMAL) - { - if (CrashDetectMenu == 0) { MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set); } - else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set); - } - else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info); - } + if(!farm_mode) + { + if (SilentModeMenu == SILENT_MODE_NORMAL) { MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set); } + else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set); + if (SilentModeMenu == SILENT_MODE_NORMAL) + { + if (CrashDetectMenu == 0) { MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set); } + else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set); + } + else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info); + } // MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu); #endif //TMC2130 - if (temp_cal_active == false) { + if (temp_cal_active == false) MENU_ITEM_FUNCTION_P(_i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1 - } - else { + else MENU_ITEM_FUNCTION_P(_i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1 - } + #ifdef HAS_SECOND_SERIAL_PORT - if (selectedSerialPort == 0) { - MENU_ITEM_FUNCTION_P(_i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1 - } - else { - MENU_ITEM_FUNCTION_P(_i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1 - } + if (selectedSerialPort == 0) + MENU_ITEM_FUNCTION_P(_i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1 + else + MENU_ITEM_FUNCTION_P(_i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1 #endif //HAS_SECOND_SERIAL - if (!isPrintPaused && !homing_flag) - { + if (!isPrintPaused && !homing_flag) MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z); - } #if (LANG_MODE != 0) MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0 #endif //(LANG_MODE != 0) - if (card.ToshibaFlashAir_isEnabled()) { - MENU_ITEM_FUNCTION_P(_i("SD card [FlshAir]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1 - } else { - MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1 - } + if (card.ToshibaFlashAir_isEnabled()) + MENU_ITEM_FUNCTION_P(_i("SD card [FlshAir]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1 + else + MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1 - #ifdef SDCARD_SORT_ALPHA - if (!farm_mode) { - uint8_t sdSort; - EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort)); - switch (sdSort) { +#ifdef SDCARD_SORT_ALPHA + if (!farm_mode) + { + uint8_t sdSort; + EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort)); + switch (sdSort) + { case SD_SORT_TIME: MENU_ITEM_FUNCTION_P(_i("Sort: [Time]"), lcd_sort_type_set); break;////MSG_SORT_TIME c=17 r=1 case SD_SORT_ALPHA: MENU_ITEM_FUNCTION_P(_i("Sort: [Alphabet]"), lcd_sort_type_set); break;////MSG_SORT_ALPHA c=17 r=1 default: MENU_ITEM_FUNCTION_P(_i("Sort: [None]"), lcd_sort_type_set);////MSG_SORT_NONE c=17 r=1 - } - } - #endif // SDCARD_SORT_ALPHA + } + } +#endif // SDCARD_SORT_ALPHA - if (farm_mode) - { - MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no); + if (farm_mode) + { + MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no); MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode); - } + } MENU_END(); } @@ -5962,7 +5951,7 @@ static void lcd_main_menu() #endif #else - #ifdef PAT9125 + #ifdef FILAMENT_SENSOR if ( ((fsensor_autoload_enabled == true) && (fsensor_enabled == true))) MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0 else @@ -6092,16 +6081,14 @@ static void lcd_tune_menu() MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7 #endif -#ifndef DEBUG_DISABLE_FSENSORCHECK -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR if (FSensorStateMenu == 0) { MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set); } else { MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set); } -#endif //PAT9125 -#endif //DEBUG_DISABLE_FSENSORCHECK +#endif //FILAMENT_SENSOR #ifdef TMC2130 if(!farm_mode) @@ -6454,16 +6441,16 @@ bool lcd_selftest() if (_result) { _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor _result = lcd_selftest_fsensor(); -#endif // PAT9125 +#endif // FILAMENT_SENSOR } if (_result) { -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK -#endif // PAT9125 +#endif // FILAMENT_SENSOR _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct } else @@ -7012,17 +6999,18 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char * } -#ifdef PAT9125 -static bool lcd_selftest_fsensor() { +#ifdef FILAMENT_SENSOR +static bool lcd_selftest_fsensor(void) +{ fsensor_init(); if (fsensor_not_responding) { const char *_err; lcd_selftest_error(11, _err, _err); } - return(!fsensor_not_responding); + return (!fsensor_not_responding); } -#endif //PAT9125 +#endif //FILAMENT_SENSOR static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite) { diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 358c8c37..5908ea91 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -58,7 +58,7 @@ extern void menu_lcd_lcdupdate_func(void); static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator); static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite); static bool lcd_selftest_fan_dialog(int _fan); - static bool lcd_selftest_fsensor(); + static bool lcd_selftest_fsensor(void); static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2); void lcd_menu_statistics(); diff --git a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h index f08e8062..9d4e58f3 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h @@ -110,7 +110,7 @@ // Filament sensor #define PAT9125 - +#define FILAMENT_SENSOR //#define DEBUG_BUILD @@ -137,7 +137,6 @@ //#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3) //#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3) //#define DEBUG_DISABLE_FANCHECK //disable fan check (no ISR INT7, check disabled) -//#define DEBUG_DISABLE_FSENSORCHECK //disable fsensor check (no ISR INT7, check disabled) //#define DEBUG_DUMP_TO_2ND_SERIAL //dump received characters to 2nd serial line //#define DEBUG_STEPPER_TIMER_MISSED // Stop on stepper timer overflow, beep and display a message. //#define PLANNER_DIAGNOSTICS // Show the planner queue status on printer display. diff --git a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h index 1a32cefe..140c8f50 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h @@ -110,7 +110,7 @@ // Filament sensor #define PAT9125 - +#define FILAMENT_SENSOR //#define DEBUG_BUILD @@ -137,7 +137,6 @@ //#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3) //#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3) //#define DEBUG_DISABLE_FANCHECK //disable fan check (no ISR INT7, check disabled) -//#define DEBUG_DISABLE_FSENSORCHECK //disable fsensor check (no ISR INT7, check disabled) //#define DEBUG_DUMP_TO_2ND_SERIAL //dump received characters to 2nd serial line //#define DEBUG_STEPPER_TIMER_MISSED // Stop on stepper timer overflow, beep and display a message. //#define PLANNER_DIAGNOSTICS // Show the planner queue status on printer display. diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 0711d3c7..112d573f 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -133,6 +133,7 @@ // Filament sensor #define PAT9125 +#define FILAMENT_SENSOR // Backlash - //#define BACKLASH_X From 2e260aeccc593b3ba80b5360dc7e12013a3eeb91 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sat, 21 Jul 2018 01:30:16 +0200 Subject: [PATCH 05/12] FSensor - autoload fixed --- Firmware/Marlin_main.cpp | 6 ++--- Firmware/fsensor.cpp | 48 +++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5bf0c74b..2dade1fd 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7490,14 +7490,14 @@ static void handleSafetyTimer() void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h { -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) { if (fsensor_check_autoload()) { + fsensor_autoload_check_stop(); if (degHotend0() > EXTRUDE_MINTEMP) { - fsensor_autoload_check_stop(); tone(BEEPER, 1000); delay_keep_alive(50); noTone(BEEPER); @@ -7520,7 +7520,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s } else fsensor_autoload_check_stop(); -#endif //PAT9125 +#endif //FILAMENT_SENSOR #ifdef SAFETYTIMER handleSafetyTimer(); diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 609e9244..acf66013 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -57,13 +57,13 @@ bool fsensor_autoload_enabled = true; //autoload watching enable/disable flag bool fsensor_watch_autoload = false; // -uint16_t fsensor_autoload_y = 0; +uint16_t fsensor_autoload_y; // -uint8_t fsensor_autoload_c = 0; +uint8_t fsensor_autoload_c; // -uint32_t fsensor_autoload_last_millis = 0; +uint32_t fsensor_autoload_last_millis; // -uint8_t fsensor_autoload_sum = 0; +uint8_t fsensor_autoload_sum; //////////////////////////////////////////////////////////////////////////////// //filament optical quality meassurement variables @@ -155,6 +155,7 @@ void pciSetup(byte pin) void fsensor_autoload_check_start(void) { +// puts_P(_N("fsensor_autoload_check_start\n")); if (!fsensor_enabled) return; if (!fsensor_autoload_enabled) return; if (fsensor_watch_autoload) return; @@ -166,6 +167,7 @@ void fsensor_autoload_check_start(void) printf_P(ERRMSG_PAT9125_NOT_RESP, 3); return; } + puts_P(_N(" autoload enabled\n")); fsensor_autoload_y = pat9125_y; //save current y value fsensor_autoload_c = 0; //reset number of changes counter fsensor_autoload_sum = 0; @@ -177,9 +179,13 @@ void fsensor_autoload_check_start(void) void fsensor_autoload_check_stop(void) { +// puts_P(_N("fsensor_autoload_check_stop\n")); if (!fsensor_enabled) return; +// puts_P(_N("fsensor_autoload_check_stop 1\n")); if (!fsensor_autoload_enabled) return; +// puts_P(_N("fsensor_autoload_check_stop 2\n")); if (!fsensor_watch_autoload) return; + puts_P(_N(" autoload disabled\n")); fsensor_autoload_sum = 0; fsensor_watch_autoload = false; fsensor_watch_runout = true; @@ -198,19 +204,19 @@ bool fsensor_check_autoload(void) uint8_t fsensor_autoload_c_old = fsensor_autoload_c; if ((millis() - fsensor_autoload_last_millis) < 25) return false; fsensor_autoload_last_millis = millis(); - if (!pat9125_update_y()) + if (!pat9125_update_y()) //update sensor { fsensor_disable(); fsensor_not_responding = true; printf_P(ERRMSG_PAT9125_NOT_RESP, 2); - return false; //update sensor + return false; } - int16_t dy = fsensor_autoload_y - pat9125_y; - if (dy) //? y value is different + int16_t dy = pat9125_y - fsensor_autoload_y; + if (dy) //? dy value is nonzero { - if (dy < 0) //? delta-y value is positive (inserting) + if (dy > 0) //? delta-y value is positive (inserting) { - fsensor_autoload_sum -= dy; + fsensor_autoload_sum += dy; fsensor_autoload_c += 3; //increment change counter by 3 } else if (fsensor_autoload_c > 1) @@ -220,10 +226,15 @@ bool fsensor_check_autoload(void) else if (fsensor_autoload_c > 0) fsensor_autoload_c--; if (fsensor_autoload_c == 0) fsensor_autoload_sum = 0; -// if (fsensor_autoload_c != fsensor_autoload_c_old) -// printf_P(PSTR("fsensor_check_autoload dy=%d c=%d sum=%d\n"), dy, fsensor_autoload_c, fsensor_autoload_sum); - if ((fsensor_autoload_c >= 15) && (fsensor_autoload_sum > 30)) +// puts_P(_N("fsensor_check_autoload\n")); + if (fsensor_autoload_c != fsensor_autoload_c_old) + printf_P(PSTR("fsensor_check_autoload dy=%d c=%d sum=%d\n"), dy, fsensor_autoload_c, fsensor_autoload_sum); +// if ((fsensor_autoload_c >= 15) && (fsensor_autoload_sum > 30)) + if ((fsensor_autoload_c >= 10) && (fsensor_autoload_sum > 20)) + { + puts_P(_N("fsensor_check_autoload = true !!!\n")); return true; + } return false; } @@ -246,7 +257,7 @@ void fsensor_oq_meassure_stop(void) { printf_P(PSTR("fsensor_oq_meassure_stop\n")); printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); - printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum); + printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum)); fsensor_oq_meassure = false; fsensor_err_cnt = 0; fsensor_watch_runout = true; @@ -257,7 +268,7 @@ bool fsensor_oq_result(void) printf(_N("fsensor_oq_result\n")); if (fsensor_oq_er_sum > FSENSOR_OQ_MAX_ER) return false; printf(_N(" er_sum OK\n")); - uint8_t yd_avg = fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum; + uint8_t yd_avg = (uint16_t)((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum); if ((yd_avg < FSENSOR_OQ_MIN_YD) || (yd_avg > FSENSOR_OQ_MAX_YD)) return false; printf(_N(" yd_avg OK\n")); if (fsensor_oq_yd_max > (yd_avg * FSENSOR_OQ_MAX_PD)) return false; @@ -328,8 +339,8 @@ ISR(PCINT2_vect) #ifdef DEBUG_FSENSOR_LOG if (fsensor_log) { - printf_P(_N("FSENSOR cnt=%d dy=%d err=%d %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); - printf_P(_N("FSENSOR st_sum=%lu yd_sum=%lu er_sum=%u er_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); + printf_P(_N("FSENSOR cnt=%d dy=%d err=%hhu %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); + printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); } #endif //DEBUG_FSENSOR_LOG @@ -395,9 +406,6 @@ void fsensor_update(void) void fsensor_setup_interrupt(void) { -// uint8_t fsensor_int_pin = FSENSOR_INT_PIN; -// uint8_t fsensor_int_pcmsk = digitalPinToPCMSKbit(pin); -// uint8_t fsensor_int_pcicr = digitalPinToPCICRbit(pin); pinMode(FSENSOR_INT_PIN, OUTPUT); digitalWrite(FSENSOR_INT_PIN, LOW); From 980c044dac9158bfc0dd2a3ae068b40f78edf3aa Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sat, 21 Jul 2018 01:57:41 +0200 Subject: [PATCH 06/12] FSensor - code cleaning --- Firmware/fsensor.cpp | 16 +++++++++++----- Firmware/fsensor.h | 32 ++++++++------------------------ 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index acf66013..3ad95254 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -1,7 +1,5 @@ #include "Marlin.h" -#ifdef PAT9125 - #include "fsensor.h" #include "pat9125.h" #include "stepper.h" @@ -9,6 +7,17 @@ #include "fastio.h" #include "cmdqueue.h" +//Basic params +#define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm +#define FSENSOR_ERR_MAX 10 //filament sensor maximum error count for runout detection + +//Optical quality meassurement params +#define FSENSOR_OQ_MAX_ER 5 //maximum error count for loading (~150mm) +#define FSENSOR_OQ_MIN_YD 2 //minimum yd per chunk +#define FSENSOR_OQ_MAX_YD 200 //maximum yd per chunk +#define FSENSOR_OQ_MAX_PD 3 //maximum positive deviation (= yd_max/yd_avg) +#define FSENSOR_OQ_MAX_ND 5 //maximum negative deviation (= yd_avg/yd_min) + const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n"; @@ -413,6 +422,3 @@ void fsensor_setup_interrupt(void) pciSetup(FSENSOR_INT_PIN); } - - -#endif //PAT9125 diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 2b22633a..913dd07e 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -1,17 +1,15 @@ #ifndef FSENSOR_H #define FSENSOR_H -#include "planner.h" +#include -#define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm -#define FSENSOR_ERR_MAX 10 //filament sensor maximum error count for runout detection -//Optical quality meassurement params -#define FSENSOR_OQ_MAX_ER 5 //maximum error count for loading (~150mm) -#define FSENSOR_OQ_MIN_YD 2 //minimum yd per chunk -#define FSENSOR_OQ_MAX_YD 200 //maximum yd per chunk -#define FSENSOR_OQ_MAX_PD 3 //maximum positive deviation (= yd_max/yd_avg) -#define FSENSOR_OQ_MAX_ND 5 //maximum negative deviation (= yd_avg/yd_min) +//minimum meassured chunk length in steps +extern int16_t fsensor_chunk_len; +//enable/disable flag +extern bool fsensor_enabled; +//not responding flag +extern bool fsensor_not_responding; //save restore printing @@ -46,23 +44,9 @@ extern void fsensor_oq_meassure_stop(void); extern bool fsensor_oq_result(void); //callbacks from stepper +#include "planner.h" extern void fsensor_st_block_begin(block_t* bl); extern void fsensor_st_block_chunk(block_t* bl, int cnt); -//minimum meassured chunk length in steps -extern int16_t fsensor_chunk_len; -//enable/disable flag -extern bool fsensor_enabled; -//watch runout flag -extern bool fsensor_watch_runout; -//not responding flag -extern bool fsensor_not_responding; - -//error counter -extern uint8_t fsensor_err_cnt; - -//autoload enable/disable flag -extern bool fsensor_watch_autoload; - #endif //FSENSOR_H From f07d08697ac50c0bea072a19458166306fb5a3ef Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sat, 21 Jul 2018 12:24:57 +0200 Subject: [PATCH 07/12] max_feedrate and max_acceleration limitation fix (M201, M203) --- Firmware/Marlin_main.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2dade1fd..1ae43932 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5748,18 +5748,19 @@ Sigma_Exit: { int val = code_value(); #ifdef TMC2130 + int val_silent = val; if ((i == X_AXIS) || (i == Y_AXIS)) { - int max_val = 0; - if (tmc2130_mode == TMC2130_MODE_NORMAL) - max_val = NORMAL_MAX_ACCEL_XY; - else if (tmc2130_mode == TMC2130_MODE_SILENT) - max_val = SILENT_MAX_ACCEL_XY; - if (val > max_val) - val = max_val; + if (val > NORMAL_MAX_ACCEL_XY) + val = NORMAL_MAX_ACCEL_XY; + if (val_silent > SILENT_MAX_ACCEL_XY) + val_silent = SILENT_MAX_ACCEL_XY; } -#endif + max_acceleration_units_per_sq_second_normal[i] = val; + max_acceleration_units_per_sq_second_silent[i] = val_silent; +#else //TMC2130 max_acceleration_units_per_sq_second[i] = val; +#endif //TMC2130 } } // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner) @@ -5779,18 +5780,19 @@ Sigma_Exit: { float val = code_value(); #ifdef TMC2130 + float val_silent = val; if ((i == X_AXIS) || (i == Y_AXIS)) { - float max_val = 0; - if (tmc2130_mode == TMC2130_MODE_NORMAL) - max_val = NORMAL_MAX_FEEDRATE_XY; - else if (tmc2130_mode == TMC2130_MODE_SILENT) - max_val = SILENT_MAX_FEEDRATE_XY; - if (val > max_val) - val = max_val; + if (val > NORMAL_MAX_FEEDRATE_XY) + val = NORMAL_MAX_FEEDRATE_XY; + if (val_silent > SILENT_MAX_FEEDRATE_XY) + val_silent = SILENT_MAX_FEEDRATE_XY; } -#endif //TMC2130 + max_feedrate_normal[i] = val; + max_feedrate_silent[i] = val_silent; +#else //TMC2130 max_feedrate[i] = val; +#endif //TMC2130 } } break; From 612e83b4735349f31ebf75cb69b616fadf3d0fb7 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sat, 21 Jul 2018 12:33:29 +0200 Subject: [PATCH 08/12] max_feedrate and max_acceleration limitation (ConfigurationStore) --- Firmware/ConfigurationStore.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index ea9d0bca..c1ef8576 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -313,6 +313,20 @@ bool Config_RetrieveSettings(uint16_t offset, uint8_t level) EEPROM_READ_VAR(i,max_feedrate_silent); EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second_silent); +#ifdef TMC2130 + for (uint8_t j = X_AXIS; j <= Y_AXIS; j++) + { + if (max_feedrate_normal[j] > NORMAL_MAX_FEEDRATE_XY) + max_feedrate_normal[j] = NORMAL_MAX_FEEDRATE_XY; + if (max_feedrate_silent[j] > SILENT_MAX_FEEDRATE_XY) + max_feedrate_silent[j] = SILENT_MAX_FEEDRATE_XY; + if (max_acceleration_units_per_sq_second_normal[j] > NORMAL_MAX_ACCEL_XY) + max_acceleration_units_per_sq_second_normal[j] = NORMAL_MAX_ACCEL_XY; + if (max_acceleration_units_per_sq_second_silent[j] > SILENT_MAX_ACCEL_XY) + max_acceleration_units_per_sq_second_silent[j] = SILENT_MAX_ACCEL_XY; + } +#endif //TMC2130 + reset_acceleration_rates(); // Call updatePID (similar to when we have processed M301) From c6a3f073dd147e1433dd0f92fe13debb4570b6db Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sat, 21 Jul 2018 17:04:29 +0200 Subject: [PATCH 09/12] FSensor - M600/autoload fix + optical quality meassurement --- Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 149 +++++++++++++++++++++------------------ Firmware/fsensor.cpp | 68 ++++++++++++------ 3 files changed, 129 insertions(+), 90 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 5cdf39ea..69f13cc7 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -469,6 +469,6 @@ void proc_commands(); bool mmu_get_reponse(); void mmu_not_responding(); void mmu_load_to_nozzle(); -void M600_load_filament(bool fsensor_enabled); +void M600_load_filament(); void mmu_M600_load_filament(); void M600_load_filament_movements(); \ No newline at end of file diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1ae43932..516c201f 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3121,16 +3121,11 @@ void gcode_M701() custom_message = false; custom_message_type = 0; - fsensor_oq_meassure_stop(); - - - if (!fsensor_oq_result()) { - bool disable = lcd_show_fullscreen_message_yes_no_and_wait_P( - _i("Filament sensor low response, disable it?"), false, true); + bool disable = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Fil. sensor response is poor, disable it?"), false, true); lcd_update_enable(true); lcd_update(2); if (disable) @@ -3193,6 +3188,9 @@ extern uint8_t st_backlash_x; extern uint8_t st_backlash_y; #endif //BACKLASH_Y +uint16_t gcode_in_progress = 0; +uint16_t mcode_in_progress = 0; + void process_commands() { if (!buflen) return; //empty command @@ -3420,7 +3418,8 @@ void process_commands() // nothing, this is a version line } else if(code_seen('G')) { - switch((int)code_value()) + gcode_in_progress = (int)code_value(); + switch (gcode_in_progress) { case 0: // G0 -> G1 case 1: // G1 @@ -4647,10 +4646,12 @@ void process_commands() default: printf_P(PSTR("Unknown G code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); } + gcode_in_progress = 0; } // end if(code_seen('G')) else if(code_seen('M')) { + int index; for (index = 1; *(strchr_pointer + index) == ' ' || *(strchr_pointer + index) == '\t'; index++); @@ -4659,7 +4660,10 @@ void process_commands() printf_P(PSTR("Invalid M code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); } else - switch((int)code_value()) + { + mcode_in_progress = (int)code_value(); + + switch(mcode_in_progress) { case 0: // M0 - Unconditional stop - Wait for user button press on LCD @@ -6233,10 +6237,6 @@ Sigma_Exit: #ifdef FILAMENTCHANGEENABLE case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] { -#ifdef PAT9125 - bool old_fsensor_enabled = fsensor_enabled; -// fsensor_enabled = false; //temporary solution for unexpected restarting -#endif //PAT9125 st_synchronize(); float lastpos[4]; @@ -6509,7 +6509,7 @@ Sigma_Exit: #ifdef SNMM_V2 mmu_M600_load_filament(); #else - M600_load_filament(old_fsensor_enabled); + M600_load_filament(); #endif //Wait for user to check the state @@ -6915,10 +6915,6 @@ Sigma_Exit: extr_unload_all(); //unload all filaments } #else -#ifdef PAT9125 - bool old_fsensor_enabled = fsensor_enabled; -// fsensor_enabled = false; -#endif //PAT9125 custom_message = true; custom_message_type = 2; lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT)); @@ -6960,9 +6956,6 @@ Sigma_Exit: lcd_setstatuspgm(_T(WELCOME_MSG)); custom_message = false; custom_message_type = 0; -#ifdef PAT9125 -// fsensor_enabled = old_fsensor_enabled; -#endif //PAT9125 #endif } break; @@ -6976,7 +6969,8 @@ Sigma_Exit: default: printf_P(PSTR("Unknown M code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); } - + mcode_in_progress = 0; + } } // end if(code_seen('M')) (end of M codes) else if(code_seen('T')) @@ -7493,35 +7487,38 @@ static void handleSafetyTimer() void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h { #ifdef FILAMENT_SENSOR - if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + if (mcode_in_progress != 600) //M600 not in progress { - if (fsensor_check_autoload()) + if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) { - fsensor_autoload_check_stop(); - if (degHotend0() > EXTRUDE_MINTEMP) - { - tone(BEEPER, 1000); - delay_keep_alive(50); - noTone(BEEPER); - loading_flag = true; - enquecommand_front_P((PSTR("M701"))); - } - else - { - lcd_update_enable(false); - lcd_clear(); - lcd_set_cursor(0, 0); - lcd_puts_P(_T(MSG_ERROR)); - lcd_set_cursor(0, 2); - lcd_puts_P(_T(MSG_PREHEAT_NOZZLE)); - delay(2000); - lcd_clear(); - lcd_update_enable(true); - } + if (fsensor_check_autoload()) + { + fsensor_autoload_check_stop(); + if (degHotend0() > EXTRUDE_MINTEMP) + { + tone(BEEPER, 1000); + delay_keep_alive(50); + noTone(BEEPER); + loading_flag = true; + enquecommand_front_P((PSTR("M701"))); + } + else + { + lcd_update_enable(false); + lcd_clear(); + lcd_set_cursor(0, 0); + lcd_puts_P(_T(MSG_ERROR)); + lcd_set_cursor(0, 2); + lcd_puts_P(_T(MSG_PREHEAT_NOZZLE)); + delay(2000); + lcd_clear(); + lcd_update_enable(true); + } + } } + else + fsensor_autoload_check_stop(); } - else - fsensor_autoload_check_stop(); #endif //FILAMENT_SENSOR #ifdef SAFETYTIMER @@ -9104,41 +9101,57 @@ void M600_load_filament_movements() { lcd_loading_filament(); } -void M600_load_filament(bool fsensor_enabled) { +void M600_load_filament() +{ + lcd_wait_interact(); - lcd_wait_interact(); - - //load_filament_time = millis(); - KEEPALIVE_STATE(PAUSED_FOR_USER); + //load_filament_time = millis(); + KEEPALIVE_STATE(PAUSED_FOR_USER); #ifdef PAT9125 - fsensor_autoload_check_start(); + fsensor_autoload_check_start(); #endif //PAT9125 - while(!lcd_clicked()) - { - manage_heater(); - manage_inactivity(true); + while(!lcd_clicked()) + { + manage_heater(); + manage_inactivity(true); #ifdef PAT9125 - if (fsensor_check_autoload()) - { + if (fsensor_check_autoload()) + { tone(BEEPER, 1000); delay_keep_alive(50); noTone(BEEPER); - break; - } + break; + } #endif //PAT9125 - - } + } #ifdef PAT9125 - fsensor_autoload_check_stop(); + fsensor_autoload_check_stop(); #endif //PAT9125 - KEEPALIVE_STATE(IN_HANDLER); + KEEPALIVE_STATE(IN_HANDLER); - M600_load_filament_movements(); +#ifdef PAT9125 + fsensor_oq_meassure_start(); +#endif //PAT9125 - tone(BEEPER, 500); - delay_keep_alive(50); - noTone(BEEPER); + M600_load_filament_movements(); + + tone(BEEPER, 500); + delay_keep_alive(50); + noTone(BEEPER); + +#ifdef PAT9125 + fsensor_oq_meassure_stop(); + + if (!fsensor_oq_result()) + { + bool disable = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Fil. sensor response is poor, disable it?"), false, true); + lcd_update_enable(true); + lcd_update(2); + if (disable) + fsensor_disable(); + } +#endif //PAT9125 } diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 3ad95254..483b3235 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -1,6 +1,7 @@ #include "Marlin.h" #include "fsensor.h" +#include #include "pat9125.h" #include "stepper.h" #include "planner.h" @@ -12,11 +13,13 @@ #define FSENSOR_ERR_MAX 10 //filament sensor maximum error count for runout detection //Optical quality meassurement params -#define FSENSOR_OQ_MAX_ER 5 //maximum error count for loading (~150mm) -#define FSENSOR_OQ_MIN_YD 2 //minimum yd per chunk -#define FSENSOR_OQ_MAX_YD 200 //maximum yd per chunk +#define FSENSOR_OQ_MAX_ES 5 //maximum error sum while loading (length 95mm = 144chunks) +#define FSENSOR_OQ_MAX_EM 1 //maximum error counter value while loading +#define FSENSOR_OQ_MIN_YD 2 //minimum yd per chunk (applied to avg value) +#define FSENSOR_OQ_MAX_YD 200 //maximum yd per chunk (applied to avg value) #define FSENSOR_OQ_MAX_PD 3 //maximum positive deviation (= yd_max/yd_avg) #define FSENSOR_OQ_MAX_ND 5 //maximum negative deviation (= yd_avg/yd_min) +#define FSENSOR_OQ_MAX_SH 13 //maximum shutter value const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n"; @@ -81,6 +84,8 @@ uint8_t fsensor_autoload_sum; bool fsensor_oq_meassure = false; //skip-chunk counter, for accurate meassurement is necesary to skip first chunk... uint8_t fsensor_oq_skipchunk; +//number of samples from start of meassurement +uint8_t fsensor_oq_cnt; //sum of steps in positive direction movements uint16_t fsensor_oq_st_sum; //sum of deltas in positive direction movements @@ -93,6 +98,8 @@ uint8_t fsensor_oq_er_max; uint16_t fsensor_oq_yd_min; //maximum delta value uint16_t fsensor_oq_yd_max; +//sum of shutter value +uint16_t fsensor_oq_sh_sum; void fsensor_init(void) @@ -176,7 +183,7 @@ void fsensor_autoload_check_start(void) printf_P(ERRMSG_PAT9125_NOT_RESP, 3); return; } - puts_P(_N(" autoload enabled\n")); + puts_P(_N("fsensor_autoload_check_start - autoload ENABLED\n")); fsensor_autoload_y = pat9125_y; //save current y value fsensor_autoload_c = 0; //reset number of changes counter fsensor_autoload_sum = 0; @@ -194,7 +201,7 @@ void fsensor_autoload_check_stop(void) if (!fsensor_autoload_enabled) return; // puts_P(_N("fsensor_autoload_check_stop 2\n")); if (!fsensor_watch_autoload) return; - puts_P(_N(" autoload disabled\n")); + puts_P(_N("fsensor_autoload_check_stop - autoload DISABLED\n")); fsensor_autoload_sum = 0; fsensor_watch_autoload = false; fsensor_watch_runout = true; @@ -249,14 +256,17 @@ bool fsensor_check_autoload(void) void fsensor_oq_meassure_start(void) { - fsensor_oq_skipchunk = 1; + printf_P(PSTR("fsensor_oq_meassure_start\n")); + fsensor_oq_skipchunk = 10; + fsensor_oq_cnt = 0; fsensor_oq_st_sum = 0; fsensor_oq_yd_sum = 0; fsensor_oq_er_sum = 0; fsensor_oq_er_max = 0; fsensor_oq_yd_min = FSENSOR_OQ_MAX_YD; fsensor_oq_yd_max = 0; - pat9125_update_y(); + fsensor_oq_sh_sum = 0; + pat9125_update(); pat9125_y = 0; fsensor_watch_runout = false; fsensor_oq_meassure = true; @@ -264,27 +274,37 @@ void fsensor_oq_meassure_start(void) void fsensor_oq_meassure_stop(void) { - printf_P(PSTR("fsensor_oq_meassure_stop\n")); + printf_P(PSTR("fsensor_oq_meassure_stop, %hhu samples\n"), fsensor_oq_cnt); printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); - printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum)); + printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_cnt)); fsensor_oq_meassure = false; fsensor_err_cnt = 0; fsensor_watch_runout = true; } +const char _OK[] PROGMEM = "OK"; +const char _NG[] PROGMEM = "NG!"; + bool fsensor_oq_result(void) { - printf(_N("fsensor_oq_result\n")); - if (fsensor_oq_er_sum > FSENSOR_OQ_MAX_ER) return false; - printf(_N(" er_sum OK\n")); - uint8_t yd_avg = (uint16_t)((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum); - if ((yd_avg < FSENSOR_OQ_MIN_YD) || (yd_avg > FSENSOR_OQ_MAX_YD)) return false; - printf(_N(" yd_avg OK\n")); - if (fsensor_oq_yd_max > (yd_avg * FSENSOR_OQ_MAX_PD)) return false; - printf(_N(" yd_max OK\n")); - if (fsensor_oq_yd_min < (yd_avg / FSENSOR_OQ_MAX_ND)) return false; - printf(_N(" yd_min OK\n")); - return true; + printf_P(_N("fsensor_oq_result\n")); + bool res_er_sum = (fsensor_oq_er_sum <= FSENSOR_OQ_MAX_ES); + printf_P(_N(" er_sum = %u %S\n"), fsensor_oq_er_sum, (res_er_sum?_OK:_NG)); + bool res_er_max = (fsensor_oq_er_max <= FSENSOR_OQ_MAX_EM); + printf_P(_N(" er_max = %hhu %S\n"), fsensor_oq_er_max, (res_er_max?_OK:_NG)); + uint8_t yd_avg = ((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum); + bool res_yd_avg = (yd_avg >= FSENSOR_OQ_MIN_YD) && (yd_avg <= FSENSOR_OQ_MAX_YD); + printf_P(_N(" yd_avg = %hhu %S\n"), yd_avg, (res_yd_avg?_OK:_NG)); + bool res_yd_max = (fsensor_oq_yd_max <= (yd_avg * FSENSOR_OQ_MAX_PD)); + printf_P(_N(" yd_max = %u %S\n"), fsensor_oq_yd_max, (res_yd_max?_OK:_NG)); + bool res_yd_min = (fsensor_oq_yd_min >= (yd_avg / FSENSOR_OQ_MAX_ND)); + printf_P(_N(" yd_min = %u %S\n"), fsensor_oq_yd_min, (res_yd_min?_OK:_NG)); + uint8_t sh_avg = (fsensor_oq_sh_sum / fsensor_oq_cnt); + bool res_sh_avg = (sh_avg <= FSENSOR_OQ_MAX_SH); + printf_P(_N(" sh_avg = %hhu %S\n"), sh_avg, (res_sh_avg?_OK:_NG)); + bool res = res_er_sum && res_er_max && res_yd_avg && res_yd_max && res_yd_min && res_sh_avg; + printf_P(_N("fsensor_oq_result %S\n"), (res?_OK:_NG)); + return res; } ISR(PCINT2_vect) @@ -298,7 +318,8 @@ ISR(PCINT2_vect) fsensor_st_cnt = 0; sei(); uint8_t old_err_cnt = fsensor_err_cnt; - if (!pat9125_update_y()) + uint8_t pat9125_res = fsensor_oq_meassure?pat9125_update():pat9125_update_y(); + if (!pat9125_res) { fsensor_disable(); fsensor_not_responding = true; @@ -320,7 +341,10 @@ ISR(PCINT2_vect) if (fsensor_oq_meassure) { if (fsensor_oq_skipchunk) + { fsensor_oq_skipchunk--; + fsensor_err_cnt = 0; + } else { if (st_cnt == FSENSOR_CHUNK_LEN) @@ -328,12 +352,14 @@ ISR(PCINT2_vect) if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2; if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2; } + fsensor_oq_cnt++; fsensor_oq_st_sum += st_cnt; fsensor_oq_yd_sum += pat9125_y; if (fsensor_err_cnt > old_err_cnt) fsensor_oq_er_sum += (fsensor_err_cnt - old_err_cnt); if (fsensor_oq_er_max < fsensor_err_cnt) fsensor_oq_er_max = fsensor_err_cnt; + fsensor_oq_sh_sum += pat9125_s; } } } From 60b4db15e0d385446c4b9530a9b3bd59c5660e40 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sun, 22 Jul 2018 16:14:13 +0200 Subject: [PATCH 10/12] FSensor - M600 fix + cond. translation + tunning filter and params --- Firmware/Marlin.h | 3 - Firmware/Marlin_main.cpp | 71 +++++++++-------- Firmware/config.h | 2 +- Firmware/fsensor.cpp | 76 +++++++++++-------- Firmware/fsensor.h | 2 +- Firmware/pat9125.c | 10 ++- Firmware/stepper.cpp | 32 ++++---- Firmware/ultralcd.cpp | 33 ++++---- .../variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h | 7 -- .../variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h | 7 -- .../variants/1_75mm_MK3-EINSy10a-E3Dv6full.h | 7 -- 11 files changed, 125 insertions(+), 125 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 69f13cc7..8d1a4c8b 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -411,9 +411,6 @@ extern void print_world_coordinates(); extern void print_physical_coordinates(); extern void print_mesh_bed_leveling_table(); -#ifdef PAT9125 -extern void fsensor_init(); -#endif //PAT9125 //estimated time to end of the print extern uint16_t print_time_remaining(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 516c201f..fcc9ef5f 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -91,10 +91,9 @@ #include "swi2c.h" #endif //SWI2C -#ifdef PAT9125 -#include "pat9125.h" +#ifdef FILAMENT_SENSOR #include "fsensor.h" -#endif //PAT9125 +#endif //FILAMENT_SENSOR #ifdef TMC2130 #include "tmc2130.h" @@ -686,12 +685,6 @@ void crashdet_stop_and_save_print2() void crashdet_detected(uint8_t mask) { -// printf("CRASH_DETECTED"); -/* while (!is_buffer_empty()) - { - process_commands(); - cmdqueue_pop_front(); - }*/ st_synchronize(); static uint8_t crashDet_counter = 0; bool automatic_recovery_after_crash = true; @@ -854,8 +847,10 @@ void factory_reset(char level, bool quiet) eeprom_update_word((uint16_t *)EEPROM_FERROR_COUNT_TOT, 0); eeprom_update_word((uint16_t *)EEPROM_POWER_COUNT_TOT, 0); - fsensor_enable(); +#ifdef FILAMENT_SENSOR + fsensor_enable(); fsensor_autoload_set(true); +#endif //FILAMENT_SENSOR WRITE(BEEPER, HIGH); _delay_ms(100); @@ -1185,8 +1180,10 @@ void setup() tmc2130_current_h[E_AXIS] = 36; tmc2130_current_r[E_AXIS] = 36; #endif //TMC2130 +#ifdef FILAMENT_SENSOR //disabled filament autoload (PFW360) fsensor_autoload_set(false); +#endif //FILAMENT_SENSOR } MYSERIAL.begin(BAUDRATE); fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream @@ -1438,9 +1435,9 @@ void setup() // It does not make sense to load the correction matrix until the machine is homed. world2machine_reset(); -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_init(); -#endif //PAT9125 +#endif //FILAMENT_SENSOR #if defined(CONTROLLERFAN_PIN) && (CONTROLLERFAN_PIN > -1) @@ -1622,9 +1619,9 @@ void setup() setup_fan_interrupt(); #endif //DEBUG_DISABLE_FANCHECK -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_setup_interrupt(); -#endif //PAT9125 +#endif //FILAMENT_SENSOR for (int i = 0; i<4; i++) EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]); #ifndef DEBUG_DISABLE_STARTMSGS @@ -1977,9 +1974,9 @@ void loop() isPrintPaused ? manage_inactivity(true) : manage_inactivity(false); checkHitEndstops(); lcd_update(0); -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_update(); -#endif //PAT9125 +#endif //FILAMENT_SENSOR #ifdef TMC2130 tmc2130_check_overtemp(); if (tmc2130_sg_crash) @@ -3075,12 +3072,14 @@ void gcode_M701() #if defined (SNMM) || defined (SNMM_V2) extr_adj(snmm_extruder);//loads current extruder -#else +#else //defined (SNMM) || defined (SNMM_V2) enable_z(); custom_message = true; custom_message_type = 2; - fsensor_oq_meassure_start(); +#ifdef FILAMENT_SENSOR + fsensor_oq_meassure_start(40); +#endif //FILAMENT_SENSOR lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT)); current_position[E_AXIS] += 40; @@ -3121,6 +3120,7 @@ void gcode_M701() custom_message = false; custom_message_type = 0; +#ifdef FILAMENT_SENSOR fsensor_oq_meassure_stop(); if (!fsensor_oq_result()) @@ -3131,7 +3131,8 @@ void gcode_M701() if (disable) fsensor_disable(); } -#endif +#endif //FILAMENT_SENSOR +#endif //defined (SNMM) || defined (SNMM_V2) } /** * @brief Get serial number from 32U2 processor @@ -3419,6 +3420,7 @@ void process_commands() } else if(code_seen('G')) { gcode_in_progress = (int)code_value(); +// printf_P(_N("BEGIN G-CODE=%u\n"), gcode_in_progress); switch (gcode_in_progress) { case 0: // G0 -> G1 @@ -4646,6 +4648,7 @@ void process_commands() default: printf_P(PSTR("Unknown G code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); } +// printf_P(_N("END G-CODE=%u\n"), gcode_in_progress); gcode_in_progress = 0; } // end if(code_seen('G')) @@ -4662,6 +4665,7 @@ void process_commands() } else { mcode_in_progress = (int)code_value(); +// printf_P(_N("BEGIN M-CODE=%u\n"), mcode_in_progress); switch(mcode_in_progress) { @@ -6969,6 +6973,7 @@ Sigma_Exit: default: printf_P(PSTR("Unknown M code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); } +// printf_P(_N("END M-CODE=%u\n"), mcode_in_progress); mcode_in_progress = 0; } } // end if(code_seen('M')) (end of M codes) @@ -7136,10 +7141,10 @@ Sigma_Exit: dcode_2130(); break; #endif //TMC2130 -#ifdef PAT9125 - case 9125: // D9125 - PAT9125 +#ifdef FILAMENT_SENSOR + case 9125: // D9125 - FILAMENT_SENSOR dcode_9125(); break; -#endif //PAT9125 +#endif //FILAMENT_SENSOR } } @@ -9108,14 +9113,14 @@ void M600_load_filament() //load_filament_time = millis(); KEEPALIVE_STATE(PAUSED_FOR_USER); -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_autoload_check_start(); -#endif //PAT9125 +#endif //FILAMENT_SENSOR while(!lcd_clicked()) { manage_heater(); manage_inactivity(true); -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR if (fsensor_check_autoload()) { tone(BEEPER, 1000); @@ -9123,16 +9128,16 @@ void M600_load_filament() noTone(BEEPER); break; } -#endif //PAT9125 +#endif //FILAMENT_SENSOR } -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_autoload_check_stop(); -#endif //PAT9125 +#endif //FILAMENT_SENSOR KEEPALIVE_STATE(IN_HANDLER); -#ifdef PAT9125 - fsensor_oq_meassure_start(); -#endif //PAT9125 +#ifdef FILAMENT_SENSOR + fsensor_oq_meassure_start(70); +#endif //FILAMENT_SENSOR M600_load_filament_movements(); @@ -9140,7 +9145,7 @@ void M600_load_filament() delay_keep_alive(50); noTone(BEEPER); -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_oq_meassure_stop(); if (!fsensor_oq_result()) @@ -9151,7 +9156,7 @@ void M600_load_filament() if (disable) fsensor_disable(); } -#endif //PAT9125 +#endif //FILAMENT_SENSOR } diff --git a/Firmware/config.h b/Firmware/config.h index 6ee4dd8d..5ba843c5 100644 --- a/Firmware/config.h +++ b/Firmware/config.h @@ -22,7 +22,7 @@ //#define PAT9125_I2C_ADDR 0x79 //ID=HI //#define PAT9125_I2C_ADDR 0x73 //ID=NC #define PAT9125_XRES 0 -#define PAT9125_YRES 200 +#define PAT9125_YRES 240 //SM4 configuration #define SM4_DEFDELAY 500 //default step delay [us] diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 483b3235..a280eda1 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -13,11 +13,11 @@ #define FSENSOR_ERR_MAX 10 //filament sensor maximum error count for runout detection //Optical quality meassurement params -#define FSENSOR_OQ_MAX_ES 5 //maximum error sum while loading (length 95mm = 144chunks) -#define FSENSOR_OQ_MAX_EM 1 //maximum error counter value while loading +#define FSENSOR_OQ_MAX_ES 6 //maximum error sum while loading (length ~64mm = 100chunks) +#define FSENSOR_OQ_MAX_EM 2 //maximum error counter value while loading #define FSENSOR_OQ_MIN_YD 2 //minimum yd per chunk (applied to avg value) #define FSENSOR_OQ_MAX_YD 200 //maximum yd per chunk (applied to avg value) -#define FSENSOR_OQ_MAX_PD 3 //maximum positive deviation (= yd_max/yd_avg) +#define FSENSOR_OQ_MAX_PD 4 //maximum positive deviation (= yd_max/yd_avg) #define FSENSOR_OQ_MAX_ND 5 //maximum negative deviation (= yd_avg/yd_min) #define FSENSOR_OQ_MAX_SH 13 //maximum shutter value @@ -51,14 +51,18 @@ bool fsensor_enabled = true; bool fsensor_watch_runout = true; //not responding - is set if any communication error occured durring initialization or readout bool fsensor_not_responding = false; +//printing saved +bool fsensor_printing_saved = false; //number of errors, updated in ISR uint8_t fsensor_err_cnt = 0; -//variable for accumolating step count +//variable for accumolating step count (updated callbacks from stepper and ISR) int16_t fsensor_st_cnt = 0; +//last dy value from pat9125 sensor (used in ISR) +uint8_t fsensor_dy_old = 0; //log flag: 0=log disabled, 1=log enabled -uint8_t fsensor_log = 1; +uint8_t fsensor_log = 0; //////////////////////////////////////////////////////////////////////////////// //filament autoload variables @@ -85,7 +89,7 @@ bool fsensor_oq_meassure = false; //skip-chunk counter, for accurate meassurement is necesary to skip first chunk... uint8_t fsensor_oq_skipchunk; //number of samples from start of meassurement -uint8_t fsensor_oq_cnt; +uint8_t fsensor_oq_samples; //sum of steps in positive direction movements uint16_t fsensor_oq_st_sum; //sum of deltas in positive direction movements @@ -114,20 +118,12 @@ void fsensor_init(void) fsensor_not_responding = true; } else - { fsensor_not_responding = false; - } - puts_P(PSTR("FSensor ")); if (fsensor) - { fsensor_enable(); - puts_P(PSTR("ENABLED\n")); - } else - { fsensor_disable(); - puts_P(PSTR("DISABLED\n")); - } + printf_P(PSTR("FSensor %S\n"), (fsensor_enabled?PSTR("ENABLED"):PSTR("DISABLED\n"))); } bool fsensor_enable(void) @@ -142,6 +138,7 @@ bool fsensor_enable(void) fsensor_watch_runout = true; fsensor_oq_meassure = false; fsensor_err_cnt = 0; + fsensor_dy_old = 0; eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled?0x01:0x00); FSensorStateMenu = fsensor_enabled?1:0; @@ -246,7 +243,7 @@ bool fsensor_check_autoload(void) if (fsensor_autoload_c != fsensor_autoload_c_old) printf_P(PSTR("fsensor_check_autoload dy=%d c=%d sum=%d\n"), dy, fsensor_autoload_c, fsensor_autoload_sum); // if ((fsensor_autoload_c >= 15) && (fsensor_autoload_sum > 30)) - if ((fsensor_autoload_c >= 10) && (fsensor_autoload_sum > 20)) + if ((fsensor_autoload_c >= 10) && (fsensor_autoload_sum > 15)) { puts_P(_N("fsensor_check_autoload = true !!!\n")); return true; @@ -254,11 +251,11 @@ bool fsensor_check_autoload(void) return false; } -void fsensor_oq_meassure_start(void) +void fsensor_oq_meassure_start(uint8_t skip) { printf_P(PSTR("fsensor_oq_meassure_start\n")); - fsensor_oq_skipchunk = 10; - fsensor_oq_cnt = 0; + fsensor_oq_skipchunk = skip; + fsensor_oq_samples = 0; fsensor_oq_st_sum = 0; fsensor_oq_yd_sum = 0; fsensor_oq_er_sum = 0; @@ -274,12 +271,12 @@ void fsensor_oq_meassure_start(void) void fsensor_oq_meassure_stop(void) { - printf_P(PSTR("fsensor_oq_meassure_stop, %hhu samples\n"), fsensor_oq_cnt); + printf_P(PSTR("fsensor_oq_meassure_stop, %hhu samples\n"), fsensor_oq_samples); printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); - printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_cnt)); + printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * FSENSOR_CHUNK_LEN / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_samples)); fsensor_oq_meassure = false; - fsensor_err_cnt = 0; fsensor_watch_runout = true; + fsensor_err_cnt = 0; } const char _OK[] PROGMEM = "OK"; @@ -299,7 +296,7 @@ bool fsensor_oq_result(void) printf_P(_N(" yd_max = %u %S\n"), fsensor_oq_yd_max, (res_yd_max?_OK:_NG)); bool res_yd_min = (fsensor_oq_yd_min >= (yd_avg / FSENSOR_OQ_MAX_ND)); printf_P(_N(" yd_min = %u %S\n"), fsensor_oq_yd_min, (res_yd_min?_OK:_NG)); - uint8_t sh_avg = (fsensor_oq_sh_sum / fsensor_oq_cnt); + uint8_t sh_avg = (fsensor_oq_sh_sum / fsensor_oq_samples); bool res_sh_avg = (sh_avg <= FSENSOR_OQ_MAX_SH); printf_P(_N(" sh_avg = %hhu %S\n"), sh_avg, (res_sh_avg?_OK:_NG)); bool res = res_er_sum && res_er_max && res_yd_avg && res_yd_max && res_yd_min && res_sh_avg; @@ -329,15 +326,16 @@ ISR(PCINT2_vect) { //movement if (st_cnt > 0) //positive movement { - if (pat9125_y <= 0) - { + if (pat9125_y < 0) fsensor_err_cnt++; - } - else + else if (pat9125_y > 0) { if (fsensor_err_cnt) fsensor_err_cnt--; } + else //(pat9125_y == 0) + if (fsensor_dy_old <= 0) + fsensor_err_cnt++; if (fsensor_oq_meassure) { if (fsensor_oq_skipchunk) @@ -349,10 +347,10 @@ ISR(PCINT2_vect) { if (st_cnt == FSENSOR_CHUNK_LEN) { - if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2; - if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2; + if (pat9125_y > 0) if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2; + if (pat9125_y >= 0) if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2; } - fsensor_oq_cnt++; + fsensor_oq_samples++; fsensor_oq_st_sum += st_cnt; fsensor_oq_yd_sum += pat9125_y; if (fsensor_err_cnt > old_err_cnt) @@ -375,11 +373,13 @@ ISR(PCINT2_vect) if (fsensor_log) { printf_P(_N("FSENSOR cnt=%d dy=%d err=%hhu %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); - printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); + if (fsensor_oq_meassure) printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu yd_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max, fsensor_oq_yd_max); } #endif //DEBUG_FSENSOR_LOG + fsensor_dy_old = pat9125_y; pat9125_y = 0; + _lock = false; return; } @@ -408,10 +408,19 @@ void fsensor_st_block_chunk(block_t* bl, int cnt) void fsensor_update(void) { - if (fsensor_enabled && fsensor_watch_runout) - if (fsensor_err_cnt > FSENSOR_ERR_MAX) + if (fsensor_enabled) + { + if (fsensor_printing_saved) + { + fsensor_printing_saved = false; + fsensor_watch_runout = true; + fsensor_err_cnt = 0; + fsensor_restore_print_and_continue(); + } + else if (fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX)) { fsensor_stop_and_save_print(); + fsensor_printing_saved = true; fsensor_err_cnt = 0; @@ -437,6 +446,7 @@ void fsensor_update(void) fsensor_watch_runout = false; } } + } } void fsensor_setup_interrupt(void) diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 913dd07e..df58def2 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -39,7 +39,7 @@ extern void fsensor_autoload_check_stop(void); extern bool fsensor_check_autoload(void); //optical quality meassurement support -extern void fsensor_oq_meassure_start(void); +extern void fsensor_oq_meassure_start(uint8_t skip); extern void fsensor_oq_meassure_stop(void); extern bool fsensor_oq_result(void); diff --git a/Firmware/pat9125.c b/Firmware/pat9125.c index c800f4a4..e917c45c 100644 --- a/Firmware/pat9125.c +++ b/Firmware/pat9125.c @@ -99,6 +99,9 @@ uint8_t pat9125_rd_reg(uint8_t addr); void pat9125_wr_reg(uint8_t addr, uint8_t data); uint8_t pat9125_wr_reg_verify(uint8_t addr, uint8_t data); +extern FILE _uartout; +#define uartout (&_uartout) + uint8_t pat9125_init(void) { @@ -162,8 +165,11 @@ uint8_t pat9125_init(void) pat9125_PID1 = pat9125_rd_reg(PAT9125_PID1); pat9125_PID2 = pat9125_rd_reg(PAT9125_PID2); #endif //PAT9125_NEW_INIT - pat9125_wr_reg(PAT9125_RES_X, 0); - pat9125_wr_reg(PAT9125_RES_Y, 200); + + pat9125_wr_reg(PAT9125_RES_X, PAT9125_XRES); + pat9125_wr_reg(PAT9125_RES_Y, PAT9125_YRES); + fprintf_P(uartout, PSTR("PAT9125_RES_X=%hhu\n"), pat9125_rd_reg(PAT9125_RES_X)); + fprintf_P(uartout, PSTR("PAT9125_RES_Y=%hhu\n"), pat9125_rd_reg(PAT9125_RES_Y)); return 1; } diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index cd14c501..b2d71e2a 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -36,10 +36,10 @@ #include "tmc2130.h" #endif //TMC2130 -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR #include "fsensor.h" int fsensor_counter = 0; //counter for e-steps -#endif //PAT9125 +#endif //FILAMENT_SENSOR #ifdef DEBUG_STACK_MONITOR uint16_t SP_min = 0x21FF; @@ -469,10 +469,10 @@ FORCE_INLINE void stepper_next_block() } #endif -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_counter = 0; fsensor_st_block_begin(current_block); -#endif //PAT9125 +#endif //FILAMENT_SENSOR // The busy flag is set by the plan_get_current_block() call. // current_block->busy = true; // Initializes the trapezoid generator from the current block. Called whenever a new @@ -760,9 +760,9 @@ FORCE_INLINE void stepper_tick_lowres() #ifdef LIN_ADVANCE ++ e_steps; #else - #ifdef PAT9125 + #ifdef FILAMENT_SENSOR ++ fsensor_counter; - #endif //PAT9125 + #endif //FILAMENT_SENSOR WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); #endif } @@ -825,9 +825,9 @@ FORCE_INLINE void stepper_tick_highres() #ifdef LIN_ADVANCE ++ e_steps; #else - #ifdef PAT9125 + #ifdef FILAMENT_SENSOR ++ fsensor_counter; - #endif //PAT9125 + #endif //FILAMENT_SENSOR WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); #endif } @@ -900,9 +900,9 @@ FORCE_INLINE void isr() { estep_loops = (e_steps & 0x0ff00) ? 4 : e_steps; if (step_loops < estep_loops) estep_loops = step_loops; - #ifdef PAT9125 + #ifdef FILAMENT_SENSOR fsensor_counter += estep_loops; - #endif //PAT9125 + #endif //FILAMENT_SENSOR do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); -- e_steps; @@ -1026,9 +1026,9 @@ FORCE_INLINE void isr() { if (eISR_Rate == 0) { // There is not enough time to fit even a single additional tick. // Tick all the extruder ticks now. - #ifdef PAT9125 + #ifdef FILAMENT_SENSOR fsensor_counter += e_steps; - #endif //PAT9125 + #endif //FILAMENT_SENSOR MSerial.checkRx(); // Check for serial chars. do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); @@ -1048,21 +1048,21 @@ FORCE_INLINE void isr() { // If current block is finished, reset pointer if (step_events_completed.wide >= current_block->step_event_count.wide) { -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR fsensor_st_block_chunk(current_block, fsensor_counter); fsensor_counter = 0; -#endif //PAT9125 +#endif //FILAMENT_SENSOR current_block = NULL; plan_discard_current_block(); } -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR else if (fsensor_counter >= fsensor_chunk_len) { fsensor_st_block_chunk(current_block, fsensor_counter); fsensor_counter = 0; } -#endif //PAT9125 +#endif //FILAMENT_SENSOR } #ifdef TMC2130 diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index da618570..1b7feeff 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -23,10 +23,6 @@ #include "SdFatUtil.h" -#ifdef PAT9125 -#include "pat9125.h" -#endif //PAT9125 - #ifdef FILAMENT_SENSOR #include "fsensor.h" #endif //FILAMENT_SENSOR @@ -221,9 +217,9 @@ static void lcd_menu_extruder_info(); static void lcd_menu_xyz_y_min(); static void lcd_menu_xyz_skew(); static void lcd_menu_xyz_offset(); -#if defined(TMC2130) || defined(PAT9125) +#if defined(TMC2130) || defined(FILAMENT_SENSOR) static void lcd_menu_fails_stats(); -#endif //TMC2130 or PAT9125 +#endif //TMC2130 or FILAMENT_SENSOR void lcd_finishstatus(); @@ -2008,7 +2004,7 @@ static void lcd_menu_extruder_info() fan_speed_RPM[0] = 60*fan_speed[0]; fan_speed_RPM[1] = 60*fan_speed[1]; -#ifdef PAT9125 +#ifdef FILAMENT_SENSOR // Display X and Y difference from Filament sensor // Display Light intensity from Filament sensor // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This @@ -2017,7 +2013,7 @@ static void lcd_menu_extruder_info() // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46. - pat9125_update(); +/* pat9125_update(); lcd_printf_P(_N( ESC_H(0,0) "Nozzle FAN: %4d RPM\n" @@ -2029,8 +2025,8 @@ static void lcd_menu_extruder_info() fan_speed_RPM[1], pat9125_x, pat9125_y, pat9125_b, pat9125_s - ); -#else //PAT9125 + );*/ +#else //FILAMENT_SENSOR printf_P(_N( ESC_H(0,0) "Nozzle FAN: %4d RPM\n" @@ -2039,12 +2035,12 @@ static void lcd_menu_extruder_info() fan_speed_RPM[0], fan_speed_RPM[1] ); -#endif //PAT9125 +#endif //FILAMENT_SENSOR menu_back_if_clicked(); } -#if defined(TMC2130) && defined(PAT9125) +#if defined(TMC2130) && defined(FILAMENT_SENSOR) static void lcd_menu_fails_stats_total() { //01234567890123456789 @@ -2091,7 +2087,7 @@ static void lcd_menu_fails_stats() MENU_ITEM_SUBMENU_P(PSTR("Total"), lcd_menu_fails_stats_total); MENU_END(); } -#elif defined(PAT9125) +#elif defined(FILAMENT_SENSOR) /** * @brief Print last print and total filament run outs * @@ -2114,6 +2110,13 @@ static void lcd_menu_fails_stats() lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal); menu_back_if_clicked(); } +#else +static void lcd_menu_fails_stats() +{ + MENU_BEGIN(); + MENU_ITEM_BACK_P(_T(MSG_MAIN)); + MENU_END(); +} #endif //TMC2130 @@ -5955,7 +5958,7 @@ static void lcd_main_menu() if ( ((fsensor_autoload_enabled == true) && (fsensor_enabled == true))) MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0 else - #endif //PAT9125 + #endif //FILAMENT_SENSOR MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament); MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament); #endif @@ -5970,7 +5973,7 @@ static void lcd_main_menu() MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0 } -#if defined(TMC2130) || defined(PAT9125) +#if defined(TMC2130) || defined(FILAMENT_SENSOR) MENU_ITEM_SUBMENU_P(PSTR("Fail stats"), lcd_menu_fails_stats); #endif diff --git a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h index 9d4e58f3..03232779 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h @@ -264,13 +264,6 @@ #define Z_HIGH_POWER 200 #endif -/*------------------------------------ - PAT9125 SETTINGS - *------------------------------------*/ - -#define PAT9125_XRES 0 -#define PAT9125_YRES 255 - /*------------------------------------ BED SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h index 140c8f50..01ab8667 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h @@ -264,13 +264,6 @@ #define Z_HIGH_POWER 200 #endif -/*------------------------------------ - PAT9125 SETTINGS - *------------------------------------*/ - -#define PAT9125_XRES 0 -#define PAT9125_YRES 255 - /*------------------------------------ BED SETTINGS *------------------------------------*/ diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 112d573f..99b8027b 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -379,13 +379,6 @@ #define DEFAULT_PWM_MOTOR_CURRENT_LOUD {400, 750, 750} // {XY,Z,E} #endif -/*------------------------------------ - PAT9125 SETTINGS - *------------------------------------*/ - -#define PAT9125_XRES 0 -#define PAT9125_YRES 255 - /*------------------------------------ BED SETTINGS *------------------------------------*/ From f0d939140b71a431ecdc8bc343d44363ba5b6bdd Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Mon, 23 Jul 2018 12:54:48 +0200 Subject: [PATCH 11/12] Menu extruder info fixed --- Firmware/ultralcd.cpp | 56 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 1b7feeff..6996cfd4 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -24,6 +24,7 @@ #include "SdFatUtil.h" #ifdef FILAMENT_SENSOR +#include "pat9125.h" #include "fsensor.h" #endif //FILAMENT_SENSOR @@ -1999,11 +2000,19 @@ static void lcd_menu_extruder_info() //|Fil. Xd: Yd: | //|Int: Shut: | //---------------------- - int fan_speed_RPM[2]; - // Display Nozzle fan RPM + int fan_speed_RPM[2]; + // Display Nozzle fan RPM fan_speed_RPM[0] = 60*fan_speed[0]; - fan_speed_RPM[1] = 60*fan_speed[1]; - + fan_speed_RPM[1] = 60*fan_speed[1]; + lcd_printf_P(_N( + ESC_H(0,0) + "Nozzle FAN: %4d RPM\n" + "Print FAN: %4d RPM\n" + ), + fan_speed_RPM[0], + fan_speed_RPM[1] + ); + #ifdef FILAMENT_SENSOR // Display X and Y difference from Filament sensor // Display Light intensity from Filament sensor @@ -2013,28 +2022,21 @@ static void lcd_menu_extruder_info() // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46. -/* pat9125_update(); - lcd_printf_P(_N( - ESC_H(0,0) - "Nozzle FAN: %4d RPM\n" - "Print FAN: %4d RPM\n" - "Fil. Xd:%3d Yd:%3d\n" - "Int: %3d Shut: %3d\n" - ), - fan_speed_RPM[0], - fan_speed_RPM[1], - pat9125_x, pat9125_y, - pat9125_b, pat9125_s - );*/ -#else //FILAMENT_SENSOR - printf_P(_N( - ESC_H(0,0) - "Nozzle FAN: %4d RPM\n" - "Print FAN: %4d RPM\n" - ), - fan_speed_RPM[0], - fan_speed_RPM[1] - ); + + if (!fsensor_enabled) + lcd_puts_P(_N("Filament sensor\n" "is disabled.")); + else + { + if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + pat9125_update(); + lcd_printf_P(_N( + "Fil. Xd:%3d Yd:%3d\n" + "Int: %3d Shut: %3d" + ), + pat9125_x, pat9125_y, + pat9125_b, pat9125_s + ); + } #endif //FILAMENT_SENSOR menu_back_if_clicked(); @@ -2172,6 +2174,7 @@ static void lcd_menu_belt_status() } #endif //TMC2130 +#ifdef RESUME_DEBUG extern void stop_and_save_print_to_ram(float z_move, float e_move); extern void restore_print_from_ram_and_continue(float e_move); @@ -2184,6 +2187,7 @@ static void lcd_menu_test_restore() { restore_print_from_ram_and_continue(0.8); } +#endif //RESUME_DEBUG static void lcd_preheat_menu() { From 896734c06bc74c0eef63e509c18d62a5b5ede7a7 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Mon, 23 Jul 2018 14:30:41 +0200 Subject: [PATCH 12/12] Display '!' instead of 'FR' on status screen when feedrate or acceleration limit reached. --- Firmware/planner.cpp | 14 ++++++++++---- Firmware/planner.h | 2 ++ Firmware/ultralcd.cpp | 8 +++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 9b08ea67..e89cbef8 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -109,6 +109,8 @@ static float previous_speed[NUM_AXIS]; // Speed of previous path line segment static float previous_nominal_speed; // Nominal speed of previous path line segment static float previous_safe_speed; // Exit speed limited by a jerk to full halt of a previous last segment. +uint8_t maxlimit_status; + #ifdef AUTOTEMP float autotemp_max=250; float autotemp_min=210; @@ -961,11 +963,15 @@ Having the real displacement of the head, we can calculate the total movement le // Calculate and limit speed in mm/sec for each axis float current_speed[4]; float speed_factor = 1.0; //factor <=1 do decrease speed +// maxlimit_status &= ~0xf; for(int i=0; i < 4; i++) { current_speed[i] = delta_mm[i] * inverse_second; if(fabs(current_speed[i]) > max_feedrate[i]) + { speed_factor = min(speed_factor, max_feedrate[i] / fabs(current_speed[i])); + maxlimit_status |= (1 << i); + } } // Correct the speed @@ -993,13 +999,13 @@ Having the real displacement of the head, we can calculate the total movement le // Limit acceleration per axis //FIXME Vojtech: One shall rather limit a projection of the acceleration vector instead of using the limit. if(((float)block->acceleration_st * (float)block->steps_x.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[X_AXIS]) - block->acceleration_st = axis_steps_per_sqr_second[X_AXIS]; + { block->acceleration_st = axis_steps_per_sqr_second[X_AXIS]; maxlimit_status |= (X_AXIS_MASK << 4); } if(((float)block->acceleration_st * (float)block->steps_y.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[Y_AXIS]) - block->acceleration_st = axis_steps_per_sqr_second[Y_AXIS]; + { block->acceleration_st = axis_steps_per_sqr_second[Y_AXIS]; maxlimit_status |= (Y_AXIS_MASK << 4); } if(((float)block->acceleration_st * (float)block->steps_e.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[E_AXIS]) - block->acceleration_st = axis_steps_per_sqr_second[E_AXIS]; + { block->acceleration_st = axis_steps_per_sqr_second[E_AXIS]; maxlimit_status |= (Z_AXIS_MASK << 4); } if(((float)block->acceleration_st * (float)block->steps_z.wide / (float)block->step_event_count.wide ) > axis_steps_per_sqr_second[Z_AXIS]) - block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS]; + { block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS]; maxlimit_status |= (E_AXIS_MASK << 4); } } // Acceleration of the segment, in mm/sec^2 block->acceleration = block->acceleration_st / steps_per_mm; diff --git a/Firmware/planner.h b/Firmware/planner.h index 779fc79b..8d648c8e 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -182,6 +182,8 @@ extern float mintravelfeedrate; extern unsigned long axis_steps_per_sqr_second[NUM_AXIS]; extern long position[NUM_AXIS]; +extern uint8_t maxlimit_status; + #ifdef AUTOTEMP extern bool autotemp_enabled; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 6996cfd4..fcbb7a51 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -653,7 +653,13 @@ static void lcd_implementation_status_screen() //Print Feedrate lcd_set_cursor(LCD_WIDTH - 8-2, 1); lcd_puts_P(PSTR(" ")); - lcd_print(LCD_STR_FEEDRATE[0]); + if (maxlimit_status) + { + maxlimit_status = 0; + lcd_print('!'); + } + else + lcd_print(LCD_STR_FEEDRATE[0]); lcd_print(itostr3(feedmultiply)); lcd_puts_P(PSTR("% ")); #endif /* PLANNER_DIAGNOSTICS */