diff --git a/src/modules/motion.h b/src/modules/motion.h index e2bd88d..cf3cf80 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -216,6 +216,14 @@ public: return axisData[axis].ctrl.SetJerk(max_jerk); } + /// Fetch the target rate of the last planned segment for the requested axis, or the + /// current effective rate when the move has been aborted. + /// @param axis axis affected + /// @returns last rate + steps_t Rate(Axis axis) const { + return axisData[axis].ctrl.Rate(); + } + /// State machine doing all the planning and stepping. Called by the stepping ISR. /// @returns the interval for the next tick st_timer_t Step(); diff --git a/src/modules/pulse_gen.cpp b/src/modules/pulse_gen.cpp index 449ff50..60cc075 100644 --- a/src/modules/pulse_gen.cpp +++ b/src/modules/pulse_gen.cpp @@ -6,6 +6,7 @@ namespace pulse_gen { PulseGen::PulseGen(steps_t max_jerk, steps_t acceleration) { // Axis status position = 0; + last_rate = 0; this->max_jerk = max_jerk; this->acceleration = acceleration; @@ -107,9 +108,10 @@ bool PulseGen::PlanMoveTo(pos_t target, steps_t feed_rate) { block->acceleration_rate = block->acceleration * (rate_t)((float)F_CPU / (F_CPU / config::stepTimerFrequencyDivider)); // Perform the trapezoid calculations - CalculateTrapezoid(block, max_jerk, max_jerk); + CalculateTrapezoid(block, entry_speed, end_rate); + last_rate = block->final_rate; - // Move forward + // Move forward and update the state block_index.push(); position = target; return true; diff --git a/src/modules/pulse_gen.h b/src/modules/pulse_gen.h index 9c10a38..e84fc9a 100644 --- a/src/modules/pulse_gen.h +++ b/src/modules/pulse_gen.h @@ -60,6 +60,10 @@ public: /// @param x position to set void SetPosition(pos_t x) { position = x; } + /// Fetch the target rate of the last planned segment, or the current effective rate + /// when the move has been aborted. + steps_t Rate() const { return last_rate; } + /// @returns true if all planned moves have been finished bool QueueEmpty() const { return block_index.empty(); } @@ -173,6 +177,7 @@ private: pos_t position; ///< Current axis position steps_t max_jerk; ///< Axis jerk (could be constant) steps_t acceleration; ///< Current axis acceleration + steps_t last_rate; ///< Target speed at the last junction // Step parameters rate_t acceleration_time, deceleration_time;