run ETB on new TPS (#1248)

* run ETB on new TPS

* why did we include all those...?

* init tps for etb test

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-04-02 18:33:49 -07:00 committed by GitHub
parent 5923cb01d4
commit b197c6ff07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View File

@ -77,13 +77,6 @@
#include "electronic_throttle.h"
#include "tps.h"
#include "sensor.h"
#include "io_pins.h"
#include "engine_configuration.h"
#include "pwm_generator_logic.h"
#include "pid.h"
#include "engine_controller.h"
#include "periodic_task.h"
#include "pin_repository.h"
#include "dc_motor.h"
#include "dc_motors.h"
#include "pid_auto_tune.h"
@ -109,6 +102,13 @@ static bool startupPositionError = false;
#define STARTUP_NEUTRAL_POSITION_ERROR_THRESHOLD 5
static SensorType indexToTpsSensor(size_t index) {
switch(index) {
case 0: return SensorType::Tps1;
default: return SensorType::Tps2;
}
}
static percent_t directPwmValue = NAN;
static percent_t currentEtbDuty;
@ -186,16 +186,20 @@ void EtbController::PeriodicTask() {
return;
}
SensorResult actualThrottlePosition = Sensor::get(indexToTpsSensor(m_myIndex));
percent_t actualThrottlePosition = getTPSWithIndex(m_myIndex PASS_ENGINE_PARAMETER_SUFFIX);
if (!actualThrottlePosition.Valid) {
m_motor->set(0);
return;
}
if (engine->etbAutoTune) {
autoTune.input = actualThrottlePosition;
autoTune.input = actualThrottlePosition.Value;
bool result = autoTune.Runtime(&logger);
tuneWorkingPid.updateFactors(autoTune.output, 0, 0);
float value = tuneWorkingPid.getOutput(50, actualThrottlePosition);
float value = tuneWorkingPid.getOutput(50, actualThrottlePosition.Value);
scheduleMsg(&logger, "AT input=%f output=%f PID=%f", autoTune.input,
autoTune.output,
value);
@ -233,7 +237,7 @@ void EtbController::PeriodicTask() {
m_pid.iTermMax = engineConfiguration->etb_iTermMax;
currentEtbDuty = engine->engineState.etbFeedForward +
m_pid.getOutput(targetPosition, actualThrottlePosition);
m_pid.getOutput(targetPosition, actualThrottlePosition.Value);
m_motor->set(ETB_PERCENT_TO_DUTY(currentEtbDuty));
@ -290,7 +294,7 @@ void EtbController::PeriodicTask() {
tsOutputChannels.etb1DutyCycle = currentEtbDuty;
// 320
// Error is positive if the throttle needs to open further
tsOutputChannels.etb1Error = targetPosition - actualThrottlePosition;
tsOutputChannels.etb1Error = targetPosition - actualThrottlePosition.Value;
#endif /* EFI_TUNER_STUDIO */
}
}
@ -300,8 +304,6 @@ EtbController etbControllers[ETB_COUNT];
static void showEthInfo(void) {
#if EFI_PROD_CODE
static char pinNameBuffer[16];
if (engine->etbActualCount == 0) {
scheduleMsg(&logger, "ETB DISABLED since no PPS");
}

View File

@ -74,6 +74,7 @@ TEST(etb, testTargetTpsIsFloatBug945) {
// Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
Sensor::setMockValue(SensorType::Tps1, 0);
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);