mirror of
https://github.com/grblHAL/core.git
synced 2026-08-17 16:41:45 +08:00
Fixed G43 "bug", added acceleration override handling for OpenPNP.
This commit is contained in:
@@ -636,11 +636,7 @@ status_code_t gc_execute_block(char *block, char *message)
|
||||
// NOTE: The NIST g-code standard vaguely states that when a tool length offset is changed,
|
||||
// there cannot be any axis motion or coordinate offsets updated. Meaning G43, G43.1, and G49
|
||||
// all are explicit axis commands, regardless if they require axis words or not.
|
||||
|
||||
if (axis_command)
|
||||
FAIL(Status_GcodeAxisCommandConflict); // [Axis word/command conflict] }
|
||||
|
||||
axis_command = AxisCommand_ToolLengthOffset;
|
||||
// NOTE: cannot find the NIST statement referenced above, changed to match LinuxCNC behaviour in build 20210513.
|
||||
if (int_value == 49) // G49
|
||||
gc_block.modal.tool_offset_mode = ToolLengthOffset_Cancel;
|
||||
#ifdef N_TOOLS
|
||||
@@ -649,9 +645,12 @@ status_code_t gc_execute_block(char *block, char *message)
|
||||
else if (mantissa == 20) // G43.2
|
||||
gc_block.modal.tool_offset_mode = ToolLengthOffset_ApplyAdditional;
|
||||
#endif
|
||||
else if (mantissa == 10) // G43.1
|
||||
else if (mantissa == 10) { // G43.1
|
||||
if (axis_command)
|
||||
FAIL(Status_GcodeAxisCommandConflict); // [Axis word/command conflict] }
|
||||
axis_command = AxisCommand_ToolLengthOffset;
|
||||
gc_block.modal.tool_offset_mode = ToolLengthOffset_EnableDynamic;
|
||||
else
|
||||
} else
|
||||
FAIL(Status_GcodeUnsupportedCommand); // [Unsupported G43.x command]
|
||||
mantissa = 0; // Set to zero to indicate valid non-integer G command.
|
||||
break;
|
||||
@@ -1316,7 +1315,9 @@ status_code_t gc_execute_block(char *block, char *message)
|
||||
// Pre-convert XYZ coordinate values to millimeters, if applicable.
|
||||
uint_fast8_t idx = N_AXIS;
|
||||
if (gc_block.modal.units_imperial) do { // Axes indices are consistent, so loop may be used.
|
||||
if (bit_istrue(axis_words.mask, bit(--idx)))
|
||||
idx--;
|
||||
// if (bit_istrue(axis_words.mask, bit(idx)) && bit_isfalse(settings.steppers.is_rotational.mask, bit(idx)))
|
||||
if (bit_istrue(axis_words.mask, bit(idx)))
|
||||
gc_block.values.xyz[idx] *= MM_PER_INCH;
|
||||
} while(idx);
|
||||
|
||||
@@ -1412,13 +1413,13 @@ status_code_t gc_execute_block(char *block, char *message)
|
||||
|
||||
// [14. Tool length compensation ]: G43.1 and G49 are always supported, G43 and G43.2 if N_TOOLS defined.
|
||||
// [G43.1 Errors]: Motion command in same line.
|
||||
// [G43.2 Errors]: Motion command in same line. Tool number not in the tool table,
|
||||
// NOTE: Although not explicitly stated so, G43.1 should be applied to only one valid
|
||||
// axis that is configured (in config.h). There should be an error if the configured axis
|
||||
// is absent or if any of the other axis words are present.
|
||||
if (axis_command == AxisCommand_ToolLengthOffset) { // Indicates called in block.
|
||||
// [G43.2 Errors]: Tool number not in the tool table,
|
||||
if (command_words.G8) { // Indicates called in block.
|
||||
|
||||
#ifdef TOOL_LENGTH_OFFSET_AXIS
|
||||
// NOTE: Although not explicitly stated so, G43.1 should be applied to only one valid
|
||||
// axis that is configured (in config.h). There should be an error if the configured axis
|
||||
// is absent or if any of the other axis words are present.
|
||||
if(gc_block.modal.tool_offset_mode == ToolLengthOffset_EnableDynamic) {
|
||||
if (axis_words.mask ^ bit(TOOL_LENGTH_OFFSET_AXIS))
|
||||
FAIL(Status_GcodeG43DynamicAxisError);
|
||||
@@ -2030,7 +2031,9 @@ status_code_t gc_execute_block(char *block, char *message)
|
||||
if (gc_block.modal.units_imperial) {
|
||||
idx = 3;
|
||||
do { // Axes indices are consistent, so loop may be used to save flash space.
|
||||
if (ijk_words.mask & bit(--idx))
|
||||
idx--;
|
||||
// if (ijk_words.mask & bit(idx) && bit_isfalse(settings.steppers.is_rotational.mask, bit(idx)))
|
||||
if (ijk_words.mask & bit(idx))
|
||||
gc_block.values.ijk[idx] *= MM_PER_INCH;
|
||||
} while(idx);
|
||||
}
|
||||
@@ -2412,7 +2415,7 @@ status_code_t gc_execute_block(char *block, char *message)
|
||||
// NOTE: If G43 were supported, its operation wouldn't be any different from G43.1 in terms
|
||||
// of execution. The error-checking step would simply load the offset value into the correct
|
||||
// axis of the block XYZ value array.
|
||||
if (axis_command == AxisCommand_ToolLengthOffset) { // Indicates a change.
|
||||
if (command_words.G8) { // Indicates a change.
|
||||
|
||||
bool tlo_changed = false;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#else
|
||||
#define GRBL_VERSION "1.1f"
|
||||
#endif
|
||||
#define GRBL_VERSION_BUILD "20210505"
|
||||
#define GRBL_VERSION_BUILD "20210513"
|
||||
|
||||
// The following symbols are set here if not already set by the compiler or in config.h
|
||||
// Do NOT change here!
|
||||
|
||||
+57
-1
@@ -32,6 +32,7 @@
|
||||
#include "limits.h"
|
||||
#include "nvs_buffer.h"
|
||||
#include "tool_change.h"
|
||||
#include "state_machine.h"
|
||||
#ifdef ENABLE_BACKLASH_COMPENSATION
|
||||
#include "motion_control.h"
|
||||
#endif
|
||||
@@ -99,6 +100,7 @@ PROGMEM const settings_t defaults = {
|
||||
.steppers.dir_invert.mask = DEFAULT_DIRECTION_INVERT_MASK,
|
||||
.steppers.enable_invert.mask = INVERT_ST_ENABLE_MASK,
|
||||
.steppers.deenergize.mask = ST_DEENERGIZE_MASK,
|
||||
// .steppers.is_rotational.mask = 0,
|
||||
#if DEFAULT_HOMING_ENABLE
|
||||
.homing.flags.enabled = DEFAULT_HOMING_ENABLE,
|
||||
.homing.flags.init_lock = DEFAULT_HOMING_INIT_LOCK,
|
||||
@@ -446,6 +448,7 @@ PROGMEM static const setting_detail_t setting_detail[] = {
|
||||
{ Setting_DualAxisLengthFailPercent, Group_Limits_DualAxis, "Dual axis length fail", "percent", Format_Decimal, "##0.0", "0", "100", Setting_IsExtended, &settings.homing.dual_axis.fail_length_percent, NULL, NULL },
|
||||
{ Setting_DualAxisLengthFailMin, Group_Limits_DualAxis, "Dual axis length fail min", "mm/min", Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtended, &settings.homing.dual_axis.fail_distance_min, NULL, NULL },
|
||||
{ Setting_DualAxisLengthFailMax, Group_Limits_DualAxis, "Dual axis length fail max", "mm/min", Format_Decimal, "#####0.000", NULL, NULL, Setting_IsExtended, &settings.homing.dual_axis.fail_distance_max, NULL, NULL }
|
||||
// { Settings_Axis_Rotational, Group_Stepper, "Rotational axes", NULL, Format_AxisMask, NULL, NULL, NULL, Setting_IsExtended, &settings.steppers.is_rotational.mask, NULL, NULL }
|
||||
};
|
||||
|
||||
static setting_details_t details = {
|
||||
@@ -456,6 +459,56 @@ static setting_details_t details = {
|
||||
.save = settings_write_global
|
||||
};
|
||||
|
||||
// Acceleration override
|
||||
|
||||
static struct {
|
||||
bool valid;
|
||||
float acceleration[N_AXIS];
|
||||
} override_backup = { .valid = false };
|
||||
|
||||
static void save_override_backup (void)
|
||||
{
|
||||
uint_fast8_t idx = N_AXIS;
|
||||
|
||||
do {
|
||||
idx--;
|
||||
override_backup.acceleration[idx] = settings.axis[idx].acceleration;
|
||||
} while(idx);
|
||||
|
||||
override_backup.valid = true;
|
||||
}
|
||||
|
||||
static void restore_override_backup (void)
|
||||
{
|
||||
uint_fast8_t idx = N_AXIS;
|
||||
|
||||
if(override_backup.valid) do {
|
||||
idx--;
|
||||
settings.axis[idx].acceleration = override_backup.acceleration[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)
|
||||
{
|
||||
if(state_get() != STATE_IDLE)
|
||||
return false;
|
||||
|
||||
if(acceleration <= 0.0f) {
|
||||
if(override_backup.valid)
|
||||
settings.axis[axis].acceleration = override_backup.acceleration[axis];
|
||||
} else {
|
||||
if(!override_backup.valid)
|
||||
save_override_backup();
|
||||
settings.axis[axis].acceleration = acceleration * 60.0f * 60.0f; // Limit max to setting value?
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
setting_details_t *settings_get_details (void)
|
||||
{
|
||||
details.on_get_settings = grbl.on_get_settings;
|
||||
@@ -796,7 +849,7 @@ static status_code_t set_axis_setting (setting_id_t setting, float value)
|
||||
break;
|
||||
|
||||
case Setting_AxisAcceleration:
|
||||
settings.axis[idx].acceleration = value * 60.0f * 60.0f; // Convert to mm/min^2 for grbl internal use.
|
||||
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_AxisMaxTravel:
|
||||
@@ -1232,6 +1285,9 @@ bool read_global_settings ()
|
||||
// Write Grbl global settings and version number to persistent storage
|
||||
void settings_write_global (void)
|
||||
{
|
||||
if(override_backup.valid)
|
||||
restore_override_backup();
|
||||
|
||||
if(hal.nvs.type != NVS_None) {
|
||||
hal.nvs.put_byte(0, SETTINGS_VERSION);
|
||||
hal.nvs.memcpy_to_nvs(NVS_ADDR_GLOBAL, (uint8_t *)&settings, sizeof(settings_t), true);
|
||||
|
||||
@@ -226,6 +226,7 @@ typedef enum {
|
||||
Settings_IoPort_OD_Enable = 373,
|
||||
Settings_ModBus_BaudRate = 374,
|
||||
Settings_ModBus_RXTimeout = 375,
|
||||
Settings_Axis_Rotational = 376,
|
||||
|
||||
Setting_EncoderSettingsBase = 400, // NOTE: Reserving settings values >= 400 for encoder settings. Up to 449.
|
||||
Setting_EncoderSettingsMax = 449,
|
||||
@@ -441,6 +442,7 @@ typedef struct {
|
||||
axes_signals_t dir_invert;
|
||||
axes_signals_t enable_invert;
|
||||
axes_signals_t deenergize;
|
||||
// axes_signals_t is_rotational; or add to axis_settings_t below as bitmap union? rotational axes are not scaled in imperial mode
|
||||
float pulse_microseconds;
|
||||
float pulse_delay_microseconds;
|
||||
uint16_t idle_lock_time; // If value = 255, steppers do not disable.
|
||||
@@ -708,6 +710,9 @@ bool settings_write_tool_data (tool_data_t *tool_data);
|
||||
// Read selected tool data from persistent storage
|
||||
bool settings_read_tool_data (uint32_t tool, tool_data_t *tool_data);
|
||||
|
||||
// Temporarily override acceleration, if 0 restore to configured setting value
|
||||
bool settings_override_acceleration (uint8_t axis, float acceleration);
|
||||
|
||||
setting_details_t *settings_get_details (void);
|
||||
bool settings_is_group_available (setting_group_t group);
|
||||
bool settings_iterator (const setting_detail_t *setting, setting_output_ptr callback, void *data);
|
||||
|
||||
Reference in New Issue
Block a user