Refactored motor su setting to use new getter/setter code

This commit is contained in:
Alden Hart
2016-12-13 19:31:30 -05:00
parent 9f6036d2c4
commit e70f003d77
6 changed files with 91 additions and 55 deletions
+8 -3
View File
@@ -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);
}
+1
View File
@@ -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
+40 -30
View File
@@ -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;
+4 -4
View File
@@ -68,12 +68,12 @@
<com_atmel_avrdbg_tool_atmelice>
<ToolOptions>
<InterfaceProperties>
<SwdClock>7992324</SwdClock>
<SwdClock>10000000</SwdClock>
</InterfaceProperties>
<InterfaceName>SWD</InterfaceName>
</ToolOptions>
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
<ToolNumber>J41800030015</ToolNumber>
<ToolNumber>J41800036434</ToolNumber>
<ToolName>Atmel-ICE</ToolName>
</com_atmel_avrdbg_tool_atmelice>
<UseGdb>True</UseGdb>
@@ -100,9 +100,9 @@
<HWProgramCounterSampling>True</HWProgramCounterSampling>
</PercepioTrace>
<preserveEEPROM>true</preserveEEPROM>
<avrtoolserialnumber>J41800030015</avrtoolserialnumber>
<avrtoolserialnumber>J41800036434</avrtoolserialnumber>
<avrdeviceexpectedsignature>0x284E0A60</avrdeviceexpectedsignature>
<avrtoolinterfaceclock>7992324</avrtoolinterfaceclock>
<avrtoolinterfaceclock>10000000</avrtoolinterfaceclock>
<custom>
<ToolOptions xmlns="">
<InterfaceProperties>
+32 -16
View File
@@ -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);
}
+6 -2
View File
@@ -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);