TPS Auto Calibration with ETB (#1382)
* switch to thread * actually use default frequency define * crank ADC too * make space in RAM * remove TS field * this should work for test * auto cal * wire up bench testing * s * fix * rearrange a bit * inject * remove unused bit * mock repair * guard for ECUs without ETB
This commit is contained in:
parent
942ebef700
commit
ba6ec4ac51
|
@ -326,12 +326,12 @@ void EtbController::update(efitick_t nowNt) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (engineConfiguration->debugMode == DBG_ETB_LOGIC) {
|
||||
#if EFI_TUNER_STUDIO
|
||||
if (engineConfiguration->debugMode == DBG_ETB_LOGIC) {
|
||||
tsOutputChannels.debugFloatField1 = engine->engineState.targetFromTable;
|
||||
tsOutputChannels.debugFloatField2 = engine->engineState.idle.etbIdleAddition;
|
||||
#endif /* EFI_TUNER_STUDIO */
|
||||
}
|
||||
#endif
|
||||
|
||||
m_pid.iTermMin = engineConfiguration->etb_iTermMin;
|
||||
m_pid.iTermMax = engineConfiguration->etb_iTermMax;
|
||||
|
@ -383,6 +383,10 @@ void EtbController::update(efitick_t nowNt) {
|
|||
/* DISPLAY_ENDIF */
|
||||
}
|
||||
|
||||
void EtbController::autoCalibrateTps() {
|
||||
m_isAutocal = true;
|
||||
}
|
||||
|
||||
#if !EFI_UNIT_TEST
|
||||
/**
|
||||
* Things running on a timer (instead of a thread) don't participate it the RTOS's thread priority system,
|
||||
|
@ -394,6 +398,52 @@ struct EtbImpl final : public EtbController, public PeriodicController<512> {
|
|||
EtbImpl() : PeriodicController("ETB", NORMALPRIO + 3, ETB_LOOP_FREQUENCY) {}
|
||||
|
||||
void PeriodicTask(efitick_t nowNt) override {
|
||||
|
||||
#if EFI_TUNER_STUDIO
|
||||
if (m_isAutocal) {
|
||||
// Don't allow if engine is running!
|
||||
if (GET_RPM() > 0) {
|
||||
m_isAutocal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
auto motor = getMotor();
|
||||
if (!motor) {
|
||||
m_isAutocal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t myIndex = getMyIndex();
|
||||
|
||||
// First grab open
|
||||
motor->set(0.5f);
|
||||
motor->enable();
|
||||
chThdSleepMilliseconds(1000);
|
||||
tsOutputChannels.calibrationMode = TsCalMode::Tps1Max;
|
||||
tsOutputChannels.calibrationValue = Sensor::getRaw(indexToTpsSensor(myIndex)) * TPS_TS_CONVERSION;
|
||||
|
||||
// Let it return
|
||||
motor->set(0);
|
||||
chThdSleepMilliseconds(200);
|
||||
|
||||
// Now grab closed
|
||||
motor->set(-0.5f);
|
||||
chThdSleepMilliseconds(1000);
|
||||
tsOutputChannels.calibrationMode = TsCalMode::Tps1Min;
|
||||
tsOutputChannels.calibrationValue = Sensor::getRaw(indexToTpsSensor(myIndex)) * TPS_TS_CONVERSION;
|
||||
|
||||
// Finally disable and reset state
|
||||
motor->disable();
|
||||
|
||||
// Wait to let TS grab the state before we leave cal mode
|
||||
chThdSleepMilliseconds(500);
|
||||
tsOutputChannels.calibrationMode = TsCalMode::None;
|
||||
|
||||
m_isAutocal = false;
|
||||
return;
|
||||
}
|
||||
#endif /* EFI_TUNER_STUDIO */
|
||||
|
||||
EtbController::update(nowNt);
|
||||
}
|
||||
|
||||
|
@ -515,7 +565,19 @@ void setEtbOffset(int value) {
|
|||
showEthInfo();
|
||||
}
|
||||
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
void etbAutocal(size_t throttleIndex) {
|
||||
if (throttleIndex >= ETB_COUNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto etb = engine->etbControllers[throttleIndex];
|
||||
|
||||
if (etb) {
|
||||
etb->autoCalibrateTps();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !EFI_UNIT_TEST */
|
||||
|
||||
/**
|
||||
* This specific throttle has default position of about 7% open
|
||||
|
@ -643,25 +705,6 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
if (engineConfiguration->etbCalibrationOnStart) {
|
||||
|
||||
for (int i = 0 ; i < engine->etbActualCount; i++) {
|
||||
setDcMotorDuty(i, 70);
|
||||
chThdSleep(600);
|
||||
// todo: grab with proper index
|
||||
grabTPSIsWideOpen();
|
||||
setDcMotorDuty(i, -70);
|
||||
chThdSleep(600);
|
||||
// todo: grab with proper index
|
||||
grabTPSIsClosed();
|
||||
}
|
||||
}
|
||||
|
||||
// manual duty cycle control without PID. Percent value from 0 to 100
|
||||
addConsoleActionNANF(CMD_ETB_DUTY, setThrottleDutyCycle);
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
etbPidReset(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
for (int i = 0 ; i < engine->etbActualCount; i++) {
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
virtual void reset() = 0;
|
||||
virtual void setIdlePosition(percent_t pos) = 0;
|
||||
virtual void start() = 0;
|
||||
virtual void autoCalibrateTps() = 0;
|
||||
};
|
||||
|
||||
class EtbController : public IEtbController {
|
||||
|
@ -61,6 +62,16 @@ public:
|
|||
// Used to inspect the internal PID controller's state
|
||||
const pid_state_s* getPidState() const { return &m_pid; };
|
||||
|
||||
// Use the throttle to automatically calibrate the relevant throttle position sensor(s).
|
||||
void autoCalibrateTps() override;
|
||||
|
||||
protected:
|
||||
// This is set if an automatic TPS calibration should be run
|
||||
bool m_isAutocal = false;
|
||||
|
||||
int getMyIndex() const { return m_myIndex; }
|
||||
DcMotor* getMotor() { return m_motor; }
|
||||
|
||||
private:
|
||||
int m_myIndex = 0;
|
||||
DcMotor *m_motor = nullptr;
|
||||
|
@ -95,3 +106,5 @@ void setEtbOffset(int value);
|
|||
void setThrottleDutyCycle(percent_t level);
|
||||
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration);
|
||||
void unregisterEtbPins();
|
||||
|
||||
void etbAutocal(size_t throttleIndex);
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "idle_thread.h"
|
||||
#include "periodic_thread_controller.h"
|
||||
#include "tps.h"
|
||||
#include "electronic_throttle.h"
|
||||
#include "cj125.h"
|
||||
#include "malfunction_central.h"
|
||||
|
||||
|
@ -264,6 +265,11 @@ static void handleCommandX14(uint16_t index) {
|
|||
case 0xD:
|
||||
engine->directSelfStimulation = true;
|
||||
return;
|
||||
#if EFI_ELECTRONIC_THROTTLE_BODY
|
||||
case 0xE:
|
||||
etbAutocal(0);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -944,7 +944,7 @@ bit useFixedBaroCorrFromMap
|
|||
bit useSeparateAdvanceForCranking;+This activates a separate advance table for cranking conditions, this allows cranking advance to be RPM dependant.
|
||||
bit useAdvanceCorrectionsForCranking;+This enables the various ignition corrections during cranking (IAT, CLT, FSIO and PID idle).
|
||||
bit useTPSAdvanceTable;+This flag allows to use TPS for ignition lookup while in Speed Density Fuel Mode
|
||||
bit etbCalibrationOnStart
|
||||
bit unused1476b20;
|
||||
bit useIacPidMultTable;+This flag allows to use a special 'PID Multiplier' table (0.0-1.0) to compensate for nonlinear nature of IAC-RPM controller
|
||||
bit isBoostControlEnabled;
|
||||
bit launchSmoothRetard;+Interpolates the Ignition Retard from 0 to 100% within the RPM Range
|
||||
|
|
|
@ -412,6 +412,8 @@ fileVersion = { @@TS_FILE_VERSION@@ }
|
|||
; defaultValue = constantName, value;
|
||||
defaultValue = wueAfrTargetOffset, -1.5 -1.4 -1.15 -0.95 -0.775 -0.65 -0.5625 -0.5 -0.4375 -0.375 -0.3125 -0.25 -0.1875 -0.125 -0.0625 0
|
||||
|
||||
maintainConstantValue = tpsMax, { (calibrationMode == 1 ) ? calibrationValue : tpsMax }
|
||||
maintainConstantValue = tpsMin, { (calibrationMode == 2 ) ? calibrationValue : tpsMin }
|
||||
|
||||
requiresPowerCycle = warningLedPin
|
||||
requiresPowerCycle = runningLedPin
|
||||
|
@ -1500,6 +1502,7 @@ cmd_write_config = "w\x00\x14\x00\x0A"
|
|||
cmd_test_starter_relay = "w\x00\x14\x00\x0B"
|
||||
cmd_etb_autotune = "w\x00\x14\x00\x0C"
|
||||
cmd_enable_self_stim = "w\x00\x14\x00\x0D"
|
||||
cmb_etb_auto_calibrate = "w\x00\x14\x00\x0E"
|
||||
|
||||
cmd_test_radiator_fan = "w\x00\x15\x00\x01"
|
||||
cmd_test_check_engine_light = "w\x00\x16\x00\x01"
|
||||
|
@ -2794,7 +2797,6 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00"
|
|||
field = "https://rusefi.com/s/etb"
|
||||
field = "Detailed status in console", isVerboseETB
|
||||
field = "Disable ETB Motor", pauseEtbControl
|
||||
field = etbCalibrationOnStart, etbCalibrationOnStart
|
||||
; we need the term about stepper idle in here, because there's a bug in TS that you can't have different visibility
|
||||
; criteria for the same panel when used in multiple places
|
||||
panel = hbridgeHardware, { throttlePedalPositionAdcChannel != 16 || useStepperIdle && useHbridges }
|
||||
|
@ -2803,6 +2805,7 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00"
|
|||
field = "!Set debug mode below to 'ETB Autotune' to show results"
|
||||
field = "Debug mode", debugMode
|
||||
commandButton = "ETB PID Autotune", cmd_etb_autotune
|
||||
commandButton = "Auto Calibrate TPS", cmb_etb_auto_calibrate
|
||||
|
||||
dialog = etbDialogRight
|
||||
panel = etbIdleDialog
|
||||
|
|
|
@ -12,6 +12,7 @@ public:
|
|||
MOCK_METHOD(void, start, (), (override));
|
||||
MOCK_METHOD(void, init, (DcMotor* motor, int ownIndex, pid_s* pidParameters, const ValueProvider3D* pedalMap), (override));
|
||||
MOCK_METHOD(void, setIdlePosition, (percent_t pos), (override));
|
||||
MOCK_METHOD(void, autoCalibrateTps, (), (override));
|
||||
|
||||
// ClosedLoopController mocks
|
||||
MOCK_METHOD(expected<percent_t>, getSetpoint, (), (const, override));
|
||||
|
|
Loading…
Reference in New Issue