Skip to content

Commit

Permalink
⚡️ Optimize Planner calculations (MarlinFirmware#24484)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrazier authored and jonootto committed Sep 9, 2024
1 parent d57bacc commit 0b38faf
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
// Use temp sensor 1 as a redundant sensor with sensor 0. If the readings
// from the two sensors differ too much the print will be aborted.
//#define TEMP_SENSOR_1_AS_REDUNDANT
#define MAX_REDUNDANT_TEMP_SENSOR_DIFF 10
#define TEMP_SENSOR_REDUNDANT_MAX_DIFF 10

#define TEMP_RESIDENCY_TIME 10 // (seconds) Time to wait for hotend to "settle" in M109
#define TEMP_WINDOW 1 // (°C) Temperature proximity for the "temperature reached" timer
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/wifi/M79.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@ void GcodeSuite::M79()
rtscheck.RTS_SndData((next_remain_time_update % 3600) / 60, PRINT_REMAIN_TIME_MIN_VP);
#endif
}
}
}
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dwin/dwin_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,4 @@ void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t pi
void DWIN_ICON_AnimationControl(uint16_t state);

void DWIN_ICON_SHOW_SRAM(uint16_t x,uint16_t y,uint16_t addr);
void DWIN_SHOW_MAIN_PIC();
void DWIN_SHOW_MAIN_PIC();
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dwin/e3v2/lcd_rts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,4 @@ char Parse_Only_Picture_Data(char* fileName, char * time, char * FilamentUsed, c
}while(1);
}
*/
////////////////////////////
////////////////////////////
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dwin/e3v2/lcd_rts.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ extern model_information_t model_information;
extern uint8_t gcodePicDataSendToDwin(char *, unsigned int , unsigned char , unsigned char );
extern uint8_t read_gcode_model_information(void);
extern char Parse_Only_Picture_Data(char* fileName,char * time, char * FilamentUsed, char * layerHeight);
#endif
#endif
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dwin/e3v2/ui_position.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,4 @@

#endif

#endif //E3S1_LASER_H
#endif //E3S1_LASER_H
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/fontdata/profont_22.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Fontname: ProFont22
Copyright: ProFont Distribution 2.2 Ñ Generated by Fontographer 4.1.5
Copyright: ProFont Distribution 2.2 Generated by Fontographer 4.1.5
Capital A Height: 14, '1' Height: 14
Calculated Max Values w=12 h=22 x= 6 y=12 dx=12 dy= 0 ascent=18 len=44
Font Bounding box w=12 h=21 x= 0 y=-4
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/AutoOffset.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,4 @@ bool probeByPress(xyz_float_t rdyPos_mm, float* outZ);
bool probeByTouch(xyz_float_t rdyPos_mm, float* outZ);
bool getZOffset(bool nozzleClr, bool runProByPress, bool runProByTouch, float* outOffset);
#endif
#endif
#endif
2 changes: 1 addition & 1 deletion Marlin/src/module/PressLeveled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,4 +855,4 @@ void doG212ExCmd(void)
clearNozzle(120, 200, 60, PA_FIL_LEN_MM);
}
}
#endif
#endif
48 changes: 30 additions & 18 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,22 +799,34 @@ void Planner::calculate_trapezoid_for_block(block_t * const block, const_float_t

const int32_t accel = block->acceleration_steps_per_s2;

// Steps required for acceleration, deceleration to/from nominal rate
uint32_t accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
decelerate_steps = FLOOR(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel));
// Steps between acceleration and deceleration, if any
int32_t plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps;

