ETB progress

This commit is contained in:
rusEfi 2018-09-24 23:57:03 -04:00
parent e08b0fb0e1
commit b24685ce65
4 changed files with 33 additions and 21 deletions

View File

@ -75,9 +75,10 @@ static THD_WORKING_AREA(etbTreadStack, UTILITY_THREAD_STACK_SIZE);
* @brief Pulse-Width Modulation state * @brief Pulse-Width Modulation state
*/ */
static SimplePwm etbPwmUp CCM_OPTIONAL; static SimplePwm etbPwmUp CCM_OPTIONAL;
/*
static SimplePwm etbPwmDown CCM_OPTIONAL; static SimplePwm etbPwmDown CCM_OPTIONAL;
static OutputPin outputDirectionOpen CCM_OPTIONAL; static OutputPin outputDirectionOpen CCM_OPTIONAL;
*/
static OutputPin outputDirectionClose CCM_OPTIONAL; static OutputPin outputDirectionClose CCM_OPTIONAL;
EXTERN_ENGINE; EXTERN_ENGINE;
@ -117,12 +118,14 @@ static msg_t etbThread(void *arg) {
etbPwmUp.setSimplePwmDutyCycle(currentEtbDuty / 100); etbPwmUp.setSimplePwmDutyCycle(currentEtbDuty / 100);
bool needEtbBraking = absF(targetPosition - actualThrottlePosition) < 3; if (boardConfiguration->etbDirectionPin2 != GPIO_UNASSIGNED) {
if (needEtbBraking != wasEtbBraking) { bool needEtbBraking = absF(targetPosition - actualThrottlePosition) < 3;
scheduleMsg(&logger, "need ETB braking: %d", needEtbBraking); if (needEtbBraking != wasEtbBraking) {
wasEtbBraking = needEtbBraking; scheduleMsg(&logger, "need ETB braking: %d", needEtbBraking);
wasEtbBraking = needEtbBraking;
}
outputDirectionClose.setValue(needEtbBraking);
} }
outputDirectionClose.setValue(needEtbBraking);
if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE) { if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE) {
pid.postState(&tsOutputChannels); pid.postState(&tsOutputChannels);
@ -145,12 +148,15 @@ static msg_t etbThread(void *arg) {
#endif #endif
} }
static void setThrottleConsole(int level) { /**
* manual duty cycle control without PID
*/
static void setThrottleDutyCycle(int level) {
scheduleMsg(&logger, "setting throttle=%d", level); scheduleMsg(&logger, "setting throttle=%d", level);
float dc = 0.01 + (minI(level, 98)) / 100.0; float dc = 0.01 + (minI(level, 98)) / 100.0;
etbPwmUp.setSimplePwmDutyCycle(dc); etbPwmUp.setSimplePwmDutyCycle(dc);
print("st = %.2f\r\n", dc); print("etb duty = %.2f\r\n", dc);
} }
static void showEthInfo(void) { static void showEthInfo(void) {
@ -175,19 +181,25 @@ static void showEthInfo(void) {
pid.showPidStatus(&logger, "ETB"); pid.showPidStatus(&logger, "ETB");
} }
static void apply(void) { static void applyPidSettings(void) {
pid.updateFactors(engineConfiguration->etb.pFactor, engineConfiguration->etb.iFactor, 0); pid.updateFactors(engineConfiguration->etb.pFactor, engineConfiguration->etb.iFactor, 0);
} }
void setEtbPFactor(float value) { void setEtbPFactor(float value) {
engineConfiguration->etb.pFactor = value; engineConfiguration->etb.pFactor = value;
apply(); applyPidSettings();
showEthInfo(); showEthInfo();
} }
void setEtbIFactor(float value) { void setEtbIFactor(float value) {
engineConfiguration->etb.iFactor = value; engineConfiguration->etb.iFactor = value;
apply(); applyPidSettings();
showEthInfo();
}
void setEtbDFactor(float value) {
engineConfiguration->etb.dFactor = value;
applyPidSettings();
showEthInfo(); showEthInfo();
} }
@ -199,6 +211,8 @@ void setDefaultEtbParameters(void) {
engineConfiguration->etb.iFactor = 0.5; engineConfiguration->etb.iFactor = 0.5;
engineConfiguration->etb.period = 100; engineConfiguration->etb.period = 100;
engineConfiguration->etbFreq = 300; engineConfiguration->etbFreq = 300;
// boardConfiguration->etbControlPin1 = GPIOE_4; // test board, matched default fuel pump relay
} }
bool isETBRestartNeeded(void) { bool isETBRestartNeeded(void) {
@ -233,32 +247,27 @@ void startETBPins(void) {
freq, freq,
0.80, 0.80,
applyPinState); applyPinState);
/*
startSimplePwmExt(&etbPwmDown, "etb2", startSimplePwmExt(&etbPwmDown, "etb2",
boardConfiguration->etbControlPin2, boardConfiguration->etbControlPin2,
&enginePins.etbOutput2, &enginePins.etbOutput2,
freq, freq,
0.80, 0.80,
applyPinState); applyPinState);
outputDirectionOpen.initPin("etb dir open", boardConfiguration->etbDirectionPin1); outputDirectionOpen.initPin("etb dir open", boardConfiguration->etbDirectionPin1);
*/
outputDirectionClose.initPin("etb dir close", boardConfiguration->etbDirectionPin2); outputDirectionClose.initPin("etb dir close", boardConfiguration->etbDirectionPin2);
} }
static void setTempOutput(float value) { static void setTempOutput(float value) {
autoTune.output = value; autoTune.output = value;
} }
static void setTempStep(float value) { static void setTempStep(float value) {
autoTune.oStep = value; autoTune.oStep = value;
} }
void initElectronicThrottle(void) { void initElectronicThrottle(void) {
// these two lines are controlling direction
// outputPinRegister("etb1", ELECTRONIC_THROTTLE_CONTROL_1, ETB_CONTROL_LINE_1_PORT, ETB_CONTROL_LINE_1_PIN);
// outputPinRegister("etb2", ELECTRONIC_THROTTLE_CONTROL_2, ETB_CONTROL_LINE_2_PORT, ETB_CONTROL_LINE_2_PIN);
addConsoleAction("ethinfo", showEthInfo); addConsoleAction("ethinfo", showEthInfo);
if (!hasPedalPositionSensor()) { if (!hasPedalPositionSensor()) {
return; return;
@ -266,12 +275,13 @@ void initElectronicThrottle(void) {
startETBPins(); startETBPins();
addConsoleActionI("set_etb", setThrottleConsole); //
addConsoleActionI("set_etb", setThrottleDutyCycle);
addConsoleActionF("set_etb_output", setTempOutput); addConsoleActionF("set_etb_output", setTempOutput);
addConsoleActionF("set_etb_step", setTempStep); addConsoleActionF("set_etb_step", setTempStep);
apply(); applyPidSettings();
chThdCreateStatic(etbTreadStack, sizeof(etbTreadStack), NORMALPRIO, (tfunc_t) etbThread, NULL); chThdCreateStatic(etbTreadStack, sizeof(etbTreadStack), NORMALPRIO, (tfunc_t) etbThread, NULL);
} }

View File

@ -13,6 +13,7 @@ void initElectronicThrottle(void);
void setDefaultEtbParameters(void); void setDefaultEtbParameters(void);
void setEtbPFactor(float value); void setEtbPFactor(float value);
void setEtbIFactor(float value); void setEtbIFactor(float value);
void setEtbDFactor(float value);
bool isETBRestartNeeded(void); bool isETBRestartNeeded(void);
void stopETBPins(void); void stopETBPins(void);
void startETBPins(void); void startETBPins(void);

View File

@ -733,5 +733,5 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0) if (initBootloader() != 0)
return 123; return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */ #endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20180831; return 20180924;
} }

View File

@ -1162,6 +1162,7 @@ command_f_s commandsF[] = {{"mock_iat_voltage", setMockIatVoltage},
{"idle_d", setIdleDFactor}, {"idle_d", setIdleDFactor},
{"etb_p", setEtbPFactor}, {"etb_p", setEtbPFactor},
{"etb_i", setEtbIFactor}, {"etb_i", setEtbIFactor},
{"etb_d", setEtbDFactor},
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
// {"", }, // {"", },