Major g-code parser overhaul. 100%* compliant. Other related updates.

- Completely overhauled the g-code parser. It’s now 100%* compliant. (*
may have some bugs). Being compliant, here are some of the major
differences.

- SMALLER and JUST AS FAST! A number of optimizations were found that
sped things up and allowed for the more thorough error-checking to be
installed without a speed hit. Trimmed a lot of ‘fat’ in the parser and
still was able to make it significantly smaller than it was.

- No default feed rate setting! Removed completely! This doesn’t exist
in the g-code standard. So, it now errors out whenever it’s undefined
for motions that require it (G1/2/3/38.2).

- Any g-code parser error expunges the ENTIRE block. This means all
information is lost and not passed on to the running state. Before some
of the states would remain, which could have led to some problems.

- If the g-code block passes all of the error-checks, the g-code state
is updated and all motions are executed according to the order of
execution.

- Changes in spindle speed, when already running, will update the
output pin accordingly. This fixes a bug, where it wouldn’t update the
speed.

- Update g-code parser error reporting. Errors now return detailed
information of what exact went wrong. The most common errors return a
short text description. For less common errors, the parser reports
‘Invalid gcode ID:20’, where 20 is a error ID. A list of error code IDs
and their descriptions will be documented for user reference elsewhere
to save flash space.

- Other notable changes:

- Added a print integer routine for uint8 variables. This saved
significant flash space by switching from a heavier universal print
integer routine.

- Saved some flash space with our own short hypotenuse calculation

- Some arc computation flash and memory optimizations.
This commit is contained in:
Sonny Jeon
2014-05-25 16:05:28 -06:00
parent 06432c9de9
commit 532c359a11
22 changed files with 1162 additions and 741 deletions

View File

@ -66,7 +66,6 @@ void settings_reset() {
settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM;
settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM;
settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS;
settings.default_feed_rate = DEFAULT_FEEDRATE;
settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE;
settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE;
settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE;
@ -161,7 +160,7 @@ uint8_t read_global_settings() {
// A helper method to set settings from command line
uint8_t settings_store_global_setting(int parameter, float value) {
if (value < 0.0) { return(STATUS_SETTING_VALUE_NEG); }
if (value < 0.0) { return(STATUS_NEGATIVE_VALUE); }
switch(parameter) {
case 0: case 1: case 2:
settings.steps_per_mm[parameter] = value; break;
@ -177,52 +176,51 @@ uint8_t settings_store_global_setting(int parameter, float value) {
case 12:
if (value < 3) { return(STATUS_SETTING_STEP_PULSE_MIN); }
settings.pulse_microseconds = round(value); break;
case 13: settings.default_feed_rate = value; break;
case 14: settings.step_invert_mask = trunc(value); break;
case 15: settings.dir_invert_mask = trunc(value); break;
case 16: settings.stepper_idle_lock_time = round(value); break;
case 17: settings.junction_deviation = fabs(value); break;
case 18: settings.arc_tolerance = value; break;
case 19: settings.decimal_places = round(value); break;
case 20:
case 13: settings.step_invert_mask = trunc(value); break;
case 14: settings.dir_invert_mask = trunc(value); break;
case 15: settings.stepper_idle_lock_time = round(value); break;
case 16: settings.junction_deviation = fabs(value); break;
case 17: settings.arc_tolerance = value; break;
case 18: settings.decimal_places = round(value); break;
case 19:
if (value) { settings.flags |= BITFLAG_REPORT_INCHES; }
else { settings.flags &= ~BITFLAG_REPORT_INCHES; }
break;
case 21: // Reset to ensure change. Immediate re-init may cause problems.
case 20: // Reset to ensure change. Immediate re-init may cause problems.
if (value) { settings.flags |= BITFLAG_AUTO_START; }
else { settings.flags &= ~BITFLAG_AUTO_START; }
break;
case 22: // Reset to ensure change. Immediate re-init may cause problems.
case 21: // Reset to ensure change. Immediate re-init may cause problems.
if (value) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; }
else { settings.flags &= ~BITFLAG_INVERT_ST_ENABLE; }
break;
case 23: // Reset to ensure change. Immediate re-init may cause problems.
case 22: // Reset to ensure change. Immediate re-init may cause problems.
if (value) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; }
else { settings.flags &= ~BITFLAG_INVERT_LIMIT_PINS; }
break;
case 24:
case 23:
if (value) {
if (bit_isfalse(settings.flags, BITFLAG_HOMING_ENABLE)) { return(STATUS_SOFT_LIMIT_ERROR); }
settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE;
} else { settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; }
break;
case 25:
case 24:
if (value) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; }
else { settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE; }
limits_init(); // Re-init to immediately change. NOTE: Nice to have but could be problematic later.
break;
case 26:
case 25:
if (value) { settings.flags |= BITFLAG_HOMING_ENABLE; }
else {
settings.flags &= ~BITFLAG_HOMING_ENABLE;
settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; // Force disable soft-limits.
}
break;
case 27: settings.homing_dir_mask = trunc(value); break;
case 28: settings.homing_feed_rate = value; break;
case 29: settings.homing_seek_rate = value; break;
case 30: settings.homing_debounce_delay = round(value); break;
case 31: settings.homing_pulloff = value; break;
case 26: settings.homing_dir_mask = trunc(value); break;
case 27: settings.homing_feed_rate = value; break;
case 28: settings.homing_seek_rate = value; break;
case 29: settings.homing_debounce_delay = round(value); break;
case 30: settings.homing_pulloff = value; break;
default:
return(STATUS_INVALID_STATEMENT);
}