grblHAL core  20240704
system.c File Reference
#include <math.h>
#include <string.h>
#include "hal.h"
#include "motion_control.h"
#include "protocol.h"
#include "tool_change.h"
#include "state_machine.h"
#include "machine_limits.h"
#include "kinematics.h"

Functions

void system_init_switches (void)
 
ISR_CODE void ISR_FUNC() control_interrupt_handler (control_signals_t signals)
 Pin change interrupt handler for pin-out commands, i.e. cycle start, feed hold, reset etc. Mainly sets the realtime command execute variable to have the main program execute these when its ready. This works exactly like the character-based realtime commands when picked off directly from the incoming data stream. More...
 
void system_execute_startup (void)
 Executes user startup scripts, if stored. More...
 
const char * help_rst (const char *cmd)
 
const char * help_rtc (const char *cmd)
 
const char * help_spindle (const char *cmd)
 
const char * help_pins (const char *cmd)
 
const char * help_pin_state (const char *cmd)
 
const char * help_switches (const char *cmd)
 
const char * help_homing (const char *cmd)
 
void system_register_commands (sys_commands_t *commands)
 
void _system_output_help (sys_commands_t *commands, bool traverse)
 
void system_output_help (const sys_command_t *commands, uint32_t num_commands)
 
void system_command_help (void)
 
status_code_t system_execute_line (char *line)
 Directs and executes one line of input from protocol_process. More...
 
void system_clear_tlo_reference (axes_signals_t homing_cycle)
 Called on homing state changes. More...
 
void system_flag_wco_change (void)
 Called on a work coordinate (WCO) changes. More...
 
void system_convert_array_steps_to_mpos (float *position, int32_t *steps)
 Sets machine position. Must be sent a 'step' array. More...
 
bool system_xy_at_fixture (coord_system_id_t id, float tolerance)
 Checks if XY position is within coordinate system XY with given tolerance. More...
 
void system_raise_alarm (alarm_code_t alarm)
 Raise and report a system alarm. More...
 
report_tracking_flags_t system_get_rt_report_flags (void)
 Get the active realtime report addon flags for the next report. More...
 
void system_add_rt_report (report_tracking_t report)
 Set(s) or clear all active realtime report addon flag(s) for the next report. More...
 

Function Documentation

◆ _system_output_help()

void _system_output_help ( sys_commands_t commands,
bool  traverse 
)

◆ control_interrupt_handler()

ISR_CODE void ISR_FUNC() control_interrupt_handler ( control_signals_t  signals)

Pin change interrupt handler for pin-out commands, i.e. cycle start, feed hold, reset etc. Mainly sets the realtime command execute variable to have the main program execute these when its ready. This works exactly like the character-based realtime commands when picked off directly from the incoming data stream.

Parameters
signalsa control_signals_t union holding status of the signals.

◆ help_homing()

const char* help_homing ( const char *  cmd)

◆ help_pin_state()

const char* help_pin_state ( const char *  cmd)

◆ help_pins()

const char* help_pins ( const char *  cmd)

◆ help_rst()

const char* help_rst ( const char *  cmd)

◆ help_rtc()

const char* help_rtc ( const char *  cmd)

◆ help_spindle()

const char* help_spindle ( const char *  cmd)

◆ help_switches()

const char* help_switches ( const char *  cmd)

◆ system_add_rt_report()

void system_add_rt_report ( report_tracking_t  report)

Set(s) or clear all active realtime report addon flag(s) for the next report.

Fires the grbl.on_rt_reports_added event.

Parameters
reporta report_tracking_t enum containing the flag(s) to set or clear.

◆ system_clear_tlo_reference()

void system_clear_tlo_reference ( axes_signals_t  homing_cycle)

Called on homing state changes.

Clears the tool length offset (TLO) when linear axis or X- or Z-axis is homed in lathe mode. Typically called on the grbl.on_homing complete event.

Parameters
ida axes_signals_t holding the axis flags that homed status was changed for.

◆ system_command_help()

void system_command_help ( void  )

◆ system_convert_array_steps_to_mpos()

void system_convert_array_steps_to_mpos ( float *  position,
int32_t *  steps 
)

Sets machine position. Must be sent a 'step' array.

NOTE: If motor steps and machine position are not in the same coordinate frame, this function serves as a central place to compute the transformation.

Parameters
positionpointer to the target float array for the machine position.
stepspointer to the source step count array to transform.

◆ system_execute_line()

status_code_t system_execute_line ( char *  line)

Directs and executes one line of input from protocol_process.

While mostly incoming streaming g-code blocks, this also executes grblHAL internal commands, such as settings, initiating the homing cycle, and toggling switch states. This differs from the realtime command module by being susceptible to when grblHAL is ready to execute the next line during a cycle, so for switches like block delete, the switch only effects the lines that are processed afterward, not necessarily real-time during a cycle, since there are motions already stored in the buffer. However, this 'lag' should not be an issue, since these commands are not typically used during a cycle. If the command is not known to the core a grbl.on_unknown_sys_command event is raised so that plugin code can check if it is a command it supports.

NOTE: Code calling this function needs to provide the command in a writable buffer since the first part of the command (up to the first = character) is changed to uppercase and having spaces removed.

Parameters
linepointer to the command string.
Returns
status_code_t enum value; Status_OK if successfully handled, another relevant status code if not.

◆ system_execute_startup()

void system_execute_startup ( void  )

Executes user startup scripts, if stored.

◆ system_flag_wco_change()

void system_flag_wco_change ( void  )

Called on a work coordinate (WCO) changes.

If configured waits for the planner buffer to empty then fires the grbl.on_wco_changed event and sets the Report_WCO flag to add the WCO report element to the next status report.

◆ system_get_rt_report_flags()

report_tracking_flags_t system_get_rt_report_flags ( void  )

Get the active realtime report addon flags for the next report.

Returns
a report_tracking_flags_t union containing the flags.

◆ system_init_switches()

void system_init_switches ( void  )

◆ system_output_help()

void system_output_help ( const sys_command_t commands,
uint32_t  num_commands 
)

◆ system_raise_alarm()

void system_raise_alarm ( alarm_code_t  alarm)

Raise and report a system alarm.

Parameters
aalarm_code_t enum representing the alarm code.

◆ system_register_commands()

void system_register_commands ( sys_commands_t commands)

◆ system_xy_at_fixture()

bool system_xy_at_fixture ( coord_system_id_t  id,
float  tolerance 
)

Checks if XY position is within coordinate system XY with given tolerance.

Parameters
ida coord_system_id_t, typically CoordinateSystem_G59_3.
toleranceas the allowed radius the current position has to be within.
Returns
false if tolerance is 0 or position is outside the allowed radius, otherwise true.