diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-10-21 22:48:47 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-10-21 22:48:47 +0300 |
commit | 894ac1aff66bbb834239b3d0dadb3f6bc67e641f (patch) | |
tree | 1ff9b032b8db8385b7b8ea93faa3d9a4cfb42248 /src/FilamentMonitors | |
parent | 111fae6e2184e5f8fde1b3487e8f50478c51541e (diff) |
Completed implementing filament monitors in expansion mode
Diffstat (limited to 'src/FilamentMonitors')
-rw-r--r-- | src/FilamentMonitors/Duet3DFilamentMonitor.cpp | 4 | ||||
-rw-r--r-- | src/FilamentMonitors/Duet3DFilamentMonitor.h | 2 | ||||
-rw-r--r-- | src/FilamentMonitors/FilamentMonitor.cpp | 72 | ||||
-rw-r--r-- | src/FilamentMonitors/FilamentMonitor.h | 13 | ||||
-rw-r--r-- | src/FilamentMonitors/LaserFilamentMonitor.cpp | 4 | ||||
-rw-r--r-- | src/FilamentMonitors/LaserFilamentMonitor.h | 2 | ||||
-rw-r--r-- | src/FilamentMonitors/PulsedFilamentMonitor.cpp | 4 | ||||
-rw-r--r-- | src/FilamentMonitors/PulsedFilamentMonitor.h | 2 | ||||
-rw-r--r-- | src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp | 4 | ||||
-rw-r--r-- | src/FilamentMonitors/RotatingMagnetFilamentMonitor.h | 2 | ||||
-rw-r--r-- | src/FilamentMonitors/SimpleFilamentMonitor.cpp | 4 | ||||
-rw-r--r-- | src/FilamentMonitors/SimpleFilamentMonitor.h | 2 |
12 files changed, 68 insertions, 47 deletions
diff --git a/src/FilamentMonitors/Duet3DFilamentMonitor.cpp b/src/FilamentMonitors/Duet3DFilamentMonitor.cpp index cc91f0d9..7e350708 100644 --- a/src/FilamentMonitors/Duet3DFilamentMonitor.cpp +++ b/src/FilamentMonitors/Duet3DFilamentMonitor.cpp @@ -27,8 +27,8 @@ #include <Platform/RepRap.h> // Constructors -Duet3DFilamentMonitor::Duet3DFilamentMonitor(unsigned int extruder, unsigned int p_type) noexcept - : FilamentMonitor(extruder, p_type), overrunErrorCount(0), polarityErrorCount(0) +Duet3DFilamentMonitor::Duet3DFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept + : FilamentMonitor(drv, monitorType, did), overrunErrorCount(0), polarityErrorCount(0) { InitReceiveBuffer(); } diff --git a/src/FilamentMonitors/Duet3DFilamentMonitor.h b/src/FilamentMonitors/Duet3DFilamentMonitor.h index 8968e729..4ed489c3 100644 --- a/src/FilamentMonitors/Duet3DFilamentMonitor.h +++ b/src/FilamentMonitors/Duet3DFilamentMonitor.h @@ -15,7 +15,7 @@ class Duet3DFilamentMonitor : public FilamentMonitor { public: - Duet3DFilamentMonitor(unsigned int extruder, unsigned int p_type) noexcept; + Duet3DFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept; bool Interrupt() noexcept override; diff --git a/src/FilamentMonitors/FilamentMonitor.cpp b/src/FilamentMonitors/FilamentMonitor.cpp index 4a72575e..5ed87a9d 100644 --- a/src/FilamentMonitors/FilamentMonitor.cpp +++ b/src/FilamentMonitors/FilamentMonitor.cpp @@ -50,13 +50,12 @@ size_t FilamentMonitor::GetNumMonitorsToReport() noexcept #endif // Constructor -FilamentMonitor::FilamentMonitor(unsigned int extruder, unsigned int t) noexcept - : extruderNumber(extruder), type(t), lastStatus(FilamentSensorStatus::noDataReceived) +FilamentMonitor::FilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept + : driveNumber(drv), type(monitorType), driverId(did), lastStatus(FilamentSensorStatus::noDataReceived) #if SUPPORT_CAN_EXPANSION , hasRemote(false) #endif { - driver = reprap.GetPlatform().GetExtruderDriver(extruder); } // Default destructor @@ -66,7 +65,7 @@ FilamentMonitor::~FilamentMonitor() noexcept if (!IsLocal() && hasRemote) { String<1> dummy; - (void)CanInterface::DeleteFilamentMonitor(driver, nullptr, dummy.GetRef()); + (void)CanInterface::DeleteFilamentMonitor(driverId, nullptr, dummy.GetRef()); } #endif } @@ -89,7 +88,7 @@ GCodeResult FilamentMonitor::CommonConfigure(GCodeBuffer& gb, const StringRef& r if (gb.TryGetQuotedString('C', portName.GetRef(), seen)) { const CanAddress portAddress = IoPort::RemoveBoardAddress(portName.GetRef()); - if (portAddress != driver.boardAddress) + if (portAddress != driverId.boardAddress) { reply.copy("Filament monitor port must be on same board as extruder driver"); return GCodeResult::error; @@ -99,7 +98,7 @@ GCodeResult FilamentMonitor::CommonConfigure(GCodeBuffer& gb, const StringRef& r if (!IsLocal()) { seen = true; // this tells the local filament monitor not to report anything - return CanInterface::ConfigureFilamentMonitor(driver, gb, reply); + return CanInterface::ConfigureFilamentMonitor(driverId, gb, reply); } #endif @@ -122,9 +121,10 @@ GCodeResult FilamentMonitor::CommonConfigure(GCodeBuffer& gb, const StringRef& r } // Check that the extruder referenced by this filament monitor is still valid -bool FilamentMonitor::IsValid() const noexcept +bool FilamentMonitor::IsValid(size_t extruderNumber) const noexcept { - return extruderNumber < reprap.GetGCodes().GetNumExtruders() && reprap.GetPlatform().GetExtruderDriver(extruderNumber) == driver; + return extruderNumber < reprap.GetGCodes().GetNumExtruders() + && reprap.GetPlatform().GetExtruderDriver(extruderNumber) == driverId; } // Static initialisation @@ -199,26 +199,27 @@ bool FilamentMonitor::IsValid() const noexcept // Factory function to create a filament monitor /*static*/ FilamentMonitor *FilamentMonitor::Create(unsigned int extruder, unsigned int monitorType, GCodeBuffer& gb, const StringRef& reply) noexcept { + const DriverId did = reprap.GetPlatform().GetExtruderDriver(extruder); FilamentMonitor *fm; switch (monitorType) { case 1: // active high switch case 2: // active low switch - fm = new SimpleFilamentMonitor(extruder, monitorType); + fm = new SimpleFilamentMonitor(extruder, monitorType, did); break; case 3: // duet3d rotating magnet, no switch case 4: // duet3d rotating magnet + switch - fm = new RotatingMagnetFilamentMonitor(extruder, monitorType); + fm = new RotatingMagnetFilamentMonitor(extruder, monitorType, did); break; case 5: // duet3d laser, no switch case 6: // duet3d laser + switch - fm = new LaserFilamentMonitor(extruder, monitorType); + fm = new LaserFilamentMonitor(extruder, monitorType, did); break; case 7: // simple pulse output sensor - fm = new PulsedFilamentMonitor(extruder, monitorType); + fm = new PulsedFilamentMonitor(extruder, monitorType, did); break; default: // no sensor, or unknown sensor @@ -229,7 +230,7 @@ bool FilamentMonitor::IsValid() const noexcept if (fm != nullptr && !fm->IsLocal()) { // Create the remote filament monitor on the expansion board - if (CanInterface::CreateFilamentMonitor(fm->driver, monitorType, gb, reply) != GCodeResult::ok) + if (CanInterface::CreateFilamentMonitor(fm->driverId, monitorType, gb, reply) != GCodeResult::ok) { delete fm; return nullptr; @@ -246,7 +247,7 @@ bool FilamentMonitor::IsValid() const noexcept FilamentMonitor * const fm = static_cast<FilamentMonitor*>(param.vp); if (fm->Interrupt()) { - fm->isrExtruderStepsCommanded = reprap.GetMove().GetAccumulatedExtrusion(fm->extruderNumber, fm->isrWasPrinting); + fm->isrExtruderStepsCommanded = reprap.GetMove().GetAccumulatedExtrusion(fm->driveNumber, fm->isrWasPrinting); fm->haveIsrStepsCommanded = true; fm->lastIsrMillis = millis(); } @@ -255,6 +256,7 @@ bool FilamentMonitor::IsValid() const noexcept /*static*/ void FilamentMonitor::Spin() noexcept { #if SUPPORT_REMOTE_COMMANDS + // TODO these 2 loops are rather similar so combine at least some of the code if (CanInterface::InExpansionMode()) { CanMessageBuffer buf(nullptr); @@ -289,8 +291,7 @@ bool FilamentMonitor::IsValid() const noexcept else { IrqEnable(); - //TODO need a version of GetAccumulatedExtruson that doesn't map extruder to drive - extruderStepsCommanded = reprap.GetMove().GetAccumulatedExtrusion(drv, isPrinting); // get and clear the net extrusion commanded + extruderStepsCommanded = reprap.GetMove().GetAccumulatedExtrusion(fs.driveNumber, isPrinting); // get and clear the net extrusion commanded fromIsr = false; locIsrMillis = 0; } @@ -298,7 +299,7 @@ bool FilamentMonitor::IsValid() const noexcept GCodes& gCodes = reprap.GetGCodes(); if (gCodes.IsReallyPrinting() && !gCodes.IsSimulating()) { - const float extrusionCommanded = (float)extruderStepsCommanded/reprap.GetPlatform().DriveStepsPerUnit(drv); + const float extrusionCommanded = (float)extruderStepsCommanded/reprap.GetPlatform().DriveStepsPerUnit(fs.driveNumber); fst = fs.Check(isPrinting, fromIsr, locIsrMillis, extrusionCommanded); } else @@ -353,7 +354,7 @@ bool FilamentMonitor::IsValid() const noexcept else { IrqEnable(); - extruderStepsCommanded = reprap.GetMove().GetAccumulatedExtrusion(extruder, isPrinting); // get and clear the net extrusion commanded + extruderStepsCommanded = reprap.GetMove().GetAccumulatedExtrusion(fs.driveNumber, isPrinting); // get and clear the net extrusion commanded fromIsr = false; locIsrMillis = 0; } @@ -361,7 +362,7 @@ bool FilamentMonitor::IsValid() const noexcept GCodes& gCodes = reprap.GetGCodes(); if (gCodes.IsReallyPrinting() && !gCodes.IsSimulating()) { - const float extrusionCommanded = (float)extruderStepsCommanded/reprap.GetPlatform().DriveStepsPerUnit(ExtruderToLogicalDrive(extruder)); + const float extrusionCommanded = (float)extruderStepsCommanded/reprap.GetPlatform().DriveStepsPerUnit(fs.driveNumber); const FilamentSensorStatus fstat = fs.Check(isPrinting, fromIsr, locIsrMillis, extrusionCommanded); fs.lastStatus = fstat; if (fstat != FilamentSensorStatus::ok) @@ -397,9 +398,9 @@ bool FilamentMonitor::IsValid() const noexcept if (filamentSensors[extruder] != nullptr) { FilamentMonitor& fs = *filamentSensors[extruder]; - if (fs.driver.boardAddress == src && fs.driver.localDriver < msg.numMonitorsReported) + if (fs.driverId.boardAddress == src && fs.driverId.localDriver < msg.numMonitorsReported) { - const FilamentSensorStatus fstat(msg.data[fs.driver.localDriver].status); + const FilamentSensorStatus fstat(msg.data[fs.driverId.localDriver].status); fs.lastStatus = fstat; GCodes& gCodes = reprap.GetGCodes(); if (gCodes.IsReallyPrinting() && !gCodes.IsSimulating()) @@ -459,9 +460,9 @@ bool FilamentMonitor::IsValid() const noexcept bool warn = false; WriteLocker lock(filamentMonitorsLock); - for (size_t extruder = 0; extruder < MaxExtruders; ++extruder) + for (size_t extruder = 0; extruder < ARRAY_SIZE(filamentSensors); ++extruder) { - if (filamentSensors[extruder] != nullptr && !filamentSensors[extruder]->IsValid()) + if (filamentSensors[extruder] != nullptr && !filamentSensors[extruder]->IsValid(extruder)) { reply.lcatf("Filament monitor for extruder %u has been deleted due to configuration change", extruder); warn = true; @@ -508,6 +509,9 @@ GCodeResult FilamentMonitor::CommonConfigure(const CanMessageGenericParser& pars return GCodeResult::error; } + DriverId did; + did.SetLocal(p_driver); + WriteLocker lock(filamentMonitorsLock); // Delete any existing filament monitor @@ -521,21 +525,21 @@ GCodeResult FilamentMonitor::CommonConfigure(const CanMessageGenericParser& pars { case 1: // active high switch case 2: // active low switch - fm = new SimpleFilamentMonitor(p_driver, monitorType); + fm = new SimpleFilamentMonitor(p_driver, monitorType, did); break; case 3: // duet3d rotating magnet, no switch case 4: // duet3d rotating magnet + switch - fm = new RotatingMagnetFilamentMonitor(p_driver, monitorType); + fm = new RotatingMagnetFilamentMonitor(p_driver, monitorType, did); break; case 5: // duet3d laser, no switch case 6: // duet3d laser + switch - fm = new LaserFilamentMonitor(p_driver, monitorType); + fm = new LaserFilamentMonitor(p_driver, monitorType, did); break; case 7: // simple pulse output sensor - fm = new PulsedFilamentMonitor(p_driver, monitorType); + fm = new PulsedFilamentMonitor(p_driver, monitorType, did); break; default: // no sensor, or unknown sensor @@ -595,6 +599,20 @@ GCodeResult FilamentMonitor::CommonConfigure(const CanMessageGenericParser& pars return fm->Configure(parser, reply); } +// Delete all filament monitors +/*static*/ void FilamentMonitor::DeleteAll() noexcept +{ + WriteLocker lock(filamentMonitorsLock); + + for (size_t extruder = 0; extruder < MaxExtruders; ++extruder) + { + if (filamentSensors[extruder] != nullptr) + { + DeleteObject(filamentSensors[extruder]); + } + } +} + #endif // End diff --git a/src/FilamentMonitors/FilamentMonitor.h b/src/FilamentMonitors/FilamentMonitor.h index b7162d0f..af7d6bea 100644 --- a/src/FilamentMonitors/FilamentMonitor.h +++ b/src/FilamentMonitors/FilamentMonitor.h @@ -61,7 +61,7 @@ public: unsigned int GetType() const noexcept { return type; } // Check that this monitor still refers to a valid extruder - bool IsValid() const noexcept; + bool IsValid(size_t extruderNumber) const noexcept; // Get the status of the filament monitor as a string const char *GetStatusText() const noexcept { return lastStatus.ToString(); } @@ -106,13 +106,16 @@ public: // Configure a filament monitor static GCodeResult Configure(const CanMessageGeneric& msg, const StringRef& reply) noexcept; + + // Delete all filament monitors + static void DeleteAll() noexcept; #endif // This must be public so that the array descriptor in class RepRap can lock it static ReadWriteLock filamentMonitorsLock; protected: - FilamentMonitor(unsigned int extruder, unsigned int t) noexcept; + FilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept; GCodeResult CommonConfigure(GCodeBuffer& gb, const StringRef& reply, InterruptMode interruptMode, bool& seen) THROWS(GCodeException); #if SUPPORT_REMOTE_COMMANDS @@ -127,7 +130,7 @@ protected: return lrintf(100 * f); } - bool IsLocal() const noexcept { return driver.IsLocal(); } + bool IsLocal() const noexcept { return driverId.IsLocal(); } private: @@ -152,10 +155,10 @@ private: int32_t isrExtruderStepsCommanded; uint32_t lastIsrMillis; - unsigned int extruderNumber; + unsigned int driveNumber; unsigned int type; IoPort port; - DriverId driver; + DriverId driverId; bool isrWasPrinting; bool haveIsrStepsCommanded; diff --git a/src/FilamentMonitors/LaserFilamentMonitor.cpp b/src/FilamentMonitors/LaserFilamentMonitor.cpp index e2c13c08..6731442c 100644 --- a/src/FilamentMonitors/LaserFilamentMonitor.cpp +++ b/src/FilamentMonitors/LaserFilamentMonitor.cpp @@ -76,8 +76,8 @@ DEFINE_GET_OBJECT_MODEL_TABLE(LaserFilamentMonitor) #endif -LaserFilamentMonitor::LaserFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept - : Duet3DFilamentMonitor(extruder, monitorType), +LaserFilamentMonitor::LaserFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept + : Duet3DFilamentMonitor(drv, monitorType, did), calibrationFactor(1.0), minMovementAllowed(DefaultMinMovementAllowed), maxMovementAllowed(DefaultMaxMovementAllowed), minimumExtrusionCheckLength(DefaultMinimumExtrusionCheckLength), comparisonEnabled(false), checkNonPrintingMoves(false) diff --git a/src/FilamentMonitors/LaserFilamentMonitor.h b/src/FilamentMonitors/LaserFilamentMonitor.h index cba64968..8a7034b7 100644 --- a/src/FilamentMonitors/LaserFilamentMonitor.h +++ b/src/FilamentMonitors/LaserFilamentMonitor.h @@ -13,7 +13,7 @@ class LaserFilamentMonitor : public Duet3DFilamentMonitor { public: - LaserFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept; + LaserFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException) override; #if SUPPORT_REMOTE_COMMANDS diff --git a/src/FilamentMonitors/PulsedFilamentMonitor.cpp b/src/FilamentMonitors/PulsedFilamentMonitor.cpp index 6f827dc3..de9c26ed 100644 --- a/src/FilamentMonitors/PulsedFilamentMonitor.cpp +++ b/src/FilamentMonitors/PulsedFilamentMonitor.cpp @@ -59,8 +59,8 @@ DEFINE_GET_OBJECT_MODEL_TABLE(PulsedFilamentMonitor) #endif -PulsedFilamentMonitor::PulsedFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept - : FilamentMonitor(extruder, monitorType), +PulsedFilamentMonitor::PulsedFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept + : FilamentMonitor(drv, monitorType, did), mmPerPulse(DefaultMmPerPulse), minMovementAllowed(DefaultMinMovementAllowed), maxMovementAllowed(DefaultMaxMovementAllowed), minimumExtrusionCheckLength(DefaultMinimumExtrusionCheckLength), comparisonEnabled(false) diff --git a/src/FilamentMonitors/PulsedFilamentMonitor.h b/src/FilamentMonitors/PulsedFilamentMonitor.h index f0009e99..d3736c17 100644 --- a/src/FilamentMonitors/PulsedFilamentMonitor.h +++ b/src/FilamentMonitors/PulsedFilamentMonitor.h @@ -13,7 +13,7 @@ class PulsedFilamentMonitor : public FilamentMonitor { public: - PulsedFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept; + PulsedFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException) override; #if SUPPORT_REMOTE_COMMANDS diff --git a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp index 018f021d..c2f7cac1 100644 --- a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp +++ b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp @@ -76,8 +76,8 @@ DEFINE_GET_OBJECT_MODEL_TABLE(RotatingMagnetFilamentMonitor) #endif -RotatingMagnetFilamentMonitor::RotatingMagnetFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept - : Duet3DFilamentMonitor(extruder, monitorType), +RotatingMagnetFilamentMonitor::RotatingMagnetFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept + : Duet3DFilamentMonitor(drv, monitorType, did), mmPerRev(DefaultMmPerRev), minMovementAllowed(DefaultMinMovementAllowed), maxMovementAllowed(DefaultMaxMovementAllowed), minimumExtrusionCheckLength(DefaultMinimumExtrusionCheckLength), comparisonEnabled(false), checkNonPrintingMoves(false) diff --git a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h index 32bca1e5..b8fc3d33 100644 --- a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h +++ b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h @@ -13,7 +13,7 @@ class RotatingMagnetFilamentMonitor : public Duet3DFilamentMonitor { public: - RotatingMagnetFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept; + RotatingMagnetFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException) override; #if SUPPORT_REMOTE_COMMANDS diff --git a/src/FilamentMonitors/SimpleFilamentMonitor.cpp b/src/FilamentMonitors/SimpleFilamentMonitor.cpp index d9555064..c6336a29 100644 --- a/src/FilamentMonitors/SimpleFilamentMonitor.cpp +++ b/src/FilamentMonitors/SimpleFilamentMonitor.cpp @@ -37,8 +37,8 @@ DEFINE_GET_OBJECT_MODEL_TABLE(SimpleFilamentMonitor) #endif -SimpleFilamentMonitor::SimpleFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept - : FilamentMonitor(extruder, monitorType), highWhenNoFilament(monitorType == 2), filamentPresent(false), enabled(false) +SimpleFilamentMonitor::SimpleFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept + : FilamentMonitor(drv, monitorType, did), highWhenNoFilament(monitorType == 2), filamentPresent(false), enabled(false) { } diff --git a/src/FilamentMonitors/SimpleFilamentMonitor.h b/src/FilamentMonitors/SimpleFilamentMonitor.h index a2bd2a7a..498db490 100644 --- a/src/FilamentMonitors/SimpleFilamentMonitor.h +++ b/src/FilamentMonitors/SimpleFilamentMonitor.h @@ -13,7 +13,7 @@ class SimpleFilamentMonitor : public FilamentMonitor { public: - SimpleFilamentMonitor(unsigned int extruder, unsigned int monitorType) noexcept; + SimpleFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) THROWS(GCodeException) override; #if SUPPORT_REMOTE_COMMANDS |