diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-07-22 18:41:00 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-07-22 18:41:00 +0300 |
commit | 5b2ae5525c1326bff42f0d376eebd5eea1b0e917 (patch) | |
tree | 6fc49cb9f43ced38ae1888a037aa9ffc850e0900 | |
parent | 84f85df38791cc775e3c4108fcddeded91cbeabf (diff) |
Corrected mag filament monitor position report in OM for ATE build
-rw-r--r-- | src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp | 14 | ||||
-rw-r--r-- | src/FilamentMonitors/RotatingMagnetFilamentMonitor.h | 4 |
2 files changed, 7 insertions, 11 deletions
diff --git a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp index a6563d67..894608bb 100644 --- a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp +++ b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp @@ -42,7 +42,7 @@ constexpr ObjectModelTableEntry RotatingMagnetFilamentMonitor::objectModelTable[ { "enabled", OBJECT_MODEL_FUNC(self->comparisonEnabled), ObjectModelEntryFlags::none }, #ifdef DUET3_ATE { "mag", OBJECT_MODEL_FUNC((int32_t)self->magnitude), ObjectModelEntryFlags::live }, - { "position", OBJECT_MODEL_FUNC((int32_t)self->sensorValue), ObjectModelEntryFlags::live }, + { "position", OBJECT_MODEL_FUNC((int32_t)self->lastKnownPosition), ObjectModelEntryFlags::live }, #endif { "status", OBJECT_MODEL_FUNC(self->GetStatusText()), ObjectModelEntryFlags::live }, { "type", OBJECT_MODEL_FUNC_NOSELF("rotatingMagnet"), ObjectModelEntryFlags::none }, @@ -90,7 +90,7 @@ RotatingMagnetFilamentMonitor::RotatingMagnetFilamentMonitor(unsigned int drv, u void RotatingMagnetFilamentMonitor::Init() noexcept { dataReceived = false; - sensorValue = 0; + sensorValue = lastKnownPosition = 0; parityErrorCount = framingErrorCount = overrunErrorCount = polarityErrorCount = overdueCount = 0; lastMeasurementTime = 0; lastErrorCode = 0; @@ -233,12 +233,6 @@ GCodeResult RotatingMagnetFilamentMonitor::Configure(GCodeBuffer& gb, const Stri return rslt; } -// Return the current wheel angle -float RotatingMagnetFilamentMonitor::GetCurrentPosition() const noexcept -{ - return (sensorValue & TypeMagnetAngleMask) * (360.0/1024.0); -} - // Deal with any received data void RotatingMagnetFilamentMonitor::HandleIncomingData() noexcept { @@ -349,6 +343,7 @@ void RotatingMagnetFilamentMonitor::HandleIncomingData() noexcept if (receivedPositionReport) { // We have a completed a position report + lastKnownPosition = sensorValue & TypeMagnetAngleMask; const uint16_t angleChange = (val - sensorValue) & TypeMagnetAngleMask; // angle change in range 0..1023 const int32_t movement = (angleChange <= 512) ? (int32_t)angleChange : (int32_t)angleChange - 1024; movementMeasuredSinceLastSync += (float)movement/1024; @@ -537,7 +532,8 @@ void RotatingMagnetFilamentMonitor::Diagnostics(MessageType mtype, unsigned int if (dataReceived) { buf.catf("pos %.2f, errs: frame %" PRIu32 " parity %" PRIu32 " ovrun %" PRIu32 " pol %" PRIu32 " ovdue %" PRIu32 "\n", - (double)GetCurrentPosition(), framingErrorCount, parityErrorCount, overrunErrorCount, polarityErrorCount, overdueCount); + (double)((float)lastKnownPosition * (360.0/1024.0)), + framingErrorCount, parityErrorCount, overrunErrorCount, polarityErrorCount, overdueCount); } else { diff --git a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h index b8fc3d33..340389c7 100644 --- a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h +++ b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h @@ -59,7 +59,6 @@ private: void Init() noexcept; void Reset() noexcept; void HandleIncomingData() noexcept; - float GetCurrentPosition() const noexcept; FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue) noexcept; bool HaveCalibrationData() const noexcept; @@ -84,7 +83,8 @@ private: float extrusionCommandedSinceLastSync; float movementMeasuredSinceLastSync; - uint16_t sensorValue; // last known filament position (10 bits) + uint16_t sensorValue; // latest word received from sensor + uint16_t lastKnownPosition; // last known filament position (10 bits) uint32_t lastMeasurementTime; // the last time we received a value uint16_t switchOpenMask; // mask to isolate the switch open bit(s) from the sensor value uint8_t version; // sensor/firmware version |