ETB target is using integer values #945
first we will write a unit test
This commit is contained in:
parent
185f4cb708
commit
f843968636
|
@ -18,10 +18,13 @@
|
|||
#include "engine_math.h"
|
||||
#include "fsio_impl.h"
|
||||
|
||||
#if EFI_ELECTRONIC_THROTTLE_BODY
|
||||
#include "electronic_throttle.h"
|
||||
#endif
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "can_hw.h"
|
||||
#include "scheduler.h"
|
||||
#include "electronic_throttle.h"
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
|
|
@ -117,6 +117,8 @@ private:
|
|||
SimplePwm etbPwmUp;
|
||||
|
||||
public:
|
||||
DECLARE_ENGINE_PTR;
|
||||
|
||||
EtbControl() : etbPwmUp("etbUp"), dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2) {}
|
||||
|
||||
TwoPinDcMotor dcMotor;
|
||||
|
@ -163,7 +165,7 @@ static EtbControl etb1;
|
|||
|
||||
extern percent_t mockPedalPosition;
|
||||
|
||||
Pid etbPid(&engineConfiguration->etb);
|
||||
Pid etbPid;
|
||||
|
||||
static percent_t directPwmValue = NAN;
|
||||
static percent_t currentEtbDuty;
|
||||
|
@ -173,6 +175,8 @@ static percent_t currentEtbDuty;
|
|||
#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 {
|
||||
return GET_PERIOD_LIMITED(&engineConfiguration->etb);
|
||||
|
@ -396,7 +400,7 @@ void setEtbOffset(int value) {
|
|||
showEthInfo();
|
||||
}
|
||||
|
||||
void setBoschVNH2SP30Curve(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
void setBoschVNH2SP30Curve(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
engineConfiguration->etbBiasBins[0] = 0;
|
||||
engineConfiguration->etbBiasBins[1] = 1;
|
||||
engineConfiguration->etbBiasBins[2] = 5;
|
||||
|
@ -426,7 +430,7 @@ void setBoschVNH2SP30Curve(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
engineConfiguration->etbBiasValues[7] = 28;
|
||||
}
|
||||
|
||||
void setDefaultEtbParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
CONFIG(etbIdleThrottleRange) = 5;
|
||||
|
||||
setLinearCurveAny<uint8_t>(config->pedalToTpsPedalBins, PEDAL_TO_TPS_SIZE, /*from*/0, /*to*/100, 1);
|
||||
|
@ -462,6 +466,7 @@ static bool isSamePins(etb_io *current, etb_io *active) {
|
|||
current->directionPin2 != active->directionPin2;
|
||||
}
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
bool isETBRestartNeeded(void) {
|
||||
/**
|
||||
* We do not want any interruption in HW pin while adjusting other properties
|
||||
|
@ -474,6 +479,7 @@ void stopETBPins(void) {
|
|||
brain_pin_markUnused(activeConfiguration.bc.etb1.directionPin1);
|
||||
brain_pin_markUnused(activeConfiguration.bc.etb1.directionPin2);
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration) {
|
||||
shouldResetPid = !etbPid.isSame(&previousConfiguration->etb);
|
||||
|
@ -513,7 +519,7 @@ static void setAutoOffset(int offset) {
|
|||
autoTune.reset();
|
||||
}
|
||||
|
||||
void setDefaultEtbBiasCurve(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
engineConfiguration->etbBiasBins[0] = 0;
|
||||
engineConfiguration->etbBiasBins[1] = 1;
|
||||
engineConfiguration->etbBiasBins[2] = 2;
|
||||
|
@ -547,12 +553,18 @@ void unregisterEtbPins() {
|
|||
|
||||
}
|
||||
|
||||
void initElectronicThrottle(void) {
|
||||
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
addConsoleAction("ethinfo", showEthInfo);
|
||||
addConsoleAction("etbreset", etbReset);
|
||||
|
||||
etbPid.initPidClass(&engineConfiguration->etb);
|
||||
|
||||
INJECT_ENGINE_REFERENCE(etb1);
|
||||
INJECT_ENGINE_REFERENCE(etbController);
|
||||
|
||||
pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins);
|
||||
|
||||
engine->engineState.hasEtbPedalPositionSensor = hasPedalPositionSensor();
|
||||
engine->engineState.hasEtbPedalPositionSensor = hasPedalPositionSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
if (!engine->engineState.hasEtbPedalPositionSensor) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
#define DEFAULT_ETB_PWM_FREQUENCY 300
|
||||
|
||||
#include "engine.h"
|
||||
void initElectronicThrottle(void);
|
||||
void setDefaultEtbBiasCurve(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void setDefaultEtbParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void setBoschVNH2SP30Curve(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void setBoschVNH2SP30Curve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void setEtbPFactor(float value);
|
||||
void setEtbIFactor(float value);
|
||||
void setEtbDFactor(float value);
|
||||
|
|
|
@ -555,11 +555,7 @@ static void initIdleHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
void startIdleThread(Logging*sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
logger = sharedLogger;
|
||||
idleControllerInstance.engine = engine;
|
||||
idleControllerInstance.engineConfiguration = engineConfiguration;
|
||||
idleControllerInstance.config = config;
|
||||
idleControllerInstance.boardConfiguration = boardConfiguration;
|
||||
|
||||
INJECT_ENGINE_REFERENCE(idleControllerInstance);
|
||||
|
||||
idlePid.initPidClass(&engineConfiguration->idleRpmPid);
|
||||
|
||||
|
|
|
@ -14,10 +14,7 @@
|
|||
|
||||
class IdleController : public PeriodicTimerController {
|
||||
public:
|
||||
Engine *engine = NULL;
|
||||
engine_configuration_s *engineConfiguration = NULL;
|
||||
persistent_config_s *config = NULL;
|
||||
board_configuration_s *boardConfiguration = NULL;
|
||||
DECLARE_ENGINE_PTR;
|
||||
|
||||
int getPeriodMs() override;
|
||||
void PeriodicTask() override;
|
||||
|
|
|
@ -587,8 +587,8 @@ static void setDefaultEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
|
||||
#if EFI_ELECTRONIC_THROTTLE_BODY
|
||||
setDefaultEtbParameters(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
setDefaultEtbBiasCurve(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
setDefaultEtbParameters(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
setDefaultEtbBiasCurve(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
||||
|
||||
CONFIGB(mafSensorType) = Bosch0280218037;
|
||||
|
|
|
@ -65,4 +65,17 @@
|
|||
#define DISPLAY_SENSOR(x) {}
|
||||
#define DISPLAY_IF(x) x
|
||||
|
||||
#define DECLARE_ENGINE_PTR \
|
||||
Engine *engine = NULL; \
|
||||
engine_configuration_s *engineConfiguration = NULL; \
|
||||
persistent_config_s *config = NULL; \
|
||||
board_configuration_s *boardConfiguration = NULL;
|
||||
|
||||
|
||||
#define INJECT_ENGINE_REFERENCE(x) \
|
||||
x.engine = engine; \
|
||||
x.engineConfiguration = engineConfiguration; \
|
||||
x.config = config; \
|
||||
x.boardConfiguration = boardConfiguration;
|
||||
|
||||
#endif /* CONTROLLERS_CORE_COMMON_HEADERS_H_ */
|
||||
|
|
|
@ -212,7 +212,7 @@ percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
DISPLAY_TEXT(Analog_MCU_reads);
|
||||
|
||||
float voltage = getVoltageDivided("pPS", CONFIG(DISPLAY_CONFIG(throttlePedalPositionAdcChannel)));
|
||||
float result = interpolateMsg("pedal", engineConfiguration->throttlePedalUpVoltage, 0, engineConfiguration->throttlePedalWOTVoltage, 100, voltage);
|
||||
percent_t result = interpolateMsg("pedal", engineConfiguration->throttlePedalUpVoltage, 0, engineConfiguration->throttlePedalWOTVoltage, 100, voltage);
|
||||
|
||||
// this would put the value into the 0-100 range
|
||||
return maxF(0, minF(100, result));
|
||||
|
|
Loading…
Reference in New Issue