Add Bézier Jerk Control option

This commit is contained in:
Scott Lahteine
2018-05-08 03:42:45 -05:00
parent bb352f9836
commit 7ee1ab4fd3
7 changed files with 1486 additions and 113 deletions

View File

@@ -55,6 +55,7 @@ extern Stepper stepper;
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
#define HAL_STEPPER_TIMER_RATE ((F_CPU) * 0.125)
// intRes = intIn1 * intIn2 >> 16
// uses:
@@ -62,16 +63,16 @@ extern Stepper stepper;
// r27 to store the byte 1 of the 24 bit result
#define MultiU16X8toH16(intRes, charIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %B2 \n\t" \
"movw %A0, r0 \n\t" \
"mul %A1, %A2 \n\t" \
"add %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \
"lsr r0 \n\t" \
"adc %A0, r26 \n\t" \
"adc %B0, r26 \n\t" \
"clr r1 \n\t" \
A("clr r26") \
A("mul %A1, %B2") \
A("movw %A0, r0") \
A("mul %A1, %A2") \
A("add %A0, r1") \
A("adc %B0, r26") \
A("lsr r0") \
A("adc %A0, r26") \
A("adc %B0, r26") \
A("clr r1") \
: \
"=&r" (intRes) \
: \
@@ -122,6 +123,16 @@ class Stepper {
static int32_t counter_X, counter_Y, counter_Z, counter_E;
static volatile uint32_t step_events_completed; // The number of step events executed in the current block
#if ENABLED(BEZIER_JERK_CONTROL)
static int32_t bezier_A, // A coefficient in Bézier speed curve
bezier_B, // B coefficient in Bézier speed curve
bezier_C; // C coefficient in Bézier speed curve
static uint32_t bezier_F, // F coefficient in Bézier speed curve
bezier_AV; // AV coefficient in Bézier speed curve
static bool A_negative, // If A coefficient was negative
bezier_2nd_half; // If Bézier curve has been initialized or not
#endif
#if ENABLED(LIN_ADVANCE)
static uint32_t LA_decelerate_after; // Copy from current executed block. Needed because current_block is set to NULL "too early".
@@ -145,8 +156,10 @@ class Stepper {
static int32_t acceleration_time, deceleration_time;
static uint8_t step_loops, step_loops_nominal;
static uint16_t OCR1A_nominal,
acc_step_rate; // needed for deceleration start point
static uint16_t OCR1A_nominal;
#if DISABLED(BEZIER_JERK_CONTROL)
static uint16_t acc_step_rate; // needed for deceleration start point
#endif
static volatile int32_t endstops_trigsteps[XYZ];
static volatile int32_t endstops_stepsTotal, endstops_stepsDone;
@@ -330,8 +343,8 @@ class Stepper {
private:
FORCE_INLINE static unsigned short calc_timer_interval(unsigned short step_rate) {
unsigned short timer;
FORCE_INLINE static uint16_t calc_timer_interval(uint16_t step_rate) {
uint16_t timer;
NOMORE(step_rate, MAX_STEP_FREQUENCY);
@@ -370,43 +383,10 @@ class Stepper {
return timer;
}
// Initialize the trapezoid generator from the current block.
// Called whenever a new block begins.
FORCE_INLINE static void trapezoid_generator_reset() {
static int8_t last_extruder = -1;
#if ENABLED(LIN_ADVANCE)
#if E_STEPPERS > 1
if (current_block->active_extruder != last_extruder) {
current_adv_steps = 0; // If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
LA_active_extruder = current_block->active_extruder;
}
#endif
if ((use_advance_lead = current_block->use_advance_lead)) {
LA_decelerate_after = current_block->decelerate_after;
final_adv_steps = current_block->final_adv_steps;
max_adv_steps = current_block->max_adv_steps;
}
#endif
if (current_block->direction_bits != last_direction_bits || current_block->active_extruder != last_extruder) {
last_direction_bits = current_block->direction_bits;
last_extruder = current_block->active_extruder;
set_directions();
}
deceleration_time = 0;
// step_rate to timer interval
OCR1A_nominal = calc_timer_interval(current_block->nominal_rate);
// make a note of the number of step loops required at nominal speed
step_loops_nominal = step_loops;
acc_step_rate = current_block->initial_rate;
acceleration_time = calc_timer_interval(acc_step_rate);
_NEXT_ISR(acceleration_time);
}
#if ENABLED(BEZIER_JERK_CONTROL)
static void _calc_bezier_curve_coeffs(const int32_t v0, const int32_t v1, const uint32_t av);
static int32_t _eval_bezier_curve(const uint32_t curr_step);
#endif
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
static void digipot_init();