From 51f450f927453ef189bedfefc35546778ad7e3b4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 8 Oct 2023 11:48:42 +0200 Subject: [PATCH 1/2] Combine planner busy flag with other flags --- Firmware/planner.cpp | 8 +++----- Firmware/planner.h | 6 ++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index a0a5c103a1..1411d731b7 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -295,7 +295,7 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit // which corresponds to a maximum repeat frequency of 228.57 kHz. // This blocking is safe in the context of a 10kHz stepper driver interrupt // or a 115200 Bd serial line receive interrupt, which will not trigger faster than 12kHz. - if (! block->busy) { // Don't update variables if block is busy. + if (!(block->flag & BLOCK_FLAG_BUSY)) { // Don't update variables if block is busy. block->accelerate_until = accelerate_steps; block->decelerate_after = accelerate_steps+plateau_steps; block->initial_rate = initial_rate; @@ -726,7 +726,8 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate block_t *block = &block_buffer[block_buffer_head]; // Mark block as not busy (Not executed by the stepper interrupt, could be still tinkered with.) - block->busy = false; + // Also reset the block flag. + block->flag = 0; // Set sdlen for calculating sd position block->sdlen = 0; @@ -1101,9 +1102,6 @@ Having the real displacement of the head, we can calculate the total movement le } } - // Reset the block flag. - block->flag = 0; - if (plan_reset_next_e_sched) { // finally propagate a pending reset diff --git a/Firmware/planner.h b/Firmware/planner.h index aae4a4b21b..bec0031ce8 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -46,6 +46,9 @@ enum BlockFlag { BLOCK_FLAG_DDA_LOWRES = 8, // Block starts with Zeroed E counter BLOCK_FLAG_E_RESET = 16, + // Block is being executed by the stepper ISR + BLOCK_FLAG_BUSY = 32, + }; union dda_isteps_t @@ -104,7 +107,6 @@ typedef struct { uint32_t final_rate; // The minimal rate at exit uint32_t acceleration_steps_per_s2; // acceleration steps/sec^2 uint8_t fan_speed; // Print fan speed, ranges from 0 to 255 - volatile char busy; // Pre-calculated division for the calculate_trapezoid_for_block() routine to run faster. @@ -233,7 +235,7 @@ FORCE_INLINE block_t *plan_get_current_block() return(NULL); } block_t *block = &block_buffer[block_buffer_tail]; - block->busy = true; + block->flag |= BLOCK_FLAG_BUSY; return(block); } From 57e7618b31eaffa127f3a5024bb6f83e775505b9 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 8 Oct 2023 11:58:27 +0200 Subject: [PATCH 2/2] Compine planner use_advance_lead with other flags --- Firmware/planner.cpp | 20 ++++++++++---------- Firmware/planner.h | 4 ++-- Firmware/stepper.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 1411d731b7..09ef08c570 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -229,7 +229,7 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit #ifdef LIN_ADVANCE uint16_t final_adv_steps = 0; uint16_t max_adv_steps = 0; - if (block->use_advance_lead) { + if (block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) { final_adv_steps = final_rate * block->adv_comp; } #endif @@ -240,7 +240,7 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit if (accel_decel_steps < block->step_event_count.wide) { plateau_steps = block->step_event_count.wide - accel_decel_steps; #ifdef LIN_ADVANCE - if (block->use_advance_lead) + if (block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) max_adv_steps = block->nominal_rate * block->adv_comp; #endif } else { @@ -277,7 +277,7 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit } #ifdef LIN_ADVANCE - if (block->use_advance_lead) { + if (block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) { if(!accelerate_steps || !decelerate_steps) { // accelerate_steps=0: deceleration-only ramp, max_rate is effectively unused // decelerate_steps=0: acceleration-only ramp, max_rate _is_ final_rate @@ -1010,7 +1010,7 @@ Having the real displacement of the head, we can calculate the total movement le { accel = ceil(cs.retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 #ifdef LIN_ADVANCE - block->use_advance_lead = false; + block->flag &= ~BLOCK_FLAG_USE_ADVANCE_LEAD; #endif } else @@ -1025,10 +1025,10 @@ Having the real displacement of the head, we can calculate the total movement le * delta_mm[E_AXIS] >= 0 : Extruding or traveling, but _not_ retracting. * |delta_mm[Z_AXIS]| < 0.5 : Z is only moved for leveling (_not_ for priming) */ - block->use_advance_lead = extruder_advance_K > 0 - && delta_mm[E_AXIS] >= 0 - && fabs(delta_mm[Z_AXIS]) < 0.5; - if (block->use_advance_lead) { + if (extruder_advance_K > 0 + && delta_mm[E_AXIS] >= 0 + && fabs(delta_mm[Z_AXIS]) < 0.5) { + block->flag |= BLOCK_FLAG_USE_ADVANCE_LEAD; #ifdef LA_FLOWADJ // M221/FLOW should change uniformly the extrusion thickness float delta_e = (e - position_float[E_AXIS]) / extruder_multiplier[extruder]; @@ -1049,7 +1049,7 @@ Having the real displacement of the head, we can calculate the total movement le // no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print // 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. if (e_D_ratio > 3.0) - block->use_advance_lead = false; + block->flag &= ~BLOCK_FLAG_USE_ADVANCE_LEAD; else if (e_D_ratio > 0) { const uint32_t max_accel_steps_per_s2 = ceil(cs.max_jerk[E_AXIS] / (extruder_advance_K * e_D_ratio) * steps_per_mm); if (accel > max_accel_steps_per_s2) { @@ -1201,7 +1201,7 @@ Having the real displacement of the head, we can calculate the total movement le block->speed_factor = block->nominal_rate / block->nominal_speed; #ifdef LIN_ADVANCE - if (block->use_advance_lead) { + if (block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) { // calculate the compression ratio for the segment (the required advance steps are computed // during trapezoid planning) float adv_comp = extruder_advance_K * e_D_ratio * cs.axis_steps_per_mm[E_AXIS]; // (step/(mm/s)) diff --git a/Firmware/planner.h b/Firmware/planner.h index bec0031ce8..ed31618e6b 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -48,7 +48,8 @@ enum BlockFlag { BLOCK_FLAG_E_RESET = 16, // Block is being executed by the stepper ISR BLOCK_FLAG_BUSY = 32, - + // Whether the block uses LA + BLOCK_FLAG_USE_ADVANCE_LEAD = 64, }; union dda_isteps_t @@ -113,7 +114,6 @@ typedef struct { float speed_factor; #ifdef LIN_ADVANCE - bool use_advance_lead; // Whether the current block uses LA uint16_t advance_rate, // Step-rate for extruder speed max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!) final_adv_steps; // advance steps due to exit speed diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 2312fbfb8a..adb700296f 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -380,7 +380,7 @@ FORCE_INLINE void stepper_next_block() acceleration_time = calc_timer(acc_step_rate, step_loops); #ifdef LIN_ADVANCE - if (current_block->use_advance_lead) { + if (current_block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) { target_adv_steps = current_block->max_adv_steps; } e_steps = 0; @@ -841,7 +841,7 @@ FORCE_INLINE void isr() { _NEXT_ISR(timer); acceleration_time += timer; #ifdef LIN_ADVANCE - if (current_block->use_advance_lead) { + if (current_block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) { if (step_events_completed.wide <= (unsigned long int)step_loops) { la_state = ADV_INIT | ADV_ACC_VARY; if (e_extruding && current_adv_steps > target_adv_steps) @@ -870,7 +870,7 @@ FORCE_INLINE void isr() { deceleration_time += timer; #ifdef LIN_ADVANCE - if (current_block->use_advance_lead) { + if (current_block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) { if (step_events_completed.wide <= current_block->decelerate_after + step_loops) { target_adv_steps = current_block->final_adv_steps; la_state = ADV_INIT | ADV_ACC_VARY; @@ -888,7 +888,7 @@ FORCE_INLINE void isr() { step_loops_nominal = step_loops; #ifdef LIN_ADVANCE - if(current_block->use_advance_lead) { + if(current_block->flag & BLOCK_FLAG_USE_ADVANCE_LEAD) { // Due to E-jerk, there can be discontinuities in pressure state where an // acceleration or deceleration can be skipped or joined with the previous block. // If LA was not previously active, re-check the pressure level