From dff2104c960f232fcef2a8e5f9e0980abbe96a55 Mon Sep 17 00:00:00 2001 From: Andrew <18502096+classicrocker883@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:38:50 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Planner=20cosmetics=20(#27497)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/module/planner.cpp | 88 ++++++++++++++------------ Marlin/src/module/planner.h | 116 +++++++++++++++++++--------------- 2 files changed, 110 insertions(+), 94 deletions(-) diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 4c54b63d92..630557180b 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -135,8 +135,8 @@ uint8_t Planner::delay_before_delivering; // Delay block delivery so initi #if ENABLED(EDITABLE_STEPS_PER_UNIT) float Planner::mm_per_step[DISTINCT_AXES]; // (mm) Millimeters per step #else - constexpr float PlannerSettings::axis_steps_per_mm[DISTINCT_AXES]; - constexpr float Planner::mm_per_step[DISTINCT_AXES]; + constexpr float PlannerSettings::axis_steps_per_mm[DISTINCT_AXES], + Planner::mm_per_step[DISTINCT_AXES]; #endif planner_settings_t Planner::settings; // Initialized by settings.load @@ -179,8 +179,8 @@ uint32_t Planner::max_acceleration_steps_per_s2[DISTINCT_AXES]; // (steps/s^2) D #endif #if DISABLED(NO_VOLUMETRICS) + float Planner::volumetric_area_nominal = CIRCLE_AREA(float(DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5f); // Nominal cross-sectional area float Planner::filament_size[EXTRUDERS], // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder - Planner::volumetric_area_nominal = CIRCLE_AREA(float(DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5f), // Nominal cross-sectional area Planner::volumetric_multiplier[EXTRUDERS]; // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner #endif @@ -782,9 +782,9 @@ block_t* Planner::get_current_block() { * sqrt(block->acceleration_steps_per_s2 / 2). This is ensured through * minimum_planner_speed_sqr / min_entry_speed_sqr though note there's one * exception in recalculate_trapezoids(). - ** + * * ############ VERY IMPORTANT ############ - * NOTE that the PRECONDITION to call this function is that the block is + * NOTE: The PRECONDITION to call this function is that the block is * NOT BUSY and it is marked as RECALCULATE. That WARRANTIES the Stepper ISR * is not and will not use the block while we modify it. */ @@ -1542,7 +1542,7 @@ void Planner::check_axes_activity() { else if (z_full_fade >= z_fade_height) // Above the fade height? raw.z = z_full_fade; // Nothing more to unapply. else // Within the fade zone? - raw.z = z_no_fade / (1.0f - z_correction * inverse_z_fade_height); // Unapply the faded Z offset + raw.z = z_no_fade / (1.0f - z_correction * inverse_z_fade_height); // Unapply the faded Z offset #else raw.z = z_no_fade; #endif @@ -1570,11 +1570,14 @@ void Planner::check_axes_activity() { void Planner::quick_stop() { - // Remove all the queued blocks. Note that this function is NOT - // called from the Stepper ISR, so we must consider tail as readonly! - // that is why we set head to tail - But there is a race condition that - // must be handled: The tail could change between the read and the assignment - // so this must be enclosed in a critical section + /** + * Remove all the queued blocks. + * NOTE: This function is NOT called from the Stepper ISR, + * so we must consider tail as readonly! + * That is why we set head to tail - But there is a race condition that + * must be handled: The tail could change between the read and the assignment + * so this must be enclosed in a critical section + */ const bool was_enabled = stepper.suspend(); @@ -1703,9 +1706,9 @@ void Planner::synchronize() { while (busy()) idle(); } * @param target Target position in steps units * @param target_float Target position in direct (mm, degrees) units. * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm - * @param fr_mm_s (target) speed of the move - * @param extruder target extruder - * @param hints parameters to aid planner calculations + * @param fr_mm_s (Target) speed of the move + * @param extruder Target extruder + * @param hints Parameters to aid planner calculations * * @return true if movement was properly queued, false otherwise (if cleaning) */ @@ -1765,7 +1768,7 @@ bool Planner::_buffer_steps(const xyze_long_t &target } /** - * @brief Populate a block in preparation for insertion + * @brief Populate a block in preparation for insertion. * @details Populate the fields of a new linear movement block * that will be added to the queue and processed soon * by the Stepper ISR. @@ -1774,9 +1777,9 @@ bool Planner::_buffer_steps(const xyze_long_t &target * @param target Target position in steps units * @param target_float Target position in native mm * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm - * @param fr_mm_s (target) speed of the move - * @param extruder target extruder - * @param hints parameters to aid planner calculations + * @param fr_mm_s (Target) speed of the move + * @param extruder Target extruder + * @param hints Parameters to aid planner calculations * * @return true if movement is acceptable, false otherwise */ @@ -2195,9 +2198,11 @@ bool Planner::_populate_block( const float inverse_millimeters = 1.0f / block->millimeters; // Inverse millimeters to remove multiple divides - // Calculate inverse time for this move. No divide by zero due to previous checks. - // Example: At 120mm/s a 60mm move involving XYZ axes takes 0.5s. So this will give 2.0. - // Example 2: At 120°/s a 60° move involving only rotational axes takes 0.5s. So this will give 2.0. + /** + * Calculate inverse time for this move. No divide by zero due to previous checks. + * EXAMPLE: At 120mm/s a 60mm move involving XYZ axes takes 0.5s. So this will give 2.0. + * EXAMPLE: At 120°/s a 60° move involving only rotational axes takes 0.5s. So this will give 2.0. + */ float inverse_secs = inverse_millimeters * ( #if ALL(HAS_ROTATIONAL_AXES, INCH_MODE_SUPPORT) /** @@ -2766,8 +2771,8 @@ bool Planner::_populate_block( } // _populate_block() /** - * @brief Add a block to the buffer that just updates the position - * Supports LASER_SYNCHRONOUS_M106_M107 and LASER_POWER_SYNC power sync block buffer queueing. + * @brief Add a block to the buffer that just updates the position. + * @details Supports LASER_SYNCHRONOUS_M106_M107 and LASER_POWER_SYNC power sync block buffer queueing. * * @param sync_flag The sync flag to set, determining the type of sync the block will do */ @@ -2813,16 +2818,15 @@ void Planner::buffer_sync_block(const BlockFlagBit sync_flag/*=BLOCK_BIT_SYNC_PO } // buffer_sync_block() /** - * @brief Add a single linear movement - * - * @description Add a new linear movement to the buffer in axis units. - * Leveling and kinematics should be applied before calling this. + * @brief Add a single linear movement. + * @details Add a new linear movement to the buffer in axis units. + * Leveling and kinematics should be applied before calling this. * * @param abce Target position in mm and/or degrees * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm - * @param fr_mm_s (target) speed of the move - * @param extruder optional target extruder (otherwise active_extruder) - * @param hints optional parameters to aid planner calculations + * @param fr_mm_s (Target) speed of the move + * @param extruder Optional target extruder (otherwise active_extruder) + * @param hints Optional parameters to aid planner calculations * * @return false if no segment was queued due to cleaning, cold extrusion, full queue, etc. */ @@ -2944,14 +2948,14 @@ bool Planner::buffer_segment(const abce_pos_t &abce } // buffer_segment() /** - * Add a new linear movement to the buffer. - * The target is cartesian. It's translated to - * delta/scara if needed. + * @brief Add a new linear movement to the buffer. + * @details The target is cartesian. It's translated to + * delta/scara if needed. * - * cart - target position in mm or degrees - * fr_mm_s - (target) speed of the move (mm/s) - * extruder - optional target extruder (otherwise active_extruder) - * hints - optional parameters to aid planner calculations + * @param cart Target position in mm or degrees + * @param fr_mm_s (Target) speed of the move (mm/s) + * @param extruder Optional target extruder (otherwise active_extruder) + * @param hints Optional parameters to aid planner calculations */ bool Planner::buffer_line(const xyze_pos_t &cart, const_feedRate_t fr_mm_s , const uint8_t extruder/*=active_extruder*/ @@ -3233,7 +3237,7 @@ inline void limit_and_warn(float &val, const AxisEnum axis, FSTR_P const setting } /** - * For the specified 'axis' set the Maximum Acceleration to the given value (mm/s^2) + * For the specified 'axis' set the Maximum Acceleration to the given value (mm/s^2). * The value may be limited with warning feedback, if configured. * Calls refresh_acceleration_rates to precalculate planner terms in steps. * @@ -3257,7 +3261,7 @@ void Planner::set_max_acceleration(const AxisEnum axis, float inMaxAccelMMS2) { } /** - * For the specified 'axis' set the Maximum Feedrate to the given value (mm/s) + * For the specified 'axis' set the Maximum Feedrate to the given value (mm/s). * The value may be limited with warning feedback, if configured. * * This hard limit is applied as a block is being added to the planner queue. @@ -3279,7 +3283,7 @@ void Planner::set_max_feedrate(const AxisEnum axis, float inMaxFeedrateMMS) { #if ENABLED(CLASSIC_JERK) /** - * For the specified 'axis' set the Maximum Jerk (instant change) to the given value (mm/s) + * For the specified 'axis' set the Maximum Jerk (instant change) to the given value (mm/s). * The value may be limited with warning feedback, if configured. * * This hard limit is applied (to the block start speed) as the block is being added to the planner queue. @@ -3310,7 +3314,7 @@ void Planner::set_max_feedrate(const AxisEnum axis, float inMaxFeedrateMMS) { uint16_t Planner::block_buffer_runtime() { #ifdef __AVR__ // Protect the access to the variable. Only required for AVR, as - // any 32bit CPU offers atomic access to 32bit variables + // any 32bit CPU offers atomic access to 32bit variables const bool was_enabled = stepper.suspend(); #endif @@ -3332,7 +3336,7 @@ void Planner::set_max_feedrate(const AxisEnum axis, float inMaxFeedrateMMS) { void Planner::clear_block_buffer_runtime() { #ifdef __AVR__ // Protect the access to the variable. Only required for AVR, as - // any 32bit CPU offers atomic access to 32bit variables + // any 32bit CPU offers atomic access to 32bit variables const bool was_enabled = stepper.suspend(); #endif diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index 5b37d7fdda..64381350cc 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -337,8 +337,8 @@ constexpr uint8_t block_inc_mod(const uint8_t v1, const uint8_t v2) { #endif typedef struct PlannerSettings { - uint32_t max_acceleration_mm_per_s2[DISTINCT_AXES], // (mm/s^2) M201 XYZE - min_segment_time_us; // (µs) M205 B + uint32_t max_acceleration_mm_per_s2[DISTINCT_AXES]; // (mm/s^2) M201 XYZE + uint32_t min_segment_time_us; // (µs) M205 B // (steps) M92 XYZE - Steps per millimeter #if ENABLED(EDITABLE_STEPS_PER_UNIT) @@ -356,12 +356,12 @@ typedef struct PlannerSettings { #undef _DLIM #endif - feedRate_t max_feedrate_mm_s[DISTINCT_AXES]; // (mm/s) M203 XYZE - Max speeds - float acceleration, // (mm/s^2) M204 S - Normal acceleration. DEFAULT ACCELERATION for all printing moves. - retract_acceleration, // (mm/s^2) M204 R - Retract acceleration. Filament pull-back and push-forward while standing still in the other axes - travel_acceleration; // (mm/s^2) M204 T - Travel acceleration. DEFAULT ACCELERATION for all NON printing moves. - feedRate_t min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate - min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate + feedRate_t max_feedrate_mm_s[DISTINCT_AXES]; // (mm/s) M203 XYZE - Max speeds + float acceleration, // (mm/s^2) M204 S - Normal acceleration. DEFAULT ACCELERATION for all printing moves. + retract_acceleration, // (mm/s^2) M204 R - Retract acceleration. Filament pull-back and push-forward while standing still in the other axes + travel_acceleration; // (mm/s^2) M204 T - Travel acceleration. DEFAULT ACCELERATION for all NON printing moves. + feedRate_t min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate + min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate } planner_settings_t; #if ENABLED(IMPROVE_HOMING_RELIABILITY) @@ -460,8 +460,8 @@ class Planner { #endif #if DISABLED(NO_VOLUMETRICS) + static float volumetric_area_nominal; // (mm^3) Nominal cross-sectional area static float filament_size[EXTRUDERS], // (mm) Diameter of filament, typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder - volumetric_area_nominal, // (mm^3) Nominal cross-sectional area volumetric_multiplier[EXTRUDERS]; // (1/mm^2) Reciprocal of cross-sectional area of filament. Pre-calculated to reduce computation in the planner // May be auto-adjusted by a filament width sensor #endif @@ -811,11 +811,12 @@ class Planner { FORCE_INLINE static uint8_t moves_free() { return (BLOCK_BUFFER_SIZE) - 1 - movesplanned(); } /** - * Planner::get_next_free_block + * @fn Planner::get_next_free_block * - * - Get the next head indices (passed by reference) - * - Wait for the number of spaces to open up in the planner - * - Return the first head block + * @details Get the next head indices (passed by reference) + * Wait for the number of spaces to open up in the planner + * + * @return The first head block */ FORCE_INLINE static block_t* get_next_free_block(uint8_t &next_buffer_head, const uint8_t count=1) { @@ -828,16 +829,18 @@ class Planner { } /** - * Planner::_buffer_steps + * @fn Planner::_buffer_steps * - * Add a new linear movement to the buffer (in terms of steps). + * @brief Add a new linear movement to the planner queue (in terms of steps). * - * target - target position in steps units - * fr_mm_s - (target) speed of the move - * extruder - target extruder - * hints - parameters to aid planner calculations + * @param target Target position in steps units + * @param target_float Target position in direct (mm, degrees) units. + * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm + * @param fr_mm_s (Target) speed of the move + * @param extruder Target extruder + * @param hints Parameters to aid planner calculations * - * Returns true if movement was buffered, false otherwise + * @return true if movement was properly queued, false otherwise (if cleaning) */ static bool _buffer_steps(const xyze_long_t &target OPTARG(HAS_POSITION_FLOAT, const xyze_pos_t &target_float) @@ -846,7 +849,9 @@ class Planner { ); /** - * @brief Populate a block in preparation for insertion + * @fn Planner::_populate_block + * + * @brief Populate a block in preparation for insertion. * @details Populate the fields of a new linear movement block * that will be added to the queue and processed soon * by the Stepper ISR. @@ -855,9 +860,9 @@ class Planner { * @param target Target position in steps units * @param target_float Target position in native mm * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm - * @param fr_mm_s (target) speed of the move - * @param extruder target extruder - * @param hints parameters to aid planner calculations + * @param fr_mm_s (Target) speed of the move + * @param extruder Target extruder + * @param hints Parameters to aid planner calculations * * @return true if movement is acceptable, false otherwise */ @@ -869,31 +874,31 @@ class Planner { ); /** - * Planner::buffer_sync_block - * Add a block to the buffer that just updates the position - * @param sync_flag sets a condition bit to process additional items - * such as sync fan pwm or sync M3/M4 laser power into a queued block + * @fn Planner::buffer_sync_block + * + * @brief Add a block to the buffer that just updates the position. + * @details Supports LASER_SYNCHRONOUS_M106_M107 and LASER_POWER_SYNC power sync block buffer queueing. + * + * @param sync_flag The sync flag to set, determining the type of sync the block will do + * Sets a condition bit to process additional items such as sync fan pwm + * or sync M3/M4 laser power into a queued block */ - static void buffer_sync_block(const BlockFlagBit flag=BLOCK_BIT_SYNC_POSITION); - - #if IS_KINEMATIC - private: - - // Allow do_homing_move to access internal functions, such as buffer_segment. - friend void do_homing_move(const AxisEnum, const float, const feedRate_t, const bool); - #endif + static void buffer_sync_block(const BlockFlagBit flag=BLOCK_BIT_SYNC_POSITION); /** - * Planner::buffer_segment + * @fn Planner::buffer_segment * - * Add a new linear movement to the buffer in axis units. + * @brief Add a single linear movement. + * @details Add a new linear movement to the buffer in axis units. + * Leveling and kinematics should be applied before calling this. * - * Leveling and kinematics should be applied ahead of calling this. + * @param abce Target position in mm and/or degrees + * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm + * @param fr_mm_s (Target) speed of the move + * @param extruder Optional target extruder (otherwise active_extruder) + * @param hints Optional parameters to aid planner calculations * - * a,b,c,e - target positions in mm and/or degrees - * fr_mm_s - (target) speed of the move - * extruder - optional target extruder (otherwise active_extruder) - * hints - optional parameters to aid planner calculations + * @return false if no segment was queued due to cleaning, cold extrusion, full queue, etc... */ static bool buffer_segment(const abce_pos_t &abce OPTARG(HAS_DIST_MM_ARG, const xyze_float_t &cart_dist_mm) @@ -902,17 +907,19 @@ class Planner { , const PlannerHints &hints=PlannerHints() ); - public: - /** - * Add a new linear movement to the buffer. - * The target is cartesian. It's translated to - * delta/scara if needed. + * @fn Planner::buffer_line * - * cart - target position in mm or degrees - * fr_mm_s - (target) speed of the move (mm/s) - * extruder - optional target extruder (otherwise active_extruder) - * hints - optional parameters to aid planner calculations + * @brief Add a new linear movement to the buffer. + * @details The target is cartesian. It's translated to + * delta/scara if needed. + * + * @param cart Target position in mm or degrees + * @param fr_mm_s (Target) speed of the move (mm/s) + * @param extruder Optional target extruder (otherwise active_extruder) + * @param hints Optional parameters to aid planner calculations + * + * @return false if no segment was queued due to cleaning, cold extrusion, full queue, etc... */ static bool buffer_line(const xyze_pos_t &cart, const_feedRate_t fr_mm_s , const uint8_t extruder=active_extruder @@ -1090,6 +1097,11 @@ class Planner { static void recalculate(const_float_t safe_exit_speed_sqr); + #if IS_KINEMATIC + // Allow do_homing_move to access internal functions, such as buffer_segment. + friend void do_homing_move(const AxisEnum, const float, const feedRate_t, const bool); + #endif + #if HAS_JUNCTION_DEVIATION FORCE_INLINE static void normalize_junction_vector(xyze_float_t &vector) {