progress towards ETB controller mocking
This commit is contained in:
parent
e9e7a66cf8
commit
236d952335
|
@ -257,8 +257,6 @@ static void onlineApplyWorkingCopyBytes(int currentPageId, uint32_t offset, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern EtbController etbController[ETB_COUNT];
|
|
||||||
|
|
||||||
static const void * getStructAddr(int structId) {
|
static const void * getStructAddr(int structId) {
|
||||||
switch (structId) {
|
switch (structId) {
|
||||||
case LDS_CLT_STATE_INDEX:
|
case LDS_CLT_STATE_INDEX:
|
||||||
|
@ -275,7 +273,7 @@ static const void * getStructAddr(int structId) {
|
||||||
return static_cast<trigger_state_s*>(&engine->triggerCentral.triggerState);
|
return static_cast<trigger_state_s*>(&engine->triggerCentral.triggerState);
|
||||||
#if EFI_ELECTRONIC_THROTTLE_BODY
|
#if EFI_ELECTRONIC_THROTTLE_BODY
|
||||||
case LDS_ETB_PID_STATE_INDEX:
|
case LDS_ETB_PID_STATE_INDEX:
|
||||||
return etbController[0].getPidState();
|
return static_cast<EtbController*>(engine->etbControllers[0])->getPidState();
|
||||||
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
||||||
|
|
||||||
#ifndef EFI_IDLE_CONTROL
|
#ifndef EFI_IDLE_CONTROL
|
||||||
|
|
|
@ -355,7 +355,8 @@ DISPLAY(DISPLAY_IF(hasEtbPedalPositionSensor))
|
||||||
}
|
}
|
||||||
|
|
||||||
static EtbHardware etbHardware[ETB_COUNT];
|
static EtbHardware etbHardware[ETB_COUNT];
|
||||||
EtbController etbController[ETB_COUNT];
|
// real implementation (we mock for some unit tests)
|
||||||
|
EtbController etbControllers[ETB_COUNT];
|
||||||
|
|
||||||
static void showEthInfo(void) {
|
static void showEthInfo(void) {
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
|
@ -389,7 +390,7 @@ static void showEthInfo(void) {
|
||||||
|
|
||||||
scheduleMsg(&logger, "ETB %%d", i);
|
scheduleMsg(&logger, "ETB %%d", i);
|
||||||
scheduleMsg(&logger, "Motor: dir=%d DC=%f", etb->dcMotor.isOpenDirection(), etb->dcMotor.get());
|
scheduleMsg(&logger, "Motor: dir=%d DC=%f", etb->dcMotor.isOpenDirection(), etb->dcMotor.get());
|
||||||
etbController[i].showStatus(&logger);
|
etbControllers[i].showStatus(&logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
@ -397,7 +398,7 @@ static void showEthInfo(void) {
|
||||||
|
|
||||||
static void etbPidReset(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
static void etbPidReset(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
for (int i = 0 ; i < engine->etbActualCount; i++) {
|
for (int i = 0 ; i < engine->etbActualCount; i++) {
|
||||||
etbController[i].reset();
|
engine->etbControllers[i]->reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,7 +577,7 @@ void stopETBPins(void) {
|
||||||
|
|
||||||
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration) {
|
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration) {
|
||||||
for (int i = 0; i < ETB_COUNT; i++) {
|
for (int i = 0; i < ETB_COUNT; i++) {
|
||||||
etbController[i].onConfigurationChange(&previousConfiguration->etb);
|
etbControllers[i].onConfigurationChange(&previousConfiguration->etb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,10 +656,18 @@ void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregisterEtbPins() {
|
void unregisterEtbPins() {
|
||||||
|
// todo: we probably need an implementation here?!
|
||||||
}
|
}
|
||||||
|
|
||||||
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
for (int i = 0; i < ETB_COUNT; i++) {
|
||||||
|
engine->etbControllers[i] = &etbControllers[i];
|
||||||
|
}
|
||||||
|
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
efiAssertVoid(OBD_PCM_Processor_Fault, engine->etbControllers != NULL, "etbControllers NULL");
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
addConsoleAction("ethinfo", showEthInfo);
|
addConsoleAction("ethinfo", showEthInfo);
|
||||||
addConsoleAction("etbreset", etbReset);
|
addConsoleAction("etbreset", etbReset);
|
||||||
|
@ -666,8 +675,8 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
|
||||||
for (int i = 0 ; i < ETB_COUNT; i++) {
|
for (int i = 0 ; i < ETB_COUNT; i++) {
|
||||||
etbController[i].init(&etbHardware[i].dcMotor, i, &engineConfiguration->etb);
|
engine->etbControllers[i]->init(&etbHardware[i].dcMotor, i, &engineConfiguration->etb);
|
||||||
INJECT_ENGINE_REFERENCE(&etbController[i]);
|
INJECT_ENGINE_REFERENCE(engine->etbControllers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -742,9 +751,10 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
etbPidReset(PASS_ENGINE_PARAMETER_SIGNATURE);
|
etbPidReset(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
for (int i = 0 ; i < engine->etbActualCount; i++) {
|
for (int i = 0 ; i < engine->etbActualCount; i++) {
|
||||||
etbController[i].Start();
|
engine->etbControllers[i]->Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
||||||
|
|
||||||
|
|
|
@ -17,15 +17,21 @@
|
||||||
class DcMotor;
|
class DcMotor;
|
||||||
class Logging;
|
class Logging;
|
||||||
|
|
||||||
class EtbController final : public PeriodicTimerController {
|
class IEtbController : public PeriodicTimerController{
|
||||||
public:
|
public:
|
||||||
DECLARE_ENGINE_PTR;
|
DECLARE_ENGINE_PTR;
|
||||||
void init(DcMotor *motor, int ownIndex, pid_s *pidParameters);
|
virtual void init(DcMotor *motor, int ownIndex, pid_s *pidParameters) = 0;
|
||||||
void reset();
|
virtual void reset() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EtbController final : public IEtbController {
|
||||||
|
public:
|
||||||
|
void init(DcMotor *motor, int ownIndex, pid_s *pidParameters) override;
|
||||||
|
|
||||||
// PeriodicTimerController implementation
|
// PeriodicTimerController implementation
|
||||||
int getPeriodMs() override;
|
int getPeriodMs() override;
|
||||||
void PeriodicTask() override;
|
void PeriodicTask() override;
|
||||||
|
void reset() override;
|
||||||
|
|
||||||
// Called when the configuration may have changed. Controller will
|
// Called when the configuration may have changed. Controller will
|
||||||
// reset if necessary.
|
// reset if necessary.
|
||||||
|
@ -45,6 +51,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
void setBoschVNH2SP30Curve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void setBoschVNH2SP30Curve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
|
|
|
@ -47,11 +47,15 @@ class RpmCalculator;
|
||||||
|
|
||||||
#define CYCLE_ALTERNATION 2
|
#define CYCLE_ALTERNATION 2
|
||||||
|
|
||||||
|
class IEtbController;
|
||||||
|
|
||||||
class Engine : public TriggerStateListener {
|
class Engine : public TriggerStateListener {
|
||||||
public:
|
public:
|
||||||
explicit Engine(persistent_config_s *config);
|
explicit Engine(persistent_config_s *config);
|
||||||
Engine();
|
Engine();
|
||||||
|
|
||||||
|
IEtbController *etbControllers[ETB_COUNT];
|
||||||
|
|
||||||
void OnTriggerStateDecodingError() override;
|
void OnTriggerStateDecodingError() override;
|
||||||
void OnTriggerStateProperState(efitick_t nowNt) override;
|
void OnTriggerStateProperState(efitick_t nowNt) override;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* This invokes PeriodicTask() immediately and starts the cycle of invocations and sleeps
|
* This invokes PeriodicTask() immediately and starts the cycle of invocations and sleeps
|
||||||
*/
|
*/
|
||||||
void Start() {
|
virtual void Start() {
|
||||||
runAndScheduleNext(this);
|
runAndScheduleNext(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -129,23 +129,22 @@ TEST(idle, timingPid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// not great that we are reusing shared instance. todo: move EtbController to Engine?
|
// not great that we are reusing shared instance. todo: move EtbController to Engine?
|
||||||
extern EtbController etbController;
|
|
||||||
|
|
||||||
TEST(idle, testTargetTpsIsFloatBug945) {
|
TEST(idle, testTargetTpsIsFloatBug945) {
|
||||||
|
|
||||||
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
||||||
|
|
||||||
setMockThrottlePedalSensorVoltage(3 PASS_ENGINE_PARAMETER_SUFFIX);
|
setMockThrottlePedalSensorVoltage(3 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
etbController.PeriodicTask();
|
engine->etbControllers[0]->PeriodicTask();
|
||||||
ASSERT_NEAR(50, engine->engineState.targetFromTable, EPS4D);
|
ASSERT_NEAR(50, engine->engineState.targetFromTable, EPS4D);
|
||||||
|
|
||||||
setMockThrottlePedalSensorVoltage(3.05 PASS_ENGINE_PARAMETER_SUFFIX);
|
setMockThrottlePedalSensorVoltage(3.05 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
ASSERT_NEAR(50.8302, getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE), EPS4D);
|
ASSERT_NEAR(50.8302, getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE), EPS4D);
|
||||||
etbController.PeriodicTask();
|
engine->etbControllers[0]->PeriodicTask();
|
||||||
ASSERT_NEAR(50.8302, engine->engineState.targetFromTable, EPS4D);
|
ASSERT_NEAR(50.8302, engine->engineState.targetFromTable, EPS4D);
|
||||||
|
|
||||||
setMockThrottlePedalSensorVoltage(3.1 PASS_ENGINE_PARAMETER_SUFFIX);
|
setMockThrottlePedalSensorVoltage(3.1 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
etbController.PeriodicTask();
|
engine->etbControllers[0]->PeriodicTask();
|
||||||
ASSERT_NEAR(51.6605, engine->engineState.targetFromTable, EPS4D);
|
ASSERT_NEAR(51.6605, engine->engineState.targetFromTable, EPS4D);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue