Refactored g-code parser. Saved 60bytes flash and some ram. Edited Readme.

- Freed up another 60 bytes of flash and 12-24 bytes of stack RAM by
using the pre-allocated IJK arc offset vector that is guaranteed to be
not in use. Only G10 and G28/30 require fetching from EEPROM and
retaining extra data. Both commands use axis words, which rules out
G2/3 arcs using IJK offsets existing in same block. Not ideal, but
every byte helps.

- Edited README.
This commit is contained in:
Sonny Jeon 2016-09-27 23:05:43 -06:00
parent 669735bea9
commit bf5fc48074
4 changed files with 36 additions and 27 deletions

View File

@ -34,13 +34,13 @@ Grbl includes full acceleration management with look ahead. That means the contr
##Update Summary for v1.1 ##Update Summary for v1.1
- **IMPORTANT:** Your EEPROM will be wiped and restored with new settings. This is due to the addition of two new spindle speed '$' settings. - **IMPORTANT:** Your EEPROM will be wiped and restored with new settings. This is due to the addition of two new spindle speed '$' settings.
- **Real-time Overrides** : Alters the machine running state immediately with feed, rapid, spindle speed, spindle stop, and coolant toggle controls. This huge contribution by the Grbl project is feature that is common only on industrial machines, often used to optimize cutting while the job is running. Most hobby CNC's try to mimic this with varying results. - **Real-time Overrides** : Alters the machine running state immediately with feed, rapid, spindle speed, spindle stop, and coolant toggle controls. This awesome new feature is common only on industrial machines, often used to optimize speeds and feeds while a job is running. Most hobby CNC's try to mimic this behavior, but usually have large amounts of lag. Grbl executes overrides in realtime and within tens of milliseconds.
- **Jogging Mode** : New jogging commands seperate from the g-code parser, so that the parser state doesn't get altered and cause a potential crash if not restored properly. Documentation is included on how to use this with a joystick with a low-latency. - **Jogging Mode** : The new jogging commands are independent of the g-code parser, so that the parser state doesn't get altered and cause a potential crash if not restored properly. Documentation is included on how this works and how it can be used to control your machine via a joystick or rotary dial with a low-latency, satisfying response.
- **Laser Mode** : Grbl now has a "laser" mode, where consecutive G1, G2, and G3 commands do not stop and continuously move through them with a spindle speed change. Spindle speed overrides also work with laser mode so you can tweak the laser power, if you need to during the job. Switch between "laser" mode and "normal" mode via a `$` setting. - **Laser Mode** : The new "laser" mode will cause Grbl to move continuously through consecutive G1, G2, and G3 commands with spindle speed changes. When "laser" mode is disabled, Grbl will instead come to a stop to ensure a spindle comes up to speed properly. Spindle speed overrides also work with laser mode so you can tweak the laser power, if you need to during the job. Switch between "laser" mode and "normal" mode via a `$` setting.
- **Significant Interface Improvements**: Just this one time and done simultaneously with adding override controls, Grbl has tweaked the communication interface to make it easier for developers to write better GUIs. _NOTE: GUIs need to specifically update their code to be compatible with v1.1 and later._ - **Significant Interface Improvements**: Just this one time and done simultaneously with adding override data and controls, Grbl has tweaked the communication interface to make it easier for developers to write and maintain their GUIs. _NOTE: GUIs need to specifically update their code to be compatible with v1.1 and later._
- **New Status Reports**: To account for the additional override data, status reports have been tweaked to cram more data into it, while still being smaller than before. Documentation is included, outlining how it has been changed. - **New Status Reports**: To account for the additional override data, status reports have been tweaked to cram more data into it, while still being smaller than before. Documentation is included, outlining how it has been changed.
- **Improved Error/Alarm Feedback** : All Grbl error and alarm messages have been changed to providing a code. Each code is associated with a specific problem, so users will know exactly what is wrong without having to guess. Documentation and an easy to parse CSV is included in the repo. - **Improved Error/Alarm Feedback** : All Grbl error and alarm messages have been changed to providing a code. Each code is associated with a specific problem, so users will know exactly what is wrong without having to guess. Documentation and an easy to parse CSV is included in the repo.

View File

@ -1,3 +1,9 @@
----------------
Date: 2016-09-27
Author: Sonny Jeon
Subject: Update README and clarifications in jogging document.
---------------- ----------------
Date: 2016-09-26 Date: 2016-09-26
Author: Sonny Jeon Author: Sonny Jeon

View File

