Skip to content

Commit

Permalink
Adds support for M114 gcode command
Browse files Browse the repository at this point in the history
[new] Reports current work position when M114 command is sent
  • Loading branch information
achingbrain committed Aug 28, 2017
1 parent 5967839 commit 40c2983
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions grbl/config.h
Expand Up @@ -168,6 +168,9 @@
// NOTE: The M8 flood coolant control pin on analog pin 3 will still be functional regardless.
// #define ENABLE_M7 // Disabled by default. Uncomment to enable.

// Enables reporting positions in response to the M114 GCode command
// #define ENABLE_M114 // Disabled by default. Uncomment to enable.

// This option causes the feed hold input to act as a safety door switch. A safety door, when triggered,
// immediately forces a feed hold and then safely de-energizes the machine. Resuming is blocked until
// the safety door is re-engaged. When it is, Grbl will re-energize the machine and then resume on the
Expand Down
5 changes: 5 additions & 0 deletions grbl/gcode.c
Expand Up @@ -280,6 +280,11 @@ uint8_t gc_execute_line(char *line)
gc_block.modal.override = OVERRIDE_PARKING_MOTION;
break;
#endif
#ifdef ENABLE_M114
case 114:
report_realtime_position();
break;
#endif
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported M command]
}

Expand Down
30 changes: 30 additions & 0 deletions grbl/report.c
Expand Up @@ -643,3 +643,33 @@ void report_realtime_status()

}
#endif

#ifdef ENABLE_M114
// Reports the current work position
void report_realtime_position()
{
int32_t current_position[N_AXIS]; // Copy current state of the system position variable
memcpy(current_position,sys_position,sizeof(sys_position));
float print_position[N_AXIS];
system_convert_array_steps_to_mpos(print_position,current_position);

float wco[N_AXIS];
uint8_t idx;
for (idx=0; idx<N_AXIS; idx++) {
if (idx == 0) { printPgmString(PSTR("X:")); }
if (idx == 1) { printPgmString(PSTR("Y:")); }
if (idx == 2) { printPgmString(PSTR("Z:")); }

// Apply work coordinate offsets and tool length offset to current position.
wco[idx] = gc_state.coord_system[idx]+gc_state.coord_offset[idx];
if (idx == TOOL_LENGTH_OFFSET_AXIS) { wco[idx] += gc_state.tool_length_offset; }
print_position[idx] -= wco[idx];

printFloat_CoordValue(print_position[idx]);

if (idx < (N_AXIS-1)) { serial_write(' '); }
}

report_util_line_feed();
}
#endif
5 changes: 5 additions & 0 deletions grbl/report.h
Expand Up @@ -108,6 +108,11 @@ void report_echo_line_received(char *line);
// Prints realtime status report
void report_realtime_status();

#ifdef ENABLE_M114
// Prints realtime position report
void report_realtime_position();
#endif

// Prints recorded probe position
void report_probe_parameters();

Expand Down

0 comments on commit 40c2983

Please sign in to comment.