Skip to content

Commit

Permalink
Renamed IS_ prefixes to _ISHAPING and shortened _inputshaping prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrazier committed Sep 29, 2022
1 parent 00713f8 commit e12a79d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
8 changes: 4 additions & 4 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,10 @@
//
#define INPUT_SHAPING
#if ENABLED(INPUT_SHAPING)
#define IS_FREQ_X 40 // (Hz) Resonant frequency.
#define IS_FREQ_Y 30 // (Hz) Resonant frequency.
#define IS_QUEUE_LENGTH_X 301 // Must be > steps/mm * maximum speed / IS_FREQ_X / 2.
#define IS_QUEUE_LENGTH_Y 401 // Must be > steps/mm * maximum speed / IS_FREQ_Y / 2.
#define ISHAPING_FREQ_X 40 // (Hz) Resonant frequency.
#define ISHAPING_FREQ_Y 40 // (Hz) Resonant frequency.
#define ISHAPING_QUEUE_LENGTH_X 301 // Must be > steps/mm * maximum speed / ISHAPING_FREQ_X / 2.
#define ISHAPING_QUEUE_LENGTH_Y 301 // Must be > steps/mm * maximum speed / ISHAPING_FREQ_Y / 2.
#endif

#define AXIS_RELATIVE_MODES { false, false, false, false }
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3719,10 +3719,10 @@

// Input shaping
#if ENABLED(INPUT_SHAPING)
#if IS_FREQ_X && IS_QUEUE_LENGTH_X
#if ISHAPING_FREQ_X && ISHAPING_QUEUE_LENGTH_X
#define INPUT_SHAPING_X
#endif
#if IS_FREQ_Y && IS_QUEUE_LENGTH_Y
#if ISHAPING_FREQ_Y && ISHAPING_QUEUE_LENGTH_Y
#define INPUT_SHAPING_Y
#endif
#endif
4 changes: 2 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4209,8 +4209,8 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
#endif

#if ENABLED(INPUT_SHAPING)
#if __AVR__ && (ENABLED(INPUT_SHAPING_X) && ((STEPPER_TIMER_RATE) > (IS_FREQ_X) * 2 * 65536) || \
ENABLED(INPUT_SHAPING_Y) && ((STEPPER_TIMER_RATE) > (IS_FREQ_Y) * 2 * 65536))
#if __AVR__ && (ENABLED(INPUT_SHAPING_X) && ((STEPPER_TIMER_RATE) > (ISHAPING_FREQ_X) * 2 * 65536) || \
ENABLED(INPUT_SHAPING_Y) && ((STEPPER_TIMER_RATE) > (ISHAPING_FREQ_Y) * 2 * 65536))
#error "Resonant frequency is below the minimum for AVR"
#endif
#endif
42 changes: 21 additions & 21 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ uint32_t Stepper::advance_divisor = 0,
#endif

#if ENABLED(INPUT_SHAPING_X)
DelayQueue<IS_QUEUE_LENGTH_X> Stepper::inputshaping_queue_x;
DelayQueue<ISHAPING_QUEUE_LENGTH_X> Stepper::ishaping_queue_x;
#endif
#if ENABLED(INPUT_SHAPING_Y)
DelayQueue<IS_QUEUE_LENGTH_Y> Stepper::inputshaping_queue_y;
DelayQueue<ISHAPING_QUEUE_LENGTH_Y> Stepper::ishaping_queue_y;
#endif

