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

Jerk Acceleration Settings and HAAS G187 Acceleration Profiles #593

Merged
merged 59 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c8619f5
Update planner.c
Dietz0r Oct 30, 2023
f003479
Update planner.h
Dietz0r Oct 30, 2023
699e943
Update stepper.c
Dietz0r Oct 30, 2023
2484538
Update planner.c
Dietz0r Oct 30, 2023
4c3cf5e
Added Axis settings for jerk
Dietz0r Oct 30, 2023
418e063
Decel Ramp Calculations Updated
Dietz0r Oct 30, 2023
fb082f3
added missing semicolons
Dietz0r Nov 2, 2023
f00bb4d
Update planner.c
Dietz0r Nov 2, 2023
b796931
Update settings.c
Dietz0r Nov 2, 2023
9951e03
Update config.h
Dietz0r Nov 2, 2023
06ac1ea
Update settings.c
Dietz0r Nov 2, 2023
f295c36
Update settings.c
Dietz0r Dec 15, 2023
92e750d
adjusted end of accel calculation
Dietz0r Dec 18, 2023
a268962
Merge branch 'grblHAL:master' into master
Dietz0r Dec 18, 2023
2361610
cleaned up config and added settings description
Dietz0r Dec 19, 2023
5bb5945
added set_axis_setting functions for jerk settings
Dietz0r Dec 19, 2023
8667292
fixed typo
Dietz0r Dec 19, 2023
04708e9
included extended axis setting in get_float check
Dietz0r Dec 19, 2023
0789f6e
Merge branch 'grblHAL:master' into master
Dietz0r Dec 23, 2023
2930759
Merge branch 'grblHAL:master' into master
Dietz0r Dec 27, 2023
0863959
Merge branch 'grblHAL:master' into master
Dietz0r Dec 29, 2023
5cbb222
Added Min/Max calculations for Jerk
Dietz0r Dec 30, 2023
4c28e42
Implemented preliminary G187 support for up to 5 Profiles
Dietz0r Jan 2, 2024
554812d
Unittype and Brackets Hotfix for G187
Dietz0r Jan 2, 2024
299a7cd
Calculation adjustment for G187
Dietz0r Jan 2, 2024
dec93aa
Fixed some typos and syntax errors.
andrewmarles Jan 2, 2024
860659f
Merge pull request #1 from Expatria-Technologies/PR_Flexi_Fix
Dietz0r Jan 2, 2024
4cc7aaf
Added compiletime check for added acceleration profile code
Dietz0r Jan 3, 2024
9f95af1
Encapsulated G-Code Function with compiletime option
Dietz0r Jan 3, 2024
e645ddb
Added compile time option for jerk controlled motion
Dietz0r Jan 7, 2024
bc003a2
Included default jerk values in compile option
Dietz0r Jan 7, 2024
fb396fc
settings_override_acceleration declaration adjusted for compile option
Dietz0r Jan 7, 2024
ba26451
added AccelerationProfile function to settings.h
Dietz0r Jan 8, 2024
f6bf39c
Updated AccelerationProfile implementation to not alter settingsvalues
Dietz0r Jan 10, 2024
a537704
reverted settings_override_acceleration to original
Dietz0r Jan 10, 2024
2bef5f7
adjusted last_segment_accel handling at end of accel ramps
Dietz0r Jan 11, 2024
9fd3ba5
Merge branch 'grblHAL:master' into master
Dietz0r Jan 12, 2024
b6135c4
Changed ActiveAccelProfile declaration/definition because of compiler…
Dietz0r Jan 14, 2024
aa9a0c4
Fixed typos and brackets
Dietz0r Jan 14, 2024
c8876e2
fixed limit_jerk_by_axis_maximum
Dietz0r Jan 14, 2024
fa6d508
Merge branch 'grblHAL:master' into master
Dietz0r Feb 25, 2024
2ec344e
Merge branch 'grblHAL:master' into master
Dietz0r Apr 2, 2024
0b69f6f
Merge branch 'grblHAL:master' into master
Dietz0r May 23, 2024
e17d782
Merge branch 'grblHAL:master' into master
Dietz0r Sep 29, 2024
b7d54d7
added acceleration profiles to gc_state, adjusted g187 and m2/30 hand…
Dietz0r Oct 31, 2024
88cf48a
adjusted settings.h to last commit too
Dietz0r Oct 31, 2024
a6ae08e
Resolve merge conflict for new setting structure
Dietz0r Dec 10, 2024
075d5ce
Merge branch 'master' into master
Dietz0r Dec 10, 2024
e504964
moved acceleration factor to plan_block_t structure, moved lookup fun…
Dietz0r Dec 10, 2024
c4969f1
missed 2 variable names
Dietz0r Dec 10, 2024
3379524
file didnt want to push. found a typo
Dietz0r Dec 10, 2024
df6aec3
Merge branch 'grblHAL:master' into master
Dietz0r Dec 26, 2024
254a3d1
Update settings.c
Dietz0r Dec 26, 2024
efcdf3f
Update gcode.h
Dietz0r Dec 26, 2024
ce60b8f
adjusted the limit by axis maximum functions to not require the block…
Dietz0r Dec 26, 2024
c47e6a3
Debugging and Compiling
Dietz0r Dec 27, 2024
9d48143
Fixed the Unused Values error, removed stray comma, removed settings.…
Dietz0r Dec 27, 2024
719017b
Adjusted lookup function for array counting (start from 0) and added …
Dietz0r Dec 27, 2024
84657b4
Cleaned up the Switchcase coder after the debugging mess (thanks terj…
Dietz0r Dec 27, 2024
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
34 changes: 34 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +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.
Expand Down Expand Up @@ -2016,6 +2019,37 @@ G90
#endif
///@}

/*! @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
#if !defined DEFAULT_Y_JERK|| defined __DOXYGEN__
#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^3
#endif
#if (defined A_AXIS && !defined DEFAULT_A_JERK) || defined __DOXYGEN__
#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^3
#endif
#if (defined C_AXIS && !defined DEFAULT_C_JERK) || defined __DOXYGEN__
#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^3
#endif
#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
__NOTE:__ Must be a positive values.
*/
Expand Down
30 changes: 30 additions & 0 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ void gc_init (bool stop)
#if NGC_PARAMETERS_ENABLE
ngc_modal_state_invalidate();
#endif
#if ENABLE_ACCELERATION_PROFILES
gc_state.modal.acceleration_factor = 1.0f; // Initialize machine with 100% Profile
#endif

// if(settings.flags.lathe_mode)
// gc_state.modal.plane_select = PlaneSelect_ZX;
Expand Down Expand Up @@ -1194,6 +1197,15 @@ 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

Expand Down Expand Up @@ -2358,7 +2370,19 @@ 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.words.e)
FAIL(Status_GcodeUnsupportedCommand);

