diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-07-19 17:26:19 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-07-19 17:26:19 +0300 |
commit | 32c87273e85297d2a02764e5454bca53eae57881 (patch) | |
tree | fd58f99134674553f8b4f89dd2cca6d6b2a36e75 /src/Movement | |
parent | 2860cf15465ee5a0dacb8309e8580744e649f776 (diff) |
Partial fixes to stopping drivers on main boards used as expansion
Diffstat (limited to 'src/Movement')
-rw-r--r-- | src/Movement/DDARing.cpp | 16 | ||||
-rw-r--r-- | src/Movement/DDARing.h | 1 | ||||
-rw-r--r-- | src/Movement/Move.cpp | 38 | ||||
-rw-r--r-- | src/Movement/Move.h | 7 |
4 files changed, 62 insertions, 0 deletions
diff --git a/src/Movement/DDARing.cpp b/src/Movement/DDARing.cpp index ed8d9e00..6e5a57d8 100644 --- a/src/Movement/DDARing.cpp +++ b/src/Movement/DDARing.cpp @@ -1020,6 +1020,22 @@ void DDARing::AddMoveFromRemote(const CanMessageMovementLinear& msg) noexcept } # endif + +void DDARing::StopDrivers(uint16_t whichDrives) noexcept +{ + const uint32_t oldPrio = ChangeBasePriority(NvicPriorityStep); + DDA *cdda = currentDda; // capture volatile + if (cdda != nullptr) + { + cdda->StopDrivers(whichDrives); + if (cdda->GetState() == DDA::completed) + { + CurrentMoveCompleted(); // tell the DDA ring that the current move is complete + } + } + RestoreBasePriority(oldPrio); +} + #endif // End diff --git a/src/Movement/DDARing.h b/src/Movement/DDARing.h index a9fd9a2f..46565a66 100644 --- a/src/Movement/DDARing.h +++ b/src/Movement/DDARing.h @@ -92,6 +92,7 @@ public: # else void AddMoveFromRemote(const CanMessageMovementLinear& msg) noexcept; // add a move from the ATE to the movement queue # endif + void StopDrivers(uint16_t whichDrives) noexcept; #endif protected: diff --git a/src/Movement/Move.cpp b/src/Movement/Move.cpp index 403f0a63..29f42402 100644 --- a/src/Movement/Move.cpp +++ b/src/Movement/Move.cpp @@ -1138,6 +1138,44 @@ GCodeResult Move::EutSetRemotePressureAdvance(const CanMessageMultipleDrivesRequ return rslt; } +void Move::RevertPosition(const CanMessageRevertPosition& msg) noexcept +{ + // Construct a MovementLinear message to revert the position. The move must be shorter than clocksAllowed. + // When writing this, clocksAllowed was equivalent to 40ms. + // We allow 10ms delay time to allow the motor to stop and reverse direction, 10ms acceleration time, 5ms steady time and 10ms deceleration time. + CanMessageMovementLinear msg2; + msg2.accelerationClocks = msg2.decelClocks = msg.clocksAllowed/4; + msg2.steadyClocks = msg.clocksAllowed/8; + msg2.whenToExecute = StepTimer::GetTimerTicks() + msg.clocksAllowed/4; + msg2.numDrivers = NumDirectDrivers; + msg2.pressureAdvanceDrives = 0; + msg2.seq = 0; + msg2.initialSpeedFraction = msg2.finalSpeedFraction = 0.0; + + size_t index = 0; + bool needSteps = false; + for (size_t driver = 0; driver < NumDirectDrivers; ++driver) + { + int32_t steps = 0; + if (msg.whichDrives & (1u << driver)) + { + const int32_t stepsWanted = msg.finalStepCounts[index++]; + const int32_t stepsTaken = lastMoveStepsTaken[driver]; + if (((stepsWanted >= 0 && stepsTaken > stepsWanted) || (stepsWanted <= 0 && stepsTaken < stepsWanted))) + { + steps = stepsWanted - stepsTaken; + needSteps = true; + } + } + msg2.perDrive[driver].steps = steps; + } + + if (needSteps) + { + AddMoveFromRemote(msg2); + } +} + #endif // Return the current live XYZ and extruder coordinates diff --git a/src/Movement/Move.h b/src/Movement/Move.h index 6007f9d1..d16b3e7e 100644 --- a/src/Movement/Move.h +++ b/src/Movement/Move.h @@ -214,6 +214,13 @@ public: MoveAvailable(); } # endif + + void StopDrivers(uint16_t whichDrives) noexcept + { + rings[0].StopDrivers(whichDrives); + } + + void RevertPosition(const CanMessageRevertPosition& msg) noexcept; #endif protected: |