#if ENABLED(INTEGRATED_BABYSTEPPING)
Expand Down Expand Up @@ -1476,8 +1476,8 @@ void Stepper::isr() {

if (!nextMainISR) pulse_phase_isr(); // 0 = Do coordinated axes Stepper pulses

TERN_(INPUT_SHAPING_X, if (!inputshaping_queue_x.peek()) inputshaping_isr_x());
TERN_(INPUT_SHAPING_Y, if (!inputshaping_queue_y.peek()) inputshaping_isr_y());
TERN_(INPUT_SHAPING_X, if (!ishaping_queue_x.peek()) ishaping_isr_x());
TERN_(INPUT_SHAPING_Y, if (!ishaping_queue_y.peek()) ishaping_isr_y());

#if ENABLED(LIN_ADVANCE)
if (!nextAdvanceISR) { // 0 = Do Linear Advance E Stepper pulses
Expand Down Expand Up @@ -1507,12 +1507,12 @@ void Stepper::isr() {

// Get the interval to the next ISR call
const uint32_t interval = _MIN(
uint32_t(HAL_TIMER_TYPE_MAX), // Come back in a very long time
nextMainISR // Time until the next Pulse / Block phase
OPTARG(INPUT_SHAPING_X, inputshaping_queue_x.peek()) // Time until next input shaping echo for X
OPTARG(INPUT_SHAPING_Y, inputshaping_queue_y.peek()) // Time until next input shaping echo for Y
OPTARG(LIN_ADVANCE, nextAdvanceISR) // Come back early for Linear Advance?
OPTARG(INTEGRATED_BABYSTEPPING, nextBabystepISR) // Come back early for Babystepping?
uint32_t(HAL_TIMER_TYPE_MAX), // Come back in a very long time
nextMainISR // Time until the next Pulse / Block phase
OPTARG(INPUT_SHAPING_X, ishaping_queue_x.peek()) // Time until next input shaping echo for X
OPTARG(INPUT_SHAPING_Y, ishaping_queue_y.peek()) // Time until next input shaping echo for Y
OPTARG(LIN_ADVANCE, nextAdvanceISR) // Come back early for Linear Advance?
OPTARG(INTEGRATED_BABYSTEPPING, nextBabystepISR) // Come back early for Babystepping?
);

//
Expand All @@ -1523,8 +1523,8 @@ void Stepper::isr() {
//

nextMainISR -= interval;
TERN_(INPUT_SHAPING_X, inputshaping_queue_x.decrement_delays(interval));
TERN_(INPUT_SHAPING_Y, inputshaping_queue_y.decrement_delays(interval));
TERN_(INPUT_SHAPING_X, ishaping_queue_x.decrement_delays(interval));
TERN_(INPUT_SHAPING_Y, ishaping_queue_y.decrement_delays(interval));

#if ENABLED(LIN_ADVANCE)
if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
Expand Down Expand Up @@ -1788,8 +1788,8 @@ void Stepper::pulse_phase_isr() {
#endif // DIRECT_STEPPING

if (!is_page) {
TERN_(INPUT_SHAPING_X, inputshaping_queue_x.enqueue(inputshaping_delay_x));
TERN_(INPUT_SHAPING_Y, inputshaping_queue_y.enqueue(inputshaping_delay_y));
TERN_(INPUT_SHAPING_X, ishaping_queue_x.enqueue(ishaping_delay_x));
TERN_(INPUT_SHAPING_Y, ishaping_queue_y.enqueue(ishaping_delay_y));

// Determine if pulses are needed
#if HAS_X_STEP
Expand Down Expand Up @@ -1928,8 +1928,8 @@ void Stepper::pulse_phase_isr() {
}

#if ENABLED(INPUT_SHAPING_X)
void Stepper::inputshaping_isr_x() {
inputshaping_queue_x.dequeue();
void Stepper::ishaping_isr_x() {
ishaping_queue_x.dequeue();

// echo step behaviour
xyze_bool_t step_needed{0};
Expand All @@ -1949,8 +1949,8 @@ void Stepper::pulse_phase_isr() {
#endif

#if ENABLED(INPUT_SHAPING_Y)
void Stepper::inputshaping_isr_y() {
inputshaping_queue_y.dequeue();
void Stepper::ishaping_isr_y() {
ishaping_queue_y.dequeue();

// echo step behaviour
xyze_bool_t step_needed{0};
Expand Down Expand Up @@ -2046,10 +2046,10 @@ uint32_t Stepper::block_phase_isr() {
// If current block is finished, reset pointer and finalize state
if (step_events_completed >= step_event_count) {
// Only end block when input shaping echoes are complete and idle in the meantime
if (TERN0(INPUT_SHAPING_X, !inputshaping_queue_x.empty()) || TERN0(INPUT_SHAPING_Y, !inputshaping_queue_y.empty())) {
if (TERN0(INPUT_SHAPING_X, !ishaping_queue_x.empty()) || TERN0(INPUT_SHAPING_Y, !ishaping_queue_y.empty())) {
interval = 0;
TERN_(INPUT_SHAPING_X, NOLESS(interval, inputshaping_queue_x.peek_tail() + 1));
TERN_(INPUT_SHAPING_Y, NOLESS(interval, inputshaping_queue_y.peek_tail() + 1));
TERN_(INPUT_SHAPING_X, NOLESS(interval, ishaping_queue_x.peek_tail() + 1));
TERN_(INPUT_SHAPING_Y, NOLESS(interval, ishaping_queue_y.peek_tail() + 1));
}
else {
#if ENABLED(DIRECT_STEPPING)
Expand Down
36 changes: 18 additions & 18 deletions Marlin/src/module/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,29 +315,29 @@ constexpr ena_mask_t enable_overlap[] = {
#if ENABLED(INPUT_SHAPING)

#ifdef __AVR__
typedef uint16_t inputshaping_time_t;
typedef uint16_t ishaping_time_t;
#else
typedef uint32_t inputshaping_time_t;
typedef uint32_t ishaping_time_t;
#endif

template <int queue_length> class DelayQueue {
private:
inputshaping_time_t now = 0, times[queue_length];
uint16_t head = 0, tail = 0;
ishaping_time_t now = 0, times[queue_length];
uint16_t head = 0, tail = 0;

public:
void decrement_delays(const inputshaping_time_t interval) { now += interval; }
void enqueue(const inputshaping_time_t delay) {
void decrement_delays(const ishaping_time_t interval) { now += interval; }
void enqueue(const ishaping_time_t delay) {
times[tail] = now + delay;
if (++tail == queue_length) tail = 0;
}
inputshaping_time_t peek() {
ishaping_time_t peek() {
if (head != tail) return times[head] - now;
else return inputshaping_time_t(-1);
else return ishaping_time_t(-1);
}
inputshaping_time_t peek_tail() {
ishaping_time_t peek_tail() {
if (head != tail) return times[(tail + queue_length - 1) % queue_length] - now;
else return inputshaping_time_t(-1);
else return ishaping_time_t(-1);
}
void dequeue() { if (++head == queue_length) head = 0; }
void purge() { tail = head; }
Expand Down Expand Up @@ -451,12 +451,12 @@ class Stepper {
#endif

#if ENABLED(INPUT_SHAPING_X)
static DelayQueue<IS_QUEUE_LENGTH_X> inputshaping_queue_x;
static constexpr inputshaping_time_t inputshaping_delay_x = uint32_t(STEPPER_TIMER_RATE) / (IS_FREQ_X) / 2;
static DelayQueue<ISHAPING_QUEUE_LENGTH_X> ishaping_queue_x;
static constexpr ishaping_time_t ishaping_delay_x = uint32_t(STEPPER_TIMER_RATE) / (ISHAPING_FREQ_X) / 2;
#endif
#if ENABLED(INPUT_SHAPING_Y)
static DelayQueue<IS_QUEUE_LENGTH_Y> inputshaping_queue_y;
static constexpr inputshaping_time_t inputshaping_delay_y = uint32_t(STEPPER_TIMER_RATE) / (IS_FREQ_Y) / 2;
static DelayQueue<ISHAPING_QUEUE_LENGTH_Y> ishaping_queue_y;
static constexpr ishaping_time_t ishaping_delay_y = uint32_t(STEPPER_TIMER_RATE) / (ISHAPING_FREQ_Y) / 2;
#endif

#if ENABLED(LIN_ADVANCE)
Expand Down Expand Up @@ -519,10 +519,10 @@ class Stepper {
static uint32_t block_phase_isr();

#if ENABLED(INPUT_SHAPING_X)
static void inputshaping_isr_x();
static void ishaping_isr_x();
#endif
#if ENABLED(INPUT_SHAPING_Y)
static void inputshaping_isr_y();
static void ishaping_isr_y();
#endif

#if ENABLED(LIN_ADVANCE)
Expand Down Expand Up @@ -564,8 +564,8 @@ class Stepper {
axis_did_move = 0;
planner.release_current_block();
TERN_(LIN_ADVANCE, la_interval = nextAdvanceISR = LA_ADV_NEVER);
TERN_(INPUT_SHAPING_X, inputshaping_queue_x.purge());
TERN_(INPUT_SHAPING_Y, inputshaping_queue_y.purge());
TERN_(INPUT_SHAPING_X, ishaping_queue_x.purge());
TERN_(INPUT_SHAPING_Y, ishaping_queue_y.purge());
}

// Quickly stop all steppers
Expand Down

0 comments on commit e12a79d

Please sign in to comment.