diff --git a/src/modules/motion.cpp b/src/modules/motion.cpp index c603116..4f3ef10 100644 --- a/src/modules/motion.cpp +++ b/src/modules/motion.cpp @@ -62,9 +62,9 @@ bool Motion::QueueEmpty() const { return true; } -void Motion::AbortPlannedMoves() { +void Motion::AbortPlannedMoves(bool halt) { for (uint8_t i = 0; i != NUM_AXIS; ++i) - axisData[i].ctrl.AbortPlannedMoves(); + axisData[i].ctrl.AbortPlannedMoves(halt); } st_timer_t Motion::Step() { diff --git a/src/modules/motion.h b/src/modules/motion.h index cf3cf80..cd78ce2 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -240,7 +240,8 @@ public: bool Full(Axis axis) const { return axisData[axis].ctrl.Full(); } /// stop whatever moves are being done - void AbortPlannedMoves(); + /// @param halt When true, also abruptly stop axis movement. + void AbortPlannedMoves(bool halt = true); /// @returns the TMC213 driver associated with the particular axis inline const hal::tmc2130::TMC2130 &DriverForAxis(Axis axis) const { diff --git a/src/modules/pulse_gen.cpp b/src/modules/pulse_gen.cpp index 60cc075..a48a16f 100644 --- a/src/modules/pulse_gen.cpp +++ b/src/modules/pulse_gen.cpp @@ -136,15 +136,20 @@ pos_t PulseGen::CurPosition() const { return cur_pos; } -void PulseGen::AbortPlannedMoves() { +void PulseGen::AbortPlannedMoves(bool halt) { // always update to effective position position = CurPosition(); // destroy the current block if (current_block) { + last_rate = acc_step_rate; current_block = nullptr; block_index.pop(); } + + // truncate the last rate if halting + if (halt) + last_rate = 0; } } // namespace motor diff --git a/src/modules/pulse_gen.h b/src/modules/pulse_gen.h index e84fc9a..1322b05 100644 --- a/src/modules/pulse_gen.h +++ b/src/modules/pulse_gen.h @@ -44,7 +44,8 @@ public: bool PlanMoveTo(pos_t pos, steps_t feedrate); /// Stop whatever moves are being done - void AbortPlannedMoves(); + /// @param halt When true, also abruptly stop axis movement. + void AbortPlannedMoves(bool halt = true); /// @returns the head position of the axis at the end of all moves pos_t Position() const { return position; } diff --git a/tests/unit/logic/stubs/stub_motion.cpp b/tests/unit/logic/stubs/stub_motion.cpp index a6e13e2..4d9f506 100644 --- a/tests/unit/logic/stubs/stub_motion.cpp +++ b/tests/unit/logic/stubs/stub_motion.cpp @@ -65,7 +65,7 @@ bool Motion::QueueEmpty() const { return true; } -void Motion::AbortPlannedMoves() { +void Motion::AbortPlannedMoves(bool halt) { for (uint8_t i = 0; i < 3; ++i) { axes[i].targetPos = axes[i].pos; // leave the axis where it was at the time of abort }