PulseGen: perform an extra queue check in Move()

Since scheduling a move on a block which is being executed will jolt the
motors, be extra-safe and perform an extra lower-level check before
committing even if the caller is responsible.

Return the status, which can be useful to build a simple busy loop.
pull/47/head
Yuri D'Elia 2021-07-06 16:10:16 +02:00
parent bd8ae62211
commit 94f11642e0
2 changed files with 12 additions and 7 deletions

View File

@ -85,15 +85,18 @@ void PulseGen::CalculateTrapezoid(block_t *block, steps_t entry_speed, steps_t e
block->final_rate = final_rate; block->final_rate = final_rate;
} }
void PulseGen::Move(pos_t target, steps_t feed_rate) { bool PulseGen::Move(pos_t target, steps_t feed_rate) {
// Prepare to set up new block // Prepare to set up new block
if (block_index.full())
return false;
block_t *block = &block_buffer[block_index.back()]; block_t *block = &block_buffer[block_index.back()];
block->steps = abs(target - position);
// Bail if this is a zero-length block // Bail if this is a zero-length block
if (block->steps <= config::dropSegments) block->steps = abs(target - position);
return; if (block->steps <= config::dropSegments) {
// behave as-if the block as been scheduled
return true;
}
// Direction and speed for this block // Direction and speed for this block
block->direction = (target >= position); block->direction = (target >= position);
@ -109,6 +112,7 @@ void PulseGen::Move(pos_t target, steps_t feed_rate) {
// Move forward // Move forward
block_index.push(); block_index.push();
position = target; position = target;
return true;
} }
void PulseGen::AbortPlannedMoves() { void PulseGen::AbortPlannedMoves() {

View File

@ -28,8 +28,9 @@ public:
/// Set acceleration for the axis /// Set acceleration for the axis
void SetAcceleration(steps_t accel) { acceleration = accel; } void SetAcceleration(steps_t accel) { acceleration = accel; }
/// Plan a single move (can only be executed when !Full()) /// Plan a single move (can only be executed when not Full())
void Move(pos_t x, steps_t feed_rate); /// @returns True if the move has been planned
bool Move(pos_t x, steps_t feed_rate);
/// stop whatever moves are being done /// stop whatever moves are being done
void AbortPlannedMoves(); void AbortPlannedMoves();