From ca546db67d92cb65694cd602a01399adb854db01 Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Thu, 12 Jan 2017 08:52:12 -0500 Subject: [PATCH] Intermediate checkpoint for isolating Gcode parser --- g2core/canonical_machine.cpp | 79 +++++++++++++----- g2core/canonical_machine.h | 23 +++--- g2core/cycle_homing.cpp | 75 +++++++++-------- g2core/g2core.cppproj | 4 +- g2core/gcode.h | 14 ++-- g2core/gcode_parser.cpp | 153 ++++++++++++++++++++++++++++------- g2core/planner.cpp | 10 +++ g2core/planner.h | 2 + g2core/spindle.cpp | 53 +++++++++--- g2core/spindle.h | 8 +- 10 files changed, 310 insertions(+), 111 deletions(-) diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp index e7225677..f66bcd87 100644 --- a/g2core/canonical_machine.cpp +++ b/g2core/canonical_machine.cpp @@ -1135,10 +1135,12 @@ stat_t cm_set_arc_distance_mode(const uint8_t mode) * cm_set_work_offsets() immediately afterwards. */ -stat_t cm_set_g10_data(const uint8_t P_word, const uint8_t L_word, +stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, + const uint8_t L_word, const bool L_flag, const float offset[], const bool flag[]) { - if (!gp.gf.L_word) { +// if (!gp.gf.L_word) { + if (!L_flag) { return (STAT_L_WORD_IS_MISSING); } @@ -1199,11 +1201,11 @@ stat_t cm_set_g10_data(const uint8_t P_word, const uint8_t L_word, * cm_set_coord_system() - G54-G59 * _exec_offset() - callback from planner */ -stat_t cm_set_tl_offset(const uint8_t H_word, bool apply_additional) +stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, const bool apply_additional) { uint8_t tool; - if (gp.gf.H_word) - { +/* + if (gp.gf.H_word) { if (gp.gn.H_word > TOOLS) { return (STAT_H_WORD_IS_INVALID); } @@ -1212,6 +1214,16 @@ stat_t cm_set_tl_offset(const uint8_t H_word, bool apply_additional) } else { tool = gp.gn.H_word; } +*/ + if (H_flag) { + if (H_word > TOOLS) { + return (STAT_H_WORD_IS_INVALID); + } + if (H_word == 0) { // interpret H0 as "current tool", just like no H at all. + tool = cm->gm.tool; + } else { + tool = H_word; + } } else { tool = cm->gm.tool; } @@ -1692,7 +1704,7 @@ stat_t cm_m48_enable(uint8_t enable) // M48, M49 } /* - * cm_feed_rate_override_enable() - M50 + * cm_mfo_control() - M50 manual feed rate override comtrol * * M50 enables manual feedrate override and the optional P override parameter. * P is expressed as M% to N% of programmed feedrate, typically a value from 0.05 to 2.000. @@ -1731,39 +1743,64 @@ stat_t cm_m48_enable(uint8_t enable) // M48, M49 * ENABLE ENABLE M50 Pn ENABLE start ramp w/new P value; store P value * (Note: new ramp will supercede any existing ramp) */ -stat_t cm_mfo_enable(uint8_t enable) // M50 + +stat_t cm_mfo_control(const float P_word, const bool P_flag) // M50 { bool new_enable = true; bool new_override = false; - if (gp.gf.parameter) { // if parameter is present in Gcode block - if (fp_ZERO(gp.gn.parameter)) { - new_enable = false; // P0 disables override + if (P_flag) { // if parameter is present in Gcode block + if (fp_ZERO(P_word)) { + new_enable = false; // P0 disables override } else { - if (gp.gn.parameter < FEED_OVERRIDE_MIN) { + if (P_word < FEED_OVERRIDE_MIN) { return (STAT_INPUT_LESS_THAN_MIN_VALUE); } - if (gp.gn.parameter > FEED_OVERRIDE_MAX) { + if (P_word > FEED_OVERRIDE_MAX) { return (STAT_INPUT_EXCEEDS_MAX_VALUE); } - cm->gmx.mfo_factor = gp.gn.parameter; // it validates - store it. + cm->gmx.mfo_factor = P_word; // P word is valid, store it. new_override = true; } } - if (cm->gmx.m48_enable) { // if master enable is ON + if (cm->gmx.m48_enable) { // if master enable is ON if (new_enable && (new_override || !cm->gmx.mfo_enable)) { // 3 cases to start a ramp mp_start_feed_override(FEED_OVERRIDE_RAMP_TIME, cm->gmx.mfo_factor); } else if (cm->gmx.mfo_enable && !new_enable) { // case to turn off the ramp mp_end_feed_override(FEED_OVERRIDE_RAMP_TIME); } } - cm->gmx.mfo_enable = new_enable; // always update the enable state + cm->gmx.mfo_enable = new_enable; // always update the enable state return (STAT_OK); } -// if ((new_enable && new_override) || (new_enable && !cm->gmx.mfo_enable)) { -// if (!(cm->gmx.mfo_enable && new_override)) { - - +stat_t cm_mto_control(const float P_word, const bool P_flag) // M50.1 +{ + bool new_enable = true; + bool new_override = false; + if (P_flag) { // if parameter is present in Gcode block + if (fp_ZERO(P_word)) { + new_enable = false; // P0 disables override + } else { + if (P_word < TRAVERSE_OVERRIDE_MIN) { + return (STAT_INPUT_LESS_THAN_MIN_VALUE); + } + if (P_word > TRAVERSE_OVERRIDE_MAX) { + return (STAT_INPUT_EXCEEDS_MAX_VALUE); + } + cm->gmx.mto_factor = P_word; // P word is valid, store it. + new_override = true; + } + } + if (cm->gmx.m48_enable) { // if master enable is ON + if (new_enable && (new_override || !cm->gmx.mfo_enable)) { // 3 cases to start a ramp + mp_start_traverse_override(FEED_OVERRIDE_RAMP_TIME, cm->gmx.mto_factor); + } else if (cm->gmx.mto_enable && !new_enable) { // case to turn off the ramp + mp_end_traverse_override(FEED_OVERRIDE_RAMP_TIME); + } + } + cm->gmx.mto_enable = new_enable; // always update the enable state + return (STAT_OK); +} /************************************************ * Feedhold and Related Functions (no NIST ref) * ************************************************/ @@ -2707,7 +2744,9 @@ stat_t cm_run_qf(nvObj_t *nv) stat_t cm_run_home(nvObj_t *nv) { if (fp_TRUE(nv->value)) { - cm_homing_cycle_start(); + float axes[] = { 1,1,1,1,1,1 }; + bool flags[] = { 1,1,1,1,1,1 }; + cm_homing_cycle_start(axes, flags); } return (STAT_OK); } diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h index ce0e9ec2..7d58e830 100644 --- a/g2core/canonical_machine.h +++ b/g2core/canonical_machine.h @@ -376,9 +376,12 @@ stat_t cm_select_plane(const uint8_t plane); // G stat_t cm_set_units_mode(const uint8_t mode); // G20, G21 stat_t cm_set_distance_mode(const uint8_t mode); // G90, G91 stat_t cm_set_arc_distance_mode(const uint8_t mode); // G90.1, G91.1 -stat_t cm_set_tl_offset(const uint8_t H_word, bool apply_additional); // G43, G43.2 +//stat_t cm_set_tl_offset(const uint8_t H_word, bool apply_additional); // G43, G43.2 +stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, // G43, G43.2 + const bool apply_additional); stat_t cm_cancel_tl_offset(void); // G49 -stat_t cm_set_g10_data(const uint8_t P_word, const uint8_t L_word, // G10 +stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, // G10 + const uint8_t L_word, const bool L_flag, const float offset[], const bool flag[]); void cm_set_position(const uint8_t axis, const float position); // set absolute position - single axis @@ -418,17 +421,19 @@ stat_t cm_arc_feed(const float target[], const bool target_f[], // G // see spindle.h for spindle functions - which would go right here // Tool Functions (4.3.8) -stat_t cm_select_tool(const uint8_t tool); // T parameter -stat_t cm_change_tool(const uint8_t tool); // M6 +stat_t cm_select_tool(const uint8_t tool); // T parameter +stat_t cm_change_tool(const uint8_t tool); // M6 // Miscellaneous Functions (4.3.9) // see coolant.h for coolant functions - which would go right here -void cm_message(const char *message); // msg to console (e.g. Gcode comments) +void cm_message(const char *message); // msg to console (e.g. Gcode comments) void cm_reset_overrides(void); -stat_t cm_m48_enable(uint8_t enable); // M48, M49 -stat_t cm_mfo_enable(uint8_t enable); // M50 +stat_t cm_m48_enable(uint8_t enable); // M48, M49 +stat_t cm_mfo_control(const float P_word, const bool P_flag); // M50 +stat_t cm_mto_control(const float P_word, const bool P_flag); // M50.1 +// See spindle.cpp for cm_sso_control() // M51 // Program Functions (4.3.10) void cm_request_feedhold(void); @@ -458,8 +463,8 @@ stat_t cm_json_wait(char *json_string); // M102 /*--- Cycles ---*/ // Homing cycles -stat_t cm_homing_cycle_start(void); // G28.2 -stat_t cm_homing_cycle_start_no_set(void); // G28.4 +stat_t cm_homing_cycle_start(const float axes[], const bool flags[]); // G28.2 +stat_t cm_homing_cycle_start_no_set(const float axes[], const bool flags[]); // G28.4 stat_t cm_homing_cycle_callback(void); // G28.2/.4 main loop callback // Probe cycles diff --git a/g2core/cycle_homing.cpp b/g2core/cycle_homing.cpp index c9858f79..adb1b4ba 100644 --- a/g2core/cycle_homing.cpp +++ b/g2core/cycle_homing.cpp @@ -59,6 +59,9 @@ struct hmHomingSingleton { // persistent homing runtime variables float max_clear_backoff; // maximum distance of switch clearing backoffs before erring out float setpoint; // ultimate setpoint, usually zero, but not always +// float axes[AXES]; // local storage for axis words and associated flags + bool axis_flags[AXES]; + // state saved from gcode model cmUnitsMode saved_units_mode; // G20,G21 global setting cmCoordSystem saved_coord_system; // G54 - G59 setting @@ -152,7 +155,7 @@ static stat_t _set_homing_func(stat_t (*func)(int8_t axis)) { * to cm_get_runtime_busy() is about. */ -stat_t cm_homing_cycle_start(void) { +stat_t cm_homing_cycle_start(const float axes[], const bool flags[]) { // save relevant non-axis parameters from Gcode model hm.saved_units_mode = (cmUnitsMode)cm_get_units_mode(ACTIVE_MODEL); hm.saved_coord_system = (cmCoordSystem)cm_get_coord_system(ACTIVE_MODEL); @@ -160,6 +163,9 @@ stat_t cm_homing_cycle_start(void) { hm.saved_feed_rate_mode = (cmFeedRateMode)cm_get_feed_rate_mode(ACTIVE_MODEL); hm.saved_feed_rate = cm_get_feed_rate(ACTIVE_MODEL); +// copy_vector(hm.axes, axes); + copy_vector(hm.axis_flags, flags); + // set working values cm_set_units_mode(MILLIMETERS); cm_set_distance_mode(INCREMENTAL_DISTANCE_MODE); @@ -178,8 +184,8 @@ stat_t cm_homing_cycle_start(void) { return (STAT_OK); } -stat_t cm_homing_cycle_start_no_set(void) { - cm_homing_cycle_start(); +stat_t cm_homing_cycle_start_no_set(const float axes[], const bool flags[]) { + cm_homing_cycle_start(axes, flags); hm.set_coordinates = false; // set flag to not update position variables at the end of the cycle return (STAT_OK); } @@ -207,6 +213,7 @@ stat_t cm_homing_cycle_callback(void) { */ static stat_t _homing_axis_start(int8_t axis) { + // get the first or next axis if ((axis = _get_next_axis(axis)) < 0) { // axes are done or error if (axis == -1) { // -1 is done @@ -407,38 +414,38 @@ static stat_t _homing_finalize_exit(int8_t axis) // third part of return to hom static int8_t _get_next_axis(int8_t axis) { #if (HOMING_AXES <= 4) if (axis == -1) { // inelegant brute force solution - if (gp.gf.target[AXIS_Z]) { + if (hm.axis_flags[AXIS_Z]) { return (AXIS_Z); } - if (gp.gf.target[AXIS_X]) { + if (hm.axis_flags[AXIS_X]) { return (AXIS_X); } - if (gp.gf.target[AXIS_Y]) { + if (hm.axis_flags[AXIS_Y]) { return (AXIS_Y); } - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } return (-2); // error } else if (axis == AXIS_Z) { - if (gp.gf.target[AXIS_X]) { + if (hm.axis_flags[AXIS_X]) { return (AXIS_X); } - if (gp.gf.target[AXIS_Y]) { + if (hm.axis_flags[AXIS_Y]) { return (AXIS_Y); } - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } } else if (axis == AXIS_X) { - if (gp.gf.target[AXIS_Y]) { + if (hm.axis_flags[AXIS_Y]) { return (AXIS_Y); } - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } } else if (axis == AXIS_Y) { - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } } @@ -446,73 +453,73 @@ static int8_t _get_next_axis(int8_t axis) { #else if (axis == -1) { - if (gp.gf.target[AXIS_Z]) { + if (hm.axis_flags[AXIS_Z]) { return (AXIS_Z); } - if (gp.gf.target[AXIS_X]) { + if (hm.axis_flags[AXIS_X]) { return (AXIS_X); } - if (gp.gf.target[AXIS_Y]) { + if (hm.axis_flags[AXIS_Y]) { return (AXIS_Y); } - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } - if (gp.gf.target[AXIS_B]) { + if (hm.axis_flags[AXIS_B]) { return (AXIS_B); } - if (gp.gf.target[AXIS_C]) { + if (hm.axis_flags[AXIS_C]) { return (AXIS_C); } return (-2); // error } else if (axis == AXIS_Z) { - if (gp.gf.target[AXIS_X]) { + if (hm.axis_flags[AXIS_X]) { return (AXIS_X); } - if (gp.gf.target[AXIS_Y]) { + if (hm.axis_flags[AXIS_Y]) { return (AXIS_Y); } - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } - if (gp.gf.target[AXIS_B]) { + if (hm.axis_flags[AXIS_B]) { return (AXIS_B); } - if (gp.gf.target[AXIS_C]) { + if (hm.axis_flags[AXIS_C]) { return (AXIS_C); } } else if (axis == AXIS_X) { - if (gp.gf.target[AXIS_Y]) { + if (hm.axis_flags[AXIS_Y]) { return (AXIS_Y); } - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } - if (gp.gf.target[AXIS_B]) { + if (hm.axis_flags[AXIS_B]) { return (AXIS_B); } - if (gp.gf.target[AXIS_C]) { + if (hm.axis_flags[AXIS_C]) { return (AXIS_C); } } else if (axis == AXIS_Y) { - if (gp.gf.target[AXIS_A]) { + if (hm.axis_flags[AXIS_A]) { return (AXIS_A); } - if (gp.gf.target[AXIS_B]) { + if (hm.axis_flags[AXIS_B]) { return (AXIS_B); } - if (gp.gf.target[AXIS_C]) { + if (hm.axis_flags[AXIS_C]) { return (AXIS_C); } } else if (axis == AXIS_A) { - if (gp.gf.target[AXIS_B]) { + if (hm.axis_flags[AXIS_B]) { return (AXIS_B); } - if (gp.gf.target[AXIS_C]) { + if (hm.axis_flags[AXIS_C]) { return (AXIS_C); } } else if (axis == AXIS_B) { - if (gp.gf.target[AXIS_C]) { + if (hm.axis_flags[AXIS_C]) { return (AXIS_C); } } diff --git a/g2core/g2core.cppproj b/g2core/g2core.cppproj index d57acc1f..c8cc86a8 100644 --- a/g2core/g2core.cppproj +++ b/g2core/g2core.cppproj @@ -73,7 +73,7 @@ SWD com.atmel.avrdbg.tool.atmelice - J41800036434 + J41800030015 Atmel-ICE True @@ -100,7 +100,7 @@ True true - J41800036434 + J41800030015 0x284E0A60 10000000 diff --git a/g2core/gcode.h b/g2core/gcode.h index 07d14167..52790525 100644 --- a/g2core/gcode.h +++ b/g2core/gcode.h @@ -279,6 +279,7 @@ typedef struct GCodeStateExtended { // Gcode dynamic state extensions - used uint16_t magic_end; } GCodeStateX_t; +/* // Structures used by Gcode parser typedef struct GCodeInput { // Gcode model inputs - meaning depends on context @@ -301,9 +302,9 @@ typedef struct GCodeInput { // Gcode model inputs - meaning depends float arc_offset[3]; // IJK - used by arc commands bool m48_enable; // M48/M49 input (enables for feed and spindle) - bool mfo_enable; // M50 feedrate override enable - bool mto_enable; // Mxx traverse override enable - bool sso_enable; // M51 spindle speed override enable + bool mfo_control; // M50 feedrate override control + bool mto_control; // M50.1 traverse override control + bool sso_control; // M51 spindle speed override control uint8_t select_plane; // G17,G18,G19 - values to set plane to uint8_t units_mode; // G20,G21 - 0=inches (G20), 1 = mm (G21) @@ -339,9 +340,9 @@ typedef struct GCodeFlags { // Gcode model input flags bool feed_rate_mode; bool m48_enable; - bool mfo_enable; - bool mto_enable; - bool sso_enable; + bool mfo_control; + bool mto_control; + bool sso_control; bool select_plane; bool units_mode; @@ -373,6 +374,7 @@ typedef struct GCodeParser { } GCodeParser_t; extern GCodeParser_t gp; +*/ /* * Global Scope Functions diff --git a/g2core/gcode_parser.cpp b/g2core/gcode_parser.cpp index 787d6882..fea72a69 100644 --- a/g2core/gcode_parser.cpp +++ b/g2core/gcode_parser.cpp @@ -27,16 +27,101 @@ #include "util.h" #include "xio.h" // for char definitions -GCodeParser gp; +// Structures used by Gcode parser -/* TODO - A series of leakages of the gp.gn and gp.gf structs that should be parameterized in the function arguments: - - cm_set_g10_data() - - cm_set_tl_offset() - - cm_mfo_enable() - - cycle_homing / _get_next_axis() - - others? - */ +typedef struct GCodeInput { // Gcode model inputs - meaning depends on context + + uint8_t next_action; // handles G modal group 1 moves & non-modals + cmMotionMode motion_mode; // Group1: G0, G1, G2, G3, G38.2, G80, G81, G82 + // G83, G84, G85, G86, G87, G88, G89 + + uint8_t program_flow; // used only by the gcode_parser + uint32_t linenum; // N word + float target[AXES]; // XYZABC where the move should go + + uint8_t H_word; // H word - used by G43s + uint8_t L_word; // L word - used by G10s + + float feed_rate; // F - normalized to millimeters/minute + uint8_t feed_rate_mode; // See cmFeedRateMode for settings + float parameter; // P - parameter used for dwell time in seconds, G10 coord select... + float arc_radius; // R - radius value in arc radius mode + float arc_offset[3]; // IJK - used by arc commands + + bool m48_enable; // M48/M49 input (enables for feed and spindle) + bool mfo_control; // M50 feedrate override control + bool mto_control; // M50.1 traverse override control + bool sso_control; // M51 spindle speed override control + + uint8_t select_plane; // G17,G18,G19 - values to set plane to + uint8_t units_mode; // G20,G21 - 0=inches (G20), 1 = mm (G21) + uint8_t coord_system; // G54-G59 - select coordinate system 1-9 + uint8_t path_control; // G61... EXACT_PATH, EXACT_STOP, CONTINUOUS + uint8_t distance_mode; // G91 0=use absolute coords(G90), 1=incremental movement + uint8_t arc_distance_mode; // G90.1=use absolute IJK offsets, G91.1=incremental IJK offsets + uint8_t origin_offset_mode; // G92...TRUE=in origin offset mode + uint8_t absolute_override; // G53 TRUE = move using machine coordinates - this block only (G53) + uint8_t tool; // Tool after T and M6 (tool_select and tool_change) + uint8_t tool_select; // T value - T sets this value + uint8_t tool_change; // M6 tool change flag - moves "tool_select" to "tool" + uint8_t mist_coolant; // TRUE = mist on (M7), FALSE = off (M9) + uint8_t flood_coolant; // TRUE = flood on (M8), FALSE = off (M9) + + uint8_t spindle_control; // 0=OFF (M5), 1=CW (M3), 2=CCW (M4) + float spindle_speed; // in RPM + float spindle_override_factor; // 1.0000 x S spindle speed. Go up or down from there + uint8_t spindle_override_enable; // TRUE = override enabled +} GCodeInput_t; + +typedef struct GCodeFlags { // Gcode model input flags + bool next_action; + bool motion_mode; + bool modals[MODAL_GROUP_COUNT]; + bool program_flow; + bool linenum; + bool target[AXES]; + + bool H_word; + bool L_word; + bool feed_rate; + bool feed_rate_mode; + + bool m48_enable; + bool mfo_control; + bool mto_control; + bool sso_control; + + bool select_plane; + bool units_mode; + bool coord_system; + bool path_control; + bool distance_mode; + bool arc_distance_mode; + bool origin_offset_mode; + bool absolute_override; + bool tool; + bool tool_select; + bool tool_change; + bool mist_coolant; + bool flood_coolant; + + bool spindle_control; + bool spindle_speed; + bool spindle_override_factor; + bool spindle_override_enable; + + bool parameter; + bool arc_radius; + bool arc_offset[3]; +} GCodeFlags_t; + +typedef struct GCodeParser { + GCodeInput_t gn; // gcode input values - transient + GCodeFlags_t gf; // gcode input flags - transient +} GCodeParser_t; + +//extern GCodeParser_t gp; +GCodeParser gp; // local helper functions and macros static void _normalize_gcode_block(char *str, char **active_comment, uint8_t *block_delete_flag); @@ -568,8 +653,15 @@ static stat_t _parse_gcode_block(char *buf, char *active_comment) case 9: SET_MODAL (MODAL_GROUP_M8, flood_coolant, false); case 48: SET_MODAL (MODAL_GROUP_M9, m48_enable, true); case 49: SET_MODAL (MODAL_GROUP_M9, m48_enable, false); - case 50: SET_MODAL (MODAL_GROUP_M9, mfo_enable, true); - case 51: SET_MODAL (MODAL_GROUP_M9, sso_enable, true); + case 50: SET_MODAL (MODAL_GROUP_M9, mfo_control, true); + switch (_point(value)) { + case 0: SET_MODAL (MODAL_GROUP_M9, mfo_control, true); + case 1: SET_MODAL (MODAL_GROUP_M9, mto_control, true); + default: status = STAT_GCODE_COMMAND_UNSUPPORTED; + } + break; +// case 50: SET_MODAL (MODAL_GROUP_M9, mfo_control, true); + case 51: SET_MODAL (MODAL_GROUP_M9, sso_control, true); case 100: SET_NON_MODAL (next_action, NEXT_ACTION_JSON_COMMAND_SYNC); case 101: SET_NON_MODAL (next_action, NEXT_ACTION_JSON_WAIT); default: status = STAT_MCODE_COMMAND_UNSUPPORTED; @@ -653,24 +745,25 @@ static stat_t _execute_gcode_block(char *active_comment) EXEC_FUNC(cm_set_feed_rate_mode, feed_rate_mode); // G93, G94 EXEC_FUNC(cm_set_feed_rate, feed_rate); // F EXEC_FUNC(cm_set_spindle_speed, spindle_speed); // S -// EXEC_FUNC(cm_spindle_override_factor, spindle_override_factor); + if (gp.gf.sso_control) { // spindle speed override + ritorno(cm_sso_control(gp.gn.parameter, gp.gf.parameter)); + } + EXEC_FUNC(cm_select_tool, tool_select); // tool_select is where it's written EXEC_FUNC(cm_change_tool, tool_change); // M6 EXEC_FUNC(cm_spindle_control, spindle_control); // spindle CW, CCW, OFF -/* - EXEC_FUNC(cm_feed_rate_override_enable, feed_rate_override_enable); - EXEC_FUNC(cm_traverse_override_enable, traverse_override_enable); - EXEC_FUNC(cm_spindle_override_enable, spindle_override_enable); - EXEC_FUNC(cm_override_enables, override_enables); -*/ EXEC_FUNC(cm_mist_coolant_control, mist_coolant); // M7, M9 EXEC_FUNC(cm_flood_coolant_control, flood_coolant); // M8, M9 also disables mist coolant if OFF EXEC_FUNC(cm_m48_enable, m48_enable); - EXEC_FUNC(cm_mfo_enable, mfo_enable); -// EXEC_FUNC(cm_mfo_enable, feed_rate_override_factor); -// EXEC_FUNC(cm_sso_enable, sso_enable); + if (gp.gf.mfo_control) { // manual feedrate override + ritorno(cm_mfo_control(gp.gn.parameter, gp.gf.parameter)); + } + if (gp.gf.mto_control) { // manual traverse override + ritorno(cm_mto_control(gp.gn.parameter, gp.gf.parameter)); + } + if (gp.gn.next_action == NEXT_ACTION_DWELL) { // G4 - dwell ritorno(cm_dwell(gp.gn.parameter)); // return if error, otherwise complete the block } @@ -680,11 +773,11 @@ static stat_t _execute_gcode_block(char *active_comment) switch (gp.gn.next_action) { // Tool length offsets case NEXT_ACTION_SET_TL_OFFSET: { // G43 - ritorno(cm_set_tl_offset(gp.gn.H_word, false)); + ritorno(cm_set_tl_offset(gp.gn.H_word, gp.gf.H_word, false)); break; } case NEXT_ACTION_SET_ADDITIONAL_TL_OFFSET: { // G43.2 - ritorno(cm_set_tl_offset(gp.gn.H_word, true)); + ritorno(cm_set_tl_offset(gp.gn.H_word, gp.gf.H_word, true)); break; } case NEXT_ACTION_CANCEL_TL_OFFSET: { // G49 @@ -694,8 +787,9 @@ static stat_t _execute_gcode_block(char *active_comment) } EXEC_FUNC(cm_set_coord_system, coord_system); // G54, G55, G56, G57, G58, G59 -// EXEC_FUNC(cm_set_path_control, path_control); // G61, G61.1, G64 - if(gp.gf.path_control) { status = cm_set_path_control(MODEL, gp.gn.path_control); } + if (gp.gf.path_control) { // G61, G61.1, G64 + status = cm_set_path_control(MODEL, gp.gn.path_control); + } EXEC_FUNC(cm_set_distance_mode, distance_mode); // G90, G91 EXEC_FUNC(cm_set_arc_distance_mode, arc_distance_mode); // G90.1, G91.1 @@ -707,16 +801,19 @@ static stat_t _execute_gcode_block(char *active_comment) case NEXT_ACTION_SET_G30_POSITION: { status = cm_set_g30_position(); break;} // G30.1 case NEXT_ACTION_GOTO_G30_POSITION: { status = cm_goto_g30_position(gp.gn.target, gp.gf.target); break;} // G30 - case NEXT_ACTION_SEARCH_HOME: { status = cm_homing_cycle_start(); break;} // G28.2 + case NEXT_ACTION_SEARCH_HOME: { status = cm_homing_cycle_start(gp.gn.target, gp.gf.target); break;} // G28.2 case NEXT_ACTION_SET_ABSOLUTE_ORIGIN: { status = cm_set_absolute_origin(gp.gn.target, gp.gf.target); break;}// G28.3 - case NEXT_ACTION_HOMING_NO_SET: { status = cm_homing_cycle_start_no_set(); break;} // G28.4 + case NEXT_ACTION_HOMING_NO_SET: { status = cm_homing_cycle_start_no_set(gp.gn.target, gp.gf.target); break;} // G28.4 case NEXT_ACTION_STRAIGHT_PROBE_ERR: { status = cm_straight_probe(gp.gn.target, gp.gf.target, true, true); break;} // G38.2 case NEXT_ACTION_STRAIGHT_PROBE: { status = cm_straight_probe(gp.gn.target, gp.gf.target, false, true); break;} // G38.3 case NEXT_ACTION_STRAIGHT_PROBE_AWAY_ERR:{ status = cm_straight_probe(gp.gn.target, gp.gf.target, true, false); break;} // G38.4 case NEXT_ACTION_STRAIGHT_PROBE_AWAY: { status = cm_straight_probe(gp.gn.target, gp.gf.target, false, false); break;} // G38.5 - case NEXT_ACTION_SET_G10_DATA: { status = cm_set_g10_data(gp.gn.parameter, gp.gn.L_word, gp.gn.target, gp.gf.target); break;} + case NEXT_ACTION_SET_G10_DATA: { status = cm_set_g10_data(gp.gn.parameter, gp.gf.parameter, + gp.gn.L_word, gp.gf.L_word, + gp.gn.target, gp.gf.target); break;} + case NEXT_ACTION_SET_ORIGIN_OFFSETS: { status = cm_set_origin_offsets(gp.gn.target, gp.gf.target); break;}// G92 case NEXT_ACTION_RESET_ORIGIN_OFFSETS: { status = cm_reset_origin_offsets(); break;} // G92.1 case NEXT_ACTION_SUSPEND_ORIGIN_OFFSETS: { status = cm_suspend_origin_offsets(); break;} // G92.2 diff --git a/g2core/planner.cpp b/g2core/planner.cpp index a26208ad..2b69f14b 100644 --- a/g2core/planner.cpp +++ b/g2core/planner.cpp @@ -637,6 +637,16 @@ void mp_end_feed_override(const float ramp_time) mp_start_feed_override (FEED_OVERRIDE_RAMP_TIME, 1.00); } +void mp_start_traverse_override(const float ramp_time, const float override_factor) +{ + return; +} + +void mp_end_traverse_override(const float ramp_time) +{ + return; +} + /* * mp_planner_time_accounting() - gather time in planner */ diff --git a/g2core/planner.h b/g2core/planner.h index 1b951965..a985c2e8 100644 --- a/g2core/planner.h +++ b/g2core/planner.h @@ -564,6 +564,8 @@ stat_t mp_planner_callback(); void mp_replan_queue(mpBuf_t *bf); void mp_start_feed_override(const float ramp_time, const float override); void mp_end_feed_override(const float ramp_time); +void mp_start_traverse_override(const float ramp_time, const float override); +void mp_end_traverse_override(const float ramp_time); void mp_planner_time_accounting(void); //**** planner buffer primitives diff --git a/g2core/spindle.cpp b/g2core/spindle.cpp index b90492b4..a60e7dd9 100644 --- a/g2core/spindle.cpp +++ b/g2core/spindle.cpp @@ -222,28 +222,63 @@ static float _get_spindle_pwm (cmSpindleEnable enable, cmSpindleDir direction) /* - * cm_spindle_override_enable() - * cm_spindle_override_factor() + * cm_spindle_override_control() + * cm_start_spindle_override() + * cm_end_spindle_override() */ -/* -stat_t cm_spindle_override_enable(uint8_t flag) // M51.1 + +void cm_start_spindle_override(const float ramp_time, const float override_factor) { + return; +} + +void cm_end_spindle_override(const float ramp_time) +{ + return; +} + +stat_t cm_sso_control(const float P_word, const bool P_flag) // M51 +{ +/* if (fp_TRUE(gp.gf.parameter) && fp_ZERO(gp.gn.parameter)) { spindle.override_enable = false; } else { spindle.override_enable = true; } return (STAT_OK); -} -stat_t cm_spindle_override_factor(uint8_t flag) // M50.1 -{ - spindle.override_enable = flag; + spindle.override_enable = ; spindle.override_factor = gp.gn.parameter; // change spindle speed return (STAT_OK); +*/ + bool new_enable = true; + bool new_override = false; + if (P_flag) { // if parameter is present in Gcode block + if (fp_ZERO(P_word)) { + new_enable = false; // P0 disables override + } else { + if (P_word < SPINDLE_OVERRIDE_MIN) { + return (STAT_INPUT_LESS_THAN_MIN_VALUE); + } + if (P_word > SPINDLE_OVERRIDE_MAX) { + return (STAT_INPUT_EXCEEDS_MAX_VALUE); + } + spindle.sso_factor = P_word; // P word is valid, store it. + new_override = true; + } + } + if (cm->gmx.m48_enable) { // if master enable is ON + if (new_enable && (new_override || !spindle.sso_enable)) { // 3 cases to start a ramp + cm_start_spindle_override(SPINDLE_OVERRIDE_RAMP_TIME, spindle.sso_factor); + } else if (spindle.sso_enable && !new_enable) { // case to turn off the ramp + cm_end_spindle_override(SPINDLE_OVERRIDE_RAMP_TIME); + } + } + spindle.sso_enable = new_enable; // always update the enable state + return (STAT_OK); } -*/ + /**************************** * END OF SPINDLE FUNCTIONS * ****************************/ diff --git a/g2core/spindle.h b/g2core/spindle.h index 33820ce8..5ed3e877 100644 --- a/g2core/spindle.h +++ b/g2core/spindle.h @@ -2,7 +2,7 @@ * spindle.h - spindle driver * This file is part of the g2core project * - * Copyright (c) 2010 - 2016 Alden S. Hart, Jr. + * Copyright (c) 2010 - 2017 Alden S. Hart, Jr. * * This file ("the software") is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 as published by the @@ -62,6 +62,7 @@ typedef enum { #define SPINDLE_OVERRIDE_FACTOR 1.00 #define SPINDLE_OVERRIDE_MIN 0.05 // 5% #define SPINDLE_OVERRIDE_MAX 2.00 // 200% +#define SPINDLE_OVERRIDE_RAMP_TIME 1 // change sped in seconds /* * Spindle control structure @@ -99,8 +100,9 @@ void cm_spindle_off_immediate(void); void cm_spindle_optional_pause(bool option); // stop spindle based on system options selected void cm_spindle_resume(float dwell_seconds); // restart spindle after pause based on previous state -// stat_t cm_spindle_override_enable(uint8_t flag); // M51 -// stat_t cm_spindle_override_factor(uint8_t flag); // M51.1 +stat_t cm_sso_control(const float P_word, const bool P_flag); // M51 +void cm_start_spindle_override(const float ramp_time, const float override_factor); +void cm_end_spindle_override(const float ramp_time); stat_t cm_set_dir(nvObj_t* nv); stat_t cm_set_sso(nvObj_t* nv);