From d2d7ddc0c0bacd4e094a779f7647a624f0ce7693 Mon Sep 17 00:00:00 2001 From: Mitchell Grams Date: Sun, 31 Aug 2025 19:33:48 -0600 Subject: [PATCH 1/3] Add initial support for distance to go in realtime report --- planner.c | 1 + planner.h | 1 + report.c | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/planner.c b/planner.c index d554ba6..0a62267 100644 --- a/planner.c +++ b/planner.c @@ -417,6 +417,7 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) block->offset_id = pl_data->offset_id; block->output_commands = pl_data->output_commands; block->message = pl_data->message; + memcpy(block->target_mm, target, sizeof(float) * N_AXIS); // Copy position data based on type of motion being planned. memcpy(position_steps, block->condition.system_motion ? sys.position : pl.position, sizeof(position_steps)); diff --git a/planner.h b/planner.h index 33864c3..ed06b8b 100644 --- a/planner.h +++ b/planner.h @@ -82,6 +82,7 @@ typedef struct plan_block { gc_override_flags_t overrides; // Block bitfield variable for overrides planner_cond_t condition; // Block bitfield variable defining block run conditions. Copied from pl_line_data. int32_t line_number; // Block line number for real-time reporting. Copied from pl_line_data. + float target_mm[N_AXIS]; // Block target end location in mm for real-time reporting of distance to go. // Fields used by the motion planner to manage acceleration. Some of these values may be updated // by the stepper module during execution of special motion cases for replanning purposes. diff --git a/report.c b/report.c index 6974887..4e249ad 100644 --- a/report.c +++ b/report.c @@ -1154,7 +1154,7 @@ void report_realtime_status (stream_write_ptr stream_write) static bool probing = false; uint_fast8_t idx; - float print_position[N_AXIS], wco[N_AXIS]; + float print_position[N_AXIS], wco[N_AXIS], dist_remaining[N_AXIS]; report_tracking_flags_t report = system_get_rt_report_flags(), delayed_report = {}; probe_state_t probe_state = { .connected = On, @@ -1254,6 +1254,19 @@ void report_realtime_status (stream_write_ptr stream_write) stream_write(appendbuf(2, "|Ln:", uitoa((uint32_t)cur_block->line_number))); } + // Report distance remaining as difference between target (end of block) and current position + plan_block_t *cur_block = plan_get_current_block(); + if (cur_block != NULL) { + system_convert_array_steps_to_mpos(dist_remaining, sys.position); + + for(idx = 0; idx < N_AXIS; idx++) { + dist_remaining[idx] = cur_block->target_mm[idx] - dist_remaining[idx]; + } + // Report distance to go + hal.stream.write_all("|DToGo:"); + hal.stream.write_all(get_axis_values(dist_remaining)); + } + spindle_ptrs_t *spindle_0; spindle_state_t spindle_0_state; From 50e10ac768668827483deae9137ba1a9ef5db786 Mon Sep 17 00:00:00 2001 From: Mitchell Grams Date: Sun, 7 Sep 2025 18:15:42 -0600 Subject: [PATCH 2/3] Add setting for including distance-to-go in realtime report --- config.h | 30 ++++++++++++++++++++---------- report.c | 22 ++++++++++++---------- settings.c | 3 ++- settings.h | 3 ++- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/config.h b/config.h index 45c1721..00e1d32 100644 --- a/config.h +++ b/config.h @@ -617,11 +617,21 @@ in the real time report. #define DEFAULT_REPORT_LINE_NUMBERS On // Default on. Set to \ref Off or 0 to disable. #endif +/*! \def DEFAULT_REPORT_DISTANCE_TO_GO +\brief +If set to \ref Off or 0 the `|DTG:` distance-to-go element is not included +in the real time report. +\internal Bit 3 in settings.status_report. +*/ +#if !defined DEFAULT_REPORT_DISTANCE_TO_GO || defined __DOXYGEN__ +#define DEFAULT_REPORT_DISTANCE_TO_GO On // Default on. Set to \ref Off or 0 to disable. +#endif + /*! \def DEFAULT_REPORT_CURRENT_FEED_SPEED \brief If set to \ref Off or 0 the `|FS:` current feed & speed element is not included in the real time report. -\internal Bit 3 in settings.status_report. +\internal Bit 4 in settings.status_report. */ #if !defined DEFAULT_REPORT_CURRENT_FEED_SPEED || defined __DOXYGEN__ #define DEFAULT_REPORT_CURRENT_FEED_SPEED On // Default on. Set to \ref Off or 0 to disable. @@ -631,7 +641,7 @@ in the real time report. \brief If set to \ref Off or 0 the `|Pn:` input pins state element is not included in the real time report. -\internal Bit 4 in settings.status_report. +\internal Bit 5 in settings.status_report. */ #if !defined DEFAULT_REPORT_PIN_STATE || defined __DOXYGEN__ #define DEFAULT_REPORT_PIN_STATE On // Default on. Set to \ref Off or 0 to disable. @@ -641,7 +651,7 @@ in the real time report. \brief If set to \ref Off or 0 the `|WCO:` work coordinate offset element is not included in the real time report. -\internal Bit 5 in settings.status_report. +\internal Bit 6 in settings.status_report. */ #if !defined DEFAULT_REPORT_WORK_COORD_OFFSET || defined __DOXYGEN__ #define DEFAULT_REPORT_WORK_COORD_OFFSET On // Default on. Set to \ref Off or 0 to disable. @@ -651,7 +661,7 @@ in the real time report. \brief If set to \ref Off or 0 the `|Pn:` input pins state element is not included in the real time report. -\internal Bit 6 in settings.status_report. +\internal Bit 7 in settings.status_report. */ #if !defined DEFAULT_REPORT_OVERRIDES || defined __DOXYGEN__ #define DEFAULT_REPORT_OVERRIDES On // Default on. Set to \ref Off or 0 to disable. @@ -662,7 +672,7 @@ in the real time report. Upon a successful probe cycle, this option provides immediately feedback of the probe coordinates through an automatically generated message. If disabled, users can still access the last probe coordinates through grblHAL `$#` print parameters command. -\internal Bit 7 in settings.status_report. +\internal Bit 8 in settings.status_report. */ #if !defined DEFAULT_REPORT_PROBE_COORDINATES || defined __DOXYGEN__ #define DEFAULT_REPORT_PROBE_COORDINATES On // Default on. Set to \ref Off or 0 to disable. @@ -676,7 +686,7 @@ can be several motions behind. This option forces the planner buffer to empty, s motion whenever there is a command that alters the work coordinate offsets `G10,G43.1,G92,G54-59.3`. This is the simplest way to ensure `WPos:` is always correct. Fortunately, it's exceedingly rare that any of these commands are used need continuous motions through them. -\internal Bit 8 in settings.status_report. +\internal Bit 9 in settings.status_report. */ #if !defined DEFAULT_REPORT_SYNC_ON_WCO_CHANGE || defined __DOXYGEN__ #define DEFAULT_REPORT_SYNC_ON_WCO_CHANGE On //!< ok @@ -687,7 +697,7 @@ that any of these commands are used need continuous motions through them. When enabled adds automatic report of the parser state following a status report request if the state was changed since the last report. The output is the same as provided by the `$G` command. -\internal Bit 9 in settings.status_report. +\internal Bit 10 in settings.status_report. */ #if !defined DEFAULT_REPORT_PARSER_STATE || defined __DOXYGEN__ #define DEFAULT_REPORT_PARSER_STATE Off // Default off. Set to \ref On or 1 to enable. @@ -701,7 +711,7 @@ normally no way to determine the cause of the alarm. Enabling this setting adds code (see \ref alarm_code_t) as a substate, separated by a colon, to the _Alarm_ state in the real time report.
__NOTE:__ Enabling this option may break senders. -\internal Bit 10 in settings.status_report. +\internal Bit 11 in settings.status_report. */ #if !defined DEFAULT_REPORT_ALARM_SUBSTATE || defined __DOXYGEN__ #define DEFAULT_REPORT_ALARM_SUBSTATE Off // Default off. Set to \ref On or 1 to enable. @@ -714,7 +724,7 @@ The following codes are defined: + `1` - a feed hold is pending, waiting for spindle synchronized motion to complete. + `2` - the motion is a probe.
__NOTE:__ Enabling this option may break senders. -\internal Bit 11 in settings.status_report. +\internal Bit 12 in settings.status_report. */ #if !defined DEFAULT_REPORT_RUN_SUBSTATE || defined __DOXYGEN__ #define DEFAULT_REPORT_RUN_SUBSTATE Off // Default off. Set to \ref On or 1 to enable. @@ -724,7 +734,7 @@ The following codes are defined: \brief Enabling this setting enables status reporting while homing.
__NOTE:__ Enabling this option may break senders. -\internal Bit 12 in settings.status_report. +\internal Bit 13 in settings.status_report. */ #if !defined DEFAULT_REPORT_WHEN_HOMING || defined __DOXYGEN__ #define DEFAULT_REPORT_WHEN_HOMING Off // Default off. Set to \ref On or 1 to enable. diff --git a/report.c b/report.c index 4e249ad..082ef45 100644 --- a/report.c +++ b/report.c @@ -1254,18 +1254,20 @@ void report_realtime_status (stream_write_ptr stream_write) stream_write(appendbuf(2, "|Ln:", uitoa((uint32_t)cur_block->line_number))); } - // Report distance remaining as difference between target (end of block) and current position - plan_block_t *cur_block = plan_get_current_block(); - if (cur_block != NULL) { - system_convert_array_steps_to_mpos(dist_remaining, sys.position); + if(settings.status_report.distance_to_go) { + // Report distance-to-go in current block (i.e., difference between target / end-of-block) and current position) + plan_block_t *cur_block = plan_get_current_block(); + if (cur_block != NULL) { + system_convert_array_steps_to_mpos(dist_remaining, sys.position); - for(idx = 0; idx < N_AXIS; idx++) { - dist_remaining[idx] = cur_block->target_mm[idx] - dist_remaining[idx]; + for(idx = 0; idx < N_AXIS; idx++) { + dist_remaining[idx] = cur_block->target_mm[idx] - dist_remaining[idx]; + } + + hal.stream.write_all("|DTG:"); + hal.stream.write_all(get_axis_values(dist_remaining)); } - // Report distance to go - hal.stream.write_all("|DToGo:"); - hal.stream.write_all(get_axis_values(dist_remaining)); - } + } spindle_ptrs_t *spindle_0; spindle_state_t spindle_0_state; diff --git a/settings.c b/settings.c index e1c85e1..327d236 100644 --- a/settings.c +++ b/settings.c @@ -152,6 +152,7 @@ PROGMEM const settings_t defaults = { .status_report.machine_position = DEFAULT_REPORT_MACHINE_POSITION, .status_report.buffer_state = DEFAULT_REPORT_BUFFER_STATE, .status_report.line_numbers = DEFAULT_REPORT_LINE_NUMBERS, + .status_report.distance_to_go = DEFAULT_REPORT_DISTANCE_TO_GO, .status_report.feed_speed = DEFAULT_REPORT_CURRENT_FEED_SPEED, .status_report.pin_state = DEFAULT_REPORT_PIN_STATE, .status_report.work_coord_offset = DEFAULT_REPORT_WORK_COORD_OFFSET, @@ -2014,7 +2015,7 @@ PROGMEM static const setting_detail_t setting_detail[] = { { Setting_GangedDirInvertMask, Group_Stepper, "Ganged axes direction invert", NULL, Format_Bitfield, ganged_axes, NULL, NULL, Setting_IsExtendedFn, set_ganged_dir_invert, get_int, is_setting_available }, { Setting_SpindlePWMOptions, Group_Spindle, "PWM spindle options", NULL, Format_XBitfield, "Enable,RPM controls spindle enable signal,Disable laser mode capability", NULL, NULL, Setting_IsExtendedFn, set_pwm_options, get_int, is_setting_available }, #if COMPATIBILITY_LEVEL <= 1 - { Setting_StatusReportMask, Group_General, "Status report options", NULL, Format_Bitfield, "Position in machine coordinate,Buffer state,Line numbers,Feed & speed,Pin state,Work coordinate offset,Overrides,Probe coordinates,Buffer sync on WCO change,Parser state,Alarm substatus,Run substatus,Enable when homing", NULL, NULL, Setting_IsExtendedFn, set_report_mask, get_int, NULL }, + { Setting_StatusReportMask, Group_General, "Status report options", NULL, Format_Bitfield, "Position in machine coordinate,Buffer state,Line numbers,Distance-to-go,Feed & speed,Pin state,Work coordinate offset,Overrides,Probe coordinates,Buffer sync on WCO change,Parser state,Alarm substatus,Run substatus,Enable when homing", NULL, NULL, Setting_IsExtendedFn, set_report_mask, get_int, NULL }, #else { Setting_StatusReportMask, Group_General, "Status report options", NULL, Format_Bitfield, "Position in machine coordinate,Buffer state", NULL, NULL, Setting_IsLegacyFn, set_report_mask, get_int, NULL }, #endif diff --git a/settings.h b/settings.h index 9095d80..f625659 100644 --- a/settings.h +++ b/settings.h @@ -631,6 +631,7 @@ typedef union { uint16_t machine_position :1, buffer_state :1, line_numbers :1, + distance_to_go :1, feed_speed :1, pin_state :1, work_coord_offset :1, @@ -641,7 +642,7 @@ typedef union { alarm_substate :1, run_substate :1, when_homing :1, - unassigned :3; + unassigned :2; }; } reportmask_t; From 65679de9950f4f8a627486297193121cc568096b Mon Sep 17 00:00:00 2001 From: Mitchell Grams Date: Mon, 8 Sep 2025 13:03:43 -0600 Subject: [PATCH 3/3] Revise DTG bit location do avoid need for setting reset --- config.h | 39 +++++++++++++++++++-------------------- settings.c | 4 ++-- settings.h | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/config.h b/config.h index 00e1d32..a8f96d1 100644 --- a/config.h +++ b/config.h @@ -617,21 +617,11 @@ in the real time report. #define DEFAULT_REPORT_LINE_NUMBERS On // Default on. Set to \ref Off or 0 to disable. #endif -/*! \def DEFAULT_REPORT_DISTANCE_TO_GO -\brief -If set to \ref Off or 0 the `|DTG:` distance-to-go element is not included -in the real time report. -\internal Bit 3 in settings.status_report. -*/ -#if !defined DEFAULT_REPORT_DISTANCE_TO_GO || defined __DOXYGEN__ -#define DEFAULT_REPORT_DISTANCE_TO_GO On // Default on. Set to \ref Off or 0 to disable. -#endif - /*! \def DEFAULT_REPORT_CURRENT_FEED_SPEED \brief If set to \ref Off or 0 the `|FS:` current feed & speed element is not included in the real time report. -\internal Bit 4 in settings.status_report. +\internal Bit 3 in settings.status_report. */ #if !defined DEFAULT_REPORT_CURRENT_FEED_SPEED || defined __DOXYGEN__ #define DEFAULT_REPORT_CURRENT_FEED_SPEED On // Default on. Set to \ref Off or 0 to disable. @@ -641,7 +631,7 @@ in the real time report. \brief If set to \ref Off or 0 the `|Pn:` input pins state element is not included in the real time report. -\internal Bit 5 in settings.status_report. +\internal Bit 4 in settings.status_report. */ #if !defined DEFAULT_REPORT_PIN_STATE || defined __DOXYGEN__ #define DEFAULT_REPORT_PIN_STATE On // Default on. Set to \ref Off or 0 to disable. @@ -651,7 +641,7 @@ in the real time report. \brief If set to \ref Off or 0 the `|WCO:` work coordinate offset element is not included in the real time report. -\internal Bit 6 in settings.status_report. +\internal Bit 5 in settings.status_report. */ #if !defined DEFAULT_REPORT_WORK_COORD_OFFSET || defined __DOXYGEN__ #define DEFAULT_REPORT_WORK_COORD_OFFSET On // Default on. Set to \ref Off or 0 to disable. @@ -661,7 +651,7 @@ in the real time report. \brief If set to \ref Off or 0 the `|Pn:` input pins state element is not included in the real time report. -\internal Bit 7 in settings.status_report. +\internal Bit 6 in settings.status_report. */ #if !defined DEFAULT_REPORT_OVERRIDES || defined __DOXYGEN__ #define DEFAULT_REPORT_OVERRIDES On // Default on. Set to \ref Off or 0 to disable. @@ -672,7 +662,7 @@ in the real time report. Upon a successful probe cycle, this option provides immediately feedback of the probe coordinates through an automatically generated message. If disabled, users can still access the last probe coordinates through grblHAL `$#` print parameters command. -\internal Bit 8 in settings.status_report. +\internal Bit 7 in settings.status_report. */ #if !defined DEFAULT_REPORT_PROBE_COORDINATES || defined __DOXYGEN__ #define DEFAULT_REPORT_PROBE_COORDINATES On // Default on. Set to \ref Off or 0 to disable. @@ -686,7 +676,7 @@ can be several motions behind. This option forces the planner buffer to empty, s motion whenever there is a command that alters the work coordinate offsets `G10,G43.1,G92,G54-59.3`. This is the simplest way to ensure `WPos:` is always correct. Fortunately, it's exceedingly rare that any of these commands are used need continuous motions through them. -\internal Bit 9 in settings.status_report. +\internal Bit 8 in settings.status_report. */ #if !defined DEFAULT_REPORT_SYNC_ON_WCO_CHANGE || defined __DOXYGEN__ #define DEFAULT_REPORT_SYNC_ON_WCO_CHANGE On //!< ok @@ -697,7 +687,7 @@ that any of these commands are used need continuous motions through them. When enabled adds automatic report of the parser state following a status report request if the state was changed since the last report. The output is the same as provided by the `$G` command. -\internal Bit 10 in settings.status_report. +\internal Bit 9 in settings.status_report. */ #if !defined DEFAULT_REPORT_PARSER_STATE || defined __DOXYGEN__ #define DEFAULT_REPORT_PARSER_STATE Off // Default off. Set to \ref On or 1 to enable. @@ -711,7 +701,7 @@ normally no way to determine the cause of the alarm. Enabling this setting adds code (see \ref alarm_code_t) as a substate, separated by a colon, to the _Alarm_ state in the real time report.
__NOTE:__ Enabling this option may break senders. -\internal Bit 11 in settings.status_report. +\internal Bit 10 in settings.status_report. */ #if !defined DEFAULT_REPORT_ALARM_SUBSTATE || defined __DOXYGEN__ #define DEFAULT_REPORT_ALARM_SUBSTATE Off // Default off. Set to \ref On or 1 to enable. @@ -724,7 +714,7 @@ The following codes are defined: + `1` - a feed hold is pending, waiting for spindle synchronized motion to complete. + `2` - the motion is a probe.
__NOTE:__ Enabling this option may break senders. -\internal Bit 12 in settings.status_report. +\internal Bit 11 in settings.status_report. */ #if !defined DEFAULT_REPORT_RUN_SUBSTATE || defined __DOXYGEN__ #define DEFAULT_REPORT_RUN_SUBSTATE Off // Default off. Set to \ref On or 1 to enable. @@ -734,12 +724,21 @@ The following codes are defined: \brief Enabling this setting enables status reporting while homing.
__NOTE:__ Enabling this option may break senders. -\internal Bit 13 in settings.status_report. +\internal Bit 12 in settings.status_report. */ #if !defined DEFAULT_REPORT_WHEN_HOMING || defined __DOXYGEN__ #define DEFAULT_REPORT_WHEN_HOMING Off // Default off. Set to \ref On or 1 to enable. #endif +/*! \def DEFAULT_REPORT_DISTANCE_TO_GO +\brief +If set to \ref Off or 0 the `|DTG:` distance-to-go element is not included in the real time report. +\internal Bit 13 in settings.status_report. +*/ +#if !defined DEFAULT_REPORT_DISTANCE_TO_GO || defined __DOXYGEN__ +#define DEFAULT_REPORT_DISTANCE_TO_GO On // Default on. Set to \ref Off or 0 to disable. +#endif + ///@} /*! @name $11 - Setting_JunctionDeviation diff --git a/settings.c b/settings.c index 327d236..e57b11d 100644 --- a/settings.c +++ b/settings.c @@ -152,7 +152,6 @@ PROGMEM const settings_t defaults = { .status_report.machine_position = DEFAULT_REPORT_MACHINE_POSITION, .status_report.buffer_state = DEFAULT_REPORT_BUFFER_STATE, .status_report.line_numbers = DEFAULT_REPORT_LINE_NUMBERS, - .status_report.distance_to_go = DEFAULT_REPORT_DISTANCE_TO_GO, .status_report.feed_speed = DEFAULT_REPORT_CURRENT_FEED_SPEED, .status_report.pin_state = DEFAULT_REPORT_PIN_STATE, .status_report.work_coord_offset = DEFAULT_REPORT_WORK_COORD_OFFSET, @@ -163,6 +162,7 @@ PROGMEM const settings_t defaults = { .status_report.alarm_substate = DEFAULT_REPORT_ALARM_SUBSTATE, .status_report.run_substate = DEFAULT_REPORT_RUN_SUBSTATE, .status_report.when_homing = DEFAULT_REPORT_WHEN_HOMING, + .status_report.distance_to_go = DEFAULT_REPORT_DISTANCE_TO_GO, .limits.flags.hard_enabled = DEFAULT_HARD_LIMIT_ENABLE, .limits.flags.jog_soft_limited = DEFAULT_JOG_LIMIT_ENABLE, .limits.flags.check_at_init = DEFAULT_CHECK_LIMITS_AT_INIT, @@ -2015,7 +2015,7 @@ PROGMEM static const setting_detail_t setting_detail[] = { { Setting_GangedDirInvertMask, Group_Stepper, "Ganged axes direction invert", NULL, Format_Bitfield, ganged_axes, NULL, NULL, Setting_IsExtendedFn, set_ganged_dir_invert, get_int, is_setting_available }, { Setting_SpindlePWMOptions, Group_Spindle, "PWM spindle options", NULL, Format_XBitfield, "Enable,RPM controls spindle enable signal,Disable laser mode capability", NULL, NULL, Setting_IsExtendedFn, set_pwm_options, get_int, is_setting_available }, #if COMPATIBILITY_LEVEL <= 1 - { Setting_StatusReportMask, Group_General, "Status report options", NULL, Format_Bitfield, "Position in machine coordinate,Buffer state,Line numbers,Distance-to-go,Feed & speed,Pin state,Work coordinate offset,Overrides,Probe coordinates,Buffer sync on WCO change,Parser state,Alarm substatus,Run substatus,Enable when homing", NULL, NULL, Setting_IsExtendedFn, set_report_mask, get_int, NULL }, + { Setting_StatusReportMask, Group_General, "Status report options", NULL, Format_Bitfield, "Position in machine coordinate,Buffer state,Line numbers,Feed & speed,Pin state,Work coordinate offset,Overrides,Probe coordinates,Buffer sync on WCO change,Parser state,Alarm substatus,Run substatus,Enable when homing,Distance-to-go", NULL, NULL, Setting_IsExtendedFn, set_report_mask, get_int, NULL }, #else { Setting_StatusReportMask, Group_General, "Status report options", NULL, Format_Bitfield, "Position in machine coordinate,Buffer state", NULL, NULL, Setting_IsLegacyFn, set_report_mask, get_int, NULL }, #endif diff --git a/settings.h b/settings.h index f625659..61c5565 100644 --- a/settings.h +++ b/settings.h @@ -631,7 +631,6 @@ typedef union { uint16_t machine_position :1, buffer_state :1, line_numbers :1, - distance_to_go :1, feed_speed :1, pin_state :1, work_coord_offset :1, @@ -642,6 +641,7 @@ typedef union { alarm_substate :1, run_substate :1, when_homing :1, + distance_to_go :1, unassigned :2; }; } reportmask_t;