diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp
index 7d292cb5..5632b1ba 100644
--- a/g2core/canonical_machine.cpp
+++ b/g2core/canonical_machine.cpp
@@ -2084,6 +2084,7 @@ static const char *const msg_frmo[] = { msg_g93, msg_g94, msg_g95 };
* _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 axis type (0 if axis is linear, 1 if rotary, -1 if NA)
+ * cm_get_axis_type_by_axis() - return axis type (0 if axis is linear, 1 if rotary, -1 if NA)
*/
static int8_t _axis(const index_t index)
@@ -2121,9 +2122,13 @@ char cm_get_axis_char(const int8_t axis)
cmAxisType cm_get_axis_type(const index_t index)
{
- int8_t axis = _axis(index);
- if (axis >= AXIS_A) return (AXIS_TYPE_ROTARY);
- if (axis == -1) return (AXIS_TYPE_UNDEFINED);
+ return (cm_get_axis_type_by_axis(_axis(index)));
+}
+
+cmAxisType cm_get_axis_type_by_axis(const int8_t axis)
+{
+ if (axis >= AXIS_A) { return (AXIS_TYPE_ROTARY); }
+ if (axis == -1) { return (AXIS_TYPE_UNDEFINED); }
return (AXIS_TYPE_LINEAR);
}
diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h
index 26f8c06c..26224296 100644
--- a/g2core/canonical_machine.h
+++ b/g2core/canonical_machine.h
@@ -424,6 +424,7 @@ float cm_get_jogging_dest(void); // get jogging d
char cm_get_axis_char(const int8_t axis);
cmAxisType cm_get_axis_type(const index_t index);
+cmAxisType cm_get_axis_type_by_axis(const int8_t axis);
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 e146fc94..61b380a0 100644
--- a/g2core/config_app.cpp
+++ b/g2core/config_app.cpp
@@ -200,7 +200,7 @@ const cfgItem_t cfgArray[] = {
{ "1","1sa",_fip, 3, st_print_sa, st_get_sa, st_set_sa, (float *)&cs.null, M1_STEP_ANGLE },
{ "1","1tr",_fipc,4, st_print_tr, st_get_tr, st_set_tr, (float *)&cs.null, M1_TRAVEL_PER_REV },
{ "1","1mi",_fip, 0, st_print_mi, st_get_mi, st_set_mi, (float *)&cs.null, 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 },
@@ -211,7 +211,7 @@ const cfgItem_t cfgArray[] = {
{ "2","2sa",_fip, 3, st_print_sa, st_get_sa, st_set_sa, (float *)&cs.null, M2_STEP_ANGLE },
{ "2","2tr",_fipc,4, st_print_tr, st_get_tr, st_set_tr, (float *)&cs.null, M2_TRAVEL_PER_REV },
{ "2","2mi",_fip, 0, st_print_mi, st_get_mi, st_set_mi, (float *)&cs.null, 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 *)&cs.null, 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},
@@ -223,7 +223,7 @@ const cfgItem_t cfgArray[] = {
{ "3","3sa",_fip, 3, st_print_sa, st_get_sa, st_set_sa, (float *)&cs.null, M3_STEP_ANGLE },
{ "3","3tr",_fipc,4, st_print_tr, st_get_tr, st_set_tr, (float *)&cs.null, M3_TRAVEL_PER_REV },
{ "3","3mi",_fip, 0, st_print_mi, st_get_mi, st_set_mi, (float *)&cs.null, 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 *)&cs.null, 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 },
@@ -235,7 +235,7 @@ const cfgItem_t cfgArray[] = {
{ "4","4sa",_fip, 3, st_print_sa, st_get_sa, st_set_sa, (float *)&cs.null, M4_STEP_ANGLE },
{ "4","4tr",_fipc,4, st_print_tr, st_get_tr, st_set_tr, (float *)&cs.null, M4_TRAVEL_PER_REV },
{ "4","4mi",_fip, 0, st_print_mi, st_get_mi, st_set_mi, (float *)&cs.null, 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 *)&cs.null, 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 },
@@ -247,7 +247,7 @@ const cfgItem_t cfgArray[] = {
{ "5","5sa",_fip, 3, st_print_sa, st_get_sa, st_set_sa, (float *)&cs.null, M5_STEP_ANGLE },
{ "5","5tr",_fipc,4, st_print_tr, st_get_tr, st_set_tr, (float *)&cs.null, M5_TRAVEL_PER_REV },
{ "5","5mi",_fip, 0, st_print_mi, st_get_mi, st_set_mi, (float *)&cs.null, 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 *)&cs.null, 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 },
@@ -259,7 +259,7 @@ const cfgItem_t cfgArray[] = {
{ "6","6sa",_fip, 3, st_print_sa, st_get_sa, st_set_sa, (float *)&cs.null, M6_STEP_ANGLE },
{ "6","6tr",_fipc,4, st_print_tr, st_get_tr, st_set_tr, (float *)&cs.null, M6_TRAVEL_PER_REV },
{ "6","6mi",_fip, 0, st_print_mi, st_get_mi, st_set_mi, (float *)&cs.null, 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 *)&cs.null, 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 },
@@ -997,28 +997,22 @@ stat_t set_flu(nvObj_t *nv)
/*
* process_incoming_float() - pre-process an incoming floating point number for canonical units
* process_outgoing_float() - pre-process an outgoing floating point number for units display
- * get_float() - boilerplate for retrieving raw floating point value
- * set_float() - boilerplate for setting a floating point value with unit conversion
- * set_float_range() - set a floating point value with inclusive range check
*
- * get_float() returns a raw float value in internal canonical units (e.g. mm, degrees)
- * without units conversion. If conversion is required call preprocess_outgoing_float()
- * afterwards. The text mode and JSON display routines do this, so you generally don't
- * have to worry about this.
- *
- * set_float() is designed to capture incoming float values, so it performs unit conversion.
- * set_float_range() perfoems an inclusive range test on the CONVERTED value
+ * Incoming floats are destined for SET operations.perform conditional unit conversion if
+ * the flags indicate. Note that SU (inverse conversion) is not converted here, but in the
+ * set_su function.
+ *
+ * Outgoing floats are the raw values from GET operations, destined for text or JSON display.
+ * These are conditionally unit converted, including SU.
*/
void process_incoming_float(nvObj_t *nv)
{
if (nv->valuetype != TYPE_FLOAT) { return; } // can be called non-destructively for any value type
- uint8_t f;
- f = GET_TABLE_BYTE(flags);
-// if (f & (F_CONVERT | F_ICONVERT)) { // unit conversion required?
- if (f & F_CONVERT) { // unit conversion required?
- if (cm_get_units_mode(MODEL) == INCHES) { // If inn inches mode
+ uint8_t flags = GET_TABLE_BYTE(flags);
+ if (flags & F_CONVERT) { // is unit conversion required?
+ if (cm_get_units_mode(MODEL) == INCHES) { // if in inches mode
if (cm_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) { // ...and a linear axis...
nv->value *= MM_PER_INCH; // convert to canonical millimeter units
}
@@ -1032,21 +1026,37 @@ void process_outgoing_float(nvObj_t *nv)
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?
- uint8_t f;
- 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 {
+ // We may need one of two types of units conversion, but only if in inches mode
+ if (cm_get_units_mode(MODEL) == INCHES) {
+ uint8_t flags = GET_TABLE_BYTE(flags);
+ if (flags & F_CONVERT) { // standard units conversion
+ if (cm_get_axis_type(nv->index) == AXIS_TYPE_LINEAR) {
nv->value *= INCHES_PER_MM;
- }
- }
+ }
+ } else if (flags & F_ICONVERT) { // inverse units conversion
+ if (st_get_axis_type_by_motor(nv->index) == AXIS_TYPE_LINEAR) { // axis motor is mapped to
+ nv->value *= MM_PER_INCH;
+ }
+ }
}
nv->precision = GET_TABLE_WORD(precision);
nv->valuetype = TYPE_FLOAT;
}
+/*
+ * get_float() - boilerplate for retrieving raw floating point value
+ * set_float() - boilerplate for setting a floating point value with unit conversion
+ * set_float_range() - set a floating point value with inclusive range check
+ *
+ * get_float() returns a raw float value in internal canonical units (e.g. mm, degrees)
+ * without units conversion. If conversion is required call preprocess_outgoing_float()
+ * afterwards. The text mode and JSON display routines do this, so you generally don't
+ * have to worry about this.
+ *
+ * set_float() is designed to capture incoming float values, so it performs unit conversion.
+ * set_float_range() perfoems an inclusive range test on the CONVERTED value
+ */
+
stat_t get_float(nvObj_t *nv, const float value) {
nv->value = value;
nv->valuetype = TYPE_FLOAT;
diff --git a/g2core/g2core.cppproj b/g2core/g2core.cppproj
index bf644c0b..d57acc1f 100644
--- a/g2core/g2core.cppproj
+++ b/g2core/g2core.cppproj
@@ -68,12 +68,12 @@
- 7992324
+ 10000000
SWD
com.atmel.avrdbg.tool.atmelice
- J41800030015
+ J41800036434
Atmel-ICE
True
@@ -100,9 +100,9 @@
True
true
- J41800030015
+ J41800036434
0x284E0A60
- 7992324
+ 10000000
diff --git a/g2core/stepper.cpp b/g2core/stepper.cpp
index fd994209..bf7e2ef7 100644
--- a/g2core/stepper.cpp
+++ b/g2core/stepper.cpp
@@ -812,7 +812,7 @@ static void _set_hw_microsteps(const uint8_t motor, const uint8_t microsteps)
***********************************************************************************/
/* HELPERS
- * _get_motor() - helper to return motor number as an index or -1 if na
+ * _motor() - motor number as an index or -1 if na
*/
static int8_t _motor(const index_t index)
@@ -828,16 +828,24 @@ static int8_t _motor(const index_t index)
return (ptr - motors);
}
+cmAxisType st_get_axis_type_by_motor(const index_t index)
+{
+ return (cm_get_axis_type_by_axis(st_cfg.mot[_motor(index)].motor_map));
+}
+
/*
* _set_motor_steps_per_unit() - what it says
* This function will need to be rethought if microstep morphing is implemented
*/
-static void _set_motor_steps_per_unit(nvObj_t *nv)
+static float _set_motor_steps_per_unit(nvObj_t *nv)
{
uint8_t m = _motor(nv->index);
- st_cfg.mot[m].units_per_step = (st_cfg.mot[m].travel_rev * st_cfg.mot[m].step_angle) / (360 * st_cfg.mot[m].microsteps);
+ st_cfg.mot[m].units_per_step = (st_cfg.mot[m].travel_rev * st_cfg.mot[m].step_angle) /
+ (360 * st_cfg.mot[m].microsteps);
+
st_cfg.mot[m].steps_per_unit = 1/st_cfg.mot[m].units_per_step;
+ return (st_cfg.mot[m].steps_per_unit);
}
/* PER-MOTOR FUNCTIONS
@@ -895,27 +903,35 @@ stat_t st_set_mi(nvObj_t *nv)
}
// motor steps per unit (direct)
+stat_t st_get_su(nvObj_t *nv)
+{
+ return(get_float(nv, st_cfg.mot[_motor(nv->index)].steps_per_unit));
+}
+
stat_t st_set_su(nvObj_t *nv)
{
- uint8_t m = _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;
- }
-
+ // 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
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
- _set_motor_steps_per_unit(nv);
+ nv->value = _set_motor_steps_per_unit(nv);
return(STAT_OK);
}
-
- set_flt(nv);
+
+ // Do unit conversion here because it's a reciprocal value (rather than process_incoming_float())
+ uint8_t m = _motor(nv->index);
+ if (cm_get_units_mode(MODEL) == INCHES) {
+ uint8_t a = st_cfg.mot[m].motor_map;
+ if (cm_get_axis_type_by_axis(a) == AXIS_TYPE_LINEAR) {
+ nv->value *= INCHES_PER_MM;
+ }
+ }
+ st_cfg.mot[m].steps_per_unit = nv->value;
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);
-
+ 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);
}
diff --git a/g2core/stepper.h b/g2core/stepper.h
index 36c650a7..50f8ce7f 100644
--- a/g2core/stepper.h
+++ b/g2core/stepper.h
@@ -576,9 +576,10 @@ void st_prep_null(void);
void st_prep_command(void *bf); // use a void pointer since we don't know about mpBuf_t yet)
void st_prep_dwell(float microseconds);
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);
+cmAxisType st_get_axis_type_by_motor(const index_t index);
+
stat_t st_get_ma(nvObj_t *nv);
stat_t st_set_ma(nvObj_t *nv);
stat_t st_get_sa(nvObj_t *nv);
@@ -588,10 +589,13 @@ stat_t st_set_tr(nvObj_t *nv);
stat_t st_get_mi(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);
+stat_t st_set_pm(nvObj_t *nv);
+stat_t st_get_pl(nvObj_t *nv);
stat_t st_set_pl(nvObj_t *nv);
+
stat_t st_get_pwr(nvObj_t *nv);
stat_t st_get_mt(nvObj_t *nv);