From 5c13dbca9f1b53323342afd0f94487bb3820c948 Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Thu, 9 Feb 2017 12:45:26 -0500 Subject: [PATCH] Cleaned up offset handling in advance of fixing a bug in G53 move display --- g2core/board/gquadratic/hardware.cpp | 2 +- g2core/canonical_machine.cpp | 181 ++++++++++++++------------- g2core/canonical_machine.h | 14 +-- g2core/config_app.cpp | 78 +++--------- g2core/gcode.h | 4 +- g2core/plan_arc.cpp | 34 ++--- g2core/plan_line.cpp | 16 +-- g2core/planner.h | 4 +- g2core/settings/settings_default.h | 5 - 9 files changed, 144 insertions(+), 194 deletions(-) diff --git a/g2core/board/gquadratic/hardware.cpp b/g2core/board/gquadratic/hardware.cpp index f1e3fe50..febd5e3d 100644 --- a/g2core/board/gquadratic/hardware.cpp +++ b/g2core/board/gquadratic/hardware.cpp @@ -92,7 +92,7 @@ void hardware_init() stat_t hardware_periodic() { - float x_pos = cm_get_work_position(ACTIVE_MODEL, AXIS_X); + float x_pos = cm_get_display_position(ACTIVE_MODEL, AXIS_X); if (fabs(LEDs::old_x_pos - x_pos) > 0.01) { LEDs::old_x_pos = x_pos; diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp index f8280a23..8d371ffe 100644 --- a/g2core/canonical_machine.cpp +++ b/g2core/canonical_machine.cpp @@ -368,7 +368,7 @@ void cm_set_tool_number(GCodeState_t *gcode_state, const uint8_t tool) void cm_set_absolute_override(GCodeState_t *gcode_state, const uint8_t absolute_override) { gcode_state->absolute_override = (cmAbsoluteOverride)absolute_override; - cm_set_work_offsets(MODEL); // must reset offsets if you change absolute override + cm_set_display_offsets(MODEL); // must reset offsets if you change absolute override } void cm_set_model_linenum(const uint32_t linenum) @@ -384,72 +384,100 @@ void cm_set_model_linenum(const uint32_t linenum) * These functions are not part of the NIST defined functions ***********************************************************************************/ /* + * cm_get_combined_offset() - return the combined offsets for an axis (G53-G59, G92, Tools) + * cm_get_display_offset() - return the current display offset from pecified Gcode model + * cm_set_display_offsets() - capture combined offsets from the model into absolute values in the active Gcode dynamic model + * * Notes on Coordinate System and Offset functions * * All positional information in the canonical machine is kept as absolute coords and in - * canonical units (mm). The offsets are only used to translate in and out of canonical form - * during interpretation and response. + * canonical units (mm, mm/min). The offsets are only used to translate in and out of + * canonical form during incoming processing, and for displays in responses. * * Managing the coordinate systems & offsets is somewhat complicated. The following affect offsets: - * - coordinate system selected. 1-9 correspond to G54-G59 - * - absolute override: forces current move to be interpreted in machine coordinates: G53 (system 0) + * - coordinate system selected. 1-6 correspond to G54-G59 * - G92 offsets are added "on top of" the coord system offsets -- if origin_offset_enable == true - * - G28 and G30 moves; these are run in absolute coordinates + * - tool offsets are also accounted for * - * The offsets themselves are considered static, are kept in cm, and are supposed to be persistent. + * Position displays {pos:n} are always in work coordinates aka using 'display' offsets + * - position displays are assembled by applying all active offsets to the current machine position + * - an absolute override forces current move to be interpreted in machine coordinates: G53 (system 0) + * - G53 is an explicit absolute override requested by the program, so displays in absolute coords + * - G28 and G30 moves are run in absolute coordinates but display using current offsets + * - Probing also has a very short move that behaves this way * - * To reduce complexity and data load the following is done: - * - Full data for coordinates/offsets is only accessible by the canonical machine, not the downstream - * - A fully resolved set of coord and G92 offsets, with per-move exceptions can be captured as "work_offsets" - * - The core gcode context (gm) only knows about the active coord system and the work offsets - */ - -/* - * cm_get_active_coord_offset() - return the currently active coordinate offset for an axis + * The offsets themselves are "the truth". These are: + * - cm.coord_offset[coord][axis] coordinate offsets for G53-G59, by axis - persistent + * - cm.tool_offset[axis] offsets for currently selected and active tool - persistent + * - cm.gmx.origin_offset[axis] G92 origin offset. Not persistent * - * This function is typically used to evaluate and set offsets, as opposed to cm_get_work_offset() - * which merely returns what's in the work_offset[] array. + * - cm_get_combined_offset() puts the above together to provide a combined, active offset. + * G92 offsets are only included if it is active * - * Takes G5x, G92 into account to return the active offset for this move. - * - * Absolute Override is the Gcode G53 convention to allow one and only one Gcode block + * Display offsets + * - cm_set_display_offsets() writes combined offsets to cm.gm.display_offset[] + * *** This is for display purposes only and should not be used to set positions *** + * - cm_set_display_offsets() should be called every time underlying data would cause a change + * - cm_set_display_offsets() takes absolute override display rules into account + * - Use cm_get_display_offset() to return the display offset value + */ +/* Absolute Override is the Gcode G53 convention to allow one and only one Gcode block * to be run in absolute coordinates, regardless of coordinate offsets, G92 offsets, and - * tool offsets. If absolute_override is set to ABSOLUTE_OVERRIDE_ON_AND_DISPLAY this - * function will return 0.0 for the offset value. This bit is here to support G28 and G30 + * tool offsets. If absolute_override is set to ABSOLUTE_OVERRIDE_ON_AND_DISPLAY the display + * values will be set to 0.0 for the offset value. This bit is here to support G28 and G30 * return moves and other moves that run in absolute override mode but may want position * to be reported using all current offsets (work offsets), versus an explicit G53 move that * should be displayed in absolute coordinates. */ - -float cm_get_active_coord_offset(const uint8_t axis, const bool absolute) + +float cm_get_combined_offset(const uint8_t axis) { - // if absolute override is on and is to be displayed with no offsets: -// if (cm->gm.absolute_override == ABSOLUTE_OVERRIDE_ON_AND_DISPLAY) { - if (absolute & (cm->gm.absolute_override == ABSOLUTE_OVERRIDE_ON)) { - return (0.0); - } - float offset = cm->offset[cm->gm.coord_system][axis] + cm->tl_offset[axis]; + float offset = cm->coord_offset[cm->gm.coord_system][axis] + cm->tool_offset[axis]; if (cm->gmx.origin_offset_enable == true) { - offset += cm->gmx.origin_offset[axis]; // includes G5x and G92 components + offset += cm->gmx.origin_offset[axis]; } return (offset); +} + +float cm_get_display_offset(const GCodeState_t *gcode_state, const uint8_t axis) +{ + return (gcode_state->display_offset[axis]); +} + +void cm_set_display_offsets(GCodeState_t *gcode_state) +{ + for (uint8_t axis = AXIS_X; axis < AXES; axis++) { + + // if absolute override is on and position is to be displayed with no offsets + if (cm->gm.absolute_override == ABSOLUTE_OVERRIDE_ON_AND_DISPLAY) { + gcode_state->display_offset[axis] = 0; + } else { + gcode_state->display_offset[axis] = cm_get_combined_offset(axis); + } + } } /* - * cm_get_work_offset() - return a coord offset from the active Gcode dynamic model - * cm_set_work_offsets() - capture coord offsets from the model into absolute values in the active Gcode dynamic model + * cm_get_display_position() - return position in external form from the active Gcode dynamic model + * + * ... that means in prevailing units (mm/inch) and with all offsets applied */ -float cm_get_work_offset(const GCodeState_t *gcode_state, const uint8_t axis) +float cm_get_display_position(const GCodeState_t *gcode_state, const uint8_t axis) { - return (gcode_state->work_offset[axis]); -} + float position; -void cm_set_work_offsets(GCodeState_t *gcode_state) -{ - for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - gcode_state->work_offset[axis] = cm_get_active_coord_offset(axis, false); + if (gcode_state == MODEL) { + position = cm->gmx.position[axis] - cm_get_display_offset(MODEL, axis); + } else { + position = mp_get_runtime_display_position(axis); } + if (axis <= AXIS_Z) { + if (gcode_state->units_mode == INCHES) { + position /= MM_PER_INCH; + } + } + return (position); } /* @@ -466,29 +494,6 @@ float cm_get_absolute_position(const GCodeState_t *gcode_state, const uint8_t ax return (mp_get_runtime_absolute_position(mr, axis)); } -/* - * cm_get_work_position() - return work position in external form from the active Gcode dynamic model - * - * ... that means in prevailing units (mm/inch) and with all offsets applied - */ - -float cm_get_work_position(const GCodeState_t *gcode_state, const uint8_t axis) -{ - float position; - - if (gcode_state == MODEL) { - position = cm->gmx.position[axis] - cm_get_active_coord_offset(axis, false); - } else { - position = mp_get_runtime_work_position(axis); - } - if (axis <= AXIS_Z) { - if (gcode_state->units_mode == INCHES) { - position /= MM_PER_INCH; - } - } - return (position); -} - /*********************************************************************************** **** CRITICAL HELPERS ************************************************************* *********************************************************************************** @@ -533,7 +538,7 @@ stat_t cm_deferred_write_callback() for (uint8_t j=0; joffset[i][j]; + nv.value = cm->coord_offset[i][j]; nv_persist(&nv); // Note: only writes values that have changed } } @@ -715,7 +720,7 @@ void cm_set_model_target(const float target[], const bool flags[]) continue; // skip axis if not flagged for update or its disabled } else if ((cm->a[axis].axis_mode == AXIS_STANDARD) || (cm->a[axis].axis_mode == AXIS_INHIBITED)) { if (cm->gm.distance_mode == ABSOLUTE_DISTANCE_MODE) { - cm->gm.target[axis] = cm_get_active_coord_offset(axis, true) + _to_millimeters(target[axis]); + cm->gm.target[axis] = cm_get_combined_offset(axis) + _to_millimeters(target[axis]); } else { cm->gm.target[axis] += _to_millimeters(target[axis]); } @@ -730,7 +735,7 @@ void cm_set_model_target(const float target[], const bool flags[]) tmp = _calc_ABC(axis, target); } if (cm->gm.distance_mode == ABSOLUTE_DISTANCE_MODE) { - cm->gm.target[axis] = tmp + cm_get_active_coord_offset(axis, true); // sacidu93's fix to Issue #22 + cm->gm.target[axis] = tmp + cm_get_combined_offset(axis); // sacidu93's fix to Issue #22 } else { cm->gm.target[axis] += tmp; } @@ -835,7 +840,7 @@ stat_t cm_set_arc_distance_mode(const uint8_t mode) * has ended. You can also use $g54x - $g59c config functions to change offsets. * * It also does not reset the work offsets which may be accomplished by calling - * cm_set_work_offsets() immediately afterwards. + * cm_set_display_offsets() immediately afterwards. */ stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, @@ -855,12 +860,12 @@ stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, for (uint8_t axis = AXIS_X; axis < AXES; axis++) { if (flag[axis]) { if (L_word == 2) { - cm->offset[P_word][axis] = _to_millimeters(offset[axis]); + cm->coord_offset[P_word][axis] = _to_millimeters(offset[axis]); } else { // Should L20 take into account G92 offsets? - cm->offset[P_word][axis] = cm->gmx.position[axis] - + cm->coord_offset[P_word][axis] = cm->gmx.position[axis] - _to_millimeters(offset[axis]) - - cm->tl_offset[axis]; + cm->tool_offset[axis]; } // persist offsets once machining cycle is over cm->deferred_write_flag = true; @@ -880,7 +885,7 @@ stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, // L10 should also take into account G92 offset tt.tt_offset[P_word][axis] = cm->gmx.position[axis] - _to_millimeters(offset[axis]) - - cm->offset[cm->gm.coord_system][axis] - + cm->coord_offset[cm->gm.coord_system][axis] - (cm->gmx.origin_offset[axis] * cm->gmx.origin_offset_enable); } // persist offsets once machining cycle is over @@ -920,11 +925,11 @@ stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, const bool appl } if (apply_additional) { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - cm->tl_offset[axis] += tt.tt_offset[tool][axis]; + cm->tool_offset[axis] += tt.tt_offset[tool][axis]; } } else { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - cm->tl_offset[axis] = tt.tt_offset[tool][axis]; + cm->tool_offset[axis] = tt.tt_offset[tool][axis]; } } float value[] = { (float)cm->gm.coord_system }; // pass coordinate system in value[0] element @@ -935,7 +940,7 @@ stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, const bool appl stat_t cm_cancel_tl_offset() { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - cm->tl_offset[axis] = 0; + cm->tool_offset[axis] = 0; } float value[] = { (float)cm->gm.coord_system }; mp_queue_command(_exec_offset, value, nullptr); @@ -945,7 +950,7 @@ stat_t cm_cancel_tl_offset() stat_t cm_set_coord_system(const uint8_t coord_system) // set coordinate system sync'd with planner { cm->gm.coord_system = (cmCoordSystem)coord_system; - cm_set_work_offsets(MODEL); // must reset offsets if you change coordinate system //++++++ + cm_set_display_offsets(MODEL); // must reset display offsets if you change coordinate system float value[] = { (float)coord_system }; mp_queue_command(_exec_offset, value, nullptr); @@ -957,10 +962,10 @@ static void _exec_offset(float *value, bool *flag) uint8_t coord_system = ((uint8_t)value[0]); // coordinate system is passed in value[0] element float offsets[AXES]; for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - offsets[axis] = cm->offset[coord_system][axis] + cm->tl_offset[axis] + + offsets[axis] = cm->coord_offset[coord_system][axis] + cm->tool_offset[axis] + (cm->gmx.origin_offset[axis] * cm->gmx.origin_offset_enable); } - mp_set_runtime_work_offset(offsets); + mp_set_runtime_display_offset(offsets); } /* @@ -1060,8 +1065,8 @@ stat_t cm_set_origin_offsets(const float offset[], const bool flag[]) for (uint8_t axis = AXIS_X; axis < AXES; axis++) { if (flag[axis]) { cm->gmx.origin_offset[axis] = cm->gmx.position[axis] - - cm->offset[cm->gm.coord_system][axis] - - cm->tl_offset[axis] - + cm->coord_offset[cm->gm.coord_system][axis] - + cm->tool_offset[axis] - _to_millimeters(offset[axis]); } } @@ -1116,7 +1121,7 @@ stat_t cm_straight_traverse(const float target[], const bool flags[]) cm_set_model_target(target, flags); ritorno (cm_test_soft_limits(cm->gm.target)); // test soft limits; exit if thrown - cm_set_work_offsets(&cm->gm); // capture the fully resolved offsets to the state + cm_set_display_offsets(&cm->gm); // capture the fully resolved offsets to the state cm_cycle_start(); // required for homing & other cycles stat_t status = mp_aline(&cm->gm); // send the move to the planner @@ -1270,7 +1275,7 @@ stat_t cm_straight_feed(const float target[], const bool flags[]) cm_set_model_target(target, flags); ritorno (cm_test_soft_limits(cm->gm.target)); // test soft limits; exit if thrown - cm_set_work_offsets(&cm->gm); // capture the fully resolved offsets to the state + cm_set_display_offsets(&cm->gm); // capture the fully resolved offsets to the state cm_cycle_start(); // required for homing & other cycles stat_t status = mp_aline(&cm->gm); // send the move to the planner @@ -1580,7 +1585,7 @@ static void _exec_program_finalize(float *value, bool *flag) cm_reset_overrides(); // reset feedrate the spindle overrides temperature_reset(); // turn off all heaters and fans } - cm_set_work_offsets(MODEL); // reset work offsets for display porpoises + cm_set_display_offsets(MODEL); // reset work offsets for display porpoises sr_request_status_report(SR_REQUEST_IMMEDIATE); // request a final and full status report (not filtered) } @@ -1999,9 +2004,9 @@ stat_t cm_get_vel(nvObj_t *nv) } stat_t cm_get_feed(nvObj_t *nv) { return (get_float(nv, cm_get_feed_rate(ACTIVE_MODEL))); } -stat_t cm_get_pos(nvObj_t *nv) { return (get_float(nv, cm_get_work_position(ACTIVE_MODEL, _axis(nv)))); } +stat_t cm_get_pos(nvObj_t *nv) { return (get_float(nv, cm_get_display_position(ACTIVE_MODEL, _axis(nv)))); } stat_t cm_get_mpo(nvObj_t *nv) { return (get_float(nv, cm_get_absolute_position(ACTIVE_MODEL, _axis(nv)))); } -stat_t cm_get_ofs(nvObj_t *nv) { return (get_float(nv, cm_get_work_offset(ACTIVE_MODEL, _axis(nv)))); } +stat_t cm_get_ofs(nvObj_t *nv) { return (get_float(nv, cm_get_display_offset(ACTIVE_MODEL, _axis(nv)))); } stat_t cm_get_home(nvObj_t *nv) { return(_get_msg_helper(nv, msg_home, cm_get_homing_state())); } stat_t cm_set_home(nvObj_t *nv) { return (set_int(nv, ((uint8_t &)(cm->homing_state)), false, true)); } @@ -2010,8 +2015,8 @@ stat_t cm_get_hom(nvObj_t *nv) { return (get_int(nv, cm->homed[_axis(nv)])); } stat_t cm_get_prob(nvObj_t *nv) { return(_get_msg_helper(nv, msg_probe, cm_get_probe_state())); } stat_t cm_get_prb(nvObj_t *nv) { return (get_float(nv, cm->probe_results[0][_axis(nv)])); } -stat_t cm_get_coord(nvObj_t *nv) { return (get_float(nv, cm->offset[_coord(nv)][_axis(nv)])); } -stat_t cm_set_coord(nvObj_t *nv) { return (set_float(nv, cm->offset[_coord(nv)][_axis(nv)])); } +stat_t cm_get_coord(nvObj_t *nv) { return (get_float(nv, cm->coord_offset[_coord(nv)][_axis(nv)])); } +stat_t cm_set_coord(nvObj_t *nv) { return (set_float(nv, cm->coord_offset[_coord(nv)][_axis(nv)])); } stat_t cm_get_g92(nvObj_t *nv) { return (get_float(nv, cm->gmx.origin_offset[_axis(nv)])); } stat_t cm_get_g28(nvObj_t *nv) { return (get_float(nv, cm->gmx.g28_position[_axis(nv)])); } @@ -2029,8 +2034,8 @@ static uint8_t _tool(nvObj_t *nv) return (atoi(&nv->token[2])); // ttNNx is all in the token } -stat_t cm_get_tof(nvObj_t *nv) { return (get_float(nv, cm->tl_offset[_axis(nv)])); } -stat_t cm_set_tof(nvObj_t *nv) { return (set_float(nv, cm->tl_offset[_axis(nv)])); } +stat_t cm_get_tof(nvObj_t *nv) { return (get_float(nv, cm->tool_offset[_axis(nv)])); } +stat_t cm_set_tof(nvObj_t *nv) { return (set_float(nv, cm->tool_offset[_axis(nv)])); } stat_t cm_get_tt(nvObj_t *nv) { diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h index a951728c..0440a6eb 100644 --- a/g2core/canonical_machine.h +++ b/g2core/canonical_machine.h @@ -187,7 +187,7 @@ typedef struct cmArc { // planner and runtime variables for uint8_t run_state; // runtime state machine sequence float position[AXES]; // accumulating runtime position - float offset[3]; // arc IJK offsets + float ijk_offset[3]; // arc IJK offsets float length; // length of line or helix in mm float radius; // Raw R value, or computed via offsets @@ -227,8 +227,8 @@ typedef struct cmMachine { // struct to manage canonical machin bool safety_interlock_enable; // true to enable safety interlock system // Coordinate systems and offsets - float offset[COORDS+1][AXES]; // persistent coordinate offsets: absolute (G53) + G54,G55,G56,G57,G58,G59 - float tl_offset[AXES]; // current tool length offset + float coord_offset[COORDS+1][AXES]; // persistent coordinate offsets: absolute (G53) + G54,G55,G56,G57,G58,G59 + float tool_offset[AXES]; // current tool offset // Axis settings cfgAxis_t a[AXES]; @@ -334,11 +334,11 @@ void cm_set_absolute_override(GCodeState_t *gcode_state, const uint8_t absolute_ void cm_set_model_linenum(const uint32_t linenum); // Coordinate systems and offsets -float cm_get_active_coord_offset(const uint8_t axis, const bool absolute); -float cm_get_work_offset(const GCodeState_t *gcode_state, const uint8_t axis); -void cm_set_work_offsets(GCodeState_t *gcode_state); +float cm_get_combined_offset(const uint8_t axis); +float cm_get_display_offset(const GCodeState_t *gcode_state, const uint8_t axis); +void cm_set_display_offsets(GCodeState_t *gcode_state); +float cm_get_display_position(const GCodeState_t *gcode_state, const uint8_t axis); float cm_get_absolute_position(const GCodeState_t *gcode_state, const uint8_t axis); -float cm_get_work_position(const GCodeState_t *gcode_state, const uint8_t axis); // Critical helpers void cm_update_model_position_from_runtime(void); diff --git a/g2core/config_app.cpp b/g2core/config_app.cpp index dff499ae..f9f3d420 100644 --- a/g2core/config_app.cpp +++ b/g2core/config_app.cpp @@ -160,20 +160,20 @@ const cfgItem_t cfgArray[] = { { "ofs","ofsc",_f0, 5, cm_print_ofs, cm_get_ofs, set_ro, (float *)&cs.null, 0 }, // C work offset { "hom","home",_f0, 0, cm_print_home,cm_get_home,cm_set_home,(float *)&cs.null,0 }, // homing state, invoke homing cycle - { "hom","homx",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // X homed - Homing status group - { "hom","homy",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // Y homed - { "hom","homz",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // Z homed - { "hom","homa",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // A homed - { "hom","homb",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // B homed - { "hom","homc",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // C homed + { "hom","homx",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // X homed - Homing status group + { "hom","homy",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // Y homed + { "hom","homz",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // Z homed + { "hom","homa",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // A homed + { "hom","homb",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // B homed + { "hom","homc",_f0, 0, cm_print_hom, cm_get_hom, set_ro, (float *)&cs.null, 0 }, // C homed - { "prb","prbe",_f0, 0, tx_print_nul, cm_get_prob,set_ro, (float *)&cs.null, 0 }, // probing state - { "prb","prbx",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // X probe results - { "prb","prby",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // Y probe results - { "prb","prbz",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // Z probe results - { "prb","prba",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // A probe results - { "prb","prbb",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // B probe results - { "prb","prbc",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // C probe results + { "prb","prbe",_f0, 0, tx_print_nul, cm_get_prob,set_ro, (float *)&cs.null, 0 }, // probing state + { "prb","prbx",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // X probe results + { "prb","prby",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // Y probe results + { "prb","prbz",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // Z probe results + { "prb","prba",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // A probe results + { "prb","prbb",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // B probe results + { "prb","prbc",_f0, 5, tx_print_nul, cm_get_prb, set_ro, (float *)&cs.null, 0 }, // C probe results { "jog","jogx",_f0, 0, tx_print_nul, get_nul, cm_run_jog, (float *)&cs.null, 0}, // jog in X axis { "jog","jogy",_f0, 0, tx_print_nul, get_nul, cm_run_jog, (float *)&cs.null, 0}, // jog in Y axis @@ -182,58 +182,8 @@ const cfgItem_t cfgArray[] = { { "jog","jogb",_f0, 0, tx_print_nul, get_nul, cm_run_jog, (float *)&cs.null, 0}, // jog in B axis { "jog","jogc",_f0, 0, tx_print_nul, get_nul, cm_run_jog, (float *)&cs.null, 0}, // jog in C axis - { "pwr","pwr1",_f0, 3, st_print_pwr, st_get_pwr, set_ro, (float *)&cs.null, 0}, // motor power readouts + { "pwr","pwr1",_f0, 3, st_print_pwr, st_get_pwr, set_ro, (float *)&cs.null, 0}, // motor power readouts { "pwr","pwr2",_f0, 3, st_print_pwr, st_get_pwr, set_ro, (float *)&cs.null, 0}, -/*======= - { "mpo","mpox",_f0, 3, cm_print_mpo, cm_get_mpo, set_ro, (float *)&cs.null, 0 }, // X machine position - { "mpo","mpoy",_f0, 3, cm_print_mpo, cm_get_mpo, set_ro, (float *)&cs.null, 0 }, // Y machine position - { "mpo","mpoz",_f0, 3, cm_print_mpo, cm_get_mpo, set_ro, (float *)&cs.null, 0 }, // Z machine position - { "mpo","mpoa",_f0, 3, cm_print_mpo, cm_get_mpo, set_ro, (float *)&cs.null, 0 }, // A machine position - { "mpo","mpob",_f0, 3, cm_print_mpo, cm_get_mpo, set_ro, (float *)&cs.null, 0 }, // B machine position - { "mpo","mpoc",_f0, 3, cm_print_mpo, cm_get_mpo, set_ro, (float *)&cs.null, 0 }, // C machine position - - { "pos","posx",_f0, 3, cm_print_pos, cm_get_pos, set_ro, (float *)&cs.null, 0 }, // X work position - { "pos","posy",_f0, 3, cm_print_pos, cm_get_pos, set_ro, (float *)&cs.null, 0 }, // Y work position - { "pos","posz",_f0, 3, cm_print_pos, cm_get_pos, set_ro, (float *)&cs.null, 0 }, // Z work position - { "pos","posa",_f0, 3, cm_print_pos, cm_get_pos, set_ro, (float *)&cs.null, 0 }, // A work position - { "pos","posb",_f0, 3, cm_print_pos, cm_get_pos, set_ro, (float *)&cs.null, 0 }, // B work position - { "pos","posc",_f0, 3, cm_print_pos, cm_get_pos, set_ro, (float *)&cs.null, 0 }, // C work position - - { "ofs","ofsx",_f0, 3, cm_print_ofs, cm_get_ofs, set_ro, (float *)&cs.null, 0 }, // X work offset - { "ofs","ofsy",_f0, 3, cm_print_ofs, cm_get_ofs, set_ro, (float *)&cs.null, 0 }, // Y work offset - { "ofs","ofsz",_f0, 3, cm_print_ofs, cm_get_ofs, set_ro, (float *)&cs.null, 0 }, // Z work offset - { "ofs","ofsa",_f0, 3, cm_print_ofs, cm_get_ofs, set_ro, (float *)&cs.null, 0 }, // A work offset - { "ofs","ofsb",_f0, 3, cm_print_ofs, cm_get_ofs, set_ro, (float *)&cs.null, 0 }, // B work offset - { "ofs","ofsc",_f0, 3, cm_print_ofs, cm_get_ofs, set_ro, (float *)&cs.null, 0 }, // C work offset - - { "hom","home",_f0, 0, cm_print_home,cm_get_home,set_01,(float *)&cm.homing_state, 0 }, // homing state, invoke homing cycle - { "hom","homx",_f0, 0, cm_print_hom, get_ui8, set_01, (float *)&cm.homed[AXIS_X], false }, // X homed - Homing status group - { "hom","homy",_f0, 0, cm_print_hom, get_ui8, set_01, (float *)&cm.homed[AXIS_Y], false }, // Y homed - { "hom","homz",_f0, 0, cm_print_hom, get_ui8, set_01, (float *)&cm.homed[AXIS_Z], false }, // Z homed - { "hom","homa",_f0, 0, cm_print_hom, get_ui8, set_01, (float *)&cm.homed[AXIS_A], false }, // A homed - { "hom","homb",_f0, 0, cm_print_hom, get_ui8, set_01, (float *)&cm.homed[AXIS_B], false }, // B homed - { "hom","homc",_f0, 0, cm_print_hom, get_ui8, set_01, (float *)&cm.homed[AXIS_C], false }, // C homed - - { "prb","prbe",_f0, 0, tx_print_nul, get_ui8, set_ro, (float *)&cm.probe_state[0], 0 }, // probing state - { "prb","prbx",_f0, 3, tx_print_nul, get_flt, set_ro, (float *)&cm.probe_results[0][AXIS_X], 0 }, - { "prb","prby",_f0, 3, tx_print_nul, get_flt, set_ro, (float *)&cm.probe_results[0][AXIS_Y], 0 }, - { "prb","prbz",_f0, 3, tx_print_nul, get_flt, set_ro, (float *)&cm.probe_results[0][AXIS_Z], 0 }, - { "prb","prba",_f0, 3, tx_print_nul, get_flt, set_ro, (float *)&cm.probe_results[0][AXIS_A], 0 }, - { "prb","prbb",_f0, 3, tx_print_nul, get_flt, set_ro, (float *)&cm.probe_results[0][AXIS_B], 0 }, - { "prb","prbc",_f0, 3, tx_print_nul, get_flt, set_ro, (float *)&cm.probe_results[0][AXIS_C], 0 }, - { "prb","prbr",_f0, 0, tx_print_nul, cm_get_prbr, cm_get_prbr, nullptr, 0 }, // enable probe report. Init in cm_init - - { "jog","jogx",_f0, 0, tx_print_nul, get_nul, cm_run_jogx, (float *)&cm.jogging_dest, 0}, - { "jog","jogy",_f0, 0, tx_print_nul, get_nul, cm_run_jogy, (float *)&cm.jogging_dest, 0}, - { "jog","jogz",_f0, 0, tx_print_nul, get_nul, cm_run_jogz, (float *)&cm.jogging_dest, 0}, - { "jog","joga",_f0, 0, tx_print_nul, get_nul, cm_run_joga, (float *)&cm.jogging_dest, 0}, -// { "jog","jogb",_f0, 0, tx_print_nul, get_nul, cm_run_jogb, (float *)&cm.jogging_dest, 0}, -// { "jog","jogc",_f0, 0, tx_print_nul, get_nul, cm_run_jogc, (float *)&cm.jogging_dest, 0}, - - { "pwr","pwr1",_f0, 3, st_print_pwr, st_get_pwr, set_ro, (float *)&cs.null, 0}, // motor power readouts - { "pwr","pwr2",_f0, 3, st_print_pwr, st_get_pwr, set_ro, (float *)&cs.null, 0}, ->>>>>>> refs/heads/dev-237-probing-improvements -*/ #if (MOTORS > 2) { "pwr","pwr3",_f0, 3, st_print_pwr, st_get_pwr, set_ro, (float *)&cs.null, 0}, #endif diff --git a/g2core/gcode.h b/g2core/gcode.h index ddee1be2..048355c3 100644 --- a/g2core/gcode.h +++ b/g2core/gcode.h @@ -216,7 +216,7 @@ typedef struct GCodeState { // Gcode model state - used by model, pl float target[AXES]; // XYZABC where the move should go float target_comp[AXES]; // summation compensation (Kahan) overflow value - float work_offset[AXES]; // work offsets from the machine coordinate system (for reporting only) + float display_offset[AXES]; // work offsets from the machine coordinate system (for reporting only) float feed_rate; // F - normalized to millimeters/minute or in inverse time mode float P_word; // P - parameter used for dwell time in seconds, G10 coord select... @@ -238,7 +238,7 @@ typedef struct GCodeState { // Gcode model state - used by model, pl for (uint8_t i = 0; i< AXES; i++) { target[i] = 0.0; - work_offset[i] = 0.0; + display_offset[i] = 0.0; } feed_rate = 0.0; diff --git a/g2core/plan_arc.cpp b/g2core/plan_arc.cpp index 8c651b03..4a61ea31 100644 --- a/g2core/plan_arc.cpp +++ b/g2core/plan_arc.cpp @@ -216,24 +216,24 @@ stat_t cm_arc_feed(const float target[], const bool target_f[], // target en // *** now get down to the rest of the work setting up the arc for execution *** cm->gm.motion_mode = motion_mode; - cm_set_work_offsets(&cm->gm); // capture the fully resolved offsets to gm + cm_set_display_offsets(&cm->gm); // capture the fully resolved offsets to gm memcpy(&(cm->arc.gm), &cm->gm, sizeof(GCodeState_t)); // copy GCode context to arc singleton - some will be overwritten to run segments copy_vector(cm->arc.position, cm->gmx.position); // set initial arc position from gcode model // setup offsets - cm->arc.offset[OFS_I] = _to_millimeters(offset[OFS_I]); // copy offsets with conversion to canonical form (mm) - cm->arc.offset[OFS_J] = _to_millimeters(offset[OFS_J]); - cm->arc.offset[OFS_K] = _to_millimeters(offset[OFS_K]); + cm->arc.ijk_offset[OFS_I] = _to_millimeters(offset[OFS_I]); // copy offsets with conversion to canonical form (mm) + cm->arc.ijk_offset[OFS_J] = _to_millimeters(offset[OFS_J]); + cm->arc.ijk_offset[OFS_K] = _to_millimeters(offset[OFS_K]); if (cm->arc.gm.arc_distance_mode == ABSOLUTE_DISTANCE_MODE) { // adjust offsets if in absolute mode - cm->arc.offset[OFS_I] -= cm->arc.position[AXIS_X]; - cm->arc.offset[OFS_J] -= cm->arc.position[AXIS_Y]; - cm->arc.offset[OFS_K] -= cm->arc.position[AXIS_Z]; + cm->arc.ijk_offset[OFS_I] -= cm->arc.position[AXIS_X]; + cm->arc.ijk_offset[OFS_J] -= cm->arc.position[AXIS_Y]; + cm->arc.ijk_offset[OFS_K] -= cm->arc.position[AXIS_Z]; } - if ((fp_ZERO(cm->arc.offset[OFS_I])) && // it's an error if no offsets are provided - (fp_ZERO(cm->arc.offset[OFS_J])) && - (fp_ZERO(cm->arc.offset[OFS_K]))) { + if ((fp_ZERO(cm->arc.ijk_offset[OFS_I])) && // it's an error if no offsets are provided + (fp_ZERO(cm->arc.ijk_offset[OFS_J])) && + (fp_ZERO(cm->arc.ijk_offset[OFS_K]))) { return (cm_alarm(STAT_ARC_OFFSETS_MISSING_FOR_SELECTED_PLANE, "arc offsets missing or zero")); } @@ -278,7 +278,7 @@ static stat_t _compute_arc(const bool radius_f) if (radius_f) { // indicates a radius arc _compute_arc_offsets_from_radius(); } else { // compute start radius - cm->arc.radius = hypotf(-cm->arc.offset[cm->arc.plane_axis_0], -cm->arc.offset[cm->arc.plane_axis_1]); + cm->arc.radius = hypotf(-cm->arc.ijk_offset[cm->arc.plane_axis_0], -cm->arc.ijk_offset[cm->arc.plane_axis_1]); } // Test arc specification for correctness according to: @@ -290,11 +290,11 @@ static stat_t _compute_arc(const bool radius_f) // Compute end radius from the center of circle (offsets) to target endpoint float end_0 = cm->arc.gm.target[cm->arc.plane_axis_0] - cm->arc.position[cm->arc.plane_axis_0] - - cm->arc.offset[cm->arc.plane_axis_0]; + cm->arc.ijk_offset[cm->arc.plane_axis_0]; float end_1 = cm->arc.gm.target[cm->arc.plane_axis_1] - cm->arc.position[cm->arc.plane_axis_1] - - cm->arc.offset[cm->arc.plane_axis_1]; + cm->arc.ijk_offset[cm->arc.plane_axis_1]; float err = fabs(hypotf(end_0, end_1) - cm->arc.radius); // end radius - start radius if ((err > ARC_RADIUS_ERROR_MAX) || @@ -305,7 +305,7 @@ static stat_t _compute_arc(const bool radius_f) // Compute the angular travel // Calculate the theta angle of the current position (theta is also needed for calculating center point) // Note: gcc atan2 reverses args, i.e.: atan2(Y,X) - cm->arc.theta = atan2(-cm->arc.offset[cm->arc.plane_axis_0], -cm->arc.offset[cm->arc.plane_axis_1]); + cm->arc.theta = atan2(-cm->arc.ijk_offset[cm->arc.plane_axis_0], -cm->arc.ijk_offset[cm->arc.plane_axis_1]); // Compute angular travel if not a full circle arc if (!cm->arc.full_circle) { @@ -470,9 +470,9 @@ static void _compute_arc_offsets_from_radius() } // Complete the operation by calculating the actual center of the arc - cm->arc.offset[cm->arc.plane_axis_0] = (x-(y*h_x2_div_d))/2; - cm->arc.offset[cm->arc.plane_axis_1] = (y+(x*h_x2_div_d))/2; - cm->arc.offset[cm->arc.linear_axis] = 0; + cm->arc.ijk_offset[cm->arc.plane_axis_0] = (x-(y*h_x2_div_d))/2; + cm->arc.ijk_offset[cm->arc.plane_axis_1] = (y+(x*h_x2_div_d))/2; + cm->arc.ijk_offset[cm->arc.linear_axis] = 0; } /* diff --git a/g2core/plan_line.cpp b/g2core/plan_line.cpp index b242761a..82be21d5 100644 --- a/g2core/plan_line.cpp +++ b/g2core/plan_line.cpp @@ -69,18 +69,18 @@ static void _set_bf_diagnostics(mpBuf_t* bf) { * mp_zero_segment_velocity() - correct velocity in last segment for reporting purposes * mp_get_runtime_velocity() - returns current velocity (aggregate) * mp_get_runtime_machine_position() - returns current axis position in machine coordinates - * mp_set_runtime_work_offset() - set offsets in the MR struct - * mp_get_runtime_work_position() - returns current axis position in work coordinates + * mp_set_runtime_display_offset() - set combined display offsets in the MR struct + * mp_get_runtime_display_position() - returns current axis position in work display coordinates * that were in effect at move planning time */ void mp_zero_segment_velocity() { mr->segment_velocity = 0; } float mp_get_runtime_velocity(void) { return (mr->segment_velocity); } float mp_get_runtime_absolute_position(mpPlannerRuntime_t *_mr, uint8_t axis) { return (_mr->position[axis]); } -void mp_set_runtime_work_offset(float offset[]) { copy_vector(mr->gm.work_offset, offset); } +void mp_set_runtime_display_offset(float offset[]) { copy_vector(mr->gm.display_offset, offset); } // We have to handle rotation - "rotate" by the transverse of the matrix to got "normal" coordinates -float mp_get_runtime_work_position(uint8_t axis) { +float mp_get_runtime_display_position(uint8_t axis) { // Shorthand: // target_rotated[0] = a x_1 + b x_2 + c x_3 // target_rotated[1] = a y_1 + b y_2 + c y_3 @@ -88,16 +88,16 @@ float mp_get_runtime_work_position(uint8_t axis) { if (axis == AXIS_X) { return mr->position[0] * cm->rotation_matrix[0][0] + mr->position[1] * cm->rotation_matrix[1][0] + - mr->position[2] * cm->rotation_matrix[2][0] - mr->gm.work_offset[0]; + mr->position[2] * cm->rotation_matrix[2][0] - mr->gm.display_offset[0]; } else if (axis == AXIS_Y) { return mr->position[0] * cm->rotation_matrix[0][1] + mr->position[1] * cm->rotation_matrix[1][1] + - mr->position[2] * cm->rotation_matrix[2][1] - mr->gm.work_offset[1]; + mr->position[2] * cm->rotation_matrix[2][1] - mr->gm.display_offset[1]; } else if (axis == AXIS_Z) { return mr->position[0] * cm->rotation_matrix[0][2] + mr->position[1] * cm->rotation_matrix[1][2] + - mr->position[2] * cm->rotation_matrix[2][2] - cm->rotation_z_offset - mr->gm.work_offset[2]; + mr->position[2] * cm->rotation_matrix[2][2] - cm->rotation_z_offset - mr->gm.display_offset[2]; } else { // ABC, UVW, we don't rotate them - return (mr->position[axis] - mr->gm.work_offset[axis]); + return (mr->position[axis] - mr->gm.display_offset[axis]); } } diff --git a/g2core/planner.h b/g2core/planner.h index 9a7d8f8a..1d7b4c68 100644 --- a/g2core/planner.h +++ b/g2core/planner.h @@ -591,8 +591,8 @@ bool mp_free_run_buffer(void); void mp_zero_segment_velocity(void); // getters and setters... float mp_get_runtime_velocity(void); float mp_get_runtime_absolute_position(mpPlannerRuntime_t *_mr, uint8_t axis); -float mp_get_runtime_work_position(uint8_t axis); -void mp_set_runtime_work_offset(float offset[]); +float mp_get_runtime_display_position(uint8_t axis); +void mp_set_runtime_display_offset(float offset[]); bool mp_get_runtime_busy(void); bool mp_runtime_is_idle(void); diff --git a/g2core/settings/settings_default.h b/g2core/settings/settings_default.h index c33132e7..7ef5eafe 100644 --- a/g2core/settings/settings_default.h +++ b/g2core/settings/settings_default.h @@ -133,11 +133,6 @@ #define PROBE_REPORT_ENABLE true // {prbr: #endif -/* - * The following is to fix an issue where feedrate override was being defined in some users - * settings files but not others. This would otherwise cause an undefined compile error. - * -*/ #ifndef MANUAL_FEEDRATE_OVERRIDE_ENABLE #define MANUAL_FEEDRATE_OVERRIDE_ENABLE false #endif