Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update planner #27497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 46 additions & 42 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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
*/
Expand Down Expand Up @@ -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)
/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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*/
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
Loading
Loading