Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MK3 PAT9125: filament runout fix for transparent and black filaments #4182

Open
wants to merge 1 commit into
base: MK3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 41 additions & 28 deletions Firmware/Filament_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,43 +476,56 @@ void PAT9125_sensor::filJam() {
}

bool PAT9125_sensor::updatePAT9125() {
if (jamDetection) {
int16_t _stepCount = getStepCount();
if (abs(_stepCount) >= chunkSteps) { // end of chunk. Check distance
resetStepCount();
if (!pat9125_update()) { // get up to date data. reinit on error.
init(); // try to reinit.
}
bool fsDir = (pat9125_y - oldPos) > 0;
bool stDir = _stepCount > 0;
if (fsDir != stDir) {
jamErrCnt++;
} else if (jamErrCnt) {
jamErrCnt--;
}
oldPos = pat9125_y;
}
if (jamErrCnt > 10) {
jamErrCnt = 0;
filJam();
}
}

if (pollingTimer.expired_cont(pollingPeriod)) {
pollingTimer.start();
if (!pat9125_update()) {
init(); // try to reinit.
}

bool present = (pat9125_s < 17) || (pat9125_s >= 17 && pat9125_b >= 50);
#if PLUG_REFLEX_WORKAROUND
// Detecting presence of transparent or black filament is difficult.
// if with or without filament, sensor readings are very close:
// pat9125_s == 17 and pat9125_b == 50..80
// To prevent false runouts:
// if filament moves, assume it is present.
bool filament_moves = pat9125_y != oldPos_presence;
oldPos_presence = pat9125_y;
#else
// if no-reflection idler plug is used,
// https://github.com/prusa3d/Original-Prusa-i3/pull/173
// without filament pat9125_s == 17 and pat9125_b == 9..20 then
// filament moves are not needed for presence detection
static constexpr bool filament_moves = false;
#endif

bool present = (pat9125_s < 17) || (pat9125_s >= 17 && (pat9125_b >= presence_threshold || filament_moves)); // without filament Support -> Sensor info -> pat9125_b == 47..50
if (present != filterFilPresent) {
filter++;
} else if (filter) {
filter--;
if (filter >= filterCnt) {
filter = 0;
filterFilPresent = present;
}
} else {
filter = 0;
}
if (filter >= filterCnt) {
filter = 0;
filterFilPresent = present;

if (jamDetection) {
int16_t _stepCount = getStepCount();
if (abs(_stepCount) >= chunkSteps) { // end of chunk. Check distance
resetStepCount();
int16_t optical_move = pat9125_y - oldPos;
oldPos = pat9125_y;
bool feed_ok = _stepCount > 0 ? optical_move > 7 : optical_move < -7;
if (!feed_ok) {
jamErrCnt += 2; // feed error counts 2x more than feed ok
if (jamErrCnt > 20) {
jamErrCnt = 0;
filJam();
}
} else if (jamErrCnt) {
jamErrCnt--;
}
}
}
}
return (filter == 0); // return stability
Expand Down
5 changes: 5 additions & 0 deletions Firmware/Filament_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,14 @@ class PAT9125_sensor: public Filament_sensor {
private:
static constexpr uint16_t pollingPeriod = 10; //[ms]
static constexpr uint8_t filterCnt = 5; //how many checks need to be done in order to determine the filament presence precisely.
static constexpr uint8_t presence_threshold = 30; // TODO: eeprom config. Remove filament and Support -> Sensor info -> B: value of pat9125_b when pat9125_s >= 17
ShortTimer pollingTimer;
uint8_t filter;
uint8_t filterFilPresent;
#define PLUG_REFLEX_WORKAROUND 1
#if PLUG_REFLEX_WORKAROUND
int16_t oldPos_presence;
#endif

bool jamDetection;
int16_t oldPos;
Expand Down