From c8619f5b05f807f0ae4f5eb4ddece51b56a85abd Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:37:01 +0100 Subject: [PATCH 01/34] Update planner.c First experimental checkin for constant jerk motions --- planner.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/planner.c b/planner.c index 474aee0..19e1b65 100644 --- a/planner.c +++ b/planner.c @@ -355,6 +355,19 @@ static inline float limit_acceleration_by_axis_maximum (float *unit_vec) return limit_value; } +static inline float limit_jerk_by_axis_maximum (float *unit_vec) +{ + uint_fast8_t idx = N_AXIS; + float limit_value = SOME_LARGE_VALUE; + + do { + if (unit_vec[--idx] != 0.0f) // Avoid divide by zero. + limit_value = min(limit_value, fabsf(settings.axis[idx].jerk / unit_vec[idx])); + } while(idx); + + return limit_value; +} + static inline float limit_max_rate_by_axis_maximum (float *unit_vec) { uint_fast8_t idx = N_AXIS; @@ -469,7 +482,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) // behave as if its doing a G93 inverse time mode move. if(!block->condition.inverse_time && - !block->condition.rapid_motion && + !block->condition.rapid_motion &&el (motion.mask & settings.steppers.is_rotational.mask) && (motion.mask & ~settings.steppers.is_rotational.mask)) { @@ -493,7 +506,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) #endif // Calculate the unit vector of the line move and the block maximum feed rate and acceleration scaled - // down such that no individual axes maximum values are exceeded with respect to the line direction. + // down such that no individual axes maximum values are exceeded with respect to the line direction.l #if N_AXIS > 3 && ROTARY_FIX // NOTE: This calculation assumes all block motion axes are orthogonal (Cartesian), and if also rotational, then // motion mode must be inverse time mode. Operates on the absolute value of the unit vector. @@ -503,7 +516,8 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) #endif block->millimeters = convert_delta_vector_to_unit_vector(unit_vec); - block->acceleration = limit_acceleration_by_axis_maximum(unit_vec); + block->max_acceleration = limit_acceleration_by_axis_maximum(unit_vec); + block->jerk = limit_jerk_by_axis_maximum(unit_vec); block->rapid_rate = limit_max_rate_by_axis_maximum(unit_vec); // Store programmed rate. @@ -517,6 +531,11 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) if (block->condition.inverse_time) block->programmed_rate *= block->millimeters; } + // Calculate effective acceleration over block. Since jerk acceleration takes longer to execute due to ramp up and + // ramp down of the acceleration at the start and end of a ramp we need to adjust the acceleration value the planner + // uses so it still calculates reasonable entry and exit speeds. We do this by adding 2x the time it takes to reach + // full acceleration to the trapezoidal acceleration time and dividing the programmed rate by the value obtained. + block->acceleration = block->programmed_rate / ((block->programmed_rate / block->max_acceleration) + 2.0f * (block->max_acceleration / block->jerk)) // TODO: Need to check this method handling zero junction speeds when starting from rest. if ((block_buffer_head == block_buffer_tail) || (block->condition.system_motion)) { From f00347979ca5b901910926ce44b46ffe2174f7b2 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:37:55 +0100 Subject: [PATCH 02/34] Update planner.h First experimental checkin for constant jerk motions --- planner.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/planner.h b/planner.h index 185a88a..3b7c166 100644 --- a/planner.h +++ b/planner.h @@ -61,7 +61,9 @@ typedef struct plan_block { float entry_speed_sqr; // The current planned entry speed at block junction in (mm/min)^2 float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and // neighboring nominal speeds with overrides in (mm/min)^2 - float acceleration; // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. + float acceleration; // Effective acceleration over plannerblock calculated from trapezoidal movement plan. + float max_acceleration // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. + float jerk // Axis-limit adjusted jerk value in (mm/min^3). Does not change. float millimeters; // The remaining distance for this block to be executed in (mm). // NOTE: This value may be altered by stepper algorithm during execution. From 699e94391d88c68aa6923593c4f8e25269799b63 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:38:25 +0100 Subject: [PATCH 03/34] Update stepper.c First experimental checkin for constant jerk motions --- stepper.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/stepper.c b/stepper.c index 2a553f9..3c77649 100644 --- a/stepper.c +++ b/stepper.c @@ -891,6 +891,7 @@ void st_prep_buffer (void) float dt_max = DT_SEGMENT; // Maximum segment time float dt = 0.0f; // Initialize segment time float time_var = dt_max; // Time worker variable + float last_segment_accel = 0.0f; // Acceleration value of last computed segment. Initialize as 0.0 float mm_var; // mm - Distance worker variable float speed_var; // Speed worker variable float mm_remaining = pl_block->millimeters; // New segment distance from end of block. @@ -919,7 +920,14 @@ void st_prep_buffer (void) case Ramp_Accel: // NOTE: Acceleration ramp only computes during first do-while loop. - speed_var = pl_block->acceleration * time_var; + if (((mm_remaining - prep.accelerate_until) / (prep.current_speed + 1.0f)) <= (pl_block->max_acceleration / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp + // Check if we are on ramp up or ramp down. Ramp down if time to end of acceleration is less than time needed to reach 0 acceleration. + // Then limit acceleration change by jerk up to max acceleration and update for next segment. + last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, 0.0f); + } else { + last_segment_accel = min(last_segment_accel + pl_block->jerk * time_var, pl_block->max_acceleration); + } + speed_var = last_segment_accel * time_var; mm_remaining -= time_var * (prep.current_speed + 0.5f * speed_var); if (mm_remaining < prep.accelerate_until) { // End of acceleration ramp. // Acceleration-cruise, acceleration-deceleration ramp junction, or end of block. @@ -947,7 +955,14 @@ void st_prep_buffer (void) default: // case Ramp_Decel: // NOTE: mm_var used as a misc worker variable to prevent errors when near zero speed. - speed_var = pl_block->acceleration * time_var; // Used as delta speed (mm/min) + if (((prep.decelerate_after - mm_remaining) / (prep.current_speed + 1.0f)) <= (pl_block->max_acceleration / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp + // Check if we are on ramp up or ramp down. Ramp down if time to end of acceleration is less than time needed to reach 0 acceleration. + // Then limit acceleration change by jerk up to max acceleration and update for next segment. + last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, 0.0f); + } else { + last_segment_accel = min(last_segment_accel + pl_block->jerk * time_var, pl_block->max_acceleration); + } + speed_var = last_segment_accel * time_var; // Used as delta speed (mm/min) if (prep.current_speed > speed_var) { // Check if at or below zero speed. // Compute distance from end of segment to end of block. mm_var = mm_remaining - time_var * (prep.current_speed - 0.5f * speed_var); // (mm) From 2484538ade99943055a33dc51a6736f8b45640da Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:41:05 +0100 Subject: [PATCH 04/34] Update planner.c --- planner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner.c b/planner.c index 19e1b65..e26f89c 100644 --- a/planner.c +++ b/planner.c @@ -482,7 +482,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) // behave as if its doing a G93 inverse time mode move. if(!block->condition.inverse_time && - !block->condition.rapid_motion &&el + !block->condition.rapid_motion && (motion.mask & settings.steppers.is_rotational.mask) && (motion.mask & ~settings.steppers.is_rotational.mask)) { From 4c3cf5eac3e2514032a46a2a4cbb6e3323744746 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:17:02 +0100 Subject: [PATCH 05/34] Added Axis settings for jerk --- config.h | 29 +++++++++++++++++++++++++++++ settings.c | 9 +++++++++ settings.h | 3 ++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index d013d2c..09c2d5b 100644 --- a/config.h +++ b/config.h @@ -1823,6 +1823,35 @@ Timezone offset from UTC in hours, allowed range is -12.0 - 12.0. #endif ///@} +/*! @name 12x - Setting_AxisJerk +*/ +///@{ +#if !defined DEFAULT_X_JERK|| defined __DOXYGEN__ +#define DEFAULT_X_Jerk 100.0f // mm/sec^2 +#endif +#if !defined DEFAULT_Y_JERK|| defined __DOXYGEN__ +#define DEFAULT_Y_JERK 100.0f // mm/sec^2 +#endif +#if !defined DEFAULT_Z_JERK || defined __DOXYGEN__ +#define DEFAULT_Z_JERK 100.0f // mm/sec^2 +#endif +#if (defined A_AXIS && !defined DEFAULT_A_JERK) || defined __DOXYGEN__ +#define DEFAULT_A_JERK 100.0f // mm/sec^2 +#endif +#if (defined B_AXIS && !defined DEFAULT_B_JERK) || defined __DOXYGEN__ +#define DEFAULT_B_JERK 100.0f // mm/sec^2 +#endif +#if (defined C_AXIS && !defined DEFAULT_C_JERK) || defined __DOXYGEN__ +#define DEFAULT_C_JERK 100.0f // mm/sec^2 +#endif +#if (defined U_AXIS && !defined DEFAULT_U_JERK) || defined __DOXYGEN__ +#define DEFAULT_U_JERK 100.0f // mm/sec^2 +#endif +#if (defined V_AXIS && !defined DEFAULT_V_JERK) || defined __DOXYGEN__ +#define DEFAULT_V_JERK 100.0f // mm/sec^2 +#endif +///@} + /*! @name 13x - Setting_AxisMaxTravel __NOTE:__ Must be a positive values. */ diff --git a/settings.c b/settings.c index 6e3099f..d37454a 100644 --- a/settings.c +++ b/settings.c @@ -202,6 +202,7 @@ PROGMEM const settings_t defaults = { .axis[X_AXIS].steps_per_mm = DEFAULT_X_STEPS_PER_MM, .axis[X_AXIS].max_rate = DEFAULT_X_MAX_RATE, .axis[X_AXIS].acceleration = (DEFAULT_X_ACCELERATION * 60.0f * 60.0f), + .axis[X_AXIS].jerk = (DEFAULT_X_JERK * 60.0f * 60.0f * 60f), .axis[X_AXIS].max_travel = (-DEFAULT_X_MAX_TRAVEL), .axis[X_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -212,6 +213,7 @@ PROGMEM const settings_t defaults = { .axis[Y_AXIS].max_rate = DEFAULT_Y_MAX_RATE, .axis[Y_AXIS].max_travel = (-DEFAULT_Y_MAX_TRAVEL), .axis[Y_AXIS].acceleration = (DEFAULT_Y_ACCELERATION * 60.0f * 60.0f), + .axis[Y_AXIS].jerk = (DEFAULT_Y_JERK * 60.0f * 60.0f * 60f), .axis[Y_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION .axis[Y_AXIS].backlash = 0.0f, @@ -220,6 +222,7 @@ PROGMEM const settings_t defaults = { .axis[Z_AXIS].steps_per_mm = DEFAULT_Z_STEPS_PER_MM, .axis[Z_AXIS].max_rate = DEFAULT_Z_MAX_RATE, .axis[Z_AXIS].acceleration = (DEFAULT_Z_ACCELERATION * 60.0f * 60.0f), + .axis[Z_AXIS].jerk = (DEFAULT_Z_JERK * 60.0f * 60.0f * 60f), .axis[Z_AXIS].max_travel = (-DEFAULT_Z_MAX_TRAVEL), .axis[Z_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -230,6 +233,7 @@ PROGMEM const settings_t defaults = { .axis[A_AXIS].steps_per_mm = DEFAULT_A_STEPS_PER_MM, .axis[A_AXIS].max_rate = DEFAULT_A_MAX_RATE, .axis[A_AXIS].acceleration =(DEFAULT_A_ACCELERATION * 60.0f * 60.0f), + .axis[A_AXIS].jerk = (DEFAULT_A_JERK * 60.0f * 60.0f * 60f), .axis[A_AXIS].max_travel = (-DEFAULT_A_MAX_TRAVEL), .axis[A_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -242,6 +246,7 @@ PROGMEM const settings_t defaults = { .axis[B_AXIS].steps_per_mm = DEFAULT_B_STEPS_PER_MM, .axis[B_AXIS].max_rate = DEFAULT_B_MAX_RATE, .axis[B_AXIS].acceleration = (DEFAULT_B_ACCELERATION * 60.0f * 60.0f), + .axis[B_AXIS].jerk = (DEFAULT_B_JERK * 60.0f * 60.0f * 60f), .axis[B_AXIS].max_travel = (-DEFAULT_B_MAX_TRAVEL), .axis[B_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -253,6 +258,7 @@ PROGMEM const settings_t defaults = { #ifdef C_AXIS .axis[C_AXIS].steps_per_mm = DEFAULT_C_STEPS_PER_MM, .axis[C_AXIS].acceleration = (DEFAULT_C_ACCELERATION * 60.0f * 60.0f), + .axis[C_AXIS].jerk = (DEFAULT_C_JERK * 60.0f * 60.0f * 60f), .axis[C_AXIS].max_rate = DEFAULT_C_MAX_RATE, .axis[C_AXIS].max_travel = (-DEFAULT_C_MAX_TRAVEL), .axis[C_AXIS].dual_axis_offset = 0.0f, @@ -265,6 +271,7 @@ PROGMEM const settings_t defaults = { #ifdef U_AXIS .axis[U_AXIS].steps_per_mm = DEFAULT_U_STEPS_PER_MM, .axis[U_AXIS].acceleration = (DEFAULT_U_ACCELERATION * 60.0f * 60.0f), + .axis[U_AXIS].jerk = (DEFAULT_U_JERK * 60.0f * 60.0f * 60f), .axis[U_AXIS].max_rate = DEFAULT_U_MAX_RATE, .axis[U_AXIS].max_travel = (-DEFAULT_U_MAX_TRAVEL), .axis[U_AXIS].dual_axis_offset = 0.0f, @@ -276,6 +283,7 @@ PROGMEM const settings_t defaults = { #ifdef V_AXIS .axis[V_AXIS].steps_per_mm = DEFAULT_V_STEPS_PER_MM, .axis[V_AXIS].acceleration = (DEFAULT_V_ACCELERATION * 60.0f * 60.0f), + .axis[V_AXIS].jerk = (DEFAULT_V_JERK * 60.0f * 60.0f * 60f), .axis[V_AXIS].max_rate = DEFAULT_V_MAX_RATE, .axis[V_AXIS].max_travel = (-DEFAULT_V_MAX_TRAVEL), .axis[V_AXIS].dual_axis_offset = 0.0f, @@ -552,6 +560,7 @@ PROGMEM static const setting_detail_t setting_detail[] = { { Setting_AxisStepsPerMM, Group_Axis0, "-axis travel resolution", axis_steps, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisMaxRate, Group_Axis0, "-axis maximum rate", axis_rate, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisAcceleration, Group_Axis0, "-axis acceleration", axis_accel, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, + { Setting_AxisJerk, Group_Axis0, "-axis jerk", axis_jerk, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtended, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisMaxTravel, Group_Axis0, "-axis maximum travel", axis_dist, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, #if ENABLE_BACKLASH_COMPENSATION { Setting_AxisBacklash, Group_Axis0, "-axis backlash compensation", axis_dist, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtendedFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, diff --git a/settings.h b/settings.h index b30591d..7ab7a72 100644 --- a/settings.h +++ b/settings.h @@ -419,7 +419,7 @@ typedef enum { // Calculated base values for driver/plugin stepper settings Setting_AxisExtended0 = Setting_AxisSettingsBase2, Setting_AxisExtended1 = Setting_AxisSettingsBase2 + AXIS_SETTINGS_INCREMENT, - Setting_AxisExtended2 = Setting_AxisSettingsBase2 + 2 * AXIS_SETTINGS_INCREMENT, + Setting_AxisJerk = Setting_AxisSettingsBase2 + 2 * AXIS_SETTINGS_INCREMENT, Setting_AxisExtended3 = Setting_AxisSettingsBase2 + 3 * AXIS_SETTINGS_INCREMENT, Setting_AxisExtended4 = Setting_AxisSettingsBase2 + 4 * AXIS_SETTINGS_INCREMENT, Setting_AxisExtended5 = Setting_AxisSettingsBase2 + 5 * AXIS_SETTINGS_INCREMENT, @@ -630,6 +630,7 @@ typedef struct { float steps_per_mm; float max_rate; float acceleration; + float jerk; float max_travel; float dual_axis_offset; #if ENABLE_BACKLASH_COMPENSATION From 418e063b3599fbb9972740420e440fa79d93a45c Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 30 Oct 2023 22:08:46 +0100 Subject: [PATCH 06/34] Decel Ramp Calculations Updated --- planner.c | 2 +- stepper.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/planner.c b/planner.c index e26f89c..176d19a 100644 --- a/planner.c +++ b/planner.c @@ -506,7 +506,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) #endif // Calculate the unit vector of the line move and the block maximum feed rate and acceleration scaled - // down such that no individual axes maximum values are exceeded with respect to the line direction.l + // down such that no individual axes maximum values are exceeded with respect to the line direction. #if N_AXIS > 3 && ROTARY_FIX // NOTE: This calculation assumes all block motion axes are orthogonal (Cartesian), and if also rotational, then // motion mode must be inverse time mode. Operates on the absolute value of the unit vector. diff --git a/stepper.c b/stepper.c index 3c77649..4aa2008 100644 --- a/stepper.c +++ b/stepper.c @@ -955,8 +955,8 @@ void st_prep_buffer (void) default: // case Ramp_Decel: // NOTE: mm_var used as a misc worker variable to prevent errors when near zero speed. - if (((prep.decelerate_after - mm_remaining) / (prep.current_speed + 1.0f)) <= (pl_block->max_acceleration / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp - // Check if we are on ramp up or ramp down. Ramp down if time to end of acceleration is less than time needed to reach 0 acceleration. + if ((mm_remaining / (prep.current_speed + 1.0f)) <= (pl_block->max_acceleration / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp + // Check if we are on ramp up or ramp down. Ramp down if time to end of deceleration is less than time needed to reach 0 acceleration. // Then limit acceleration change by jerk up to max acceleration and update for next segment. last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, 0.0f); } else { From fb082f35812be462831ea476eb45544a5370b02e Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:49:33 +0100 Subject: [PATCH 07/34] added missing semicolons --- planner.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner.h b/planner.h index 3b7c166..a51f19e 100644 --- a/planner.h +++ b/planner.h @@ -62,8 +62,8 @@ typedef struct plan_block { float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and // neighboring nominal speeds with overrides in (mm/min)^2 float acceleration; // Effective acceleration over plannerblock calculated from trapezoidal movement plan. - float max_acceleration // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. - float jerk // Axis-limit adjusted jerk value in (mm/min^3). Does not change. + float max_acceleration; // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. + float jerk; // Axis-limit adjusted jerk value in (mm/min^3). Does not change. float millimeters; // The remaining distance for this block to be executed in (mm). // NOTE: This value may be altered by stepper algorithm during execution. From f00bb4d269275a87bdfcbdcca697568ecf56001b Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:01:51 +0100 Subject: [PATCH 08/34] Update planner.c missing semicolon --- planner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner.c b/planner.c index 176d19a..bfb92e8 100644 --- a/planner.c +++ b/planner.c @@ -535,7 +535,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) // ramp down of the acceleration at the start and end of a ramp we need to adjust the acceleration value the planner // uses so it still calculates reasonable entry and exit speeds. We do this by adding 2x the time it takes to reach // full acceleration to the trapezoidal acceleration time and dividing the programmed rate by the value obtained. - block->acceleration = block->programmed_rate / ((block->programmed_rate / block->max_acceleration) + 2.0f * (block->max_acceleration / block->jerk)) + block->acceleration = block->programmed_rate / ((block->programmed_rate / block->max_acceleration) + 2.0f * (block->max_acceleration / block->jerk)); // TODO: Need to check this method handling zero junction speeds when starting from rest. if ((block_buffer_head == block_buffer_tail) || (block->condition.system_motion)) { From b7969318296e94ab5134e1f4ac5aeccc28b4e1fe Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:05:22 +0100 Subject: [PATCH 09/34] Update settings.c bugfixing float variables --- settings.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/settings.c b/settings.c index d37454a..aad597d 100644 --- a/settings.c +++ b/settings.c @@ -202,8 +202,8 @@ PROGMEM const settings_t defaults = { .axis[X_AXIS].steps_per_mm = DEFAULT_X_STEPS_PER_MM, .axis[X_AXIS].max_rate = DEFAULT_X_MAX_RATE, .axis[X_AXIS].acceleration = (DEFAULT_X_ACCELERATION * 60.0f * 60.0f), - .axis[X_AXIS].jerk = (DEFAULT_X_JERK * 60.0f * 60.0f * 60f), - .axis[X_AXIS].max_travel = (-DEFAULT_X_MAX_TRAVEL), + .axis[X_AXIS].jerk = (DEFAULT_X_JERK * 60.0f * 60.0f * 60.0f), + .axis[X_AXIS].max_travel = (DEFAULT_X_MAX_TRAVEL), .axis[X_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION .axis[X_AXIS].backlash = 0.0f, @@ -213,7 +213,7 @@ PROGMEM const settings_t defaults = { .axis[Y_AXIS].max_rate = DEFAULT_Y_MAX_RATE, .axis[Y_AXIS].max_travel = (-DEFAULT_Y_MAX_TRAVEL), .axis[Y_AXIS].acceleration = (DEFAULT_Y_ACCELERATION * 60.0f * 60.0f), - .axis[Y_AXIS].jerk = (DEFAULT_Y_JERK * 60.0f * 60.0f * 60f), + .axis[Y_AXIS].jerk = (DEFAULT_Y_JERK * 60.0f * 60.0f * 60.0f), .axis[Y_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION .axis[Y_AXIS].backlash = 0.0f, @@ -222,7 +222,7 @@ PROGMEM const settings_t defaults = { .axis[Z_AXIS].steps_per_mm = DEFAULT_Z_STEPS_PER_MM, .axis[Z_AXIS].max_rate = DEFAULT_Z_MAX_RATE, .axis[Z_AXIS].acceleration = (DEFAULT_Z_ACCELERATION * 60.0f * 60.0f), - .axis[Z_AXIS].jerk = (DEFAULT_Z_JERK * 60.0f * 60.0f * 60f), + .axis[Z_AXIS].jerk = (DEFAULT_Z_JERK * 60.0f * 60.0f * 60.0f), .axis[Z_AXIS].max_travel = (-DEFAULT_Z_MAX_TRAVEL), .axis[Z_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -233,7 +233,7 @@ PROGMEM const settings_t defaults = { .axis[A_AXIS].steps_per_mm = DEFAULT_A_STEPS_PER_MM, .axis[A_AXIS].max_rate = DEFAULT_A_MAX_RATE, .axis[A_AXIS].acceleration =(DEFAULT_A_ACCELERATION * 60.0f * 60.0f), - .axis[A_AXIS].jerk = (DEFAULT_A_JERK * 60.0f * 60.0f * 60f), + .axis[A_AXIS].jerk = (DEFAULT_A_JERK * 60.0f * 60.0f * 60.0f), .axis[A_AXIS].max_travel = (-DEFAULT_A_MAX_TRAVEL), .axis[A_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -246,7 +246,7 @@ PROGMEM const settings_t defaults = { .axis[B_AXIS].steps_per_mm = DEFAULT_B_STEPS_PER_MM, .axis[B_AXIS].max_rate = DEFAULT_B_MAX_RATE, .axis[B_AXIS].acceleration = (DEFAULT_B_ACCELERATION * 60.0f * 60.0f), - .axis[B_AXIS].jerk = (DEFAULT_B_JERK * 60.0f * 60.0f * 60f), + .axis[B_AXIS].jerk = (DEFAULT_B_JERK * 60.0f * 60.0f * 60.0f), .axis[B_AXIS].max_travel = (-DEFAULT_B_MAX_TRAVEL), .axis[B_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -258,7 +258,7 @@ PROGMEM const settings_t defaults = { #ifdef C_AXIS .axis[C_AXIS].steps_per_mm = DEFAULT_C_STEPS_PER_MM, .axis[C_AXIS].acceleration = (DEFAULT_C_ACCELERATION * 60.0f * 60.0f), - .axis[C_AXIS].jerk = (DEFAULT_C_JERK * 60.0f * 60.0f * 60f), + .axis[C_AXIS].jerk = (DEFAULT_C_JERK * 60.0f * 60.0f * 60.0f), .axis[C_AXIS].max_rate = DEFAULT_C_MAX_RATE, .axis[C_AXIS].max_travel = (-DEFAULT_C_MAX_TRAVEL), .axis[C_AXIS].dual_axis_offset = 0.0f, @@ -271,7 +271,7 @@ PROGMEM const settings_t defaults = { #ifdef U_AXIS .axis[U_AXIS].steps_per_mm = DEFAULT_U_STEPS_PER_MM, .axis[U_AXIS].acceleration = (DEFAULT_U_ACCELERATION * 60.0f * 60.0f), - .axis[U_AXIS].jerk = (DEFAULT_U_JERK * 60.0f * 60.0f * 60f), + .axis[U_AXIS].jerk = (DEFAULT_U_JERK * 60.0f * 60.0f * 60.0f), .axis[U_AXIS].max_rate = DEFAULT_U_MAX_RATE, .axis[U_AXIS].max_travel = (-DEFAULT_U_MAX_TRAVEL), .axis[U_AXIS].dual_axis_offset = 0.0f, @@ -283,7 +283,7 @@ PROGMEM const settings_t defaults = { #ifdef V_AXIS .axis[V_AXIS].steps_per_mm = DEFAULT_V_STEPS_PER_MM, .axis[V_AXIS].acceleration = (DEFAULT_V_ACCELERATION * 60.0f * 60.0f), - .axis[V_AXIS].jerk = (DEFAULT_V_JERK * 60.0f * 60.0f * 60f), + .axis[V_AXIS].jerk = (DEFAULT_V_JERK * 60.0f * 60.0f * 60.0f), .axis[V_AXIS].max_rate = DEFAULT_V_MAX_RATE, .axis[V_AXIS].max_travel = (-DEFAULT_V_MAX_TRAVEL), .axis[V_AXIS].dual_axis_offset = 0.0f, From 9951e03833e86e40962c6eea8f8be7d8b5a7ffe6 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:08:14 +0100 Subject: [PATCH 10/34] Update config.h DEFAULT_X_JERK capitalization --- config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.h b/config.h index 09c2d5b..65f628b 100644 --- a/config.h +++ b/config.h @@ -1827,7 +1827,7 @@ Timezone offset from UTC in hours, allowed range is -12.0 - 12.0. */ ///@{ #if !defined DEFAULT_X_JERK|| defined __DOXYGEN__ -#define DEFAULT_X_Jerk 100.0f // mm/sec^2 +#define DEFAULT_X_JERK 100.0f // mm/sec^2 #endif #if !defined DEFAULT_Y_JERK|| defined __DOXYGEN__ #define DEFAULT_Y_JERK 100.0f // mm/sec^2 From 06ac1ead8a375dbc741e30a385997ab01f0ee276 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 2 Nov 2023 19:27:18 +0100 Subject: [PATCH 11/34] Update settings.c static char added for axis_jerk --- settings.c | 1 + 1 file changed, 1 insertion(+) diff --git a/settings.c b/settings.c index aad597d..321473e 100644 --- a/settings.c +++ b/settings.c @@ -434,6 +434,7 @@ static char spindle_types[100] = ""; static char axis_dist[4] = "mm"; static char axis_rate[8] = "mm/min"; static char axis_accel[10] = "mm/sec^2"; +static char axis_jerk[15] = "mm/sec^3"; #if DELTA_ROBOT static char axis_steps[9] = "step/rev"; #else From f295c361d7085e9ba879301297a9fde2f8c467a2 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Fri, 15 Dec 2023 11:39:19 +0100 Subject: [PATCH 12/34] Update settings.c --- settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.c b/settings.c index 321473e..68c0701 100644 --- a/settings.c +++ b/settings.c @@ -203,7 +203,7 @@ PROGMEM const settings_t defaults = { .axis[X_AXIS].max_rate = DEFAULT_X_MAX_RATE, .axis[X_AXIS].acceleration = (DEFAULT_X_ACCELERATION * 60.0f * 60.0f), .axis[X_AXIS].jerk = (DEFAULT_X_JERK * 60.0f * 60.0f * 60.0f), - .axis[X_AXIS].max_travel = (DEFAULT_X_MAX_TRAVEL), + .axis[X_AXIS].max_travel = (-DEFAULT_X_MAX_TRAVEL), .axis[X_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION .axis[X_AXIS].backlash = 0.0f, From 92e750dc0596bee4700839f0733e86ad0c9a696b Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 18 Dec 2023 23:30:26 +0100 Subject: [PATCH 13/34] adjusted end of accel calculation --- stepper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stepper.c b/stepper.c index 4aa2008..121c5cc 100644 --- a/stepper.c +++ b/stepper.c @@ -920,7 +920,8 @@ void st_prep_buffer (void) case Ramp_Accel: // NOTE: Acceleration ramp only computes during first do-while loop. - if (((mm_remaining - prep.accelerate_until) / (prep.current_speed + 1.0f)) <= (pl_block->max_acceleration / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp + if (((mm_remaining - prep.accelerate_until) / (prep.current_speed + 1.0f)) <= (last_segment_accel / pl_block->jerk)) { + //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp // Check if we are on ramp up or ramp down. Ramp down if time to end of acceleration is less than time needed to reach 0 acceleration. // Then limit acceleration change by jerk up to max acceleration and update for next segment. last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, 0.0f); @@ -955,7 +956,8 @@ void st_prep_buffer (void) default: // case Ramp_Decel: // NOTE: mm_var used as a misc worker variable to prevent errors when near zero speed. - if ((mm_remaining / (prep.current_speed + 1.0f)) <= (pl_block->max_acceleration / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp + if ((mm_remaining / (prep.current_speed + 1.0f)) <= (last_segment_accel / pl_block->jerk)) { + //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp // Check if we are on ramp up or ramp down. Ramp down if time to end of deceleration is less than time needed to reach 0 acceleration. // Then limit acceleration change by jerk up to max acceleration and update for next segment. last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, 0.0f); From 2361610bda09520b02a5736008c7441860851a55 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Tue, 19 Dec 2023 01:28:41 +0100 Subject: [PATCH 14/34] cleaned up config and added settings description --- config.h | 18 +++++++++--------- settings.c | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/config.h b/config.h index 3c8fe6e..a0e6dc9 100644 --- a/config.h +++ b/config.h @@ -1831,32 +1831,32 @@ Timezone offset from UTC in hours, allowed range is -12.0 - 12.0. #endif ///@} -/*! @name 12x - Setting_AxisJerk +/*! @name 22x - Setting_AxisJerk */ ///@{ #if !defined DEFAULT_X_JERK|| defined __DOXYGEN__ -#define DEFAULT_X_JERK 100.0f // mm/sec^2 +#define DEFAULT_X_JERK 100.0f // mm/sec^3 #endif #if !defined DEFAULT_Y_JERK|| defined __DOXYGEN__ -#define DEFAULT_Y_JERK 100.0f // mm/sec^2 +#define DEFAULT_Y_JERK 100.0f // mm/sec^3 #endif #if !defined DEFAULT_Z_JERK || defined __DOXYGEN__ -#define DEFAULT_Z_JERK 100.0f // mm/sec^2 +#define DEFAULT_Z_JERK 100.0f // mm/sec^3 #endif #if (defined A_AXIS && !defined DEFAULT_A_JERK) || defined __DOXYGEN__ -#define DEFAULT_A_JERK 100.0f // mm/sec^2 +#define DEFAULT_A_JERK 100.0f // mm/sec^3 #endif #if (defined B_AXIS && !defined DEFAULT_B_JERK) || defined __DOXYGEN__ -#define DEFAULT_B_JERK 100.0f // mm/sec^2 +#define DEFAULT_B_JERK 100.0f // mm/sec^3 #endif #if (defined C_AXIS && !defined DEFAULT_C_JERK) || defined __DOXYGEN__ -#define DEFAULT_C_JERK 100.0f // mm/sec^2 +#define DEFAULT_C_JERK 100.0f // mm/sec^3 #endif #if (defined U_AXIS && !defined DEFAULT_U_JERK) || defined __DOXYGEN__ -#define DEFAULT_U_JERK 100.0f // mm/sec^2 +#define DEFAULT_U_JERK 100.0f // mm/sec^3 #endif #if (defined V_AXIS && !defined DEFAULT_V_JERK) || defined __DOXYGEN__ -#define DEFAULT_V_JERK 100.0f // mm/sec^2 +#define DEFAULT_V_JERK 100.0f // mm/sec^3 #endif ///@} diff --git a/settings.c b/settings.c index b7ab307..6156363 100644 --- a/settings.c +++ b/settings.c @@ -567,7 +567,7 @@ PROGMEM static const setting_detail_t setting_detail[] = { { Setting_AxisStepsPerMM, Group_Axis0, "-axis travel resolution", axis_steps, Format_Decimal, "#####0.000##", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisMaxRate, Group_Axis0, "-axis maximum rate", axis_rate, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisAcceleration, Group_Axis0, "-axis acceleration", axis_accel, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, - { Setting_AxisJerk, Group_Axis0, "-axis jerk", axis_jerk, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtended, set_axis_setting, get_float, NULL, AXIS_OPTS }, + { Setting_AxisJerk, Group_Axis0, "-axis jerk", axis_jerk, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtendedFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisMaxTravel, Group_Axis0, "-axis maximum travel", axis_dist, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, #if ENABLE_BACKLASH_COMPENSATION { Setting_AxisBacklash, Group_Axis0, "-axis backlash compensation", axis_dist, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtendedFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, @@ -757,6 +757,7 @@ PROGMEM static const setting_descr_t setting_descr[] = { { (setting_id_t)(Setting_AxisStepsPerMM + 1), "Travel resolution in steps per degree." }, // "Hack" to get correct description for rotary axes { Setting_AxisMaxRate, "Maximum rate. Used as G0 rapid rate." }, { Setting_AxisAcceleration, "Acceleration. Used for motion planning to not exceed motor torque and lose steps." }, + { Setting_AxisJerk, "Maximum rate of acceleration change - smoothes out acceleration profile up to max axis acceleration."}, { Setting_AxisMaxTravel, "Maximum axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." }, #if ENABLE_BACKLASH_COMPENSATION { Setting_AxisBacklash, "Backlash distance to compensate for." }, From 5bb5945ad8859a7bb91921481741aeec0acd84b7 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:17:46 +0100 Subject: [PATCH 15/34] added set_axis_setting functions for jerk settings --- settings.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/settings.c b/settings.c index 6156363..3bffc4d 100644 --- a/settings.c +++ b/settings.c @@ -1347,6 +1347,10 @@ static const char *set_axis_setting_unit (setting_id_t setting_id, uint_fast8_t unit = is_rotary ? "deg/sec^2" : "mm/sec^2"; break; + case Setting_AxisJerk: + unit = is_rotary ? "deg/sec^3" : "mm/sec^3"; + break; + case Setting_AxisMaxTravel: case Setting_AxisBacklash: unit = is_rotary ? "deg" : "mm"; @@ -1454,6 +1458,10 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) case Setting_AxisAcceleration: settings.axis[idx].acceleration = override_backup.acceleration[idx] = value * 60.0f * 60.0f; // Convert to mm/min^2 for grbl internal use. break; + + case Setting_AxisJerk: + settings.axis[idx].jerk = value * 60.0f * 60.0f *60.0f; // Convert to mm/min^3 for grbl internal use. + break; case Setting_AxisMaxTravel: if(settings.axis[idx].max_travel != -value) { @@ -1517,6 +1525,10 @@ static float get_float (setting_id_t setting) case Setting_AxisAcceleration: value = settings.axis[idx].acceleration / (60.0f * 60.0f); // Convert from mm/min^2 to mm/sec^2. break; + + case Setting_AxisJerk: + value = settings.axis[idx].acceleration / (60.0f * 60.0f * 60.0f); // Convert from mm/min^3 to mm/sec^3. + break; case Setting_AxisMaxTravel: value = -settings.axis[idx].max_travel; // Store as negative for grbl internal use. From 86672922490a233b87be5e3a9c960e1f2b4069f6 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:00:15 +0100 Subject: [PATCH 16/34] fixed typo --- settings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings.c b/settings.c index 3bffc4d..94f9e9a 100644 --- a/settings.c +++ b/settings.c @@ -1460,7 +1460,7 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) break; case Setting_AxisJerk: - settings.axis[idx].jerk = value * 60.0f * 60.0f *60.0f; // Convert to mm/min^3 for grbl internal use. + settings.axis[idx].jerk = value * 60.0f * 60.0f * 60.0f; // Convert to mm/min^3 for grbl internal use. break; case Setting_AxisMaxTravel: @@ -1527,7 +1527,7 @@ static float get_float (setting_id_t setting) break; case Setting_AxisJerk: - value = settings.axis[idx].acceleration / (60.0f * 60.0f * 60.0f); // Convert from mm/min^3 to mm/sec^3. + value = settings.axis[idx].jerk / (60.0f * 60.0f * 60.0f); // Convert from mm/min^3 to mm/sec^3. break; case Setting_AxisMaxTravel: From 04708e92ffffa635ac89aab61b48ae3d9e5d8611 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Tue, 19 Dec 2023 20:22:39 +0100 Subject: [PATCH 17/34] included extended axis setting in get_float check --- settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.c b/settings.c index 94f9e9a..48f296a 100644 --- a/settings.c +++ b/settings.c @@ -1508,7 +1508,7 @@ static float get_float (setting_id_t setting) { float value = 0.0f; - if (setting >= Setting_AxisSettingsBase && setting <= Setting_AxisSettingsMax) { + if (setting >= Setting_AxisSettingsBase && setting <= Setting_AxisSettingsMax2) { uint_fast8_t idx; From 5cbb222b68cb3de242e758677ff3d11d4102ae17 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Sat, 30 Dec 2023 19:44:48 +0100 Subject: [PATCH 18/34] Added Min/Max calculations for Jerk --- settings.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/settings.c b/settings.c index 97087e7..ff8ff61 100644 --- a/settings.c +++ b/settings.c @@ -759,7 +759,11 @@ PROGMEM static const setting_descr_t setting_descr[] = { { (setting_id_t)(Setting_AxisStepsPerMM + 1), "Travel resolution in steps per degree." }, // "Hack" to get correct description for rotary axes { Setting_AxisMaxRate, "Maximum rate. Used as G0 rapid rate." }, { Setting_AxisAcceleration, "Acceleration. Used for motion planning to not exceed motor torque and lose steps." }, - { Setting_AxisJerk, "Maximum rate of acceleration change - smoothes out acceleration profile up to max axis acceleration."}, + { Setting_AxisJerk, "Maximum rate of acceleration change - smoothes out acceleration profile up to max axis acceleration.\\n\\n" + "Minimum value of x10 Acceleration setting to ensure decent acceleration times.\\n" + "Maximum is calcualted by current acceleration and stepper segment time.\\n" + "At Maximum value motion is effectively trapezoidal instead of constant jerk.\\n\\n" + "Can be increased by adjusting ACCELERATION_TICKS_PER_SECOND to a larger value before compiling."}, { Setting_AxisMaxTravel, "Maximum axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." }, #if ENABLE_BACKLASH_COMPENSATION { Setting_AxisBacklash, "Backlash distance to compensate for." }, @@ -1459,10 +1463,16 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) case Setting_AxisAcceleration: settings.axis[idx].acceleration = override_backup.acceleration[idx] = value * 60.0f * 60.0f; // Convert to mm/min^2 for grbl internal use. + settings.axis[idx].jerk = (settings.axis[idx].acceleration * 10.0f * 60.0f); //reset jerk to axis minimum. break; case Setting_AxisJerk: - settings.axis[idx].jerk = value * 60.0f * 60.0f * 60.0f; // Convert to mm/min^3 for grbl internal use. + if ((value * 60.0f * 60.0f) < (settings.axis[idx].acceleration * 10.0f)) //ensuring that the acceleration time is limited to at maximum 100ms (or 10 stepper segments). + settings.axis[idx].jerk = settings.axis[idx].acceleration * 10.0f * 60.0f; // mm/min^2 -> mm/min^3 + else if ((settings.axis[idx].acceleration / (value * 60.0f * 60.0f * 60.0f)) < (1.0f / ACCELERATION_TICKS_PER_SECOND)) // Limit Jerk if Value is so large that it reverts back to trapezoidal. + settings.axis[idx].jerk = settings.axis[idx].acceleration * ACCELERATION_TICKS_PER_SECOND * 60.0f; // mm/min^2 -> mm/min^3 + else + settings.axis[idx].jerk = value * 60.0f * 60.0f * 60.0f; // Convert to mm/min^3 for grbl internal use. break; case Setting_AxisMaxTravel: From 4c28e420785c8e8e01b0e7b5fa19af3ba0a4681a Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:35:18 +0100 Subject: [PATCH 19/34] Implemented preliminary G187 support for up to 5 Profiles --- gcode.c | 18 ++++++++++++++++++ gcode.h | 3 ++- settings.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/gcode.c b/gcode.c index 07aad75..3d43f19 100644 --- a/gcode.c +++ b/gcode.c @@ -1130,6 +1130,13 @@ status_code_t gc_execute_block (char *block) gc_block.modal.scaling_active = int_value == 51; break; + case 187: + word_bit.modal_group.G0 = On; + gc_block.non_modal_command = (non_modal_t)int_value; + if(mantissa != 0) + FAIL(Status_GcodeUnsupportedCommand); + break; + default: FAIL(Status_GcodeUnsupportedCommand); // [Unsupported G command] } // end G-value switch @@ -2234,6 +2241,17 @@ status_code_t gc_execute_block (char *block) } while(idx); break; + case NonModal_SetAccelerationProfile: + uint_fast8_t idx = N_AXIS; + if (!gc_block.values.p) + gc_block.values.p = 1.0f; + else if (gc_block.values.p < 1.0f) + FAIL(Status_NegativeValue); + do { + idx--; + settings_override_acceleration(idx, (settings.axis[idx].acceleration * AccelerationProfile[gc_block.values.p]), (settings.axis[idx].jerk * AccelerationProfile[gc_block.values.p])); + } while(idx); + break; default: // At this point, the rest of the explicit axis commands treat the axis values as the traditional diff --git a/gcode.h b/gcode.h index a5ba6b6..3c19cb9 100644 --- a/gcode.h +++ b/gcode.h @@ -56,7 +56,8 @@ typedef enum { NonModal_SetCoordinateOffset = 92, //!< 92 - G92 NonModal_ResetCoordinateOffset = 102, //!< 102 - G92.1 NonModal_ClearCoordinateOffset = 112, //!< 112 - G92.2 - NonModal_RestoreCoordinateOffset = 122 //!< 122 - G92.3 + NonModal_RestoreCoordinateOffset = 122, //!< 122 - G92.3 + NonModal_SetAccelerationProfile = 187 //!< 187 - G187 } non_modal_t; /*! Modal Group G1: Motion modes diff --git a/settings.c b/settings.c index ff8ff61..faab20f 100644 --- a/settings.c +++ b/settings.c @@ -829,6 +829,7 @@ static setting_details_t setting_details = { static struct { bool valid; float acceleration[N_AXIS]; + float jerk[N_AXIS]; } override_backup = { .valid = false }; static void save_override_backup (void) @@ -838,6 +839,7 @@ static void save_override_backup (void) do { idx--; override_backup.acceleration[idx] = settings.axis[idx].acceleration; + override_backup.jerk[idx] = settings.axis[idx].jerk; } while(idx); override_backup.valid = true; @@ -850,12 +852,13 @@ static void restore_override_backup (void) if(override_backup.valid) do { idx--; settings.axis[idx].acceleration = override_backup.acceleration[idx]; + settings.axis[idx].jerk = override_backup.jerk[idx]; } while(idx); } // Temporarily override acceleration, if 0 restore to setting value. // Note: only allowed when current state is idle. -bool settings_override_acceleration (uint8_t axis, float acceleration) +bool settings_override_acceleration (uint8_t axis, float acceleration, float jerk) { sys_state_t state = state_get(); @@ -868,12 +871,32 @@ bool settings_override_acceleration (uint8_t axis, float acceleration) } else { if(!override_backup.valid) save_override_backup(); - settings.axis[axis].acceleration = acceleration * 60.0f * 60.0f; // Limit max to setting value? + settings.axis[axis].acceleration = (override_backup.acceleration[axis] >= (acceleration * 60.0f * 60.0f)) ? (acceleration * 60.0f * 60.0f) : override_backup.aceceleration[axis]; // Limited to max setting value + } + if(jerk <= 0.0f) { + if(override_backup.valid) + settings.axis[axis].jerk = override_backup.jerk[axis]; + } else { + if(!override_backup.valid) + save_override_backup(); + settings.axis[axis].jerk = (override_backup.jerk[axis] >= (jerk * 60.0f * 60.0f * 60.0f)) ? (jerk * 60.0f * 60.0f * 60.0f) : override_backup.jerk[axis]; // Limited to max setting value } - return true; } +//Acceleration Profiles for G187 P[x] in percent of maximum machine acceleration. +float AccelerationProfile(uint8_t Profile) { + static const float lookup[5] = { + 1.0f, // 100% - Roughing - Max Acceleration Default + 0.8f, // 80% - Semi Roughing + 0.6f, // 60% - Semi Finish + 0.4f, // 40% - Finish + 0.2f, // 20% - Slow AF Mode + }; + Profile = lookup[Profile]; + return Profile; +} + // --- static setting_details_t *settingsd = &setting_details; From 554812d5f13a27cc94c4d9ab5b03f1188b7b52e0 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:45:05 +0100 Subject: [PATCH 20/34] Unittype and Brackets Hotfix for G187 --- gcode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcode.c b/gcode.c index 3d43f19..fa49685 100644 --- a/gcode.c +++ b/gcode.c @@ -2242,16 +2242,19 @@ status_code_t gc_execute_block (char *block) break; case NonModal_SetAccelerationProfile: - uint_fast8_t idx = N_AXIS; if (!gc_block.values.p) gc_block.values.p = 1.0f; else if (gc_block.values.p < 1.0f) FAIL(Status_NegativeValue); + else if (gc_block.values.p > 5.0f) + FAIL(Status_GcodeValueOutOfRange); + uint8_t idx = N_AXIS; do { idx--; - settings_override_acceleration(idx, (settings.axis[idx].acceleration * AccelerationProfile[gc_block.values.p]), (settings.axis[idx].jerk * AccelerationProfile[gc_block.values.p])); + settings_override_acceleration(idx, (settings.axis[idx].acceleration * AccelerationProfile(gc_block.values.p)), (settings.axis[idx].jerk * AccelerationProfile(gc_block.values.p))); } while(idx); break; + default: // At this point, the rest of the explicit axis commands treat the axis values as the traditional From 299a7cd1aa241aef9983e9cfd98348a2ed301745 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Tue, 2 Jan 2024 16:20:59 +0100 Subject: [PATCH 21/34] Calculation adjustment for G187 --- gcode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcode.c b/gcode.c index fa49685..43b7dae 100644 --- a/gcode.c +++ b/gcode.c @@ -2251,10 +2251,10 @@ status_code_t gc_execute_block (char *block) uint8_t idx = N_AXIS; do { idx--; - settings_override_acceleration(idx, (settings.axis[idx].acceleration * AccelerationProfile(gc_block.values.p)), (settings.axis[idx].jerk * AccelerationProfile(gc_block.values.p))); + settings_override_acceleration(idx, ((settings.axis[idx].acceleration / (60.0f * 60.0f)) * AccelerationProfile(gc_block.values.p)), ((settings.axis[idx].jerk / (60.0f * 60.0f * 60.0f)) * AccelerationProfile(gc_block.values.p))); } while(idx); break; - + default: // At this point, the rest of the explicit axis commands treat the axis values as the traditional From dec93aa379f6026bdfb367bc467d145162faeeea Mon Sep 17 00:00:00 2001 From: andrew_marles Date: Tue, 2 Jan 2024 09:38:02 -0800 Subject: [PATCH 22/34] Fixed some typos and syntax errors. --- gcode.c | 12 ++++++------ settings.c | 2 +- settings.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gcode.c b/gcode.c index 43b7dae..27e6e76 100644 --- a/gcode.c +++ b/gcode.c @@ -2242,12 +2242,12 @@ status_code_t gc_execute_block (char *block) break; case NonModal_SetAccelerationProfile: - if (!gc_block.values.p) - gc_block.values.p = 1.0f; - else if (gc_block.values.p < 1.0f) - FAIL(Status_NegativeValue); - else if (gc_block.values.p > 5.0f) - FAIL(Status_GcodeValueOutOfRange); + if (!gc_block.values.p){ + gc_block.values.p = 1.0f;} + else if (gc_block.values.p < 1.0f){ + FAIL(Status_NegativeValue);} + else if (gc_block.values.p > 5.0f){ + FAIL(Status_GcodeValueOutOfRange);} uint8_t idx = N_AXIS; do { idx--; diff --git a/settings.c b/settings.c index faab20f..d5827ac 100644 --- a/settings.c +++ b/settings.c @@ -871,7 +871,7 @@ bool settings_override_acceleration (uint8_t axis, float acceleration, float jer } else { if(!override_backup.valid) save_override_backup(); - settings.axis[axis].acceleration = (override_backup.acceleration[axis] >= (acceleration * 60.0f * 60.0f)) ? (acceleration * 60.0f * 60.0f) : override_backup.aceceleration[axis]; // Limited to max setting value + settings.axis[axis].acceleration = (override_backup.acceleration[axis] >= (acceleration * 60.0f * 60.0f)) ? (acceleration * 60.0f * 60.0f) : override_backup.acceleration[axis]; // Limited to max setting value } if(jerk <= 0.0f) { if(override_backup.valid) diff --git a/settings.h b/settings.h index f5ecbc3..5868ffb 100644 --- a/settings.h +++ b/settings.h @@ -958,7 +958,7 @@ void settings_write_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS] bool settings_read_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS]); // Temporarily override acceleration, if 0 restore to configured setting value -bool settings_override_acceleration (uint8_t axis, float acceleration); +bool settings_override_acceleration (uint8_t axis, float acceleration, float jerk); void settings_register (setting_details_t *details); setting_details_t *settings_get_details (void); From 4cc7aaf171d0851ee2b9bf199499dd4fcccfbda2 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:30:18 +0100 Subject: [PATCH 23/34] Added compiletime check for added acceleration profile code --- config.h | 1 + gcode.c | 2 ++ gcode.h | 4 ++++ settings.c | 2 ++ 4 files changed, 9 insertions(+) diff --git a/config.h b/config.h index c5fbb7a..f4ad7bf 100644 --- a/config.h +++ b/config.h @@ -190,6 +190,7 @@ or EMI triggering the related interrupt falsely or too many times. // ADVANCED CONFIGURATION OPTIONS: #define ENABLE_PATH_BLENDING Off // Do NOT enable unless working on adding this feature! +#define ENABLE_ACCELERATION_PROFILES Off // Enable to allow G-Code changeable acceleration profiles. // Enables code for debugging purposes. Not for general use and always in constant flux. //#define DEBUG // Uncomment to enable. Default disabled. diff --git a/gcode.c b/gcode.c index 27e6e76..b83490d 100644 --- a/gcode.c +++ b/gcode.c @@ -1130,12 +1130,14 @@ status_code_t gc_execute_block (char *block) gc_block.modal.scaling_active = int_value == 51; break; +#if ENABLE_ACCELERATION_PROFILES case 187: word_bit.modal_group.G0 = On; gc_block.non_modal_command = (non_modal_t)int_value; if(mantissa != 0) FAIL(Status_GcodeUnsupportedCommand); break; +#endif default: FAIL(Status_GcodeUnsupportedCommand); // [Unsupported G command] } // end G-value switch diff --git a/gcode.h b/gcode.h index 3c19cb9..208535b 100644 --- a/gcode.h +++ b/gcode.h @@ -56,8 +56,12 @@ typedef enum { NonModal_SetCoordinateOffset = 92, //!< 92 - G92 NonModal_ResetCoordinateOffset = 102, //!< 102 - G92.1 NonModal_ClearCoordinateOffset = 112, //!< 112 - G92.2 + #if ENABLE_ACCELERATION_PROFILES NonModal_RestoreCoordinateOffset = 122, //!< 122 - G92.3 NonModal_SetAccelerationProfile = 187 //!< 187 - G187 + #else + NonModal_RestoreCoordinateOffset = 122 //!< 122 - G92.3 + #endif } non_modal_t; /*! Modal Group G1: Motion modes diff --git a/settings.c b/settings.c index d5827ac..fab733f 100644 --- a/settings.c +++ b/settings.c @@ -884,6 +884,7 @@ bool settings_override_acceleration (uint8_t axis, float acceleration, float jer return true; } +#if ENABLE_ACCELERATION_PROFILES //Acceleration Profiles for G187 P[x] in percent of maximum machine acceleration. float AccelerationProfile(uint8_t Profile) { static const float lookup[5] = { @@ -896,6 +897,7 @@ float AccelerationProfile(uint8_t Profile) { Profile = lookup[Profile]; return Profile; } +#endif // --- From 9f95af13a245646d65659407356ebb5177714216 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:33:10 +0100 Subject: [PATCH 24/34] Encapsulated G-Code Function with compiletime option --- gcode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcode.c b/gcode.c index b83490d..c1c03d7 100644 --- a/gcode.c +++ b/gcode.c @@ -2242,7 +2242,8 @@ status_code_t gc_execute_block (char *block) gc_block.values.xyz[idx] = gc_state.g92_coord_offset[idx]; } while(idx); break; - + +#if ENABLE_ACCELERATION_PROFILES case NonModal_SetAccelerationProfile: if (!gc_block.values.p){ gc_block.values.p = 1.0f;} @@ -2256,7 +2257,7 @@ status_code_t gc_execute_block (char *block) settings_override_acceleration(idx, ((settings.axis[idx].acceleration / (60.0f * 60.0f)) * AccelerationProfile(gc_block.values.p)), ((settings.axis[idx].jerk / (60.0f * 60.0f * 60.0f)) * AccelerationProfile(gc_block.values.p))); } while(idx); break; - +#endif default: // At this point, the rest of the explicit axis commands treat the axis values as the traditional From e645ddbdd95ab8a263a06b69e74c67a273de1913 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:58:26 +0100 Subject: [PATCH 25/34] Added compile time option for jerk controlled motion --- config.h | 2 ++ planner.c | 10 ++++++++-- planner.h | 4 +++- settings.c | 44 ++++++++++++++++++++++++++++++++++++++------ settings.h | 10 ++++++++++ stepper.c | 16 ++++++++++++++-- 6 files changed, 75 insertions(+), 11 deletions(-) diff --git a/config.h b/config.h index f4ad7bf..f3a1d1e 100644 --- a/config.h +++ b/config.h @@ -189,8 +189,10 @@ or EMI triggering the related interrupt falsely or too many times. // --------------------------------------------------------------------------------------- // ADVANCED CONFIGURATION OPTIONS: +// EXPERIMENTAL OPTIONS #define ENABLE_PATH_BLENDING Off // Do NOT enable unless working on adding this feature! #define ENABLE_ACCELERATION_PROFILES Off // Enable to allow G-Code changeable acceleration profiles. +#define ENABLE_JERK_ACCELERATION Off // Enable to use 3rd order Acceleration calculations. May need more processing power, tiny chips beware. // Enables code for debugging purposes. Not for general use and always in constant flux. //#define DEBUG // Uncomment to enable. Default disabled. diff --git a/planner.c b/planner.c index bfb92e8..a195897 100644 --- a/planner.c +++ b/planner.c @@ -354,7 +354,7 @@ static inline float limit_acceleration_by_axis_maximum (float *unit_vec) return limit_value; } - +#if ENABLE_JERK_ACCELERATION static inline float limit_jerk_by_axis_maximum (float *unit_vec) { uint_fast8_t idx = N_AXIS; @@ -367,7 +367,7 @@ static inline float limit_jerk_by_axis_maximum (float *unit_vec) return limit_value; } - +#endif static inline float limit_max_rate_by_axis_maximum (float *unit_vec) { uint_fast8_t idx = N_AXIS; @@ -516,8 +516,12 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) #endif block->millimeters = convert_delta_vector_to_unit_vector(unit_vec); +#if ENABLE_ACCELERATION_PROFILES block->max_acceleration = limit_acceleration_by_axis_maximum(unit_vec); block->jerk = limit_jerk_by_axis_maximum(unit_vec); +#else + block->acceleration = limit_acceleration_by_axis_maximum(unit_vec); +#endif block->rapid_rate = limit_max_rate_by_axis_maximum(unit_vec); // Store programmed rate. @@ -531,11 +535,13 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) if (block->condition.inverse_time) block->programmed_rate *= block->millimeters; } +#if ENABLE_ACCELERATION_PROFILES // Calculate effective acceleration over block. Since jerk acceleration takes longer to execute due to ramp up and // ramp down of the acceleration at the start and end of a ramp we need to adjust the acceleration value the planner // uses so it still calculates reasonable entry and exit speeds. We do this by adding 2x the time it takes to reach // full acceleration to the trapezoidal acceleration time and dividing the programmed rate by the value obtained. block->acceleration = block->programmed_rate / ((block->programmed_rate / block->max_acceleration) + 2.0f * (block->max_acceleration / block->jerk)); +#endif // TODO: Need to check this method handling zero junction speeds when starting from rest. if ((block_buffer_head == block_buffer_tail) || (block->condition.system_motion)) { diff --git a/planner.h b/planner.h index acb509b..fc03307 100644 --- a/planner.h +++ b/planner.h @@ -61,9 +61,11 @@ typedef struct plan_block { float entry_speed_sqr; // The current planned entry speed at block junction in (mm/min)^2 float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and // neighboring nominal speeds with overrides in (mm/min)^2 - float acceleration; // Effective acceleration over plannerblock calculated from trapezoidal movement plan. + float acceleration; // Effective acceleration over plannerblock calculated from trapezoidal movement plan. Does not change in trapezoidal mode. +#if ENABLE_JERK_ACCELERATION float max_acceleration; // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. float jerk; // Axis-limit adjusted jerk value in (mm/min^3). Does not change. +#endif float millimeters; // The remaining distance for this block to be executed in (mm). // NOTE: This value may be altered by stepper algorithm during execution. diff --git a/settings.c b/settings.c index fab733f..56817d3 100644 --- a/settings.c +++ b/settings.c @@ -204,7 +204,9 @@ PROGMEM const settings_t defaults = { .axis[X_AXIS].steps_per_mm = DEFAULT_X_STEPS_PER_MM, .axis[X_AXIS].max_rate = DEFAULT_X_MAX_RATE, .axis[X_AXIS].acceleration = (DEFAULT_X_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[X_AXIS].jerk = (DEFAULT_X_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[X_AXIS].max_travel = (-DEFAULT_X_MAX_TRAVEL), .axis[X_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -215,7 +217,9 @@ PROGMEM const settings_t defaults = { .axis[Y_AXIS].max_rate = DEFAULT_Y_MAX_RATE, .axis[Y_AXIS].max_travel = (-DEFAULT_Y_MAX_TRAVEL), .axis[Y_AXIS].acceleration = (DEFAULT_Y_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[Y_AXIS].jerk = (DEFAULT_Y_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[Y_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION .axis[Y_AXIS].backlash = 0.0f, @@ -224,7 +228,9 @@ PROGMEM const settings_t defaults = { .axis[Z_AXIS].steps_per_mm = DEFAULT_Z_STEPS_PER_MM, .axis[Z_AXIS].max_rate = DEFAULT_Z_MAX_RATE, .axis[Z_AXIS].acceleration = (DEFAULT_Z_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[Z_AXIS].jerk = (DEFAULT_Z_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[Z_AXIS].max_travel = (-DEFAULT_Z_MAX_TRAVEL), .axis[Z_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -235,7 +241,9 @@ PROGMEM const settings_t defaults = { .axis[A_AXIS].steps_per_mm = DEFAULT_A_STEPS_PER_MM, .axis[A_AXIS].max_rate = DEFAULT_A_MAX_RATE, .axis[A_AXIS].acceleration =(DEFAULT_A_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[A_AXIS].jerk = (DEFAULT_A_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[A_AXIS].max_travel = (-DEFAULT_A_MAX_TRAVEL), .axis[A_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -248,7 +256,9 @@ PROGMEM const settings_t defaults = { .axis[B_AXIS].steps_per_mm = DEFAULT_B_STEPS_PER_MM, .axis[B_AXIS].max_rate = DEFAULT_B_MAX_RATE, .axis[B_AXIS].acceleration = (DEFAULT_B_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[B_AXIS].jerk = (DEFAULT_B_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[B_AXIS].max_travel = (-DEFAULT_B_MAX_TRAVEL), .axis[B_AXIS].dual_axis_offset = 0.0f, #if ENABLE_BACKLASH_COMPENSATION @@ -260,7 +270,9 @@ PROGMEM const settings_t defaults = { #ifdef C_AXIS .axis[C_AXIS].steps_per_mm = DEFAULT_C_STEPS_PER_MM, .axis[C_AXIS].acceleration = (DEFAULT_C_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[C_AXIS].jerk = (DEFAULT_C_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[C_AXIS].max_rate = DEFAULT_C_MAX_RATE, .axis[C_AXIS].max_travel = (-DEFAULT_C_MAX_TRAVEL), .axis[C_AXIS].dual_axis_offset = 0.0f, @@ -273,7 +285,9 @@ PROGMEM const settings_t defaults = { #ifdef U_AXIS .axis[U_AXIS].steps_per_mm = DEFAULT_U_STEPS_PER_MM, .axis[U_AXIS].acceleration = (DEFAULT_U_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[U_AXIS].jerk = (DEFAULT_U_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[U_AXIS].max_rate = DEFAULT_U_MAX_RATE, .axis[U_AXIS].max_travel = (-DEFAULT_U_MAX_TRAVEL), .axis[U_AXIS].dual_axis_offset = 0.0f, @@ -285,7 +299,9 @@ PROGMEM const settings_t defaults = { #ifdef V_AXIS .axis[V_AXIS].steps_per_mm = DEFAULT_V_STEPS_PER_MM, .axis[V_AXIS].acceleration = (DEFAULT_V_ACCELERATION * 60.0f * 60.0f), +#if ENABLE_JERK_ACCELERATION .axis[V_AXIS].jerk = (DEFAULT_V_JERK * 60.0f * 60.0f * 60.0f), +#endif .axis[V_AXIS].max_rate = DEFAULT_V_MAX_RATE, .axis[V_AXIS].max_travel = (-DEFAULT_V_MAX_TRAVEL), .axis[V_AXIS].dual_axis_offset = 0.0f, @@ -440,7 +456,9 @@ static char spindle_types[100] = ""; static char axis_dist[4] = "mm"; static char axis_rate[8] = "mm/min"; static char axis_accel[10] = "mm/sec^2"; +#if ENABLE_JERK_ACCELERATION static char axis_jerk[15] = "mm/sec^3"; +#endif #if DELTA_ROBOT static char axis_steps[9] = "step/rev"; #else @@ -569,7 +587,9 @@ PROGMEM static const setting_detail_t setting_detail[] = { { Setting_AxisStepsPerMM, Group_Axis0, "-axis travel resolution", axis_steps, Format_Decimal, "#####0.000##", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisMaxRate, Group_Axis0, "-axis maximum rate", axis_rate, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, { Setting_AxisAcceleration, Group_Axis0, "-axis acceleration", axis_accel, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, +#if ENABLE_JERK_ACCELERATION { Setting_AxisJerk, Group_Axis0, "-axis jerk", axis_jerk, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtendedFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, +#endif { Setting_AxisMaxTravel, Group_Axis0, "-axis maximum travel", axis_dist, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsLegacyFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, #if ENABLE_BACKLASH_COMPENSATION { Setting_AxisBacklash, Group_Axis0, "-axis backlash compensation", axis_dist, Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtendedFn, set_axis_setting, get_float, NULL, AXIS_OPTS }, @@ -759,11 +779,13 @@ PROGMEM static const setting_descr_t setting_descr[] = { { (setting_id_t)(Setting_AxisStepsPerMM + 1), "Travel resolution in steps per degree." }, // "Hack" to get correct description for rotary axes { Setting_AxisMaxRate, "Maximum rate. Used as G0 rapid rate." }, { Setting_AxisAcceleration, "Acceleration. Used for motion planning to not exceed motor torque and lose steps." }, +#if ENABLE_JERK_ACCELERATION { Setting_AxisJerk, "Maximum rate of acceleration change - smoothes out acceleration profile up to max axis acceleration.\\n\\n" "Minimum value of x10 Acceleration setting to ensure decent acceleration times.\\n" "Maximum is calcualted by current acceleration and stepper segment time.\\n" "At Maximum value motion is effectively trapezoidal instead of constant jerk.\\n\\n" "Can be increased by adjusting ACCELERATION_TICKS_PER_SECOND to a larger value before compiling."}, +#endif { Setting_AxisMaxTravel, "Maximum axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." }, #if ENABLE_BACKLASH_COMPENSATION { Setting_AxisBacklash, "Backlash distance to compensate for." }, @@ -829,7 +851,9 @@ static setting_details_t setting_details = { static struct { bool valid; float acceleration[N_AXIS]; +#if ENABLE_JERK_ACCELERATION float jerk[N_AXIS]; +#endif } override_backup = { .valid = false }; static void save_override_backup (void) @@ -839,7 +863,9 @@ static void save_override_backup (void) do { idx--; override_backup.acceleration[idx] = settings.axis[idx].acceleration; +#if ENABLE_JERK_ACCELERATION override_backup.jerk[idx] = settings.axis[idx].jerk; +#endif } while(idx); override_backup.valid = true; @@ -852,7 +878,9 @@ static void restore_override_backup (void) if(override_backup.valid) do { idx--; settings.axis[idx].acceleration = override_backup.acceleration[idx]; +#if ENABLE_JERK_ACCELERATION settings.axis[idx].jerk = override_backup.jerk[idx]; +#endif } while(idx); } @@ -873,6 +901,7 @@ bool settings_override_acceleration (uint8_t axis, float acceleration, float jer save_override_backup(); settings.axis[axis].acceleration = (override_backup.acceleration[axis] >= (acceleration * 60.0f * 60.0f)) ? (acceleration * 60.0f * 60.0f) : override_backup.acceleration[axis]; // Limited to max setting value } +#if ENABLE_JERK_ACCELERATION if(jerk <= 0.0f) { if(override_backup.valid) settings.axis[axis].jerk = override_backup.jerk[axis]; @@ -881,6 +910,7 @@ bool settings_override_acceleration (uint8_t axis, float acceleration, float jer save_override_backup(); settings.axis[axis].jerk = (override_backup.jerk[axis] >= (jerk * 60.0f * 60.0f * 60.0f)) ? (jerk * 60.0f * 60.0f * 60.0f) : override_backup.jerk[axis]; // Limited to max setting value } +#endif return true; } @@ -1377,11 +1407,11 @@ static const char *set_axis_setting_unit (setting_id_t setting_id, uint_fast8_t case Setting_AxisAcceleration: unit = is_rotary ? "deg/sec^2" : "mm/sec^2"; break; - +#if ENABLE_JERK_ACCELERATION case Setting_AxisJerk: unit = is_rotary ? "deg/sec^3" : "mm/sec^3"; break; - +#endif case Setting_AxisMaxTravel: case Setting_AxisBacklash: unit = is_rotary ? "deg" : "mm"; @@ -1488,9 +1518,11 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) case Setting_AxisAcceleration: settings.axis[idx].acceleration = override_backup.acceleration[idx] = value * 60.0f * 60.0f; // Convert to mm/min^2 for grbl internal use. +#if ENABLE_JERK_ACCELERATION settings.axis[idx].jerk = (settings.axis[idx].acceleration * 10.0f * 60.0f); //reset jerk to axis minimum. +#endif break; - +#if ENABLE_JERK_ACCELERATION case Setting_AxisJerk: if ((value * 60.0f * 60.0f) < (settings.axis[idx].acceleration * 10.0f)) //ensuring that the acceleration time is limited to at maximum 100ms (or 10 stepper segments). settings.axis[idx].jerk = settings.axis[idx].acceleration * 10.0f * 60.0f; // mm/min^2 -> mm/min^3 @@ -1499,7 +1531,7 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) else settings.axis[idx].jerk = value * 60.0f * 60.0f * 60.0f; // Convert to mm/min^3 for grbl internal use. break; - +#endif case Setting_AxisMaxTravel: if(settings.axis[idx].max_travel != -value) { bit_false(sys.homed.mask, bit(idx)); @@ -1562,11 +1594,11 @@ static float get_float (setting_id_t setting) case Setting_AxisAcceleration: value = settings.axis[idx].acceleration / (60.0f * 60.0f); // Convert from mm/min^2 to mm/sec^2. break; - +#if ENABLE_JERK_ACCELERATION case Setting_AxisJerk: value = settings.axis[idx].jerk / (60.0f * 60.0f * 60.0f); // Convert from mm/min^3 to mm/sec^3. break; - +#endif case Setting_AxisMaxTravel: value = -settings.axis[idx].max_travel; // Store as negative for grbl internal use. break; diff --git a/settings.h b/settings.h index 5868ffb..1de8c57 100644 --- a/settings.h +++ b/settings.h @@ -441,7 +441,11 @@ typedef enum { // Calculated base values for driver/plugin stepper settings Setting_AxisExtended0 = Setting_AxisSettingsBase2, Setting_AxisExtended1 = Setting_AxisSettingsBase2 + AXIS_SETTINGS_INCREMENT, +#if ENABLE_JERK_ACCELERATION Setting_AxisJerk = Setting_AxisSettingsBase2 + 2 * AXIS_SETTINGS_INCREMENT, +#else + Setting_AxisExtended2 = Setting_AxisSettingsBase2 + 2 * AXIS_SETTINGS_INCREMENT, +#endif Setting_AxisExtended3 = Setting_AxisSettingsBase2 + 3 * AXIS_SETTINGS_INCREMENT, Setting_AxisExtended4 = Setting_AxisSettingsBase2 + 4 * AXIS_SETTINGS_INCREMENT, Setting_AxisExtended5 = Setting_AxisSettingsBase2 + 5 * AXIS_SETTINGS_INCREMENT, @@ -614,7 +618,9 @@ typedef struct { float steps_per_mm; float max_rate; float acceleration; +#if ENABLE_JERK_ACCELERATION float jerk; +#endif float max_travel; float dual_axis_offset; #if ENABLE_BACKLASH_COMPENSATION @@ -958,7 +964,11 @@ void settings_write_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS] bool settings_read_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS]); // Temporarily override acceleration, if 0 restore to configured setting value +#if ENABLE_JERK_ACCELERATION bool settings_override_acceleration (uint8_t axis, float acceleration, float jerk); +#else +bool settings_override_acceleration (uint8_t axis, float acceleration); +#endif void settings_register (setting_details_t *details); setting_details_t *settings_get_details (void); diff --git a/stepper.c b/stepper.c index a06a38c..36553e6 100644 --- a/stepper.c +++ b/stepper.c @@ -892,7 +892,9 @@ void st_prep_buffer (void) float dt_max = DT_SEGMENT; // Maximum segment time float dt = 0.0f; // Initialize segment time float time_var = dt_max; // Time worker variable +#if ENABLE_JERK_ACCELERATION float last_segment_accel = 0.0f; // Acceleration value of last computed segment. Initialize as 0.0 +#endif float mm_var; // mm - Distance worker variable float speed_var; // Speed worker variable float mm_remaining = pl_block->millimeters; // New segment distance from end of block. @@ -921,15 +923,20 @@ void st_prep_buffer (void) case Ramp_Accel: // NOTE: Acceleration ramp only computes during first do-while loop. +#if ENABLE_JERK_ACCELERATION if (((mm_remaining - prep.accelerate_until) / (prep.current_speed + 1.0f)) <= (last_segment_accel / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp // Check if we are on ramp up or ramp down. Ramp down if time to end of acceleration is less than time needed to reach 0 acceleration. // Then limit acceleration change by jerk up to max acceleration and update for next segment. - last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, 0.0f); + // Minimum acceleration jerk per time_var to ensure acceleartion completes. Acceleration change at end of ramp is in acceptable jerk range. + last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, pl_block->jerk * time_var); } else { last_segment_accel = min(last_segment_accel + pl_block->jerk * time_var, pl_block->max_acceleration); } speed_var = last_segment_accel * time_var; +#else + speed_var = pl_block->acceleration * time_var; +#endif mm_remaining -= time_var * (prep.current_speed + 0.5f * speed_var); if (mm_remaining < prep.accelerate_until) { // End of acceleration ramp. // Acceleration-cruise, acceleration-deceleration ramp junction, or end of block. @@ -957,15 +964,20 @@ void st_prep_buffer (void) default: // case Ramp_Decel: // NOTE: mm_var used as a misc worker variable to prevent errors when near zero speed. +#if ENABLE_JERK_ACCELERATION if ((mm_remaining / (prep.current_speed + 1.0f)) <= (last_segment_accel / pl_block->jerk)) { //+1.0f to avoid divide by 0 speed, minor effect on jerk ramp // Check if we are on ramp up or ramp down. Ramp down if time to end of deceleration is less than time needed to reach 0 acceleration. // Then limit acceleration change by jerk up to max acceleration and update for next segment. - last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, 0.0f); + // Minimum acceleration of jerk per time_var to ensure acceleration completes. Acceleration change at end of ramp is in acceptable jerk range. + last_segment_accel = max(last_segment_accel - pl_block->jerk * time_var, pl_block->jerk * time_var); } else { last_segment_accel = min(last_segment_accel + pl_block->jerk * time_var, pl_block->max_acceleration); } speed_var = last_segment_accel * time_var; // Used as delta speed (mm/min) +#else + speed_var = pl_block->acceleration * time_var; // Used as delta speed (mm/min) +#endif if (prep.current_speed > speed_var) { // Check if at or below zero speed. // Compute distance from end of segment to end of block. mm_var = mm_remaining - time_var * (prep.current_speed - 0.5f * speed_var); // (mm) From bc003a2f64024061d78651f5d507894f3d9a009a Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:23:27 +0100 Subject: [PATCH 26/34] Included default jerk values in compile option --- config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.h b/config.h index f3a1d1e..62ee289 100644 --- a/config.h +++ b/config.h @@ -1848,6 +1848,7 @@ Timezone offset from UTC in hours, allowed range is -12.0 - 12.0. /*! @name 22x - Setting_AxisJerk */ ///@{ +#if ENABLE_JERK_ACCELERATION #if !defined DEFAULT_X_JERK|| defined __DOXYGEN__ #define DEFAULT_X_JERK 100.0f // mm/sec^3 #endif @@ -1872,6 +1873,7 @@ Timezone offset from UTC in hours, allowed range is -12.0 - 12.0. #if (defined V_AXIS && !defined DEFAULT_V_JERK) || defined __DOXYGEN__ #define DEFAULT_V_JERK 100.0f // mm/sec^3 #endif +#endif ///@} /*! @name 13x - Setting_AxisMaxTravel From fb396fc290adb17c21a8224b5c87424e557b1f4e Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 8 Jan 2024 00:47:17 +0100 Subject: [PATCH 27/34] settings_override_acceleration declaration adjusted for compile option --- settings.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/settings.c b/settings.c index 56817d3..3bd6bba 100644 --- a/settings.c +++ b/settings.c @@ -886,7 +886,11 @@ static void restore_override_backup (void) // Temporarily override acceleration, if 0 restore to setting value. // Note: only allowed when current state is idle. +#if ENABLE_JERK_ACCELERATION bool settings_override_acceleration (uint8_t axis, float acceleration, float jerk) +#else +bool settings_override_acceleration (uint8_t axis, float acceleration) +#endif { sys_state_t state = state_get(); From ba26451c57a39f2e787d33db1bfd0969d454507e Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:22:53 +0100 Subject: [PATCH 28/34] added AccelerationProfile function to settings.h --- settings.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/settings.h b/settings.h index 1de8c57..f3f057e 100644 --- a/settings.h +++ b/settings.h @@ -970,6 +970,10 @@ bool settings_override_acceleration (uint8_t axis, float acceleration, float jer bool settings_override_acceleration (uint8_t axis, float acceleration); #endif +#if ENABLE_ACCELERATION_PROFILES +float AccelerationProfile(uint8_t Profile); +#endif + void settings_register (setting_details_t *details); setting_details_t *settings_get_details (void); bool settings_is_group_available (setting_group_t group); From f6bf39c52cea2726e9fcf8805e55fa0d8cf66702 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Wed, 10 Jan 2024 23:27:45 +0100 Subject: [PATCH 29/34] Updated AccelerationProfile implementation to not alter settingsvalues --- gcode.c | 6 +----- planner.c | 14 ++++++++++---- settings.c | 16 +--------------- settings.h | 7 ++----- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/gcode.c b/gcode.c index c1c03d7..c6f77a3 100644 --- a/gcode.c +++ b/gcode.c @@ -2251,11 +2251,7 @@ status_code_t gc_execute_block (char *block) FAIL(Status_NegativeValue);} else if (gc_block.values.p > 5.0f){ FAIL(Status_GcodeValueOutOfRange);} - uint8_t idx = N_AXIS; - do { - idx--; - settings_override_acceleration(idx, ((settings.axis[idx].acceleration / (60.0f * 60.0f)) * AccelerationProfile(gc_block.values.p)), ((settings.axis[idx].jerk / (60.0f * 60.0f * 60.0f)) * AccelerationProfile(gc_block.values.p))); - } while(idx); + ActiveAccelProfile = gc_block.values.p; break; #endif default: diff --git a/planner.c b/planner.c index a195897..008db7a 100644 --- a/planner.c +++ b/planner.c @@ -351,9 +351,12 @@ static inline float limit_acceleration_by_axis_maximum (float *unit_vec) if (unit_vec[--idx] != 0.0f) // Avoid divide by zero. limit_value = min(limit_value, fabsf(settings.axis[idx].acceleration / unit_vec[idx])); } while(idx); - +#if ENABLE_ACCELERATION_PROFILES + limit_value *= AccelerationProfile(ActiveAccelProfile); +#endif return limit_value; } + #if ENABLE_JERK_ACCELERATION static inline float limit_jerk_by_axis_maximum (float *unit_vec) { @@ -364,10 +367,13 @@ static inline float limit_jerk_by_axis_maximum (float *unit_vec) if (unit_vec[--idx] != 0.0f) // Avoid divide by zero. limit_value = min(limit_value, fabsf(settings.axis[idx].jerk / unit_vec[idx])); } while(idx); - +#if ENABLE_ACCELERATION_PROFILES + limit_value *= AccelerationProfile(ActiveAccelProfile); +#endif return limit_value; } #endif + static inline float limit_max_rate_by_axis_maximum (float *unit_vec) { uint_fast8_t idx = N_AXIS; @@ -516,7 +522,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) #endif block->millimeters = convert_delta_vector_to_unit_vector(unit_vec); -#if ENABLE_ACCELERATION_PROFILES +#if ENABLE_JERK_ACCELERATION block->max_acceleration = limit_acceleration_by_axis_maximum(unit_vec); block->jerk = limit_jerk_by_axis_maximum(unit_vec); #else @@ -535,7 +541,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) if (block->condition.inverse_time) block->programmed_rate *= block->millimeters; } -#if ENABLE_ACCELERATION_PROFILES +#if ENABLE_JERK_ACCELERATION // Calculate effective acceleration over block. Since jerk acceleration takes longer to execute due to ramp up and // ramp down of the acceleration at the start and end of a ramp we need to adjust the acceleration value the planner // uses so it still calculates reasonable entry and exit speeds. We do this by adding 2x the time it takes to reach diff --git a/settings.c b/settings.c index 3bd6bba..6ba547c 100644 --- a/settings.c +++ b/settings.c @@ -886,11 +886,7 @@ static void restore_override_backup (void) // Temporarily override acceleration, if 0 restore to setting value. // Note: only allowed when current state is idle. -#if ENABLE_JERK_ACCELERATION -bool settings_override_acceleration (uint8_t axis, float acceleration, float jerk) -#else bool settings_override_acceleration (uint8_t axis, float acceleration) -#endif { sys_state_t state = state_get(); @@ -905,22 +901,12 @@ bool settings_override_acceleration (uint8_t axis, float acceleration) save_override_backup(); settings.axis[axis].acceleration = (override_backup.acceleration[axis] >= (acceleration * 60.0f * 60.0f)) ? (acceleration * 60.0f * 60.0f) : override_backup.acceleration[axis]; // Limited to max setting value } -#if ENABLE_JERK_ACCELERATION - if(jerk <= 0.0f) { - if(override_backup.valid) - settings.axis[axis].jerk = override_backup.jerk[axis]; - } else { - if(!override_backup.valid) - save_override_backup(); - settings.axis[axis].jerk = (override_backup.jerk[axis] >= (jerk * 60.0f * 60.0f * 60.0f)) ? (jerk * 60.0f * 60.0f * 60.0f) : override_backup.jerk[axis]; // Limited to max setting value - } -#endif return true; } #if ENABLE_ACCELERATION_PROFILES //Acceleration Profiles for G187 P[x] in percent of maximum machine acceleration. -float AccelerationProfile(uint8_t Profile) { +float LookupProfile(uint8_t Profile) { static const float lookup[5] = { 1.0f, // 100% - Roughing - Max Acceleration Default 0.8f, // 80% - Semi Roughing diff --git a/settings.h b/settings.h index f3f057e..3a40c69 100644 --- a/settings.h +++ b/settings.h @@ -964,14 +964,11 @@ void settings_write_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS] bool settings_read_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS]); // Temporarily override acceleration, if 0 restore to configured setting value -#if ENABLE_JERK_ACCELERATION -bool settings_override_acceleration (uint8_t axis, float acceleration, float jerk); -#else bool settings_override_acceleration (uint8_t axis, float acceleration); -#endif #if ENABLE_ACCELERATION_PROFILES -float AccelerationProfile(uint8_t Profile); +extern uint8_t ActiveAccelProfile = 1; +float AccelerationProfile (uint8_t Profile); #endif void settings_register (setting_details_t *details); From a53770489626b588a5b395dc6e9baef119f5b59d Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Wed, 10 Jan 2024 23:37:52 +0100 Subject: [PATCH 30/34] reverted settings_override_acceleration to original --- settings.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/settings.c b/settings.c index 6ba547c..e56ca22 100644 --- a/settings.c +++ b/settings.c @@ -851,9 +851,6 @@ static setting_details_t setting_details = { static struct { bool valid; float acceleration[N_AXIS]; -#if ENABLE_JERK_ACCELERATION - float jerk[N_AXIS]; -#endif } override_backup = { .valid = false }; static void save_override_backup (void) @@ -863,9 +860,6 @@ static void save_override_backup (void) do { idx--; override_backup.acceleration[idx] = settings.axis[idx].acceleration; -#if ENABLE_JERK_ACCELERATION - override_backup.jerk[idx] = settings.axis[idx].jerk; -#endif } while(idx); override_backup.valid = true; @@ -878,9 +872,6 @@ static void restore_override_backup (void) if(override_backup.valid) do { idx--; settings.axis[idx].acceleration = override_backup.acceleration[idx]; -#if ENABLE_JERK_ACCELERATION - settings.axis[idx].jerk = override_backup.jerk[idx]; -#endif } while(idx); } From 2bef5f707158aab7b56bcbbce8510af282715b52 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Thu, 11 Jan 2024 14:52:30 +0100 Subject: [PATCH 31/34] adjusted last_segment_accel handling at end of accel ramps --- stepper.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stepper.c b/stepper.c index 36553e6..ce77bd0 100644 --- a/stepper.c +++ b/stepper.c @@ -944,6 +944,9 @@ void st_prep_buffer (void) time_var = 2.0f * (pl_block->millimeters - mm_remaining) / (prep.current_speed + prep.maximum_speed); prep.ramp_type = mm_remaining == prep.decelerate_after ? Ramp_Decel : Ramp_Cruise; prep.current_speed = prep.maximum_speed; +#if ENABLE_JERK_ACCELERATION + last_segment_accel = 0.0f; // reset acceleration variable to 0 for next accel ramp +#endif } else // Acceleration only. prep.current_speed += speed_var; break; @@ -991,6 +994,9 @@ void st_prep_buffer (void) time_var = 2.0f * (mm_remaining - prep.mm_complete) / (prep.current_speed + prep.exit_speed); mm_remaining = prep.mm_complete; prep.current_speed = prep.exit_speed; +#if ENABLE_JERK_ACCELERATION + last_segment_accel = 0.0f; // reset acceleration variable to 0 for next accel ramp +#endif } dt += time_var; // Add computed ramp time to total segment time. From b6135c421873990eb4d56838a8bc336a0e328edb Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:20:10 +0100 Subject: [PATCH 32/34] Changed ActiveAccelProfile declaration/definition because of compiler warning --- planner.c | 4 ++-- settings.c | 2 ++ settings.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/planner.c b/planner.c index 008db7a..0ade5f7 100644 --- a/planner.c +++ b/planner.c @@ -352,7 +352,7 @@ static inline float limit_acceleration_by_axis_maximum (float *unit_vec) limit_value = min(limit_value, fabsf(settings.axis[idx].acceleration / unit_vec[idx])); } while(idx); #if ENABLE_ACCELERATION_PROFILES - limit_value *= AccelerationProfile(ActiveAccelProfile); + limit_value *= LookupProfile(ActiveAccelProfile); #endif return limit_value; } @@ -368,7 +368,7 @@ static inline float limit_jerk_by_axis_maximum (float *unit_vec) limit_value = min(limit_value, fabsf(settings.axis[idx].jerk / unit_vec[idx])); } while(idx); #if ENABLE_ACCELERATION_PROFILES - limit_value *= AccelerationProfile(ActiveAccelProfile); + limit_value *= LookupProfileProfile(ActiveAccelProfile); #endif return limit_value; } diff --git a/settings.c b/settings.c index 52e8495..d97798c 100644 --- a/settings.c +++ b/settings.c @@ -896,6 +896,8 @@ bool settings_override_acceleration (uint8_t axis, float acceleration) } #if ENABLE_ACCELERATION_PROFILES +ActiveAccelProfile = 1; // Initialize machine with 100% Profile + //Acceleration Profiles for G187 P[x] in percent of maximum machine acceleration. float LookupProfile(uint8_t Profile) { static const float lookup[5] = { diff --git a/settings.h b/settings.h index 3a40c69..e1d0e00 100644 --- a/settings.h +++ b/settings.h @@ -967,7 +967,7 @@ bool settings_read_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS]) bool settings_override_acceleration (uint8_t axis, float acceleration); #if ENABLE_ACCELERATION_PROFILES -extern uint8_t ActiveAccelProfile = 1; +extern uint8_t ActiveAccelProfile; float AccelerationProfile (uint8_t Profile); #endif From aa9a0c45797fed824fa0da665ea231777aa31db1 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:48:39 +0100 Subject: [PATCH 33/34] Fixed typos and brackets --- settings.c | 15 ++++++++++----- settings.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/settings.c b/settings.c index d97798c..e1a1bbc 100644 --- a/settings.c +++ b/settings.c @@ -1393,11 +1393,13 @@ static const char *set_axis_setting_unit (setting_id_t setting_id, uint_fast8_t case Setting_AxisAcceleration: unit = is_rotary ? "deg/sec^2" : "mm/sec^2"; break; + #if ENABLE_JERK_ACCELERATION case Setting_AxisJerk: unit = is_rotary ? "deg/sec^3" : "mm/sec^3"; break; #endif + case Setting_AxisMaxTravel: case Setting_AxisBacklash: unit = is_rotary ? "deg" : "mm"; @@ -1504,20 +1506,21 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) case Setting_AxisAcceleration: settings.axis[idx].acceleration = override_backup.acceleration[idx] = value * 60.0f * 60.0f; // Convert to mm/min^2 for grbl internal use. -#if ENABLE_JERK_ACCELERATION - settings.axis[idx].jerk = (settings.axis[idx].acceleration * 10.0f * 60.0f); //reset jerk to axis minimum. -#endif break; + #if ENABLE_JERK_ACCELERATION case Setting_AxisJerk: - if ((value * 60.0f * 60.0f) < (settings.axis[idx].acceleration * 10.0f)) //ensuring that the acceleration time is limited to at maximum 100ms (or 10 stepper segments). + if ((value * 60.0f * 60.0f) < (settings.axis[idx].acceleration * 10.0f)) { //ensuring that the acceleration ramp time is limited to at maximum 100ms (or 10 stepper segments). settings.axis[idx].jerk = settings.axis[idx].acceleration * 10.0f * 60.0f; // mm/min^2 -> mm/min^3 - else if ((settings.axis[idx].acceleration / (value * 60.0f * 60.0f * 60.0f)) < (1.0f / ACCELERATION_TICKS_PER_SECOND)) // Limit Jerk if Value is so large that it reverts back to trapezoidal. + } + else if ((settings.axis[idx].acceleration / (value * 60.0f * 60.0f * 60.0f)) < (1.0f / ACCELERATION_TICKS_PER_SECOND)) { // Limit Jerk if value is so large that it reverts back to trapezoidal. settings.axis[idx].jerk = settings.axis[idx].acceleration * ACCELERATION_TICKS_PER_SECOND * 60.0f; // mm/min^2 -> mm/min^3 + } else settings.axis[idx].jerk = value * 60.0f * 60.0f * 60.0f; // Convert to mm/min^3 for grbl internal use. break; #endif + case Setting_AxisMaxTravel: if(settings.axis[idx].max_travel != -value) { bit_false(sys.homed.mask, bit(idx)); @@ -1580,11 +1583,13 @@ static float get_float (setting_id_t setting) case Setting_AxisAcceleration: value = settings.axis[idx].acceleration / (60.0f * 60.0f); // Convert from mm/min^2 to mm/sec^2. break; + #if ENABLE_JERK_ACCELERATION case Setting_AxisJerk: value = settings.axis[idx].jerk / (60.0f * 60.0f * 60.0f); // Convert from mm/min^3 to mm/sec^3. break; #endif + case Setting_AxisMaxTravel: value = -settings.axis[idx].max_travel; // Store as negative for grbl internal use. break; diff --git a/settings.h b/settings.h index e1d0e00..7301ecc 100644 --- a/settings.h +++ b/settings.h @@ -968,7 +968,7 @@ bool settings_override_acceleration (uint8_t axis, float acceleration); #if ENABLE_ACCELERATION_PROFILES extern uint8_t ActiveAccelProfile; -float AccelerationProfile (uint8_t Profile); +float LookupProfile (uint8_t Profile); #endif void settings_register (setting_details_t *details); From c8876e2d92208f66ba972982ca95ab7fd182f462 Mon Sep 17 00:00:00 2001 From: Dietz0r <102995203+Dietz0r@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:53:50 +0100 Subject: [PATCH 34/34] fixed limit_jerk_by_axis_maximum --- planner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner.c b/planner.c index 0ade5f7..eec3450 100644 --- a/planner.c +++ b/planner.c @@ -368,7 +368,7 @@ static inline float limit_jerk_by_axis_maximum (float *unit_vec) limit_value = min(limit_value, fabsf(settings.axis[idx].jerk / unit_vec[idx])); } while(idx); #if ENABLE_ACCELERATION_PROFILES - limit_value *= LookupProfileProfile(ActiveAccelProfile); + limit_value *= LookupProfile(ActiveAccelProfile); #endif return limit_value; }