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

debounce (wait msecs) option for pulse type filament monitors #176

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 19 additions & 7 deletions src/FilamentMonitors/PulsedFilamentMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PulsedFilamentMonitor::PulsedFilamentMonitor(unsigned int extruder, int type)
: FilamentMonitor(extruder, type),
mmPerPulse(DefaultMmPerPulse),
minMovementAllowed(DefaultMinMovementAllowed), maxMovementAllowed(DefaultMaxMovementAllowed),
minimumExtrusionCheckLength(DefaultMinimumExtrusionCheckLength), comparisonEnabled(false)
minimumExtrusionCheckLength(DefaultMinimumExtrusionCheckLength), comparisonEnabled(false), waitMsec(DefaultWaitMsec)
{
Init();
}
Expand Down Expand Up @@ -63,6 +63,12 @@ bool PulsedFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, b
}
}

if (gb.Seen('W'))
{
seen = true;
waitMsec = gb.GetIValue();
}

if (gb.Seen('S'))
{
seen = true;
Expand All @@ -75,22 +81,23 @@ bool PulsedFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, b
}
else
{
reply.printf("Pulse-type filament monitor on endstop input %u, %s, sensitivity %.2fmm/pulse, allowed movement %ld%% to %ld%%, check every %.1fmm, ",
reply.printf("Pulse-type filament monitor on endstop input %u, %s, sensitivity %.2fmm/pulse, allowed movement %ld%% to %ld%%, check every %.1fmm, wait %lu msec, ",
GetEndstopNumber(),
(comparisonEnabled) ? "enabled" : "disabled",
(double)mmPerPulse,
lrintf(minMovementAllowed * 100.0),
lrintf(maxMovementAllowed * 100.0),
(double)minimumExtrusionCheckLength);
(double)minimumExtrusionCheckLength,
waitMsec);

if (samplesReceived < 2)
{
reply.cat("no data received");
}
else
{
reply.catf("current position %.1f, ", (double)GetCurrentPosition());
if (calibrationStarted && fabsf(totalMovementMeasured) > 1.0 && totalExtrusionCommanded > 20.0)
reply.catf("current position %.1f, ", (double) GetCurrentPosition());
if (calibrationStarted && fabsf(totalMovementMeasured) > 1.0 && totalExtrusionCommanded > 20.0)
{
const float measuredMmPerPulse = totalExtrusionCommanded/totalMovementMeasured;
reply.catf("measured sensitivity %.3fmm/pulse, measured minimum %ld%%, maximum %ld%% over %.1fmm\n",
Expand All @@ -112,12 +119,17 @@ bool PulsedFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, b
// ISR for when the pin state changes. It should return true if the ISR wants the commanded extrusion to be fetched.
bool PulsedFilamentMonitor::Interrupt()
{
uint32_t localMillis = millis();
if (localMillis < (lastMeasurementTime + waitMsec)) {
return false;
}

++sensorValue;
if (samplesReceived < 100)
{
++samplesReceived;
}
lastMeasurementTime = millis();
lastMeasurementTime = localMillis;
return true;
}

Expand Down Expand Up @@ -277,7 +289,7 @@ void PulsedFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder
{
Poll();
const char* const statusText = (samplesReceived < 2) ? "no data received" : "ok";
reprap.GetPlatform().MessageF(mtype, "Extruder %u sensor: position %.2f, %s, ", extruder, (double)GetCurrentPosition(), statusText);
reprap.GetPlatform().MessageF(mtype, "Extruder %u sensor: position %.2f, %s, ", extruder, (double) GetCurrentPosition(), statusText);
if (calibrationStarted && fabsf(totalMovementMeasured) > 1.0 && totalExtrusionCommanded > 20.0)
{
const float measuredMmPerRev = totalExtrusionCommanded/totalMovementMeasured;
Expand Down
4 changes: 3 additions & 1 deletion src/FilamentMonitors/PulsedFilamentMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class PulsedFilamentMonitor : public FilamentMonitor
static constexpr float DefaultMinMovementAllowed = 0.6;
static constexpr float DefaultMaxMovementAllowed = 1.6;
static constexpr float DefaultMinimumExtrusionCheckLength = 5.0;

static constexpr uint32_t DefaultWaitMsec = 0;

void Init();
void Reset();
void Poll();
Expand All @@ -38,6 +39,7 @@ class PulsedFilamentMonitor : public FilamentMonitor
float minMovementAllowed, maxMovementAllowed;
float minimumExtrusionCheckLength;
bool comparisonEnabled;
uint32_t waitMsec;

// Other data
uint32_t sensorValue; // how many pulses received
Expand Down