ETB progress

This commit is contained in:
rusefi 2019-02-10 19:13:04 -05:00
parent fe7d75a185
commit dc0ae33a54
2 changed files with 15 additions and 9 deletions

View File

@ -4,6 +4,8 @@
* *
* todo: make this more universal if/when we get other hardware options * todo: make this more universal if/when we get other hardware options
* *
* Jan 2019 actually driven around the block but still need some work.
*
* Jan 2017 status: * Jan 2017 status:
* Electronic throttle body with it's spring is definitely not linear - both P and I factors of PID are required to get any results * Electronic throttle body with it's spring is definitely not linear - both P and I factors of PID are required to get any results
* PID implementation tested on a bench only * PID implementation tested on a bench only
@ -86,8 +88,8 @@ static SimplePwm etbPwmUp("etbUp") CCM_OPTIONAL;
static float valueOverride = NAN; static float valueOverride = NAN;
/* /*
static SimplePwm etbPwmDown("etbDown") CCM_OPTIONAL; static SimplePwm etbPwmDown("etbDown") 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;
@ -157,7 +159,7 @@ static msg_t etbThread(void *arg) {
currentEtbDuty = pid.getValue(targetPosition, actualThrottlePosition); currentEtbDuty = pid.getValue(targetPosition, actualThrottlePosition);
etbPwmUp.setSimplePwmDutyCycle(PERCENT_TO_DUTY(currentEtbDuty)); etbPwmUp.setSimplePwmDutyCycle(PERCENT_TO_DUTY(currentEtbDuty));
/*
if (CONFIGB(etbDirectionPin2) != GPIO_UNASSIGNED) { if (CONFIGB(etbDirectionPin2) != GPIO_UNASSIGNED) {
bool needEtbBraking = absF(targetPosition - actualThrottlePosition) < 3; bool needEtbBraking = absF(targetPosition - actualThrottlePosition) < 3;
if (needEtbBraking != wasEtbBraking) { if (needEtbBraking != wasEtbBraking) {
@ -166,7 +168,7 @@ static msg_t etbThread(void *arg) {
} }
outputDirectionClose.setValue(needEtbBraking); outputDirectionClose.setValue(needEtbBraking);
} }
*/
if (engineConfiguration->isVerboseETB) { if (engineConfiguration->isVerboseETB) {
pid.showPidStatus(&logger, "ETB"); pid.showPidStatus(&logger, "ETB");
} }
@ -295,8 +297,8 @@ void startETBPins(void) {
freq, freq,
0.80, 0.80,
applyPinState); applyPinState);
outputDirectionOpen.initPin("etb dir open", CONFIGB(etbDirectionPin1));
*/ */
outputDirectionOpen.initPin("etb dir open", CONFIGB(etbDirectionPin1));
outputDirectionClose.initPin("etb dir close", CONFIGB(etbDirectionPin2)); outputDirectionClose.initPin("etb dir close", CONFIGB(etbDirectionPin2));
} }

View File

@ -15,19 +15,23 @@ TwoPinDcMotor::TwoPinDcMotor(SimplePwm* pwm, OutputPin* dir1, OutputPin* dir2)
{ {
} }
/**
* @param duty value between -1.0 and 1.0
*/
bool TwoPinDcMotor::Set(float duty) bool TwoPinDcMotor::Set(float duty)
{ {
bool dir; bool isPositiveOrZero;
if(duty < 0) if(duty < 0)
{ {
dir = false; isPositiveOrZero = false;
duty = -duty; duty = -duty;
} }
else else
{ {
dir = true; isPositiveOrZero = true;
} }
// below here 'duty' is a not negative
// Clamp to 100% // Clamp to 100%
if(duty > 1.0f) if(duty > 1.0f)
@ -47,8 +51,8 @@ bool TwoPinDcMotor::Set(float duty)
} }
else else
{ {
m_dir1->setValue(dir); m_dir1->setValue(isPositiveOrZero);
m_dir2->setValue(!dir); m_dir2->setValue(!isPositiveOrZero);
} }
m_pwm->setSimplePwmDutyCycle(duty); m_pwm->setSimplePwmDutyCycle(duty);