diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-03-03 13:52:37 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-03-03 13:52:37 +0300 |
commit | f5b540bdca881d09fac7aecfbf4fefdbe0d48da0 (patch) | |
tree | 40c4c0bb32378ee33e53c251be74d4764d9df350 /src | |
parent | 7a3045b53e3e303a988ce4565b2ac21206182ffb (diff) |
Got rid of "near endstop" status
Cherry picked from commit 165b178f7de75b1d00b26fec28f2a03fb36d6119
Diffstat (limited to 'src')
-rw-r--r-- | src/Endstops/Endstop.cpp | 2 | ||||
-rw-r--r-- | src/Endstops/Endstop.h | 2 | ||||
-rw-r--r-- | src/Endstops/EndstopDefs.h | 16 | ||||
-rw-r--r-- | src/Endstops/EndstopsManager.cpp | 20 | ||||
-rw-r--r-- | src/Endstops/EndstopsManager.h | 4 | ||||
-rw-r--r-- | src/Endstops/StallDetectionEndstop.cpp | 4 | ||||
-rw-r--r-- | src/Endstops/StallDetectionEndstop.h | 2 | ||||
-rw-r--r-- | src/Endstops/SwitchEndstop.cpp | 6 | ||||
-rw-r--r-- | src/Endstops/SwitchEndstop.h | 2 | ||||
-rw-r--r-- | src/Endstops/ZProbe.cpp | 24 | ||||
-rw-r--r-- | src/Endstops/ZProbe.h | 2 | ||||
-rw-r--r-- | src/Endstops/ZProbeEndstop.cpp | 20 | ||||
-rw-r--r-- | src/Endstops/ZProbeEndstop.h | 2 | ||||
-rw-r--r-- | src/GCodes/GCodes3.cpp | 2 | ||||
-rw-r--r-- | src/GCodes/GCodes4.cpp | 6 | ||||
-rw-r--r-- | src/GCodes/Trigger.cpp | 2 | ||||
-rw-r--r-- | src/RepRap.cpp | 2 |
17 files changed, 38 insertions, 80 deletions
diff --git a/src/Endstops/Endstop.cpp b/src/Endstops/Endstop.cpp index 5f7f29fc..d96ef6e5 100644 --- a/src/Endstops/Endstop.cpp +++ b/src/Endstops/Endstop.cpp @@ -26,7 +26,7 @@ constexpr ObjectModelTableEntry Endstop::objectModelTable[] = // Within each group, these entries must be in alphabetical order // 0. Endstop members { "highEnd", OBJECT_MODEL_FUNC(self->GetAtHighEnd()), ObjectModelEntryFlags::none }, - { "triggered", OBJECT_MODEL_FUNC(self->Stopped() == EndStopHit::atStop), ObjectModelEntryFlags::live }, + { "triggered", OBJECT_MODEL_FUNC(self->Stopped()), ObjectModelEntryFlags::live }, { "type", OBJECT_MODEL_FUNC(self->GetEndstopType().ToString()), ObjectModelEntryFlags::none }, }; diff --git a/src/Endstops/Endstop.h b/src/Endstops/Endstop.h index 3d288a02..0bdc7649 100644 --- a/src/Endstops/Endstop.h +++ b/src/Endstops/Endstop.h @@ -29,7 +29,7 @@ public: EndstopOrZProbe(const EndstopOrZProbe&) = delete; virtual ~EndstopOrZProbe() noexcept {} - virtual EndStopHit Stopped() const noexcept = 0; + virtual bool Stopped() const noexcept = 0; virtual EndstopHitDetails CheckTriggered(bool goingSlow) noexcept = 0; virtual bool Acknowledge(EndstopHitDetails what) noexcept = 0; diff --git a/src/Endstops/EndstopDefs.h b/src/Endstops/EndstopDefs.h index 948bd957..74835705 100644 --- a/src/Endstops/EndstopDefs.h +++ b/src/Endstops/EndstopDefs.h @@ -19,10 +19,9 @@ class ZProbe; enum class EndstopHitAction : uint8_t { none = 0, // don't stop anything - reduceSpeed = 1, // reduce speed because an endstop or Z probe is close to triggering - stopDriver = 2, // stop a single motor driver - stopAxis = 3, // stop all drivers for an axis - stopAll = 4 // stop movement completely + stopDriver = 1, // stop a single motor driver + stopAxis = 2, // stop all drivers for an axis + stopAll = 3 // stop movement completely }; // Struct to return info about what endstop has been triggered and what to do about it @@ -64,15 +63,6 @@ NamedEnum numInputTypes ); -// This is used as the return type of function Stopped. -// Note the ordering: we need more-stopped-value > less-stopped-value -enum class EndStopHit -{ - noStop = 0, // no endstop hit - nearStop = 1, // approaching Z-probe threshold - atStop = 2 -}; - enum class ZProbeType : uint8_t { none = 0, diff --git a/src/Endstops/EndstopsManager.cpp b/src/Endstops/EndstopsManager.cpp index e8104eef..8456d41e 100644 --- a/src/Endstops/EndstopsManager.cpp +++ b/src/Endstops/EndstopsManager.cpp @@ -280,7 +280,7 @@ EndstopHitDetails EndstopsManager::CheckEndstops(bool goingSlow) noexcept } } - if (ret.GetAction() > EndstopHitAction::reduceSpeed) + if (ret.GetAction() != EndstopHitAction::none) { if (actioned->Acknowledge(ret)) { @@ -506,9 +506,9 @@ bool EndstopsManager::HomingZWithProbe() const noexcept return axisEndstops[Z_AXIS] == nullptr || axisEndstops[Z_AXIS]->GetEndstopType() == EndStopType::zProbeAsEndstop; } -EndStopHit EndstopsManager::Stopped(size_t axis) const noexcept +bool EndstopsManager::Stopped(size_t axis) const noexcept { - return (axisEndstops[axis] == nullptr) ? EndStopHit::noStop : axisEndstops[axis]->Stopped(); + return (axisEndstops[axis] != nullptr) && axisEndstops[axis]->Stopped(); } void EndstopsManager::GetM119report(const StringRef& reply) noexcept @@ -524,20 +524,14 @@ void EndstopsManager::GetM119report(const StringRef& reply) noexcept reply.catf("Z probe: %s", TranslateEndStopResult(GetZProbeOrDefault(0)->Stopped(), false)); } -const char *EndstopsManager::TranslateEndStopResult(EndStopHit es, bool atHighEnd) noexcept +const char *EndstopsManager::TranslateEndStopResult(bool hit, bool atHighEnd) noexcept { - switch (es) + if (hit) { - case EndStopHit::atStop: return (atHighEnd) ? "at max stop" : "at min stop"; - - case EndStopHit::nearStop: - return "near stop"; - - case EndStopHit::noStop: - default: - return "not stopped"; } + + return "not stopped"; } void EndstopsManager::SetZProbeDefaults() noexcept diff --git a/src/Endstops/EndstopsManager.h b/src/Endstops/EndstopsManager.h index 10c09388..c3ce99a8 100644 --- a/src/Endstops/EndstopsManager.h +++ b/src/Endstops/EndstopsManager.h @@ -48,7 +48,7 @@ public: EndStopPosition GetEndStopPosition(size_t axis) const pre(axis < MaxAxes) noexcept; bool HomingZWithProbe() const noexcept; - EndStopHit Stopped(size_t axis) const noexcept; + bool Stopped(size_t axis) const noexcept; void GetM119report(const StringRef& reply) noexcept; @@ -90,7 +90,7 @@ private: #endif // Translate end stop result to text - static const char *TranslateEndStopResult(EndStopHit es, bool atHighEnd) noexcept; + static const char *TranslateEndStopResult(bool hit, bool atHighEnd) noexcept; ReadLockedPointer<Endstop> FindEndstop(size_t axis) const noexcept; diff --git a/src/Endstops/StallDetectionEndstop.cpp b/src/Endstops/StallDetectionEndstop.cpp index 89112829..987c6b48 100644 --- a/src/Endstops/StallDetectionEndstop.cpp +++ b/src/Endstops/StallDetectionEndstop.cpp @@ -24,9 +24,9 @@ StallDetectionEndstop::StallDetectionEndstop() noexcept } // Test whether we are at or near the stop -EndStopHit StallDetectionEndstop::Stopped() const noexcept +bool StallDetectionEndstop::Stopped() const noexcept { - return (GetStalledDrivers(driversMonitored).IsNonEmpty()) ? EndStopHit::atStop : EndStopHit::noStop; + return GetStalledDrivers(driversMonitored).IsNonEmpty(); } // This is called to prime axis endstops diff --git a/src/Endstops/StallDetectionEndstop.h b/src/Endstops/StallDetectionEndstop.h index 1f405f81..4765ce7c 100644 --- a/src/Endstops/StallDetectionEndstop.h +++ b/src/Endstops/StallDetectionEndstop.h @@ -23,7 +23,7 @@ public: StallDetectionEndstop() noexcept; // for creating the single extruders endstop EndStopType GetEndstopType() const noexcept override { return (individualMotors) ? EndStopType::motorStallIndividual : EndStopType::motorStallAny; } - EndStopHit Stopped() const noexcept override; + bool Stopped() const noexcept override; bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) noexcept override; EndstopHitDetails CheckTriggered(bool goingSlow) noexcept override; bool Acknowledge(EndstopHitDetails what) noexcept override; diff --git a/src/Endstops/SwitchEndstop.cpp b/src/Endstops/SwitchEndstop.cpp index 87af1b9b..63716235 100644 --- a/src/Endstops/SwitchEndstop.cpp +++ b/src/Endstops/SwitchEndstop.cpp @@ -118,16 +118,16 @@ EndStopType SwitchEndstop::GetEndstopType() const noexcept } // Test whether we are at or near the stop -EndStopHit SwitchEndstop::Stopped() const noexcept +bool SwitchEndstop::Stopped() const noexcept { for (size_t i = 0; i < numPortsUsed; ++i) { if (IsTriggered(i)) { - return EndStopHit::atStop; + return true; } } - return EndStopHit::noStop; + return false; } // This is called to prime axis endstops diff --git a/src/Endstops/SwitchEndstop.h b/src/Endstops/SwitchEndstop.h index b2cc997e..ae35ca50 100644 --- a/src/Endstops/SwitchEndstop.h +++ b/src/Endstops/SwitchEndstop.h @@ -22,7 +22,7 @@ public: SwitchEndstop(uint8_t p_axis, EndStopPosition pos) noexcept; EndStopType GetEndstopType() const noexcept override; - EndStopHit Stopped() const noexcept override; + bool Stopped() const noexcept override; bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) noexcept override; EndstopHitDetails CheckTriggered(bool goingSlow) noexcept override; bool Acknowledge(EndstopHitDetails what) noexcept override; diff --git a/src/Endstops/ZProbe.cpp b/src/Endstops/ZProbe.cpp index ba9ea24c..4141d2a3 100644 --- a/src/Endstops/ZProbe.cpp +++ b/src/Endstops/ZProbe.cpp @@ -208,40 +208,26 @@ int ZProbe::GetSecondaryValues(int& v1) const noexcept } // Test whether we are at or near the stop -EndStopHit ZProbe::Stopped() const noexcept +bool ZProbe::Stopped() const noexcept { const int zProbeVal = GetReading(); - return (zProbeVal >= adcValue) ? EndStopHit::atStop - : (zProbeVal * 10 >= adcValue * 9) ? EndStopHit::nearStop // if we are at/above 90% of the target value - : EndStopHit::noStop; + return zProbeVal >= adcValue; } // Check whether the probe is triggered and return the action that should be performed. Called from the step ISR. EndstopHitDetails ZProbe::CheckTriggered(bool goingSlow) noexcept { - EndStopHit e = Stopped(); + bool b = Stopped(); if (misc.parts.probingAway) { - e = (e == EndStopHit::atStop) ? EndStopHit::noStop : EndStopHit::atStop; + b = !b; } EndstopHitDetails rslt; // initialised by default constructor - switch (e) + if (b) { - case EndStopHit::atStop: rslt.SetAction(EndstopHitAction::stopAll); rslt.isZProbe = true; - break; - - case EndStopHit::nearStop: - if (!goingSlow) - { - rslt.SetAction(EndstopHitAction::reduceSpeed); - } - break; - - default: - break; } return rslt; } diff --git a/src/Endstops/ZProbe.h b/src/Endstops/ZProbe.h index cf0144d3..23fe8116 100644 --- a/src/Endstops/ZProbe.h +++ b/src/Endstops/ZProbe.h @@ -28,7 +28,7 @@ public: virtual void HandleRemoteInputChange(CanAddress src, uint8_t handleMinor, bool newState) noexcept { } #endif - EndStopHit Stopped() const noexcept override; + bool Stopped() const noexcept override; EndstopHitDetails CheckTriggered(bool goingSlow) noexcept override; bool Acknowledge(EndstopHitDetails what) noexcept override; diff --git a/src/Endstops/ZProbeEndstop.cpp b/src/Endstops/ZProbeEndstop.cpp index 1771eceb..bd02d813 100644 --- a/src/Endstops/ZProbeEndstop.cpp +++ b/src/Endstops/ZProbeEndstop.cpp @@ -18,10 +18,10 @@ ZProbeEndstop::ZProbeEndstop(uint8_t p_axis, EndStopPosition pos) noexcept : End } // Test whether we are at or near the stop -EndStopHit ZProbeEndstop::Stopped() const noexcept +bool ZProbeEndstop::Stopped() const noexcept { const auto zp = reprap.GetPlatform().GetEndstops().GetZProbe(zProbeNumber); - return (zp.IsNotNull()) ? zp->Stopped() : EndStopHit::atStop; + return zp.IsNotNull() && zp->Stopped(); } // This is called to prime axis endstops @@ -41,9 +41,8 @@ bool ZProbeEndstop::Prime(const Kinematics& kin, const AxisDriversConfig& axisDr EndstopHitDetails ZProbeEndstop::CheckTriggered(bool goingSlow) noexcept { EndstopHitDetails rslt; // initialised by default constructor - switch (Stopped()) + if (Stopped()) { - case EndStopHit::atStop: rslt.SetAction((stopAll) ? EndstopHitAction::stopAll : EndstopHitAction::stopAxis); rslt.axis = GetAxis(); if (GetAtHighEnd()) @@ -54,17 +53,6 @@ EndstopHitDetails ZProbeEndstop::CheckTriggered(bool goingSlow) noexcept { rslt.setAxisLow = true; } - break; - - case EndStopHit::nearStop: - if (!goingSlow) - { - rslt.SetAction(EndstopHitAction::reduceSpeed); - } - break; - - default: - break; } return rslt; } @@ -73,7 +61,7 @@ EndstopHitDetails ZProbeEndstop::CheckTriggered(bool goingSlow) noexcept // Return true if we have finished with this endstop or probe in this move. bool ZProbeEndstop::Acknowledge(EndstopHitDetails what) noexcept { - return what.GetAction() != EndstopHitAction::reduceSpeed; + return true; } void ZProbeEndstop::AppendDetails(const StringRef& str) noexcept diff --git a/src/Endstops/ZProbeEndstop.h b/src/Endstops/ZProbeEndstop.h index 573105e1..f31778fe 100644 --- a/src/Endstops/ZProbeEndstop.h +++ b/src/Endstops/ZProbeEndstop.h @@ -19,7 +19,7 @@ public: ZProbeEndstop(uint8_t p_axis, EndStopPosition pos) noexcept; EndStopType GetEndstopType() const noexcept override { return EndStopType::zProbeAsEndstop; } - EndStopHit Stopped() const noexcept override; + bool Stopped() const noexcept override; bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) noexcept override; EndstopHitDetails CheckTriggered(bool goingSlow) noexcept override; bool Acknowledge(EndstopHitDetails what) noexcept override; diff --git a/src/GCodes/GCodes3.cpp b/src/GCodes/GCodes3.cpp index a30193e1..599caf83 100644 --- a/src/GCodes/GCodes3.cpp +++ b/src/GCodes/GCodes3.cpp @@ -508,7 +508,7 @@ GCodeResult GCodes::WaitForPin(GCodeBuffer& gb, const StringRef &reply) Platform& pfm = platform; const bool ok = endstopsToWaitFor.IterateWhile([&pfm, activeHigh](unsigned int axis, unsigned int)->bool { - const bool stopped = pfm.GetEndstops().Stopped(axis) == EndStopHit::atStop; + const bool stopped = pfm.GetEndstops().Stopped(axis); return stopped == activeHigh; } ) diff --git a/src/GCodes/GCodes4.cpp b/src/GCodes/GCodes4.cpp index 44fb7af8..3d1f0455 100644 --- a/src/GCodes/GCodes4.cpp +++ b/src/GCodes/GCodes4.cpp @@ -624,7 +624,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept doingManualBedProbe = true; // suspend the Z movement limit DoManualBedProbe(gb); } - else if (zp->Stopped() == EndStopHit::atStop) + else if (zp->Stopped()) { reprap.GetMove().heightMapLock.ReleaseWriter(); reprap.GetHeat().SuspendHeaters(false); @@ -910,7 +910,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept doingManualBedProbe = true; // suspend the Z movement limit DoManualBedProbe(gb); } - else if (zp->Stopped() == EndStopHit::atStop) // check for probe already triggered at start + else if (zp->Stopped()) // check for probe already triggered at start { // Z probe is already triggered at the start of the move, so abandon the probe and record an error reprap.GetHeat().SuspendHeaters(false); @@ -1200,7 +1200,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept else { const bool probingAway = sps.ProbingAway(); - const bool atStop = (zp->Stopped() == EndStopHit::atStop); + const bool atStop = zp->Stopped(); if (probingAway != atStop) { // Z probe is already in target state at the start of the move, so abandon the probe and signal an error if the type demands so diff --git a/src/GCodes/Trigger.cpp b/src/GCodes/Trigger.cpp index 49583d9b..7383e7e9 100644 --- a/src/GCodes/Trigger.cpp +++ b/src/GCodes/Trigger.cpp @@ -44,7 +44,7 @@ bool Trigger::Check() noexcept EndstopsManager& endstops = reprap.GetPlatform().GetEndstops(); endstopsMonitored.Iterate([this, &endstops, &triggered](unsigned int axis, unsigned int) { - const bool stopped = (endstops.Stopped(axis) == EndStopHit::atStop); + const bool stopped = endstops.Stopped(axis); if (stopped != endstopStates.IsBitSet(axis)) { if (stopped) diff --git a/src/RepRap.cpp b/src/RepRap.cpp index b6bf0d83..9ba74647 100644 --- a/src/RepRap.cpp +++ b/src/RepRap.cpp @@ -1606,7 +1606,7 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) con const size_t numTotalAxes = gCodes->GetTotalAxes(); for (size_t axis = 0; axis < numTotalAxes; axis++) { - if (platform->GetEndstops().Stopped(axis) == EndStopHit::atStop) + if (platform->GetEndstops().Stopped(axis)) { endstops |= (1u << axis); } |