FSensor - optical quality meassurement durring load filament

This commit is contained in:
Robert Pelnar 2018-07-20 20:30:08 +02:00
parent fd9b9acf4e
commit 0f91bf9527
3 changed files with 105 additions and 39 deletions

View File

@ -3085,12 +3085,7 @@ void gcode_M701()
custom_message_type = 2; custom_message_type = 2;
bool old_watch_runout = fsensor_watch_runout; bool old_watch_runout = fsensor_watch_runout;
fsensor_watch_runout = false; fsensor_oq_meassure_start();
fsensor_st_sum = 0;
fsensor_yd_sum = 0;
fsensor_er_sum = 0;
fsensor_yd_min = 65535;
fsensor_yd_max = 0;
lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT)); lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
current_position[E_AXIS] += 40; current_position[E_AXIS] += 40;
@ -3132,11 +3127,25 @@ void gcode_M701()
custom_message_type = 0; custom_message_type = 0;
#endif #endif
fsensor_oq_meassure_stop();
fsensor_err_cnt = 0; fsensor_err_cnt = 0;
fsensor_watch_runout = old_watch_runout; 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")); 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 * @brief Get serial number from 32U2 processor

View File

@ -12,8 +12,6 @@
const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n"; 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 63 //filament sensor interrupt pin PK1
#define FSENSOR_INT_PIN_MSK 0x02 //filament sensor interrupt pin mask (bit1) #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; uint32_t fsensor_autoload_last_millis = 0;
uint8_t fsensor_autoload_sum = 0; uint8_t fsensor_autoload_sum = 0;
uint32_t fsensor_st_sum = 0; //filament optical quality meassurement
uint32_t fsensor_yd_sum = 0; bool fsensor_oq_meassure = false;
uint32_t fsensor_er_sum = 0; uint8_t fsensor_oq_skipchunk;
uint16_t fsensor_yd_min = 65535; uint32_t fsensor_oq_st_sum;
uint16_t fsensor_yd_max = 0; 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) bool fsensor_enable(void)
{ {
// puts_P(PSTR("fsensor_enable\n"));
int pat9125 = pat9125_init(); int pat9125 = pat9125_init();
printf_P(PSTR("PAT9125_init:%d\n"), pat9125); printf_P(PSTR("PAT9125_init:%d\n"), pat9125);
if (pat9125) if (pat9125)
@ -100,14 +102,11 @@ bool fsensor_enable(void)
fsensor_not_responding = true; fsensor_not_responding = true;
fsensor_enabled = pat9125?true:false; fsensor_enabled = pat9125?true:false;
fsensor_watch_runout = true; fsensor_watch_runout = true;
fsensor_oq_meassure = false;
fsensor_err_cnt = 0; fsensor_err_cnt = 0;
eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled?0x01:0x00); eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled?0x01:0x00);
FSensorStateMenu = fsensor_enabled?1:0; 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; return fsensor_enabled;
} }
@ -194,6 +193,41 @@ bool fsensor_check_autoload(void)
return false; 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) ISR(PCINT2_vect)
{ {
if (!((fsensor_int_pin_old ^ PINK) & FSENSOR_INT_PIN_MSK)) return; if (!((fsensor_int_pin_old ^ PINK) & FSENSOR_INT_PIN_MSK)) return;
@ -218,20 +252,31 @@ ISR(PCINT2_vect)
if (pat9125_y <= 0) if (pat9125_y <= 0)
{ {
fsensor_err_cnt++; fsensor_err_cnt++;
fsensor_er_sum++;
} }
else else
{ {
if (fsensor_err_cnt) if (fsensor_err_cnt)
fsensor_err_cnt--; fsensor_err_cnt--;
}
if (fsensor_oq_meassure)
{
if (fsensor_oq_skipchunk)
fsensor_oq_skipchunk--;
else
{
if (st_cnt == FSENSOR_CHUNK_LEN) if (st_cnt == FSENSOR_CHUNK_LEN)
{ {
if (fsensor_yd_min > pat9125_y) fsensor_yd_min = (fsensor_yd_min + pat9125_y) / 2; if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2;
if (fsensor_yd_max < pat9125_y) fsensor_yd_max = (fsensor_yd_max + 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 else //negative movement
{ {
@ -245,7 +290,7 @@ ISR(PCINT2_vect)
if (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 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 #endif //DEBUG_FSENSOR_LOG

View File

@ -3,8 +3,16 @@
#include "planner.h" #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_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 //save restore printing
extern void fsensor_stop_and_save_print(void); extern void fsensor_stop_and_save_print(void);
@ -25,15 +33,16 @@ extern void fsensor_update(void);
//setup pin-change interrupt //setup pin-change interrupt
extern void fsensor_setup_interrupt(void); extern void fsensor_setup_interrupt(void);
// //autoload support
extern void fsensor_autoload_check_start(void); extern void fsensor_autoload_check_start(void);
//
extern void fsensor_autoload_check_stop(void); extern void fsensor_autoload_check_stop(void);
//
extern bool fsensor_check_autoload(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 //callbacks from stepper
extern void fsensor_st_block_begin(block_t* bl); extern void fsensor_st_block_begin(block_t* bl);
extern void fsensor_st_block_chunk(block_t* bl, int cnt); 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 //autoload enable/disable flag
extern bool fsensor_watch_autoload; extern bool fsensor_watch_autoload;
//filament optical quality meassurement
extern uint32_t fsensor_st_sum; extern bool fsensor_oq_meassure;
extern uint32_t fsensor_yd_sum; extern uint8_t fsensor_oq_skipchunk;
extern uint32_t fsensor_er_sum; extern uint32_t fsensor_oq_st_sum;
extern uint16_t fsensor_yd_min; extern uint32_t fsensor_oq_yd_sum;
extern uint16_t fsensor_yd_max; 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 #endif //FSENSOR_H