// Does accelerate_steps + decelerate_steps exceed step_event_count?
// Then we can't possibly reach the nominal rate, there will be no cruising.
// Use intersection_distance() to calculate accel / braking time in order to
// reach the final_rate exactly at the end of this block.
if (plateau_steps < 0) {
const float accelerate_steps_float = CEIL(intersection_distance(initial_rate, final_rate, accel, block->step_event_count));
accelerate_steps = _MIN(uint32_t(_MAX(accelerate_steps_float, 0)), block->step_event_count);
decelerate_steps = block->step_event_count - accelerate_steps;
plateau_steps = 0;

// Steps for acceleration, plateau and deceleration
int32_t plateau_steps = block->step_event_count;
uint32_t accelerate_steps = 0,
decelerate_steps = 0;

if (accel != 0) {
// Steps required for acceleration, deceleration to/from nominal rate
const float nominal_rate_sq = sq(float(block->nominal_rate));
float accelerate_steps_float = (nominal_rate_sq - sq(float(initial_rate))) * (0.5f / accel);
accelerate_steps = CEIL(accelerate_steps_float);
const float decelerate_steps_float = (nominal_rate_sq - sq(float(final_rate))) * (0.5f / accel);
decelerate_steps = decelerate_steps_float;

<<<<<<< HEAD
=======
// Steps between acceleration and deceleration, if any
plateau_steps -= accelerate_steps + decelerate_steps;

// Does accelerate_steps + decelerate_steps exceed step_event_count?
// Then we can't possibly reach the nominal rate, there will be no cruising.
// Calculate accel / braking time in order to reach the final_rate exactly
// at the end of this block.
if (plateau_steps < 0) {
accelerate_steps_float = CEIL((block->step_event_count + accelerate_steps_float - decelerate_steps_float) * 0.5f);
accelerate_steps = _MIN(uint32_t(_MAX(accelerate_steps_float, 0)), block->step_event_count);
decelerate_steps = block->step_event_count - accelerate_steps;

>>>>>>> fc0615fbd1 (⚡️ Optimize Planner calculations (#24484))
#if ENABLED(S_CURVE_ACCELERATION)
// We won't reach the cruising rate. Let's calculate the speed we will reach
cruise_rate = final_speed(initial_rate, accel, accelerate_steps);
Expand Down Expand Up @@ -1449,7 +1461,7 @@ void Planner::check_axes_activity() {
for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
const block_t * const block = &block_buffer[b];
if (NUM_AXIS_GANG(block->steps.x, || block->steps.y, || block->steps.z, || block->steps.i, || block->steps.j, || block->steps.k, || block->steps.u, || block->steps.v, || block->steps.w)) {
const float se = (float)block->steps.e / block->step_event_count * SQRT(block->nominal_speed_sqr); // mm/sec;
const float se = float(block->steps.e) / block->step_event_count * block->nominal_speed; // mm/sec
NOLESS(high, se);
}
}
Expand Down Expand Up @@ -2390,7 +2402,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
if (speed_factor < 1.0f) {
current_speed *= speed_factor;
block->nominal_rate *= speed_factor;
block->nominal_speed_sqr = block->nominal_speed_sqr * sq(speed_factor);
block->nominal_speed *= speed_factor;
}

// Compute and limit the acceleration rate for the trapezoid generator.
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ void Temperature::manage_heater() {

#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
// Make sure measured temperatures are close together
if (ABS(degHotend(0) - degHotendRedundant()) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
if (ABS(degHotend(0) - degHotendRedundant()) > TEMP_SENSOR_REDUNDANT_MAX_DIFF)
_temp_error(H_E0, PSTR(STR_REDUNDANCY), GET_TEXT(MSG_ERR_REDUNDANT_TEMP));
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/stm32f1/pins_CREALITY_S1.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,4 @@
#define SPINDLE_DIR_PIN PC0 // FET 4

#define LASER_SOFT_PWM_PIN PC0 //激光软PWM引脚
#endif
#endif
2 changes: 1 addition & 1 deletion Marlin/src/pins/stm32f1/pins_CREALITY_V3_GD303.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@

#define BEEPER_PIN PA5

#endif
#endif
2 changes: 1 addition & 1 deletion Marlin/src/pins/stm32f4/pins_CREALITY_S1_F401RC.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,4 @@
#define SPINDLE_DIR_PIN PC0 // FET 4

#define LASER_SOFT_PWM_PIN PC0 // Laser soft PWM pin
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
#ifdef USBCON
USB_DM = PA_11,
USB_DP = PA_12,
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
USB_OTG_FS_ID = PA_10,
USB_OTG_FS_DM = PA_11,
USB_OTG_FS_DP = PA_12,
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,4 @@ WEAK void SystemClock_Config(void)

#ifdef __cplusplus
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@ extern "C" {
#define SERIAL_PORT_HARDWARE_OPEN Serial2
#endif

#endif /* _VARIANT_ARDUINO_STM32_ */
#endif /* _VARIANT_ARDUINO_STM32_ */

0 comments on commit 0b38faf

Please sign in to comment.