if(gc_block.words.p && (gc_block.values.p < 1.0f || gc_block.values.p > 5.0f))
FAIL(Status_GcodeValueOutOfRange);

gc_state.modal.acceleration_factor = lookupfactor(gc_block.words.p ? (uint8_t)gc_block.values.p - 1 : 0);
gc_block.words.p = Off;
break;
#endif
default:

// At this point, the rest of the explicit axis commands treat the axis values as the traditional
Expand Down Expand Up @@ -3030,6 +3054,9 @@ status_code_t gc_execute_block (char *block)
memset(&plan_data, 0, sizeof(plan_line_data_t)); // Zero plan_data struct
plan_data.offset_id = gc_state.offset_id;
plan_data.condition.target_validated = plan_data.condition.target_valid = sys.soft_limits.mask == 0;
#if ENABLE_ACCELERATION_PROFILES
plan_data.acceleration_factor = gc_state.modal.acceleration_factor;
#endif

// Intercept jog commands and complete error checking for valid jog commands and execute.
// NOTE: G-code parser state is not updated, except the position to ensure sequential jog
Expand Down Expand Up @@ -3819,6 +3846,9 @@ status_code_t gc_execute_block (char *block)
gc_state.modal.coolant = (coolant_state_t){0};
gc_state.modal.override_ctrl.feed_rate_disable = Off;
gc_state.modal.override_ctrl.spindle_rpm_disable = Off;
#if ENABLE_ACCELERATION_PROFILES
gc_state.modal.acceleration_factor = 1.0f;
#endif

#if N_SYS_SPINDLE > 1

Expand Down
10 changes: 9 additions & 1 deletion gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ 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
#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;


Expand Down Expand Up @@ -541,6 +546,9 @@ typedef struct {
bool auto_restore;
float feed_rate; //!< {F} NOTE: only set when saving modal state
#endif
#if ENABLE_ACCELERATION_PROFILES
float acceleration_factor; //!< {G187} currently active factor of acceleration profile
#endif
} gc_modal_t;

//! Data for canned cycles.
Expand Down
37 changes: 37 additions & 0 deletions planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,22 @@ 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);
return limit_value;
}

#if ENABLE_JERK_ACCELERATION
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;
}
#endif

static inline float limit_max_rate_by_axis_maximum (float *unit_vec)
{
Expand Down Expand Up @@ -502,10 +515,24 @@ 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_JERK_ACCELERATION
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);
#ifdef KINEMATICS_API
block->rate_multiplier = pl_data->rate_multiplier;
#endif
#if ENABLE_ACCELERATION_PROFILES // recalculate the acceleration limits when enabled.
block->acceleration_factor = pl_data->acceleration_factor;
#if ENABLE_JERK_ACCELERATION
block->max_acceleration *= block->acceleration_factor;
block->jerk *= block->acceleration_factor;
#else
block->acceleration *= block->acceleration_factor;
#endif
#endif

// Store programmed rate.
Expand All @@ -516,6 +543,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_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
// 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)) {
Expand Down Expand Up @@ -704,4 +738,7 @@ void plan_data_init (plan_line_data_t *plan_data)
#ifdef KINEMATICS_API
plan_data->rate_multiplier = 1.0f;
#endif
#ifdef ENABLE_ACCELERATION_PROFILES
plan_data->acceleration_factor = 1.0f;
#endif
}
12 changes: 11 additions & 1 deletion planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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; // Axis-limit adjusted line acceleration in (mm/min^2). Does not change.
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.

Expand All @@ -73,6 +77,9 @@ typedef struct plan_block {
float programmed_rate; // Programmed rate of this block (mm/min).
#ifdef KINEMATICS_API
float rate_multiplier; // Rate multiplier of this block.
#endif
#ifdef ENABLE_ACCELERATION_PROFILES
float acceleration_factor; // Stores the currently used acceleration factor.
#endif
// Stored spindle speed data used by spindle overrides and resuming methods.
spindle_t spindle; // Block spindle parameters. Copied from pl_line_data.
Expand All @@ -89,6 +96,9 @@ typedef struct {
#ifdef KINEMATICS_API
float rate_multiplier; // Feed rate multiplier.
#endif
#ifdef ENABLE_ACCELERATION_PROFILES
float acceleration_factor; // Stores the currently used acceleration factor.
#endif
#if ENABLE_PATH_BLENDING
float path_tolerance; //!< Path blending tolerance.
float cam_tolerance; //!< Naive CAM tolerance.
Expand Down
Loading