PulseGen: store/return the last segment speed

pull/93/head
Yuri D'Elia 2021-08-29 17:32:21 +02:00 committed by DRracer
parent 60c83b0af2
commit d18143dff2
3 changed files with 17 additions and 2 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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;