From 3be859ece951c6c4bdeb8ed112c7e14a439636d6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 6 Feb 2020 13:48:23 +0100 Subject: [PATCH] FS: Improve reliability on speeds with poor optical tracking Depending on the filament surface and moving speed, the PAT9125 sensor can stop being able to track movement. In such cases, instead of triggering false errors and/or relying on previous states, read and use the exposure data off the sensor and increase error counts only for poorly exposed images instead, which is a good indicator of a far-away (or missing!) tracking surface. --- Firmware/fsensor.cpp | 23 +++++++++++++++++++---- Firmware/pat9125.c | 14 ++++---------- Firmware/pat9125.h | 6 +++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 41d9a506..9e7b2f6c 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -488,10 +488,25 @@ ISR(FSENSOR_INT_PIN_VECT) if (pat9125_y == 0) { - // no movement detected: increase error count only when extruding, since fast retracts - // cannot always be seen. We also need to ensure that no runout is generated while - // retracting as it's not currently handled everywhere - if (st_dir) ++fsensor_err_cnt; + if (st_dir) + { + // no movement detected: we might be within a blind sensor range, + // update the frame and shutter parameters we didn't earlier + if (!fsensor_oq_meassure) + pat9125_update_bs(); + + // increment the error count only if underexposed: filament likely missing + if ((pat9125_b < 80) && (pat9125_s > 10)) + { + // check for a dark frame (<30% avg brightness) with long exposure + ++fsensor_err_cnt; + } + else + { + // good frame, filament likely present + if(fsensor_err_cnt) --fsensor_err_cnt; + } + } } else if (pat9125_dir != st_dir) { diff --git a/Firmware/pat9125.c b/Firmware/pat9125.c index 5b17345c..ae291c21 100644 --- a/Firmware/pat9125.c +++ b/Firmware/pat9125.c @@ -219,19 +219,13 @@ uint8_t pat9125_update_y(void) return 0; } -uint8_t pat9125_update_y2(void) +uint8_t pat9125_update_bs(void) { if ((pat9125_PID1 == 0x31) && (pat9125_PID2 == 0x91)) { - uint8_t ucMotion = pat9125_rd_reg(PAT9125_MOTION); - if (pat9125_PID1 == 0xff) return 0; //NOACK error - if (ucMotion & 0x80) - { - int8_t dy = pat9125_rd_reg(PAT9125_DELTA_YL); - if (pat9125_PID1 == 0xff) return 0; //NOACK error - pat9125_y -= dy; //negative number, because direction switching does not work - } - return 1; + pat9125_b = pat9125_rd_reg(PAT9125_FRAME); + pat9125_s = pat9125_rd_reg(PAT9125_SHUTTER); + if (pat9125_PID1 == 0xff) return 0; } return 0; } diff --git a/Firmware/pat9125.h b/Firmware/pat9125.h index 6d36a82e..12f7fe94 100755 --- a/Firmware/pat9125.h +++ b/Firmware/pat9125.h @@ -19,9 +19,9 @@ extern uint8_t pat9125_b; extern uint8_t pat9125_s; extern uint8_t pat9125_init(void); -extern uint8_t pat9125_update(void); -extern uint8_t pat9125_update_y(void); -extern uint8_t pat9125_update_y2(void); +extern uint8_t pat9125_update(void); // update all sensor data +extern uint8_t pat9125_update_y(void); // update _y only +extern uint8_t pat9125_update_bs(void); // update _b/_s only #if defined(__cplusplus)