ETB target is using integer values #945

now we have a unit test! now we can fix the issue :)
This commit is contained in:
rusefi 2019-09-22 17:58:27 -04:00
parent e99955fce5
commit e7b658547b
4 changed files with 29 additions and 8 deletions

View File

@ -174,15 +174,12 @@ static percent_t currentEtbDuty;
// this macro clamps both positive and negative percentages from about -100% to 100%
#define ETB_PERCENT_TO_DUTY(X) (maxF(minF((X * 0.01), ETB_DUTY_LIMIT - 0.01), 0.01 - ETB_DUTY_LIMIT))
class EtbController : public PeriodicTimerController {
public:
DECLARE_ENGINE_PTR;
int getPeriodMs() override {
int EtbController::getPeriodMs() {
return GET_PERIOD_LIMITED(&engineConfiguration->etb);
}
void PeriodicTask() override {
void EtbController::PeriodicTask() {
// set debug_mode 17
if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) {
#if EFI_TUNER_STUDIO
@ -312,9 +309,8 @@ DISPLAY(DISPLAY_IF(hasEtbPedalPositionSensor))
tsOutputChannels.etb1Error = targetPosition - actualThrottlePosition;
#endif /* EFI_TUNER_STUDIO */
}
};
static EtbController etbController;
EtbController etbController;
/**
* set_etb_duty X

View File

@ -13,6 +13,16 @@
#define DEFAULT_ETB_PWM_FREQUENCY 300
#include "engine.h"
#include "periodic_task.h"
class EtbController : public PeriodicTimerController {
public:
DECLARE_ENGINE_PTR;
int getPeriodMs() override;
void PeriodicTask() override;
};
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);

View File

@ -13,6 +13,7 @@ float testMafValue = 0;
float testCltValue = 0;
float testIatValue = 0;
// see setMockVoltage
float getVoltageDivided(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) {
switch(hwChannel) {
case TEST_MAF_CHANNEL:
@ -24,7 +25,7 @@ float getVoltageDivided(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_
return testIatValue;
//return adcToVolts(engine->engineState.mockAdcState.getMockAdcValue(hwChannel));
}
return 0;
return adcToVolts(engine->engineState.mockAdcState.getMockAdcValue(hwChannel));;
}
float getVoltage(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) {

View File

@ -13,6 +13,7 @@
#include "idle_thread.h"
#include "allsensors.h"
#include "engine_controller.h"
#include "electronic_throttle.h"
extern IdleController idleControllerInstance;
extern int timeNowUs;
@ -183,10 +184,23 @@ TEST(idle, timingPid) {
}
// not great that we are reusing shared instance. todo: move EtbController to Engine?
extern EtbController etbController;
TEST(idle, testTargetTpsIsFloatBug945) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
setMockThrottlePedalSensorVoltage(3 PASS_ENGINE_PARAMETER_SUFFIX);
etbController.PeriodicTask();
ASSERT_NEAR(50, engine->engineState.targetFromTable, EPS4D);
setMockThrottlePedalSensorVoltage(3.05 PASS_ENGINE_PARAMETER_SUFFIX);
etbController.PeriodicTask();
ASSERT_NEAR(50, engine->engineState.targetFromTable, EPS4D);
setMockThrottlePedalSensorVoltage(3.1 PASS_ENGINE_PARAMETER_SUFFIX);
etbController.PeriodicTask();
ASSERT_NEAR(51, engine->engineState.targetFromTable, EPS4D);
}