From eac9d03a250aa6933200eda76081ed75e51e6da2 Mon Sep 17 00:00:00 2001 From: "Stephen M. Moraco" Date: Tue, 16 Aug 2022 18:45:34 -0600 Subject: [PATCH] Move to single mech for motor geom request --- src/isp_bldc_motor.spin2 | 23 ++++++++++++++--------- src/isp_steering_2wheel.spin2 | 18 ++---------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/isp_bldc_motor.spin2 b/src/isp_bldc_motor.spin2 index cbb53dd..15a766e 100644 --- a/src/isp_bldc_motor.spin2 +++ b/src/isp_bldc_motor.spin2 @@ -106,15 +106,7 @@ PUB start(eMotorBasePin, eMotorVoltage) : ok | legalBase, fwdDegrees, revDegrees targetAngle := $FFFFFFFF ' set to not used! (other values only used during testing) - case user.MOTOR_TYPE - MOTR_DOCO_4KRPM: - ' 15 degrees per tic - degrPerTic := 15 - hallTicsPerRotation := 24 - other: - ' 4 degrees per tic - degrPerTic := 4 - hallTicsPerRotation := 90 + degrPerTic, hallTicsPerRotation := hallTicInfoForMotor() fwdDegrees, revDegrees := offsetsForMotor(user.MOTOR_TYPE) offset_fwd := fwdDegrees frac 360 @@ -618,6 +610,19 @@ PUB validMotorForChoice(userMotor) : legalMotor legalMotor := INVALID_MOTOR debug("*VAL* ", sdec_long(legalMotor)) +PUB hallTicInfoForMotor() : degreesPerTic, ticsPerRotation +'' Return numbers for user selected motor (for use by two-wheel-steering object!) + if user.MOTOR_TYPE == user.MOTR_DOCO_4KRPM + ' degrees = ticks * 15 + degreesPerTic := 15 + ' rotations = ticks / 24 + ticsPerRotation := 24 + else + ' degrees = ticks * 4 + degreesPerTic := 4 + ' rotations = ticks / 90 + ticsPerRotation := 90 + CON { --- TEST-USE ONLY Methods --- } PUB testSetLimit(newMaxLimit) diff --git a/src/isp_steering_2wheel.spin2 b/src/isp_steering_2wheel.spin2 index 4df4ed8..64f05f2 100644 --- a/src/isp_steering_2wheel.spin2 +++ b/src/isp_steering_2wheel.spin2 @@ -205,7 +205,7 @@ PUB stopAfterRotation(nRotationCount, eRotationUnits) | degreesPerTic, ticsPerRo ' FIXME: UNDONE should be more than ticks needed for spin-up/down ramps!!! abort - degreesPerTic, ticsPerRotation := hallTicInfoForMotor() + degreesPerTic, ticsPerRotation := ltWheel.hallTicInfoForMotor() ' convert rotation info to ticks (will stop at ticks limit) motorStopHallTicks := 0 @@ -352,7 +352,7 @@ PRI convertRotationCount(nValue, eRotationUnits) : rotationCount | degreesPerTic ' Returns accumulated {rotationCount} in {rotationUnits} [DRU_DEGREES, DRU_ROTATIONS, or DRU_HALL_TICKS], since last reset, for this motor. rotationCount := -1 - degreesPerTic, ticsPerRotation := hallTicInfoForMotor() + degreesPerTic, ticsPerRotation := ltWheel.hallTicInfoForMotor() case eRotationUnits DRU_HALL_TICKS: @@ -426,20 +426,6 @@ PRI calcPowerForDirection(power, direction) : ltPower, rtPower | bIsLeft, absPow debug("* calcPowerForDirection(", sdec_long(power), ", ", sdec_long(direction), ") -> ", sdec_long(ltPower), sdec_long(rtPower)) -PRI hallTicInfoForMotor() : degreesPerTic, ticsPerRotation -' return numbers for user selected motor - if user.MOTOR_TYPE == user.MOTR_DOCO_4KRPM - ' degrees = ticks * 15 - degreesPerTic := 15 - ' rotations = ticks / 24 - ticsPerRotation := 24 - else - ' degrees = ticks * 4 - degreesPerTic := 4 - ' rotations = ticks / 90 - ticsPerRotation := 90 - - PUB isReady() : bState '' Return T/F where T means the both motor cogs are running bState := ltWheel.isReady() and rtWheel.isReady()