Auto cal dual etb (#1725)

* implement

* add bench mode

* add ts cal mode

* TS impl

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-08-23 20:41:35 -07:00 committed by GitHub
parent 7fab55ad3e
commit 12bc5eb28b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 5 deletions

View File

@ -28,6 +28,10 @@ enum class TsCalMode : uint8_t {
EtbKd = 5, EtbKd = 5,
Tps1SecondaryMax = 6, Tps1SecondaryMax = 6,
Tps1SecondaryMin = 7, Tps1SecondaryMin = 7,
Tps2Max = 8,
Tps2Min = 9,
Tps2SecondaryMax = 10,
Tps2SecondaryMin = 11,
}; };
/** /**

View File

@ -124,6 +124,34 @@ static SensorType indexToTpsSensorSecondary(size_t index) {
} }
} }
static TsCalMode indexToCalModePriMin(size_t index) {
switch (index) {
case 0: return TsCalMode::Tps1Min;
default: return TsCalMode::Tps2Min;
}
}
static TsCalMode indexToCalModePriMax(size_t index) {
switch (index) {
case 0: return TsCalMode::Tps1Max;
default: return TsCalMode::Tps2Max;
}
}
static TsCalMode indexToCalModeSecMin(size_t index) {
switch (index) {
case 0: return TsCalMode::Tps1SecondaryMin;
default: return TsCalMode::Tps2SecondaryMin;
}
}
static TsCalMode indexToCalModeSecMax(size_t index) {
switch (index) {
case 0: return TsCalMode::Tps1SecondaryMax;
default: return TsCalMode::Tps2SecondaryMax;
}
}
static percent_t directPwmValue = NAN; static percent_t directPwmValue = NAN;
static percent_t currentEtbDuty; static percent_t currentEtbDuty;
@ -496,17 +524,17 @@ struct EtbImpl final : public EtbController, public PeriodicController<512> {
motor->disable(); motor->disable();
// Write out the learned values to TS, waiting briefly after setting each to let TS grab it // Write out the learned values to TS, waiting briefly after setting each to let TS grab it
tsOutputChannels.calibrationMode = TsCalMode::Tps1Max; tsOutputChannels.calibrationMode = indexToCalModePriMax(myIndex);
tsOutputChannels.calibrationValue = primaryMax; tsOutputChannels.calibrationValue = primaryMax;
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
tsOutputChannels.calibrationMode = TsCalMode::Tps1Min; tsOutputChannels.calibrationMode = indexToCalModePriMin(myIndex);
tsOutputChannels.calibrationValue = primaryMin; tsOutputChannels.calibrationValue = primaryMin;
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
tsOutputChannels.calibrationMode = TsCalMode::Tps1SecondaryMax; tsOutputChannels.calibrationMode = indexToCalModeSecMax(myIndex);
tsOutputChannels.calibrationValue = secondaryMax; tsOutputChannels.calibrationValue = secondaryMax;
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
tsOutputChannels.calibrationMode = TsCalMode::Tps1SecondaryMin; tsOutputChannels.calibrationMode = indexToCalModeSecMin(myIndex);
tsOutputChannels.calibrationValue = secondaryMin; tsOutputChannels.calibrationValue = secondaryMin;
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);

View File

@ -270,6 +270,9 @@ static void handleCommandX14(uint16_t index) {
case 0xE: case 0xE:
etbAutocal(0); etbAutocal(0);
return; return;
case 0x11:
etbAutocal(1);
return;
case 0xC: case 0xC:
engine->etbAutoTune = true; engine->etbAutoTune = true;
return; return;

View File

@ -404,6 +404,14 @@ enable2ndByteCanID = false
maintainConstantValue = tps1SecondaryMax, { (calibrationMode == 6 ) ? calibrationValue : tps1SecondaryMax } maintainConstantValue = tps1SecondaryMax, { (calibrationMode == 6 ) ? calibrationValue : tps1SecondaryMax }
maintainConstantValue = tps1SecondaryMin, { (calibrationMode == 7 ) ? calibrationValue : tps1SecondaryMin } maintainConstantValue = tps1SecondaryMin, { (calibrationMode == 7 ) ? calibrationValue : tps1SecondaryMin }
; TPS 2 Primary
maintainConstantValue = tps2Max, { (calibrationMode == 8 ) ? calibrationValue : tps2Max }
maintainConstantValue = tps2Min, { (calibrationMode == 9 ) ? calibrationValue : tps2Min }
; TPS 2 Secondary
maintainConstantValue = tps2SecondaryMax, { (calibrationMode == 10 ) ? calibrationValue : tps2SecondaryMax }
maintainConstantValue = tps2SecondaryMin, { (calibrationMode == 11 ) ? calibrationValue : tps2SecondaryMin }
; ETB Auto Gain Calibration ; ETB Auto Gain Calibration
maintainConstantValue = etb_pFactor, { (calibrationMode == 3 ) ? calibrationValue : etb_pFactor } maintainConstantValue = etb_pFactor, { (calibrationMode == 3 ) ? calibrationValue : etb_pFactor }
maintainConstantValue = etb_iFactor, { (calibrationMode == 4 ) ? calibrationValue : etb_iFactor } maintainConstantValue = etb_iFactor, { (calibrationMode == 4 ) ? calibrationValue : etb_iFactor }
@ -1439,6 +1447,7 @@ cmd_test_starter_relay = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0B"
cmd_etb_autotune = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0C" cmd_etb_autotune = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0C"
cmd_enable_self_stim = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0D" cmd_enable_self_stim = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0D"
cmb_etb_auto_calibrate = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0E" cmb_etb_auto_calibrate = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0E"
cmb_etb_auto_calibrate_2 = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x11"
cmd_disable_self_stim = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0F" cmd_disable_self_stim = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0F"
cmd_etb_autotune_stop = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x10" cmd_etb_autotune_stop = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x10"
@ -1732,6 +1741,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
field = "Secondary sensor", tps1_2AdcChannel field = "Secondary sensor", tps1_2AdcChannel
field = "Secondary min", tps1SecondaryMin, {tps1_2AdcChannel != @@ADC_CHANNEL_NONE@@} field = "Secondary min", tps1SecondaryMin, {tps1_2AdcChannel != @@ADC_CHANNEL_NONE@@}
field = "Secondary max", tps1SecondaryMax, {tps1_2AdcChannel != @@ADC_CHANNEL_NONE@@} field = "Secondary max", tps1SecondaryMax, {tps1_2AdcChannel != @@ADC_CHANNEL_NONE@@}
commandButton = "Auto Calibrate TPS 1", cmb_etb_auto_calibrate, {tps1_2AdcChannel != @@ADC_CHANNEL_NONE@@ && throttlePedalPositionAdcChannel != @@ADC_CHANNEL_NONE@@}
dialog = tpsNum2, "Throttle #2" dialog = tpsNum2, "Throttle #2"
field = "Primary sensor", tps2_1AdcChannel field = "Primary sensor", tps2_1AdcChannel
@ -1740,6 +1750,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
field = "Secondary sensor", tps2_2AdcChannel field = "Secondary sensor", tps2_2AdcChannel
field = "Secondary min", tps2SecondaryMin, {tps2_2AdcChannel != @@ADC_CHANNEL_NONE@@} field = "Secondary min", tps2SecondaryMin, {tps2_2AdcChannel != @@ADC_CHANNEL_NONE@@}
field = "Secondary max", tps2SecondaryMax, {tps2_2AdcChannel != @@ADC_CHANNEL_NONE@@} field = "Secondary max", tps2SecondaryMax, {tps2_2AdcChannel != @@ADC_CHANNEL_NONE@@}
commandButton = "Auto Calibrate TPS 2", cmb_etb_auto_calibrate_2, {tps2_2AdcChannel != @@ADC_CHANNEL_NONE@@ && throttlePedalPositionAdcChannel != @@ADC_CHANNEL_NONE@@}
dialog = tpsLimits, "TPS Limits" dialog = tpsLimits, "TPS Limits"
field = "TPS minimum valid value", tpsErrorDetectionTooLow, {tps1_1AdcChannel != @@ADC_CHANNEL_NONE@@} field = "TPS minimum valid value", tpsErrorDetectionTooLow, {tps1_1AdcChannel != @@ADC_CHANNEL_NONE@@}
@ -2868,7 +2879,8 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
dialog = etbAutotune, "PID Autotune" dialog = etbAutotune, "PID Autotune"
field = "First step: calibrate TPS and hit 'Burn'" field = "First step: calibrate TPS and hit 'Burn'"
commandButton = "Auto Calibrate TPS", cmb_etb_auto_calibrate commandButton = "Auto Calibrate TPS 1", cmb_etb_auto_calibrate
commandButton = "Auto Calibrate TPS 2", cmb_etb_auto_calibrate_2
field = "Second step" field = "Second step"
commandButton = "Start ETB PID Autotune", cmd_etb_autotune commandButton = "Start ETB PID Autotune", cmd_etb_autotune
commandButton = "Stop ETB PID Autotune", cmd_etb_autotune_stop commandButton = "Stop ETB PID Autotune", cmd_etb_autotune_stop