@ -77,8 +77,6 @@ uint8_t gc_execute_line(char *line)
uint8_t axis_command = AXIS_COMMAND_NONE; uint8_t axis_command = AXIS_COMMAND_NONE;
uint8_t axis_0, axis_1, axis_linear; uint8_t axis_0, axis_1, axis_linear;
uint8_t coord_select = 0; // Tracks G10 P coordinate selection for execution uint8_t coord_select = 0; // Tracks G10 P coordinate selection for execution
float coordinate_data[N_AXIS]; // Multi-use variable to store coordinate data for execution
float parameter_data[N_AXIS]; // Multi-use variable to store parameter data for execution
// Initialize bitflag tracking variables for axis indices compatible operations. // Initialize bitflag tracking variables for axis indices compatible operations.
uint8_t axis_words = 0; // XYZ tracking uint8_t axis_words = 0; // XYZ tracking
@ -526,11 +524,12 @@ uint8_t gc_execute_line(char *line)
// is active. The read pauses the processor temporarily and may cause a rare crash. For // is active. The read pauses the processor temporarily and may cause a rare crash. For
// future versions on processors with enough memory, all coordinate data should be stored // future versions on processors with enough memory, all coordinate data should be stored
// in memory and written to EEPROM only when there is not a cycle active. // in memory and written to EEPROM only when there is not a cycle active.
memcpy(coordinate_data,gc_state.coord_system,sizeof(gc_state.coord_system)); float block_coord_system[N_AXIS];
memcpy(block_coord_system,gc_state.coord_system,sizeof(gc_state.coord_system));
if ( bit_istrue(command_words,bit(MODAL_GROUP_G12)) ) { // Check if called in block if ( bit_istrue(command_words,bit(MODAL_GROUP_G12)) ) { // Check if called in block
if (gc_block.modal.coord_select > N_COORDINATE_SYSTEM) { FAIL(STATUS_GCODE_UNSUPPORTED_COORD_SYS); } // [Greater than N sys] if (gc_block.modal.coord_select > N_COORDINATE_SYSTEM) { FAIL(STATUS_GCODE_UNSUPPORTED_COORD_SYS); } // [Greater than N sys]
if (gc_state.modal.coord_select != gc_block.modal.coord_select) { if (gc_state.modal.coord_select != gc_block.modal.coord_select) {
if (!(settings_read_coord_data(gc_block.modal.coord_select,coordinate_data))) { FAIL(STATUS_SETTING_READ_FAIL); } if (!(settings_read_coord_data(gc_block.modal.coord_select,block_coord_system))) { FAIL(STATUS_SETTING_READ_FAIL); }
} }
} }
@ -562,21 +561,24 @@ uint8_t gc_execute_line(char *line)
// Determine coordinate system to change and try to load from EEPROM. // Determine coordinate system to change and try to load from EEPROM.
if (coord_select > 0) { coord_select--; } // Adjust P1-P6 index to EEPROM coordinate data indexing. if (coord_select > 0) { coord_select--; } // Adjust P1-P6 index to EEPROM coordinate data indexing.
else { coord_select = gc_block.modal.coord_select; } // Index P0 as the active coordinate system else { coord_select = gc_block.modal.coord_select; } // Index P0 as the active coordinate system
if (!settings_read_coord_data(coord_select,parameter_data)) { FAIL(STATUS_SETTING_READ_FAIL); } // [EEPROM read fail]
// Pre-calculate the coordinate data changes. NOTE: Uses parameter_data since coordinate_data may be in use by G54-59. // NOTE: Store parameter data in IJK values. By rule, they are not in use with this command.
if (!settings_read_coord_data(coord_select,gc_block.values.ijk)) { FAIL(STATUS_SETTING_READ_FAIL); } // [EEPROM read fail]
// Pre-calculate the coordinate data changes.
for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used. for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used.
// Update axes defined only in block. Always in machine coordinates. Can change non-active system. // Update axes defined only in block. Always in machine coordinates. Can change non-active system.
if (bit_istrue(axis_words,bit(idx)) ) { if (bit_istrue(axis_words,bit(idx)) ) {
if (gc_block.values.l == 20) { if (gc_block.values.l == 20) {
// L20: Update coordinate system axis at current position (with modifiers) with programmed value // L20: Update coordinate system axis at current position (with modifiers) with programmed value
parameter_data[idx] = gc_state.position[idx]-gc_state.coord_offset[idx]-gc_block.values.xyz[idx]; // WPos = MPos - WCS - G92 - TLO -> WCS = MPos - G92 - TLO - WPos
if (idx == TOOL_LENGTH_OFFSET_AXIS) { parameter_data[idx] -= gc_state.tool_length_offset; } gc_block.values.ijk[idx] = gc_state.position[idx]-gc_state.coord_offset[idx]-gc_block.values.xyz[idx];
if (idx == TOOL_LENGTH_OFFSET_AXIS) { gc_block.values.ijk[idx] -= gc_state.tool_length_offset; }
} else { } else {
// L2: Update coordinate system axis to programmed value. // L2: Update coordinate system axis to programmed value.
parameter_data[idx] = gc_block.values.xyz[idx]; gc_block.values.ijk[idx] = gc_block.values.xyz[idx];
} }
} } // Else, keep current stored value.
} }
break; break;
case NON_MODAL_SET_COORDINATE_OFFSET: case NON_MODAL_SET_COORDINATE_OFFSET:
@ -587,7 +589,8 @@ uint8_t gc_execute_line(char *line)
// active coordinate system is selected, but is still active unless G92.1 disables it. // active coordinate system is selected, but is still active unless G92.1 disables it.
for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used. for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used.
if (bit_istrue(axis_words,bit(idx)) ) { if (bit_istrue(axis_words,bit(idx)) ) {
gc_block.values.xyz[idx] = gc_state.position[idx]-coordinate_data[idx]-gc_block.values.xyz[idx]; // WPos = MPos - WCS - G92 - TLO -> G92 = MPos - WCS - TLO - WPos
gc_block.values.xyz[idx] = gc_state.position[idx]-block_coord_system[idx]-gc_block.values.xyz[idx];
if (idx == TOOL_LENGTH_OFFSET_AXIS) { gc_block.values.xyz[idx] -= gc_state.tool_length_offset; } if (idx == TOOL_LENGTH_OFFSET_AXIS) { gc_block.values.xyz[idx] -= gc_state.tool_length_offset; }
} else { } else {
gc_block.values.xyz[idx] = gc_state.coord_offset[idx]; gc_block.values.xyz[idx] = gc_state.coord_offset[idx];
@ -612,7 +615,7 @@ uint8_t gc_execute_line(char *line)
if (gc_block.non_modal_command != NON_MODAL_ABSOLUTE_OVERRIDE) { if (gc_block.non_modal_command != NON_MODAL_ABSOLUTE_OVERRIDE) {
// Apply coordinate offsets based on distance mode. // Apply coordinate offsets based on distance mode.
if (gc_block.modal.distance == DISTANCE_MODE_ABSOLUTE) { if (gc_block.modal.distance == DISTANCE_MODE_ABSOLUTE) {
gc_block.values.xyz[idx] += coordinate_data[idx] + gc_state.coord_offset[idx]; gc_block.values.xyz[idx] += block_coord_system[idx] + gc_state.coord_offset[idx];
if (idx == TOOL_LENGTH_OFFSET_AXIS) { gc_block.values.xyz[idx] += gc_state.tool_length_offset; } if (idx == TOOL_LENGTH_OFFSET_AXIS) { gc_block.values.xyz[idx] += gc_state.tool_length_offset; }
} else { // Incremental mode } else { // Incremental mode
gc_block.values.xyz[idx] += gc_state.position[idx]; gc_block.values.xyz[idx] += gc_state.position[idx];
@ -629,15 +632,16 @@ uint8_t gc_execute_line(char *line)
case NON_MODAL_GO_HOME_1: // G30 case NON_MODAL_GO_HOME_1: // G30
// [G28/30 Errors]: Cutter compensation is enabled. // [G28/30 Errors]: Cutter compensation is enabled.
// Retreive G28/30 go-home position data (in machine coordinates) from EEPROM // Retreive G28/30 go-home position data (in machine coordinates) from EEPROM
// NOTE: Store parameter data in IJK values. By rule, they are not in use with this command.
if (gc_block.non_modal_command == NON_MODAL_GO_HOME_0) { if (gc_block.non_modal_command == NON_MODAL_GO_HOME_0) {
if (!settings_read_coord_data(SETTING_INDEX_G28,parameter_data)) { FAIL(STATUS_SETTING_READ_FAIL); } if (!settings_read_coord_data(SETTING_INDEX_G28,gc_block.values.ijk)) { FAIL(STATUS_SETTING_READ_FAIL); }
} else { // == NON_MODAL_GO_HOME_1 } else { // == NON_MODAL_GO_HOME_1
if (!settings_read_coord_data(SETTING_INDEX_G30,parameter_data)) { FAIL(STATUS_SETTING_READ_FAIL); } if (!settings_read_coord_data(SETTING_INDEX_G30,gc_block.values.ijk)) { FAIL(STATUS_SETTING_READ_FAIL); }
} }
if (axis_words) { if (axis_words) {
// Move only the axes specified in secondary move. // Move only the axes specified in secondary move.
for (idx=0; idx<N_AXIS; idx++) { for (idx=0; idx<N_AXIS; idx++) {
if (!(axis_words & (1<<idx))) { parameter_data[idx] = gc_state.position[idx]; } if (!(axis_words & (1<<idx))) { gc_block.values.ijk[idx] = gc_state.position[idx]; }
} }
} else { } else {
axis_command = AXIS_COMMAND_NONE; // Set to none if no intermediate motion. axis_command = AXIS_COMMAND_NONE; // Set to none if no intermediate motion.
@ -964,7 +968,7 @@ uint8_t gc_execute_line(char *line)
// [15. Coordinate system selection ]: // [15. Coordinate system selection ]:
if (gc_state.modal.coord_select != gc_block.modal.coord_select) { if (gc_state.modal.coord_select != gc_block.modal.coord_select) {
gc_state.modal.coord_select = gc_block.modal.coord_select; gc_state.modal.coord_select = gc_block.modal.coord_select;
memcpy(gc_state.coord_system,coordinate_data,sizeof(coordinate_data)); memcpy(gc_state.coord_system,block_coord_system,N_AXIS*sizeof(float));
system_flag_wco_change(); system_flag_wco_change();
} }
@ -979,10 +983,10 @@ uint8_t gc_execute_line(char *line)
// [19. Go to predefined position, Set G10, or Set axis offsets ]: // [19. Go to predefined position, Set G10, or Set axis offsets ]:
switch(gc_block.non_modal_command) { switch(gc_block.non_modal_command) {
case NON_MODAL_SET_COORDINATE_DATA: case NON_MODAL_SET_COORDINATE_DATA:
settings_write_coord_data(coord_select,parameter_data); settings_write_coord_data(coord_select,gc_block.values.xyz);
// Update system coordinate system if currently active. // Update system coordinate system if currently active.
if (gc_state.modal.coord_select == coord_select) { if (gc_state.modal.coord_select == coord_select) {
memcpy(gc_state.coord_system,parameter_data,sizeof(parameter_data)); memcpy(gc_state.coord_system,gc_block.values.xyz,N_AXIS*sizeof(float));
system_flag_wco_change(); system_flag_wco_change();
} }
break; break;
@ -991,8 +995,8 @@ uint8_t gc_execute_line(char *line)
// and absolute and incremental modes. // and absolute and incremental modes.
pl_data->condition |= PL_COND_FLAG_RAPID_MOTION; // Set rapid motion condition flag. pl_data->condition |= PL_COND_FLAG_RAPID_MOTION; // Set rapid motion condition flag.
if (axis_command) { mc_line(gc_block.values.xyz, pl_data); } if (axis_command) { mc_line(gc_block.values.xyz, pl_data); }
mc_line(parameter_data, pl_data); mc_line(gc_block.values.ijk, pl_data);
memcpy(gc_state.position, parameter_data, sizeof(parameter_data)); memcpy(gc_state.position, gc_block.values.ijk, N_AXIS*sizeof(float));
break; break;
case NON_MODAL_SET_HOME_0: case NON_MODAL_SET_HOME_0:
settings_write_coord_data(SETTING_INDEX_G28,gc_state.position); settings_write_coord_data(SETTING_INDEX_G28,gc_state.position);
@ -1085,8 +1089,7 @@ uint8_t gc_execute_line(char *line)
// Execute coordinate change and spindle/coolant stop. // Execute coordinate change and spindle/coolant stop.
if (sys.state != STATE_CHECK_MODE) { if (sys.state != STATE_CHECK_MODE) {
if (!(settings_read_coord_data(gc_state.modal.coord_select,coordinate_data))) { FAIL(STATUS_SETTING_READ_FAIL); } if (!(settings_read_coord_data(gc_state.modal.coord_select,gc_state.coord_system))) { FAIL(STATUS_SETTING_READ_FAIL); }
memcpy(gc_state.coord_system,coordinate_data,sizeof(coordinate_data));
system_flag_wco_change(); // Set to refresh immediately just in case something altered. system_flag_wco_change(); // Set to refresh immediately just in case something altered.
spindle_stop(); spindle_stop();
coolant_set_state(COOLANT_DISABLE); coolant_set_state(COOLANT_DISABLE);

View File

@ -23,7 +23,7 @@
// Grbl versioning system // Grbl versioning system
#define GRBL_VERSION "1.1b" #define GRBL_VERSION "1.1b"
#define GRBL_VERSION_BUILD "20160926" #define GRBL_VERSION_BUILD "20160927"
// Define standard libraries used by Grbl. // Define standard libraries used by Grbl.
#include <avr/io.h> #include <avr/io.h>