PulseGen: complete implementation
parent
ed04bd02e2
commit
6f518f1ed2
|
|
@ -41,6 +41,9 @@ static constexpr uint16_t maxStepFrequency = 40000;
|
|||
/// Minimum stepping rate 120Hz
|
||||
static constexpr uint16_t minStepRate = 120;
|
||||
|
||||
/// Size for the motion planner block buffer size
|
||||
static constexpr uint8_t blockBufferSize = 2;
|
||||
|
||||
/// Idler configuration
|
||||
static constexpr AxisConfig idler = {
|
||||
.dirOn = true,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ PulseGen::PulseGen(steps_t max_jerk, steps_t acceleration) {
|
|||
this->acceleration = acceleration;
|
||||
|
||||
// Block buffer
|
||||
block_buffer_head = block_buffer_tail = 0;
|
||||
current_block = nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +93,7 @@ void PulseGen::CalculateTrapezoid(block_t *block, steps_t entry_speed, steps_t e
|
|||
|
||||
void PulseGen::Move(pos_t target, steps_t feed_rate) {
|
||||
// Prepare to set up new block
|
||||
block_t *block = &block_buffer[block_buffer_head];
|
||||
block_t *block = &block_buffer[block_index.back()];
|
||||
|
||||
block->steps = abs(target - position);
|
||||
|
||||
|
|
@ -113,17 +112,16 @@ void PulseGen::Move(pos_t target, steps_t feed_rate) {
|
|||
// Perform the trapezoid calculations
|
||||
CalculateTrapezoid(block, max_jerk, max_jerk);
|
||||
|
||||
// TODO: Move the buffer head
|
||||
//block_buffer_head++;
|
||||
|
||||
// Move forward
|
||||
block_index.push();
|
||||
position = target;
|
||||
}
|
||||
|
||||
st_timer_t PulseGen::Step(const MotorParams &motorParams) {
|
||||
if (!current_block) {
|
||||
// TODO: fetch next block
|
||||
if (!block_buffer_head)
|
||||
current_block = &block_buffer[block_buffer_head++];
|
||||
// fetch next block
|
||||
if (!block_index.empty())
|
||||
current_block = &block_buffer[block_index.front()];
|
||||
if (!current_block)
|
||||
return 0;
|
||||
|
||||
|
|
@ -136,9 +134,9 @@ st_timer_t PulseGen::Step(const MotorParams &motorParams) {
|
|||
acceleration_time = calc_timer(acc_step_rate, step_loops);
|
||||
steps_completed = 0;
|
||||
|
||||
// Set the nominal step loops to zero to indicate, that the timer value is not known yet.
|
||||
// That means, delay the initialization of nominal step rate and step loops until the steady
|
||||
// state is reached.
|
||||
// Set the nominal step loops to zero to indicate, that the timer value is not
|
||||
// known yet. That means, delay the initialization of nominal step rate and step
|
||||
// loops until the steady state is reached.
|
||||
step_loops_nominal = 0;
|
||||
}
|
||||
|
||||
|
|
@ -181,8 +179,8 @@ st_timer_t PulseGen::Step(const MotorParams &motorParams) {
|
|||
deceleration_time += timer;
|
||||
} else {
|
||||
if (!step_loops_nominal) {
|
||||
// Calculation of the steady state timer rate has been delayed to the 1st tick of the steady state to lower
|
||||
// the initial interrupt blocking.
|
||||
// Calculation of the steady state timer rate has been delayed to the 1st tick
|
||||
// of the steady state to lower the initial interrupt blocking.
|
||||
timer_nominal = calc_timer(uint16_t(current_block->nominal_rate), step_loops);
|
||||
step_loops_nominal = step_loops;
|
||||
}
|
||||
|
|
@ -192,6 +190,7 @@ st_timer_t PulseGen::Step(const MotorParams &motorParams) {
|
|||
// If current block is finished, reset pointer
|
||||
if (steps_completed >= current_block->steps) {
|
||||
current_block = nullptr;
|
||||
block_index.pop();
|
||||
}
|
||||
|
||||
return timer;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@
|
|||
#include <stdint.h>
|
||||
#include "speed_table.h"
|
||||
#include "../hal/tmc2130.h"
|
||||
#include "../hal/circular_buffer.h"
|
||||
|
||||
namespace modules {
|
||||
|
||||
/// Acceleration ramp and stepper pulse generator
|
||||
namespace pulse_gen {
|
||||
|
||||
using config::blockBufferSize;
|
||||
using speed_table::st_timer_t;
|
||||
typedef uint32_t steps_t; ///< Absolute step units
|
||||
typedef uint32_t rate_t; ///< Type for step rates
|
||||
|
|
@ -33,10 +35,10 @@ public:
|
|||
void SetPosition(pos_t x) { position = x; }
|
||||
|
||||
/// @returns true if all planned moves have been finished
|
||||
bool QueueEmpty() const;
|
||||
bool QueueEmpty() const { return block_index.empty(); }
|
||||
|
||||
/// @returns false if new moves can still be planned
|
||||
bool Full() const;
|
||||
bool Full() const { return block_index.full(); }
|
||||
|
||||
/// Single-step the axis
|
||||
/// @returns the interval for the next tick
|
||||
|
|
@ -60,10 +62,9 @@ private:
|
|||
};
|
||||
|
||||
// Block buffer parameters
|
||||
block_t block_buffer[2];
|
||||
block_t block_buffer[blockBufferSize];
|
||||
CircularIndex<uint8_t, blockBufferSize> block_index;
|
||||
block_t *current_block;
|
||||
uint8_t block_buffer_head;
|
||||
uint8_t block_buffer_tail;
|
||||
|
||||
// Axis data
|
||||
pos_t position; ///< Current axis position
|
||||
|
|
|
|||
Loading…
Reference in New Issue