diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp
index e0014161..a4e8c780 100644
--- a/g2core/canonical_machine.cpp
+++ b/g2core/canonical_machine.cpp
@@ -126,7 +126,6 @@ static void _exec_absolute_origin(float *value, bool *flag);
static void _exec_program_finalize(float *value, bool *flag);
static int8_t _get_axis(const index_t index);
-static int8_t _get_axis_type(const index_t index);
/***********************************************************************************
**** CODE *************************************************************************
@@ -2171,11 +2170,64 @@ static const char *const msg_frmo[] = { msg_g93, msg_g94, msg_g95 };
/***** AXIS HELPERS *****************************************************************
- * cm_get_axis_char() - return ASCII char for axis given the axis number
- * _get_axis() - return axis number or -1 if NA
- * _get_axis_type() - return 0 -f axis is linear, 1 if rotary, -1 if NA
+ * _get_axis() - return axis # or -1 if not an axis (works for mapped motors as well)
+ * _coord() - return coordinate system number or -1 if error
+ * cm_get_axis_char() - return ASCII char for axis given the axis number
+ * cm_get_axis_type() - return linear axis (0), rotary axis (1) or error (-1)
*/
+/* _get_axis()
+ *
+ * Cases that are handled by _get_axis():
+ * - sys/... value is a system parameter (global), there is no axis
+ * - xam any axis parameter will return the axis number
+ * - 1ma any motor parameter will return the mapped axis for that motor
+ * - 1su an example of the above
+ * - mpox readouts
+ * - g54x offsets
+ * - tlx tool length offset
+ * - tt1x tool table
+ * - tt32x tool table
+ * - _tex diagnostic parameters
+ */
+
+static int8_t _get_axis(const index_t index)
+{
+ // test if this is a SYS parameter (global), in which case there will be no axis
+ if (strcmp("sys", cfgArray[index].group) == 0) {
+ return (AXIS_TYPE_SYSTEM);
+ }
+
+ // if the leading character of the token is a number it's a motor
+ char c = cfgArray[index].token[0];
+ if (isdigit(cfgArray[index].token[0])) {
+ return(st_cfg.mot[c-0x31].motor_map);
+ }
+
+ // otherwise it's an axis. Or undefined, which is usually a global.
+ char *ptr;
+ char axes[] = {"xyzabc"};
+ if ((ptr = strchr(axes, c)) == NULL) { // test the character in the 0 and 3 positions
+ if ((ptr = strchr(axes, cfgArray[index].token[3])) == NULL) { // to accommodate 'xam' and 'g54x' styles
+ return (AXIS_TYPE_UNDEFINED);
+ }
+ }
+ return (ptr - axes);
+}
+
+/**** not used yet ****
+static int8_t _coord(char *token) // extract coordinate system from 3rd character
+{
+ char *ptr;
+ char coord_list[] = {"456789"};
+
+ if ((ptr = strchr(coord_list, token[2])) == NULL) { // test the 3rd character against the string
+ return (-1);
+ }
+ return (ptr - coord_list);
+}
+*/
+
char cm_get_axis_char(const int8_t axis)
{
char axis_char[] = "XYZABC";
@@ -2183,45 +2235,13 @@ char cm_get_axis_char(const int8_t axis)
return (axis_char[axis]);
}
-/*
- * _get_axis() - return axis number or -1 if no match
- * _get_axis_type() - return linear axis (0), rotary axis (1) or error (-1)
- *
- * It's possible top get a false positive if a non-axis token is passed
- * This function should only be called from functions that process axis commands
- *
- * Cases that are handled:
- * - xam ( axis parameters )
- * - mpox ( readouts)
- * - g54x ( offsets )
- * - tlx ( tool length offset )
- * - tt1x ( tool table )
- * - tt16x ( tool table )
- * - _tex ( diagnostic parameters )
- */
-
-static int8_t _get_axis(const index_t index)
-{
- char *ptr;
- char axes[] = {"xyzabc"};
-
- // test first character cases - e.g. xam
- if ((ptr = strchr(axes, cfgArray[index].token[0])) != NULL) {
- return (ptr - axes);
- }
- // test last character cases - e.g. g54x
- if ((ptr = strchr(axes, cfgArray[index].token[strlen(cfgArray[index].token)-1])) != NULL) {
- return (ptr - axes);
- }
- return (-1);
-}
-
-static int8_t _get_axis_type(const index_t index)
+cmAxisType cm_get_axis_type(const index_t index)
{
int8_t axis = _get_axis(index);
- if (axis >= AXIS_A) return (1);
- if (axis == -1) return (-1);
- return (0);
+ if (axis == AXIS_TYPE_UNDEFINED) { return (AXIS_TYPE_UNDEFINED); }
+ if (axis == AXIS_TYPE_SYSTEM) { return (AXIS_TYPE_SYSTEM); }
+ if (axis >= AXIS_A) { return (AXIS_TYPE_ROTARY); }
+ return (AXIS_TYPE_LINEAR);
}
/**** Functions called directly from cfgArray table - mostly wrappers ****
@@ -2376,7 +2396,7 @@ stat_t cm_get_am(nvObj_t *nv)
stat_t cm_set_am(nvObj_t *nv) // axis mode
{
- if (_get_axis_type(nv->index) == 0) { // linear
+ if (cm_get_axis_type(nv->index) == 0) { // linear
if (nv->value > AXIS_MODE_MAX_LINEAR) {
nv->valuetype = TYPE_NULL;
return (STAT_INPUT_EXCEEDS_MAX_VALUE);
@@ -2791,7 +2811,7 @@ static void _print_axis_ui8(nvObj_t *nv, const char *format)
static void _print_axis_flt(nvObj_t *nv, const char *format)
{
char *units;
- if (_get_axis_type(nv->index) == 0) { // linear
+ if (cm_get_axis_type(nv->index) == 0) { // linear
units = (char *)GET_UNITS(MODEL);
} else {
units = (char *)GET_TEXT_ITEM(msg_units, DEGREE_INDEX);
@@ -2803,7 +2823,7 @@ static void _print_axis_flt(nvObj_t *nv, const char *format)
static void _print_axis_coord_flt(nvObj_t *nv, const char *format)
{
char *units;
- if (_get_axis_type(nv->index) == 0) { // linear
+ if (cm_get_axis_type(nv->index) == 0) { // linear
units = (char *)GET_UNITS(MODEL);
} else {
units = (char *)GET_TEXT_ITEM(msg_units, DEGREE_INDEX);
diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h
index 7fa90d3c..bc881234 100644
--- a/g2core/canonical_machine.h
+++ b/g2core/canonical_machine.h
@@ -280,6 +280,13 @@ typedef enum { // used for spindle and arc dir
DIRECTION_CCW
} cmDirection;
+typedef enum { // axis types
+ AXIS_TYPE_UNDEFINED=-2, // invalid type
+ AXIS_TYPE_SYSTEM=-1, // token is global system token, not axis
+ AXIS_TYPE_LINEAR, // linear axis
+ AXIS_TYPE_ROTARY // rotary axis
+} cmAxisType;
+
typedef enum { // axis modes (ordered: see _cm_get_feed_time())
AXIS_DISABLED = 0, // kill axis
AXIS_STANDARD, // axis in coordinated motion w/standard behaviors
@@ -773,6 +780,7 @@ float cm_get_jogging_dest(void);
/*--- cfgArray interface functions ---*/
char cm_get_axis_char(const int8_t axis);
+cmAxisType cm_get_axis_type(const index_t index);
stat_t cm_get_mline(nvObj_t *nv); // get model line number
stat_t cm_get_line(nvObj_t *nv); // get active (model or runtime) line number
diff --git a/g2core/config_app.cpp b/g2core/config_app.cpp
index 17b28781..71dea152 100644
--- a/g2core/config_app.cpp
+++ b/g2core/config_app.cpp
@@ -158,14 +158,7 @@ const cfgItem_t cfgArray[] = {
{ "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
-/*
- { "tof","tofx",_f0, 3, cm_print_tof, cm_get_tof, set_ro, (float *)&cs.null, 0 }, // X tool offset
- { "tof","tofy",_f0, 3, cm_print_tof, cm_get_tof, set_ro, (float *)&cs.null, 0 }, // Y tool offset
- { "tof","tofz",_f0, 3, cm_print_tof, cm_get_tof, set_ro, (float *)&cs.null, 0 }, // Z tool offset
- { "tof","tofa",_f0, 3, cm_print_tof, cm_get_tof, set_ro, (float *)&cs.null, 0 }, // A tool offset
- { "tof","tofb",_f0, 3, cm_print_tof, cm_get_tof, set_ro, (float *)&cs.null, 0 }, // B tool offset
- { "tof","tofc",_f0, 3, cm_print_tof, cm_get_tof, set_ro, (float *)&cs.null, 0 }, // C tool 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
@@ -205,22 +198,22 @@ const cfgItem_t cfgArray[] = {
#endif
// Motor parameters
- { "1","1ma",_fip, 0, st_print_ma, get_ui8, set_ui8, (float *)&st_cfg.mot[MOTOR_1].motor_map, M1_MOTOR_MAP },
+ { "1","1ma",_fip, 0, st_print_ma, get_ui8, st_set_ma, (float *)&st_cfg.mot[MOTOR_1].motor_map, M1_MOTOR_MAP },
{ "1","1sa",_fip, 3, st_print_sa, get_flt, st_set_sa, (float *)&st_cfg.mot[MOTOR_1].step_angle, M1_STEP_ANGLE },
{ "1","1tr",_fipc,4, st_print_tr, get_flt, st_set_tr, (float *)&st_cfg.mot[MOTOR_1].travel_rev, M1_TRAVEL_PER_REV },
{ "1","1mi",_fip, 0, st_print_mi, get_ui8, st_set_mi, (float *)&st_cfg.mot[MOTOR_1].microsteps, M1_MICROSTEPS },
- { "1","1su",_fipi,5, st_print_su, get_flt, st_set_su, (float *)&st_cfg.mot[MOTOR_1].steps_per_unit, M1_STEPS_PER_UNIT },
+ { "1","1su",_fipi,5, st_print_su, st_get_su,st_set_su, (float *)&st_cfg.mot[MOTOR_1].steps_per_unit, M1_STEPS_PER_UNIT },
{ "1","1po",_fip, 0, st_print_po, get_ui8, set_01, (float *)&st_cfg.mot[MOTOR_1].polarity, M1_POLARITY },
{ "1","1pm",_fip, 0, st_print_pm, st_get_pm, st_set_pm, (float *)&cs.null, M1_POWER_MODE },
{ "1","1pl",_fip, 3, st_print_pl, get_flt, st_set_pl, (float *)&st_cfg.mot[MOTOR_1].power_level, M1_POWER_LEVEL },
// { "1","1pi",_fip, 3, st_print_pi, get_flt, st_set_pi, (float *)&st_cfg.mot[MOTOR_1].power_idle, M1_POWER_IDLE },
// { "1","1mt",_fip, 2, st_print_mt, get_flt, st_set_mt, (float *)&st_cfg.mot[MOTOR_1].motor_timeout, M1_MOTOR_TIMEOUT },
#if (MOTORS >= 2)
- { "2","2ma",_fip, 0, st_print_ma, get_ui8, set_ui8, (float *)&st_cfg.mot[MOTOR_2].motor_map, M2_MOTOR_MAP },
+ { "2","2ma",_fip, 0, st_print_ma, get_ui8, st_set_ma, (float *)&st_cfg.mot[MOTOR_2].motor_map, M2_MOTOR_MAP },
{ "2","2sa",_fip, 3, st_print_sa, get_flt, st_set_sa, (float *)&st_cfg.mot[MOTOR_2].step_angle, M2_STEP_ANGLE },
{ "2","2tr",_fipc,4, st_print_tr, get_flt, st_set_tr, (float *)&st_cfg.mot[MOTOR_2].travel_rev, M2_TRAVEL_PER_REV },
{ "2","2mi",_fip, 0, st_print_mi, get_ui8, st_set_mi, (float *)&st_cfg.mot[MOTOR_2].microsteps, M2_MICROSTEPS },
- { "2","2su",_fipi,5, st_print_su, get_flt, st_set_su, (float *)&st_cfg.mot[MOTOR_2].steps_per_unit, M2_STEPS_PER_UNIT },
+ { "2","2su",_fipi,5, st_print_su, st_get_su,st_set_su, (float *)&st_cfg.mot[MOTOR_2].steps_per_unit, M2_STEPS_PER_UNIT },
{ "2","2po",_fip, 0, st_print_po, get_ui8, set_01, (float *)&st_cfg.mot[MOTOR_2].polarity, M2_POLARITY },
{ "2","2pm",_fip, 0, st_print_pm, st_get_pm, st_set_pm, (float *)&cs.null, M2_POWER_MODE },
{ "2","2pl",_fip, 3, st_print_pl, get_flt, st_set_pl, (float *)&st_cfg.mot[MOTOR_2].power_level, M2_POWER_LEVEL},
@@ -228,11 +221,11 @@ const cfgItem_t cfgArray[] = {
// { "2","2mt",_fip, 2, st_print_mt, get_flt, st_set_mt, (float *)&st_cfg.mot[MOTOR_2].motor_timeout, M2_MOTOR_TIMEOUT },
#endif
#if (MOTORS >= 3)
- { "3","3ma",_fip, 0, st_print_ma, get_ui8, set_ui8, (float *)&st_cfg.mot[MOTOR_3].motor_map, M3_MOTOR_MAP },
+ { "3","3ma",_fip, 0, st_print_ma, get_ui8, st_set_ma, (float *)&st_cfg.mot[MOTOR_3].motor_map, M3_MOTOR_MAP },
{ "3","3sa",_fip, 3, st_print_sa, get_flt, st_set_sa, (float *)&st_cfg.mot[MOTOR_3].step_angle, M3_STEP_ANGLE },
{ "3","3tr",_fipc,4, st_print_tr, get_flt, st_set_tr, (float *)&st_cfg.mot[MOTOR_3].travel_rev, M3_TRAVEL_PER_REV },
{ "3","3mi",_fip, 0, st_print_mi, get_ui8, st_set_mi, (float *)&st_cfg.mot[MOTOR_3].microsteps, M3_MICROSTEPS },
- { "3","3su",_fipi,5, st_print_su, get_flt, st_set_su, (float *)&st_cfg.mot[MOTOR_3].steps_per_unit, M3_STEPS_PER_UNIT },
+ { "3","3su",_fipi,5, st_print_su, st_get_su,st_set_su, (float *)&st_cfg.mot[MOTOR_3].steps_per_unit, M3_STEPS_PER_UNIT },
{ "3","3po",_fip, 0, st_print_po, get_ui8, set_01, (float *)&st_cfg.mot[MOTOR_3].polarity, M3_POLARITY },
{ "3","3pm",_fip, 0, st_print_pm, st_get_pm, st_set_pm, (float *)&cs.null, M3_POWER_MODE },
{ "3","3pl",_fip, 3, st_print_pl, get_flt, st_set_pl, (float *)&st_cfg.mot[MOTOR_3].power_level, M3_POWER_LEVEL },
@@ -240,11 +233,11 @@ const cfgItem_t cfgArray[] = {
// { "3","3mt",_fip, 2, st_print_mt, get_flt, st_set_mt, (float *)&st_cfg.mot[MOTOR_3].motor_timeout, M3_MOTOR_TIMEOUT },
#endif
#if (MOTORS >= 4)
- { "4","4ma",_fip, 0, st_print_ma, get_ui8, set_ui8, (float *)&st_cfg.mot[MOTOR_4].motor_map, M4_MOTOR_MAP },
+ { "4","4ma",_fip, 0, st_print_ma, get_ui8, st_set_ma, (float *)&st_cfg.mot[MOTOR_4].motor_map, M4_MOTOR_MAP },
{ "4","4sa",_fip, 3, st_print_sa, get_flt, st_set_sa, (float *)&st_cfg.mot[MOTOR_4].step_angle, M4_STEP_ANGLE },
{ "4","4tr",_fipc,4, st_print_tr, get_flt, st_set_tr, (float *)&st_cfg.mot[MOTOR_4].travel_rev, M4_TRAVEL_PER_REV },
{ "4","4mi",_fip, 0, st_print_mi, get_ui8, st_set_mi, (float *)&st_cfg.mot[MOTOR_4].microsteps, M4_MICROSTEPS },
- { "4","4su",_fipi,5, st_print_su, get_flt, st_set_su, (float *)&st_cfg.mot[MOTOR_4].steps_per_unit, M4_STEPS_PER_UNIT },
+ { "4","4su",_fipi,5, st_print_su, st_get_su,st_set_su, (float *)&st_cfg.mot[MOTOR_4].steps_per_unit, M4_STEPS_PER_UNIT },
{ "4","4po",_fip, 0, st_print_po, get_ui8, set_01, (float *)&st_cfg.mot[MOTOR_4].polarity, M4_POLARITY },
{ "4","4pm",_fip, 0, st_print_pm, st_get_pm, st_set_pm, (float *)&cs.null, M4_POWER_MODE },
{ "4","4pl",_fip, 3, st_print_pl, get_flt, st_set_pl, (float *)&st_cfg.mot[MOTOR_4].power_level, M4_POWER_LEVEL },
@@ -252,11 +245,11 @@ const cfgItem_t cfgArray[] = {
// { "4","4mt",_fip, 2, st_print_mt, get_flt, st_set_mt, (float *)&st_cfg.mot[MOTOR_4].motor_timeout, M4_MOTOR_TIMEOUT },
#endif
#if (MOTORS >= 5)
- { "5","5ma",_fip, 0, st_print_ma, get_ui8, set_ui8, (float *)&st_cfg.mot[MOTOR_5].motor_map, M5_MOTOR_MAP },
+ { "5","5ma",_fip, 0, st_print_ma, get_ui8, st_set_ma, (float *)&st_cfg.mot[MOTOR_5].motor_map, M5_MOTOR_MAP },
{ "5","5sa",_fip, 3, st_print_sa, get_flt, st_set_sa, (float *)&st_cfg.mot[MOTOR_5].step_angle, M5_STEP_ANGLE },
{ "5","5tr",_fipc,4, st_print_tr, get_flt, st_set_tr, (float *)&st_cfg.mot[MOTOR_5].travel_rev, M5_TRAVEL_PER_REV },
{ "5","5mi",_fip, 0, st_print_mi, get_ui8, st_set_mi, (float *)&st_cfg.mot[MOTOR_5].microsteps, M5_MICROSTEPS },
- { "5","5su",_fipi,5, st_print_su, get_flt, st_set_su, (float *)&st_cfg.mot[MOTOR_5].steps_per_unit, M5_STEPS_PER_UNIT },
+ { "5","5su",_fipi,5, st_print_su, st_get_su,st_set_su, (float *)&st_cfg.mot[MOTOR_5].steps_per_unit, M5_STEPS_PER_UNIT },
{ "5","5po",_fip, 0, st_print_po, get_ui8, set_01, (float *)&st_cfg.mot[MOTOR_5].polarity, M5_POLARITY },
{ "5","5pm",_fip, 0, st_print_pm, st_get_pm, st_set_pm, (float *)&cs.null, M5_POWER_MODE },
{ "5","5pl",_fip, 3, st_print_pl, get_flt, st_set_pl, (float *)&st_cfg.mot[MOTOR_5].power_level, M5_POWER_LEVEL },
@@ -264,11 +257,11 @@ const cfgItem_t cfgArray[] = {
// { "5","5mt",_fip, 2, st_print_mt, get_flt, st_set_mt, (float *)&st_cfg.mot[MOTOR_5].motor_timeout, M5_MOTOR_TIMEOUT },
#endif
#if (MOTORS >= 6)
- { "6","6ma",_fip, 0, st_print_ma, get_ui8, set_ui8, (float *)&st_cfg.mot[MOTOR_6].motor_map, M6_MOTOR_MAP },
+ { "6","6ma",_fip, 0, st_print_ma, get_ui8, st_set_ma, (float *)&st_cfg.mot[MOTOR_6].motor_map, M6_MOTOR_MAP },
{ "6","6sa",_fip, 3, st_print_sa, get_flt, st_set_sa, (float *)&st_cfg.mot[MOTOR_6].step_angle, M6_STEP_ANGLE },
{ "6","6tr",_fipc,4, st_print_tr, get_flt, st_set_tr, (float *)&st_cfg.mot[MOTOR_6].travel_rev, M6_TRAVEL_PER_REV },
{ "6","6mi",_fip, 0, st_print_mi, get_ui8, st_set_mi, (float *)&st_cfg.mot[MOTOR_6].microsteps, M6_MICROSTEPS },
- { "6","6su",_fipi,5, st_print_su, get_flt, st_set_su, (float *)&st_cfg.mot[MOTOR_6].steps_per_unit, M6_STEPS_PER_UNIT },
+ { "6","6su",_fipi,5, st_print_su, st_get_su,st_set_su, (float *)&st_cfg.mot[MOTOR_6].steps_per_unit, M6_STEPS_PER_UNIT },
{ "6","6po",_fip, 0, st_print_po, get_ui8, set_01, (float *)&st_cfg.mot[MOTOR_6].polarity, M6_POLARITY },
{ "6","6pm",_fip, 0, st_print_pm, st_get_pm, st_set_pm, (float *)&cs.null, M6_POWER_MODE },
{ "6","6pl",_fip, 3, st_print_pl, get_flt, st_set_pl, (float *)&st_cfg.mot[MOTOR_6].power_level, M6_POWER_LEVEL },
@@ -1252,10 +1245,10 @@ bool nv_index_lt_groups(index_t index) { return ((index <= NV_INDEX_START_GROUPS
stat_t set_flu(nvObj_t *nv)
{
- if (cm_get_units_mode(MODEL) == INCHES) { // if in inches...
- nv->value *= MM_PER_INCH; // convert to canonical millimeter units
+ if (cm_get_units_mode(MODEL) == INCHES) { // if in inches...
+ nv->value *= MM_PER_INCH; // convert to canonical millimeter units
}
- *((float *)GET_TABLE_WORD(target)) = nv->value; // write value as millimeters or degrees
+ *((float *)GET_TABLE_WORD(target)) = nv->value; // write value as millimeters or degrees
nv->precision = GET_TABLE_WORD(precision);
nv->valuetype = TYPE_FLOAT;
return(STAT_OK);
@@ -1281,32 +1274,39 @@ stat_t set_fltp(nvObj_t *nv)
/*
* preprocess_float() - pre-process floating point number for units display
+ *
+ * Apologies in advance for this twisty little function. This function is used to
+ * convert the native, canonical form of a parameter (mm, or whatever), into a display
+ * format appropriate to the units mode in effect. It uses the flags in the config table
+ * to determine what type of conversion to perform. It's complicated by the fact that
+ * only linear axes actually convert - rotaries do not. Plus, determining the axis for
+ * a motor requires unraveling the motor mapping (handled in cm_get_axis_type()).
+ * Also, there are global SYS group values that are not associated with any axis.
+ * Lastly, the steps-per-unit value (1su) is actually kept in inverse conversion form,
+ * as its native form would be units-per-step.
*/
void preprocess_float(nvObj_t *nv)
-/*
{
- if (isnan((double)nv->value) || isinf((double)nv->value)) return; // illegal float values
- if (GET_TABLE_BYTE(flags) & F_CONVERT) { // unit conversion required?
- if (cm_get_units_mode(MODEL) == INCHES) {
- nv->value *= INCHES_PER_MM;
+ if (nv->valuetype != TYPE_FLOAT) { return; } // can be called non-destructively for any value type
+ if (isnan((double)nv->value) || isinf((double)nv->value)) { return; } // trap illegal float values
+ ///+++ transform these checks into NaN or INF strings with an error return?
+
+ // We may need one of two types of units conversion, but only if in inches mode
+ if (cm_get_units_mode(MODEL) == INCHES) {
+ cmAxisType type = cm_get_axis_type(nv->index); // linear, rotary or global
+ if (cfgArray[nv->index].flags & F_CONVERT) { // standard units conversion
+ if ((type == AXIS_TYPE_LINEAR) || (type == AXIS_TYPE_SYSTEM)) {
+ nv->value *= INCHES_PER_MM;
+ }
+ } else if (cfgArray[nv->index].flags & F_ICONVERT) {// inverse units conversion
+ if ((type == AXIS_TYPE_LINEAR) || (type == AXIS_TYPE_SYSTEM)) {
+ nv->value *= MM_PER_INCH;
+ }
}
}
-}
-*/
-{
- uint8_t f;
- if (isnan((double)nv->value) || isinf((double)nv->value)) return; // illegal float values
- f = GET_TABLE_BYTE(flags);
- if (f & (F_CONVERT | F_ICONVERT)) { // unit conversion required?
- if (cm_get_units_mode(MODEL) == INCHES) {
- if(f & F_ICONVERT) {
- nv->value *= MM_PER_INCH;
- } else {
- nv->value *= INCHES_PER_MM;
- }
- }
- }
+ nv->precision = GET_TABLE_WORD(precision);
+ nv->valuetype = TYPE_FLOAT;
}
/*
@@ -1317,7 +1317,7 @@ void preprocess_float(nvObj_t *nv)
*/
bool nv_group_is_prefixed(char *group)
{
- if (strcmp("sys", group) == 0) {
+ if (strcmp("sys", group) == 0) { // =0 means its a match
return (false);
}
if (strcmp("sr", group) == 0) {
@@ -1422,7 +1422,7 @@ static stat_t _do_all(nvObj_t *nv) // print all parameters
_do_axes(nv);
_do_inputs(nv);
_do_outputs(nv);
- _do_heaters(nv); // there are no text mode prints for heaters
+ _do_heaters(nv); // there are no text mode prints for heaters
_do_group(nv, (char *)"p1"); // PWM group
_do_offsets(nv); // coordinate system offsets
return (STAT_COMPLETE); // STAT_COMPLETE suppresses a second JSON write that would cause a fault
diff --git a/g2core/g2core.cppproj b/g2core/g2core.cppproj
index cd07d32a..591d31b0 100644
--- a/g2core/g2core.cppproj
+++ b/g2core/g2core.cppproj
@@ -73,7 +73,7 @@
SWD
com.atmel.avrdbg.tool.atmelice
- J41800030015
+ J41800036434
Atmel-ICE
True
@@ -100,7 +100,7 @@
True
true
- J41800030015
+ J41800036434
0x284E0A60
10000000
diff --git a/g2core/json_parser.cpp b/g2core/json_parser.cpp
index 00e89f2b..9ae5da39 100644
--- a/g2core/json_parser.cpp
+++ b/g2core/json_parser.cpp
@@ -617,7 +617,10 @@ void json_print_response(uint8_t status, const bool only_to_muted /*= false*/)
stat_t json_set_jv(nvObj_t *nv)
{
- if ((uint8_t)nv->value >= JV_MAX_VALUE) { return (STAT_INPUT_EXCEEDS_MAX_VALUE);}
+ if ((uint8_t)nv->value >= JV_MAX_VALUE) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_EXCEEDS_MAX_VALUE);
+ }
js.json_verbosity = (jsonVerbosity)nv->value;
js.echo_json_footer = false;
diff --git a/g2core/stepper.cpp b/g2core/stepper.cpp
index 0413af71..85514ed2 100644
--- a/g2core/stepper.cpp
+++ b/g2core/stepper.cpp
@@ -840,6 +840,7 @@ static void _set_motor_steps_per_unit(nvObj_t *nv)
}
/* PER-MOTOR FUNCTIONS
+ * st_set_ma() - map motor to axis
* st_set_sa() - set motor step angle
* st_set_tr() - set travel per motor revolution
* st_set_mi() - set motor microsteps
@@ -848,8 +849,30 @@ static void _set_motor_steps_per_unit(nvObj_t *nv)
* st_set_pl() - set motor power level
*/
+stat_t st_set_ma(nvObj_t *nv) // map motor to axis
+{
+ if (nv->value < 0) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_LESS_THAN_MIN_VALUE);
+ }
+ if (nv->value >= AXES) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_EXCEEDS_MAX_VALUE);
+ }
+ set_ui8(nv);
+ return(STAT_OK);
+}
+
stat_t st_set_sa(nvObj_t *nv) // motor step angle
{
+ if (nv->value <= 0) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_LESS_THAN_MIN_VALUE);
+ }
+ if (nv->value >= 360) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_EXCEEDS_MAX_VALUE);
+ }
set_flt(nv);
_set_motor_steps_per_unit(nv);
return(STAT_OK);
@@ -857,6 +880,10 @@ stat_t st_set_sa(nvObj_t *nv) // motor step angle
stat_t st_set_tr(nvObj_t *nv) // motor travel per revolution
{
+ if (nv->value <= 0) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_LESS_THAN_MIN_VALUE);
+ }
set_flu(nv);
_set_motor_steps_per_unit(nv);
return(STAT_OK);
@@ -864,8 +891,12 @@ stat_t st_set_tr(nvObj_t *nv) // motor travel per revolution
stat_t st_set_mi(nvObj_t *nv) // motor microsteps
{
- uint8_t mi = (uint8_t)nv->value;
+ if (nv->value <= 0) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_LESS_THAN_MIN_VALUE);
+ }
+ uint8_t mi = (uint8_t)nv->value;
if ((mi != 1) && (mi != 2) && (mi != 4) && (mi != 8) && (mi != 16) && (mi != 32)) {
nv_add_conditional_message((const char *)"*** WARNING *** Setting non-standard microstep value");
}
@@ -875,49 +906,70 @@ stat_t st_set_mi(nvObj_t *nv) // motor microsteps
return (STAT_OK);
}
-stat_t st_set_su(nvObj_t *nv) // motor steps per unit (direct)
+stat_t st_get_su(nvObj_t *nv) // motor steps per unit (direct)
{
uint8_t m = _get_motor(nv->index);
- // Do the unit conversion here (rather than using set_flu) because it's a reciprocal value
- if ((m <= 3) && (cm_get_units_mode(MODEL) == INCHES)) {
- nv->value *= INCHES_PER_MM;
- }
+ nv->value = st_cfg.mot[m].steps_per_unit;
+ nv->valuetype = TYPE_FLOAT;
+ nv->precision = cfgArray[nv->index].precision;
+ return(STAT_OK);
+}
+stat_t st_set_su(nvObj_t *nv) // motor steps per unit (direct)
+{
+ // Don't set a zero or negative value - just calculate based on sa, tr, and mi
+ // This way, if STEPS_PER_UNIT is set to 0 it is unused and we get the computed value
+ uint8_t m = _get_motor(nv->index);
if(nv->value <= 0) {
- // Don't set a zero or negative value - just calculate based on sa,tr,mi
- // This way, if we set the STEPS_PER_UNIT to default to 0, it is unused and we get the computed value
+ nv->value = st_cfg.mot[m].steps_per_unit;
_set_motor_steps_per_unit(nv);
return(STAT_OK);
}
-
+
+ // Do unit conversion here because it's a reciprocal value (rather than process_incoming_float())
+ if (cm_get_units_mode(MODEL) == INCHES) {
+ if (cm_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) {
+ nv->value *= INCHES_PER_MM;
+ }
+ }
set_flt(nv);
st_cfg.mot[m].units_per_step = 1.0/st_cfg.mot[m].steps_per_unit;
+
// Scale TR so all the other values make sense
// You could scale any one of the other values, but TR makes the most sense
st_cfg.mot[m].travel_rev = (360.0*st_cfg.mot[m].microsteps)/(st_cfg.mot[m].steps_per_unit*st_cfg.mot[m].step_angle);
-
return(STAT_OK);
}
stat_t st_set_pm(nvObj_t *nv) // set motor power mode
{
- if (nv->value >= MOTOR_POWER_MODE_MAX_VALUE) { return (STAT_INPUT_EXCEEDS_MAX_VALUE); }
-
+ if (nv->value >= MOTOR_POWER_MODE_MAX_VALUE) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_EXCEEDS_MAX_VALUE);
+ }
uint8_t motor = _get_motor(nv->index);
- if (motor > MOTORS) { return STAT_INPUT_VALUE_RANGE_ERROR; };
+ if (motor > MOTORS) {
+ nv->valuetype = TYPE_NULL;
+ return STAT_INPUT_VALUE_RANGE_ERROR;
+ };
- Motors[motor]->setPowerMode((stPowerMode)nv->value);
// We do this *here* in order for this to take effect immediately.
// setPowerMode() sets the value and also executes it.
+ Motors[motor]->setPowerMode((stPowerMode)nv->value);
return (STAT_OK);
}
stat_t st_get_pm(nvObj_t *nv) // get motor power mode
{
- if (nv->value >= MOTOR_POWER_MODE_MAX_VALUE) { return (STAT_INPUT_EXCEEDS_MAX_VALUE); }
-
+ if (nv->value >= MOTOR_POWER_MODE_MAX_VALUE) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_EXCEEDS_MAX_VALUE);
+ }
uint8_t motor = _get_motor(nv->index);
- if (motor > MOTORS) { return STAT_INPUT_VALUE_RANGE_ERROR; };
+ if (motor > MOTORS) {
+ nv->valuetype = TYPE_NULL;
+ return STAT_INPUT_VALUE_RANGE_ERROR;
+ };
nv->value = (float)Motors[motor]->getPowerMode();
nv->valuetype = TYPE_INT;
@@ -933,7 +985,12 @@ stat_t st_get_pm(nvObj_t *nv) // get motor power mode
*/
stat_t st_set_pl(nvObj_t *nv) // motor power level
{
- if ((nv->value < (float)0.0) || (nv->value > (float)1.0)) {
+ if (nv->value < (float)0.0) {
+ nv->valuetype = TYPE_NULL;
+ return (STAT_INPUT_LESS_THAN_MIN_VALUE);
+ }
+ if (nv->value > (float)1.0) {
+ nv->valuetype = TYPE_NULL;
return (STAT_INPUT_VALUE_RANGE_ERROR);
}
set_flt(nv); // set power_setting value in the motor config struct (st)
diff --git a/g2core/stepper.h b/g2core/stepper.h
index 5711c1c4..5734ef0e 100644
--- a/g2core/stepper.h
+++ b/g2core/stepper.h
@@ -579,9 +579,11 @@ void st_request_out_of_band_dwell(float microseconds);
//stat_t st_prep_line(float travel_steps[], float following_error[], float segment_time);
stat_t st_prep_line(float travel_steps[], float following_error[], float segment_time);
+stat_t st_set_ma(nvObj_t *nv);
stat_t st_set_sa(nvObj_t *nv);
stat_t st_set_tr(nvObj_t *nv);
stat_t st_set_mi(nvObj_t *nv);
+stat_t st_get_su(nvObj_t *nv);
stat_t st_set_su(nvObj_t *nv);
stat_t st_set_pm(nvObj_t *nv);
stat_t st_get_pm(nvObj_t *nv);