From 3c1762513c2574a3c0ed6b29fb7a29d539a51ee3 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Sun, 11 Sep 2016 05:03:53 -0700 Subject: [PATCH] boolean flags in parser --- src/gcode_parser.c | 14 ++--- src/gcode_parser.h | 4 +- src/gcode_state.c | 97 ++++++++++++++++++++++++++++++++++ src/gcode_state.def | 69 +++++++++++++++++++++++++ src/gcode_state.h | 64 ++++++++--------------- src/homing.c | 14 ++--- src/machine.c | 123 ++++++++------------------------------------ src/machine.h | 33 ++++-------- src/plan/arc.c | 8 +-- src/probing.c | 7 ++- src/probing.h | 2 +- src/varcb.c | 14 ++--- 12 files changed, 252 insertions(+), 197 deletions(-) create mode 100644 src/gcode_state.c create mode 100644 src/gcode_state.def diff --git a/src/gcode_parser.c b/src/gcode_parser.c index cc602c9..72657e2 100644 --- a/src/gcode_parser.c +++ b/src/gcode_parser.c @@ -45,10 +45,10 @@ parser_t parser = {{0}}; #define SET_MODAL(m, parm, val) \ - {parser.gn.parm = val; parser.gf.parm = 1; modals[m] += 1; break;} + {parser.gn.parm = val; parser.gf.parm = true; modals[m] += 1; break;} #define SET_NON_MODAL(parm, val) \ - {parser.gn.parm = val; parser.gf.parm = 1; break;} -#define EXEC_FUNC(f, parm) if ((uint8_t)parser.gf.parm) f(parser.gn.parm) + {parser.gn.parm = val; parser.gf.parm = true; break;} +#define EXEC_FUNC(f, parm) if (parser.gf.parm) f(parser.gn.parm) static uint8_t modals[MODAL_GROUP_COUNT]; // collects modal groups in a block @@ -241,13 +241,13 @@ static stat_t _validate_gcode_block() { static stat_t _execute_gcode_block() { stat_t status = STAT_OK; - mach_set_model_line(parser.gn.line); + mach_set_line(parser.gn.line); EXEC_FUNC(mach_set_feed_mode, feed_mode); EXEC_FUNC(mach_set_feed_rate, feed_rate); EXEC_FUNC(mach_feed_override_factor, feed_override_factor); EXEC_FUNC(mach_set_spindle_speed, spindle_speed); EXEC_FUNC(mach_spindle_override_factor, spindle_override_factor); - EXEC_FUNC(mach_select_tool, tool_select); + EXEC_FUNC(mach_select_tool, tool); EXEC_FUNC(mach_change_tool, tool_change); EXEC_FUNC(mach_set_spindle_mode, spindle_mode); EXEC_FUNC(mach_mist_coolant_control, mist_coolant); @@ -371,7 +371,7 @@ static stat_t _parse_gcode_block(char *buf) { // set initial state for new move memset(modals, 0, sizeof(modals)); // clear all parser values - memset(&parser.gf, 0, sizeof(gcode_state_t)); // clear all next-state flags + memset(&parser.gf, 0, sizeof(gcode_flags_t)); // clear all next-state flags memset(&parser.gn, 0, sizeof(gcode_state_t)); // clear all next-state values // get motion mode from previous block @@ -508,7 +508,7 @@ static stat_t _parse_gcode_block(char *buf) { } break; - case 'T': SET_NON_MODAL(tool_select, (uint8_t)trunc(value)); + case 'T': SET_NON_MODAL(tool, (uint8_t)trunc(value)); case 'F': SET_NON_MODAL(feed_rate, value); // used for dwell time, G10 coord select, rotations case 'P': SET_NON_MODAL(parameter, value); diff --git a/src/gcode_parser.h b/src/gcode_parser.h index 037fef1..4d729a0 100644 --- a/src/gcode_parser.h +++ b/src/gcode_parser.h @@ -56,8 +56,8 @@ typedef enum { // Used for detecting gcode errors. See NIST section 3.4 typedef struct { - gcode_state_t gn; // gcode input values - gcode_state_t gf; // gcode input flags + gcode_state_t gn; // gcode input values + gcode_flags_t gf; // gcode input flags } parser_t; diff --git a/src/gcode_state.c b/src/gcode_state.c new file mode 100644 index 0000000..c368b29 --- /dev/null +++ b/src/gcode_state.c @@ -0,0 +1,97 @@ +/******************************************************************************\ + + This file is part of the Buildbotics firmware. + + Copyright (c) 2015 - 2016 Buildbotics LLC + All rights reserved. + + 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 Free Software Foundation. You should + have received a copy of the GNU General Public License, version 2 + along with the software. If not, see . + + The software is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the software. If not, see + . + + For information regarding this software email: + "Joseph Coffland" + +\******************************************************************************/ + +#include "gcode_state.h" + + +PGM_P gs_get_units_pgmstr(units_t mode) { + switch (mode) { + case INCHES: return PSTR("IN"); + case MILLIMETERS: return PSTR("MM"); + case DEGREES: return PSTR("DEG"); + } + + return PSTR("INVALID"); +} + + +PGM_P gs_get_feed_mode_pgmstr(feed_mode_t mode) { + switch (mode) { + case INVERSE_TIME_MODE: return PSTR("INVERSE TIME"); + case UNITS_PER_MINUTE_MODE: return PSTR("PER MIN"); + case UNITS_PER_REVOLUTION_MODE: return PSTR("PER REV"); + } + + return PSTR("INVALID"); +} + + +PGM_P gs_get_plane_pgmstr(plane_t plane) { + switch (plane) { + case PLANE_XY: return PSTR("XY"); + case PLANE_XZ: return PSTR("XZ"); + case PLANE_YZ: return PSTR("YZ"); + } + + return PSTR("INVALID"); +} + + +PGM_P gs_get_coord_system_pgmstr(coord_system_t cs) { + switch (cs) { + case ABSOLUTE_COORDS: return PSTR("ABS"); + case G54: return PSTR("G54"); + case G55: return PSTR("G55"); + case G56: return PSTR("G56"); + case G57: return PSTR("G57"); + case G58: return PSTR("G58"); + case G59: return PSTR("G59"); + } + + return PSTR("INVALID"); +} + + +PGM_P gs_get_path_mode_pgmstr(path_mode_t mode) { + switch (mode) { + case PATH_EXACT_PATH: return PSTR("EXACT PATH"); + case PATH_EXACT_STOP: return PSTR("EXACT STOP"); + case PATH_CONTINUOUS: return PSTR("CONTINUOUS"); + } + + return PSTR("INVALID"); +} + + +PGM_P gs_get_distance_mode_pgmstr(distance_mode_t mode) { + switch (mode) { + case ABSOLUTE_MODE: return PSTR("ABSOLUTE"); + case INCREMENTAL_MODE: return PSTR("INCREMENTAL"); + } + + return PSTR("INVALID"); +} diff --git a/src/gcode_state.def b/src/gcode_state.def new file mode 100644 index 0000000..90d7e48 --- /dev/null +++ b/src/gcode_state.def @@ -0,0 +1,69 @@ +/******************************************************************************\ + + This file is part of the Buildbotics firmware. + + Copyright (c) 2015 - 2016 Buildbotics LLC + Copyright (c) 2010 - 2015 Alden S. Hart, Jr. + All rights reserved. + + 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 Free Software Foundation. You should + have received a copy of the GNU General Public License, version 2 + along with the software. If not, see . + + The software is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the software. If not, see + . + + For information regarding this software email: + "Joseph Coffland" + +\******************************************************************************/ + +MEMBER(uint32_t, line) // Gcode block line number + +MEMBER(uint8_t, tool) // T - sets this value + +MEMBER(float, feed_rate) // F - mm/min or inverse time mode +MEMBER(feed_mode_t, feed_mode) +MEMBER(float, feed_override_factor) // 1.0000 x F feed rate +MEMBER(bool, feed_override_enable) // M48, M49 + +MEMBER(float, spindle_speed) // in RPM +MEMBER(spindle_mode_t, spindle_mode) +MEMBER(float, spindle_override_factor) // 1.0000 x S spindle speed +MEMBER(bool, spindle_override_enable) // true = override enabled + +MEMBER(motion_mode_t, motion_mode) // Group 1 modal motion +MEMBER(plane_t, plane) // G17, G18, G19 +MEMBER(units_t, units) // G20, G21 +MEMBER(coord_system_t, coord_system) // G54-G59 - select coord system 1-9 +MEMBER(bool, absolute_mode) // G53 move in machine coordinates +MEMBER(path_mode_t, path_mode) // G61 +MEMBER(distance_mode_t, distance_mode) // G91 +MEMBER(distance_mode_t, arc_distance_mode) // G91.1 + +MEMBER(bool, mist_coolant) // mist on (M7), off (M9) +MEMBER(bool, flood_coolant) // mist on (M8), off (M9) + +MEMBER(next_action_t, next_action) // G group 1 moves & non-modals +MEMBER(program_flow_t, program_flow) // used only by the gcode_parser + +// TODO unimplemented gcode parameters +// MEMBER(float cutter_radius) // D - cutter radius compensation (0 is off) +// MEMBER(float cutter_length) // H - cutter length compensation (0 is off) + +// Used for input only +MEMBER(float, target[AXES]) // XYZABC where the move should go +MEMBER(bool, override_enables) // feed and spindle enable +MEMBER(bool, tool_change) // M6 tool change flag + +MEMBER(float, parameter) // P - dwell & G10 coord select +MEMBER(float, arc_radius) // R - in arc radius mode +MEMBER(float, arc_offset[3]) // IJK - used by arc commands diff --git a/src/gcode_state.h b/src/gcode_state.h index 03cf2c1..af30e96 100644 --- a/src/gcode_state.h +++ b/src/gcode_state.h @@ -28,6 +28,10 @@ #pragma once +#include "config.h" + +#include + #include #include @@ -180,46 +184,22 @@ typedef enum { /// Gcode model state typedef struct { - uint32_t line; // Gcode block line number - - uint8_t tool; // Tool after T and M6 - uint8_t tool_select; // T - sets this value - - float feed_rate; // F - in mm/min or inverse time mode - feed_mode_t feed_mode; - float feed_override_factor; // 1.0000 x F feed rate - bool feed_override_enable; // M48, M49 - - float spindle_speed; // in RPM - spindle_mode_t spindle_mode; - float spindle_override_factor; // 1.0000 x S spindle speed - bool spindle_override_enable; // true = override enabled - - motion_mode_t motion_mode; // Group 1 modal motion - plane_t plane; // G17, G18, G19 - units_t units; // G20, G21 - coord_system_t coord_system; // G54-G59 - select coordinate system 1-9 - bool absolute_mode; // G53 true = move in machine coordinates - path_mode_t path_mode; // G61 - distance_mode_t distance_mode; // G91 - distance_mode_t arc_distance_mode; // G91.1 - - bool mist_coolant; // true = mist on (M7), false = off (M9) - bool flood_coolant; // true = mist on (M8), false = off (M9) - - next_action_t next_action; // handles G group 1 moves & non-modals - program_flow_t program_flow; // used only by the gcode_parser - - // TODO unimplemented gcode parameters - // float cutter_radius; // D - cutter radius compensation (0 is off) - // float cutter_length; // H - cutter length compensation (0 is off) - - // Used for input only - float target[AXES]; // XYZABC where the move should go - bool override_enables; // feed and spindle enable - bool tool_change; // M6 tool change flag - - float parameter; // P - dwell time in sec, G10 coord select - float arc_radius; // R - radius value in arc radius mode - float arc_offset[3]; // IJK - used by arc commands +#define MEMBER(TYPE, VAR) TYPE VAR; +#include "gcode_state.def" +#undef MEMBER } gcode_state_t; + + +typedef struct { +#define MEMBER(TYPE, VAR) bool VAR; +#include "gcode_state.def" +#undef MEMBER +} gcode_flags_t; + + +PGM_P gs_get_units_pgmstr(units_t mode); +PGM_P gs_get_feed_mode_pgmstr(feed_mode_t mode); +PGM_P gs_get_plane_pgmstr(plane_t plane); +PGM_P gs_get_coord_system_pgmstr(coord_system_t cs); +PGM_P gs_get_path_mode_pgmstr(path_mode_t mode); +PGM_P gs_get_distance_mode_pgmstr(distance_mode_t mode); diff --git a/src/homing.c b/src/homing.c index b6a80aa..bd78989 100644 --- a/src/homing.c +++ b/src/homing.c @@ -171,12 +171,12 @@ static homing_t hm = {0}; */ static int8_t _get_next_axis(int8_t axis) { switch (axis) { - case -1: if (fp_TRUE(parser.gf.target[AXIS_Z])) return AXIS_Z; - case AXIS_Z: if (fp_TRUE(parser.gf.target[AXIS_X])) return AXIS_X; - case AXIS_X: if (fp_TRUE(parser.gf.target[AXIS_Y])) return AXIS_Y; - case AXIS_Y: if (fp_TRUE(parser.gf.target[AXIS_A])) return AXIS_A; - case AXIS_A: if (fp_TRUE(parser.gf.target[AXIS_B])) return AXIS_B; - case AXIS_B: if (fp_TRUE(parser.gf.target[AXIS_C])) return AXIS_C; + case -1: if (parser.gf.target[AXIS_Z]) return AXIS_Z; + case AXIS_Z: if (parser.gf.target[AXIS_X]) return AXIS_X; + case AXIS_X: if (parser.gf.target[AXIS_Y]) return AXIS_Y; + case AXIS_Y: if (parser.gf.target[AXIS_A]) return AXIS_A; + case AXIS_A: if (parser.gf.target[AXIS_B]) return AXIS_B; + case AXIS_B: if (parser.gf.target[AXIS_C]) return AXIS_C; } return axis == -1 ? -2 : -1; // error or done @@ -206,7 +206,7 @@ static void _homing_error_exit(stat_t status) { /// Execute moves static void _homing_axis_move(int8_t axis, float target, float velocity) { float vect[AXES] = {0}; - float flags[AXES] = {0}; + bool flags[AXES] = {0}; vect[axis] = target; flags[axis] = true; diff --git a/src/machine.c b/src/machine.c index 009d415..ba654c1 100644 --- a/src/machine.c +++ b/src/machine.c @@ -71,6 +71,7 @@ #include "util.h" #include "report.h" #include "homing.h" +#include "gcode_state.h" #include "plan/planner.h" #include "plan/runtime.h" @@ -144,75 +145,6 @@ distance_mode_t mach_get_distance_mode() {return mach.gm.distance_mode;} distance_mode_t mach_get_arc_distance_mode() {return mach.gm.arc_distance_mode;} -PGM_P mach_get_units_pgmstr(units_t mode) { - switch (mode) { - case INCHES: return PSTR("IN"); - case MILLIMETERS: return PSTR("MM"); - case DEGREES: return PSTR("DEG"); - } - - return PSTR("INVALID"); -} - - -PGM_P mach_get_feed_mode_pgmstr(feed_mode_t mode) { - switch (mode) { - case INVERSE_TIME_MODE: return PSTR("INVERSE TIME"); - case UNITS_PER_MINUTE_MODE: return PSTR("PER MIN"); - case UNITS_PER_REVOLUTION_MODE: return PSTR("PER REV"); - } - - return PSTR("INVALID"); -} - - -PGM_P mach_get_plane_pgmstr(plane_t plane) { - switch (plane) { - case PLANE_XY: return PSTR("XY"); - case PLANE_XZ: return PSTR("XZ"); - case PLANE_YZ: return PSTR("YZ"); - } - - return PSTR("INVALID"); -} - - -PGM_P mach_get_coord_system_pgmstr(coord_system_t cs) { - switch (cs) { - case ABSOLUTE_COORDS: return PSTR("ABS"); - case G54: return PSTR("G54"); - case G55: return PSTR("G55"); - case G56: return PSTR("G56"); - case G57: return PSTR("G57"); - case G58: return PSTR("G58"); - case G59: return PSTR("G59"); - } - - return PSTR("INVALID"); -} - - -PGM_P mach_get_path_mode_pgmstr(path_mode_t mode) { - switch (mode) { - case PATH_EXACT_PATH: return PSTR("EXACT PATH"); - case PATH_EXACT_STOP: return PSTR("EXACT STOP"); - case PATH_CONTINUOUS: return PSTR("CONTINUOUS"); - } - - return PSTR("INVALID"); -} - - -PGM_P mach_get_distance_mode_pgmstr(distance_mode_t mode) { - switch (mode) { - case ABSOLUTE_MODE: return PSTR("ABSOLUTE"); - case INCREMENTAL_MODE: return PSTR("INCREMENTAL"); - } - - return PSTR("INVALID"); -} - - void mach_set_motion_mode(motion_mode_t motion_mode) { mach.gm.motion_mode = motion_mode; } @@ -253,7 +185,7 @@ void mach_set_absolute_mode(bool absolute_mode) { } -void mach_set_model_line(uint32_t line) {mach.gm.line = line;} +void mach_set_line(uint32_t line) {mach.gm.line = line;} /* Coordinate systems and offsets @@ -453,7 +385,7 @@ float mach_calc_move_time(const float axis_length[], } -/* Set target vector in GM model +/*** Calculate target vector * * This is a core routine. It handles: * - conversion of linear units to internal canonical form (mm) @@ -473,12 +405,11 @@ float mach_calc_move_time(const float axis_length[], * Target coordinates are provided in target[] * Axes that need processing are signaled in flag[] */ - void mach_calc_model_target(float target[], const float values[], - const float flags[]) { + const bool flags[]) { // process XYZABC for lower modes for (int axis = AXIS_X; axis <= AXIS_Z; axis++) { - if (fp_FALSE(flags[axis]) || axes[axis].axis_mode == AXIS_DISABLED) + if (!flags[axis] || axes[axis].axis_mode == AXIS_DISABLED) continue; // skip axis if not flagged for update or its disabled if (axes[axis].axis_mode == AXIS_STANDARD || @@ -492,7 +423,7 @@ void mach_calc_model_target(float target[], const float values[], // Note: The ABC loop below relies on the XYZ loop having been run first for (int axis = AXIS_A; axis <= AXIS_C; axis++) { - if (fp_FALSE(flags[axis]) || axes[axis].axis_mode == AXIS_DISABLED) + if (!flags[axis] || axes[axis].axis_mode == AXIS_DISABLED) continue; // skip axis if not flagged for update or its disabled float tmp; @@ -603,11 +534,11 @@ void mach_set_arc_distance_mode(distance_mode_t mode) { * This function applies the offset to the GM model. */ void mach_set_coord_offsets(coord_system_t coord_system, float offset[], - float flag[]) { + bool flags[]) { if (coord_system < G54 || G59 < coord_system) return; for (int axis = 0; axis < AXES; axis++) - if (fp_TRUE(flag[axis])) + if (flags[axis]) mach.offset[coord_system][axis] = TO_MILLIMETERS(offset[axis]); } @@ -671,7 +602,7 @@ static stat_t _exec_absolute_origin(mp_buffer_t *bf) { const float *flags = bf->unit; for (int axis = 0; axis < AXES; axis++) - if (fp_TRUE(flags[axis])) { + if (flags[axis]) { mp_runtime_set_axis_position(axis, origin[axis]); mach_set_homed(axis, true); // G28.3 is not considered homed until here } @@ -694,11 +625,11 @@ static stat_t _exec_absolute_origin(mp_buffer_t *bf) { * recording done by the encoders. At that point any axis that is set * is also marked as homed. */ -void mach_set_absolute_origin(float origin[], float flags[]) { +void mach_set_absolute_origin(float origin[], bool flags[]) { float value[AXES]; for (int axis = 0; axis < AXES; axis++) - if (fp_TRUE(flags[axis])) { + if (flags[axis]) { value[axis] = TO_MILLIMETERS(origin[axis]); mach.position[axis] = value[axis]; // set model position mp_set_axis_position(axis, value[axis]); // set mm position @@ -716,11 +647,11 @@ void mach_set_absolute_origin(float origin[], float flags[]) { */ /// G92 -void mach_set_origin_offsets(float offset[], float flag[]) { +void mach_set_origin_offsets(float offset[], bool flags[]) { // set offsets in the Gcode model extended context mach.origin_offset_enable = true; for (int axis = 0; axis < AXES; axis++) - if (fp_TRUE(flag[axis])) + if (flags[axis]) mach.origin_offset[axis] = mach.position[axis] - mach.offset[mach.gm.coord_system][axis] - TO_MILLIMETERS(offset[axis]); } @@ -749,7 +680,7 @@ void mach_resume_origin_offsets() { // Free Space Motion (4.3.4) /// G0 linear rapid -stat_t mach_rapid(float values[], float flags[]) { +stat_t mach_rapid(float values[], bool flags[]) { mach.gm.motion_mode = MOTION_MODE_RAPID; float target[AXES]; @@ -773,14 +704,14 @@ void mach_set_g28_position() {copy_vector(mach.g28_position, mach.position);} /// G28 -stat_t mach_goto_g28_position(float target[], float flags[]) { +stat_t mach_goto_g28_position(float target[], bool flags[]) { mach_set_absolute_mode(true); // move through intermediate point, or skip mach_rapid(target, flags); // execute actual stored move - float f[] = {1, 1, 1, 1, 1, 1}; + bool f[] = {true, true, true, true, true, true}; return mach_rapid(mach.g28_position, f); } @@ -790,14 +721,14 @@ void mach_set_g30_position() {copy_vector(mach.g30_position, mach.position);} /// G30 -stat_t mach_goto_g30_position(float target[], float flags[]) { +stat_t mach_goto_g30_position(float target[], bool flags[]) { mach_set_absolute_mode(true); // move through intermediate point, or skip mach_rapid(target, flags); // execute actual stored move - float f[] = {1, 1, 1, 1, 1, 1}; + bool f[] = {true, true, true, true, true, true}; return mach_rapid(mach.g30_position, f); } @@ -838,7 +769,7 @@ stat_t mach_dwell(float seconds) { /// G1 -stat_t mach_feed(float values[], float flags[]) { +stat_t mach_feed(float values[], bool flags[]) { // trap zero feed rate condition if (fp_ZERO(mach.gm.feed_rate) || (mach.gm.feed_mode == INVERSE_TIME_MODE && !parser.gf.feed_rate)) @@ -867,7 +798,7 @@ stat_t mach_feed(float values[], float flags[]) { // Tool Functions (4.3.8) /// T parameter -void mach_select_tool(uint8_t tool_select) {mach.gm.tool_select = tool_select;} +void mach_select_tool(uint8_t tool) {mach.gm.tool = tool;} static stat_t _exec_change_tool(mp_buffer_t *bf) { @@ -878,8 +809,6 @@ static stat_t _exec_change_tool(mp_buffer_t *bf) { /// M6 This might become a complete tool change cycle void mach_change_tool(bool x) { - mach.gm.tool = mach.gm.tool_select; - mp_buffer_t *bf = mp_queue_get_tail(); bf->value = mach.gm.tool; mp_queue_push(_exec_change_tool, mach_get_line()); @@ -930,7 +859,7 @@ void mach_override_enables(bool flag) { /// M50 void mach_feed_override_enable(bool flag) { - if (fp_TRUE(parser.gf.parameter) && fp_ZERO(parser.gn.parameter)) + if (parser.gf.parameter && fp_ZERO(parser.gn.parameter)) mach.gm.feed_override_enable = false; else mach.gm.feed_override_enable = true; } @@ -945,7 +874,7 @@ void mach_feed_override_factor(bool flag) { /// M51 void mach_spindle_override_enable(bool flag) { - if (fp_TRUE(parser.gf.parameter) && fp_ZERO(parser.gn.parameter)) + if (parser.gf.parameter && fp_ZERO(parser.gn.parameter)) mach.gm.spindle_override_enable = false; else mach.gm.spindle_override_enable = true; } @@ -1051,11 +980,3 @@ void mach_program_end() { mach_set_feed_mode(UNITS_PER_MINUTE_MODE); // G94 mach_set_motion_mode(MOTION_MODE_CANCEL_MOTION_MODE); } - - -/// return ASCII char for axis given the axis number -char mach_get_axis_char(int8_t axis) { - char axis_char[] = "XYZABC"; - if (axis < 0 || axis > AXES) return ' '; - return axis_char[axis]; -} diff --git a/src/machine.h b/src/machine.h index 2c66840..317ebbe 100644 --- a/src/machine.h +++ b/src/machine.h @@ -33,8 +33,6 @@ #include "status.h" #include "gcode_state.h" -#include - #define TO_MILLIMETERS(a) (mach_get_units() == INCHES ? (a) * MM_PER_INCH : a) @@ -53,18 +51,11 @@ path_mode_t mach_get_path_mode(); distance_mode_t mach_get_distance_mode(); distance_mode_t mach_get_arc_distance_mode(); -PGM_P mach_get_units_pgmstr(units_t mode); -PGM_P mach_get_feed_mode_pgmstr(feed_mode_t mode); -PGM_P mach_get_plane_pgmstr(plane_t plane); -PGM_P mach_get_coord_system_pgmstr(coord_system_t cs); -PGM_P mach_get_path_mode_pgmstr(path_mode_t mode); -PGM_P mach_get_distance_mode_pgmstr(distance_mode_t mode); - void mach_set_motion_mode(motion_mode_t motion_mode); void mach_set_spindle_mode(spindle_mode_t spindle_mode); void mach_set_spindle_speed(float speed); void mach_set_absolute_mode(bool absolute_mode); -void mach_set_model_line(uint32_t line); +void mach_set_line(uint32_t line); // Coordinate systems and offsets float mach_get_active_coord_offset(uint8_t axis); @@ -76,7 +67,7 @@ float mach_get_axis_position(uint8_t axis); // Critical helpers float mach_calc_move_time(const float axis_length[], const float axis_square[]); void mach_calc_model_target(float target[], const float values[], - const float flags[]); + const bool flags[]); stat_t mach_test_soft_limits(float target[]); // machining functions defined by NIST [organized by NIST Gcode doc] @@ -90,26 +81,26 @@ void mach_set_units(units_t mode); void mach_set_distance_mode(distance_mode_t mode); void mach_set_arc_distance_mode(distance_mode_t mode); void mach_set_coord_offsets(coord_system_t coord_system, float offset[], - float flag[]); + bool flags[]); void mach_set_axis_position(unsigned axis, float position); -void mach_set_absolute_origin(float origin[], float flag[]); +void mach_set_absolute_origin(float origin[], bool flags[]); stat_t mach_zero_all(); stat_t mach_zero_axis(unsigned axis); void mach_set_coord_system(coord_system_t coord_system); -void mach_set_origin_offsets(float offset[], float flag[]); +void mach_set_origin_offsets(float offset[], bool flags[]); void mach_reset_origin_offsets(); void mach_suspend_origin_offsets(); void mach_resume_origin_offsets(); // Free Space Motion (4.3.4) -stat_t mach_rapid(float target[], float flags[]); +stat_t mach_rapid(float target[], bool flags[]); void mach_set_g28_position(); -stat_t mach_goto_g28_position(float target[], float flags[]); +stat_t mach_goto_g28_position(float target[], bool flags[]); void mach_set_g30_position(); -stat_t mach_goto_g30_position(float target[], float flags[]); +stat_t mach_goto_g30_position(float target[], bool flags[]); // Machining Attributes (4.3.5) void mach_set_feed_rate(float feed_rate); @@ -117,9 +108,9 @@ void mach_set_feed_mode(feed_mode_t mode); void mach_set_path_mode(path_mode_t mode); // Machining Functions (4.3.6) -stat_t mach_feed(float target[], float flags[]); -stat_t mach_arc_feed(float target[], float flags[], float offsets[], - float offset_f[], float radius, bool radius_f, +stat_t mach_feed(float target[], bool flags[]); +stat_t mach_arc_feed(float target[], bool flags[], float offsets[], + bool offset_f[], float radius, bool radius_f, float P, bool P_f, bool modal_g1_f, uint8_t motion_mode); stat_t mach_dwell(float seconds); @@ -146,5 +137,3 @@ void mach_program_stop(); void mach_optional_program_stop(); void mach_pallet_change_stop(); void mach_program_end(); - -char mach_get_axis_char(int8_t axis); diff --git a/src/plan/arc.c b/src/plan/arc.c index 1874b13..b822ce6 100644 --- a/src/plan/arc.c +++ b/src/plan/arc.c @@ -342,10 +342,10 @@ static stat_t _compute_arc(bool radius_f, const float position[], * Generates an arc by queuing line segments to the move buffer. The arc is * approximated by generating a large number of tiny, linear segments. */ -stat_t mach_arc_feed(float values[], float values_f[], // arc endpoints - float offsets[], float offsets_f[], // arc offsets - float radius, bool radius_f, // radius - float P, bool P_f, // parameter +stat_t mach_arc_feed(float values[], bool values_f[], // arc endpoints + float offsets[], bool offsets_f[], // arc offsets + float radius, bool radius_f, // radius + float P, bool P_f, // parameter bool modal_g1_f, uint8_t motion_mode) { // defined motion mode diff --git a/src/probing.c b/src/probing.c index ab7dcc3..e37bbee 100644 --- a/src/probing.c +++ b/src/probing.c @@ -68,7 +68,7 @@ typedef struct { // probe destination float start_position[AXES]; float target[AXES]; - float flags[AXES]; + bool flags[AXES]; } probing_t; @@ -191,15 +191,14 @@ bool mach_is_probing() { /// G38.2 homing cycle using limit switches -stat_t mach_probe(float target[], float flags[]) { +stat_t mach_probe(float target[], bool flags[]) { // trap zero feed rate condition if (mach_get_feed_mode() != INVERSE_TIME_MODE && fp_ZERO(mach_get_feed_rate())) return STAT_GCODE_FEEDRATE_NOT_SPECIFIED; // trap no axes specified - if (fp_NOT_ZERO(flags[AXIS_X]) && fp_NOT_ZERO(flags[AXIS_Y]) && - fp_NOT_ZERO(flags[AXIS_Z])) + if (!flags[AXIS_X] && !flags[AXIS_Y] && !flags[AXIS_Z]) return STAT_GCODE_AXIS_IS_MISSING; // set probe move endpoint diff --git a/src/probing.h b/src/probing.h index 870eed6..0e3fc01 100644 --- a/src/probing.h +++ b/src/probing.h @@ -33,5 +33,5 @@ bool mach_is_probing(); -stat_t mach_probe(float target[], float flags[]); +stat_t mach_probe(float target[], bool flags[]); void mach_probe_callback(); diff --git a/src/varcb.c b/src/varcb.c index 3ccb3a2..9ef970e 100644 --- a/src/varcb.c +++ b/src/varcb.c @@ -38,36 +38,36 @@ float get_position(int index) {return mp_runtime_get_axis_position(index);} // GCode int32_t get_line() {return mp_runtime_get_line();} -PGM_P get_unit() {return mach_get_units_pgmstr(mach_get_units());} +PGM_P get_unit() {return gs_get_units_pgmstr(mach_get_units());} float get_speed() {return spindle_get_speed();} float get_feed() {return mach_get_feed_rate();} // TODO get runtime value uint8_t get_tool() {return mp_runtime_get_tool();} PGM_P get_feed_mode() { - return mach_get_feed_mode_pgmstr(mach_get_feed_mode()); + return gs_get_feed_mode_pgmstr(mach_get_feed_mode()); } -PGM_P get_plane() {return mach_get_plane_pgmstr(mach_get_plane());} +PGM_P get_plane() {return gs_get_plane_pgmstr(mach_get_plane());} PGM_P get_coord_system() { - return mach_get_coord_system_pgmstr(mach_get_coord_system()); + return gs_get_coord_system_pgmstr(mach_get_coord_system()); } bool get_abs_override() {return mach_get_absolute_mode();} -PGM_P get_path_mode() {return mach_get_path_mode_pgmstr(mach_get_path_mode());} +PGM_P get_path_mode() {return gs_get_path_mode_pgmstr(mach_get_path_mode());} PGM_P get_distance_mode() { - return mach_get_distance_mode_pgmstr(mach_get_distance_mode()); + return gs_get_distance_mode_pgmstr(mach_get_distance_mode()); } PGM_P get_arc_dist_mode() { - return mach_get_distance_mode_pgmstr(mach_get_arc_distance_mode()); + return gs_get_distance_mode_pgmstr(mach_get_arc_distance_mode()); } -- 2.27.0