This commit is contained in:
Alexandra Voinea 2025-08-26 01:09:39 -04:00 committed by GitHub
commit 173c13ea30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 22 deletions

View File

@ -221,7 +221,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
@ -232,7 +232,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 {
@ -269,7 +269,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
@ -287,7 +287,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;
@ -718,7 +718,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;
@ -956,7 +957,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
@ -971,10 +972,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];
@ -995,7 +996,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) {
@ -1048,9 +1049,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
@ -1150,7 +1148,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))

View File

@ -42,6 +42,10 @@ 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,
// Whether the block uses LA
BLOCK_FLAG_USE_ADVANCE_LEAD = 64,
};
union dda_isteps_t
@ -100,14 +104,12 @@ 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.
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
@ -208,7 +210,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);
}

View File

@ -369,7 +369,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;
@ -832,7 +832,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)
@ -861,7 +861,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;
@ -879,7 +879,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