Goodbye, old TPS (#1266)

* clear out tps

* boost control

* aux valves

* launch, aux valves

* unused field
This commit is contained in:
Matthew Kennedy 2020-04-05 16:33:33 -07:00 committed by GitHub
parent b43da0d0f8
commit 345bf61bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 143 deletions

View File

@ -13,7 +13,7 @@
#endif /* EFI_TUNER_STUDIO */
#include "engine.h"
#include "boost_control.h"
#include "tps.h"
#include "sensor.h"
#include "map.h"
#include "io_pins.h"
#include "engine_configuration.h"
@ -79,10 +79,13 @@ class BoostControl: public PeriodicTimerController {
percent_t duty = openLoopDuty;
if (engineConfiguration->boostType == CLOSED_LOOP) {
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
float targetBoost = boostMapClosed.getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps / TPS_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT;
closedLoopDuty = openLoopDuty + boostControlPid.getOutput(targetBoost, mapValue);
duty += closedLoopDuty;
auto [valid, tps] = Sensor::get(SensorType::DriverThrottleIntent);
if (valid) {
float targetBoost = boostMapClosed.getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps / TPS_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT;
closedLoopDuty = openLoopDuty + boostControlPid.getOutput(targetBoost, mapValue);
duty += closedLoopDuty;
}
}
boostControlPid.iTermMin = -50;

View File

@ -17,6 +17,7 @@
#include "periodic_task.h"
#include "pin_repository.h"
#include "allsensors.h"
#include "sensor.h"
#include "engine_math.h"
#include "efi_gpio.h"
#include "advance_map.h"
@ -67,7 +68,7 @@ class LaunchControl: public PeriodicTimerController {
int rpm = GET_RPM_VALUE;
int speed = getVehicleSpeed();
int tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
auto tps = Sensor::get(SensorType::DriverThrottleIntent);
int tpstreshold = engineConfiguration->launchTpsTreshold;
float timeDelay = engineConfiguration->launchActivateDelay;
int cutRpmRange = engineConfiguration->hardCutRpmRange;
@ -77,7 +78,7 @@ class LaunchControl: public PeriodicTimerController {
bool activateSwitchCondition = getActivateSwitchCondition(PASS_ENGINE_PARAMETER_SIGNATURE);
bool rpmCondition = (launchRpm < rpm);
bool tpsCondition = (tpstreshold < tps);
bool tpsCondition = tps.Valid && (tpstreshold < tps.Value);
bool speedCondition = (CONFIG(launchSpeedTreshold) > speed) || !engineConfiguration->launchDisableBySpeed;

View File

@ -16,6 +16,7 @@
#include "engine_math.h"
#include "aux_valves.h"
#include "allsensors.h"
#include "sensor.h"
#include "trigger_central.h"
#include "spark_logic.h"
@ -124,14 +125,8 @@ void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
return;
}
#if !EFI_UNIT_TEST
// let's give it time to grab TPS value
chThdSleepMilliseconds(50);
#endif /* EFI_UNIT_TESTS */
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
if (cisnan(tps)) {
firmwareError(CUSTOM_OBD_91, "No TPS for Aux Valves");
if (!Sensor::hasSensor(SensorType::DriverThrottleIntent)) {
warning(CUSTOM_OBD_91, "No TPS for Aux Valves");
return;
}
@ -166,11 +161,12 @@ void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return;
}
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
if (cisnan(tps)) {
auto [valid, tps] = Sensor::get(SensorType::DriverThrottleIntent);
if (!valid) {
// error should be already reported by now
return;
}
engine->engineState.auxValveStart = interpolate2d("aux", tps,
engineConfiguration->fsioCurve1Bins,
engineConfiguration->fsioCurve1);

View File

@ -3,102 +3,17 @@
*/
#include "engine.h"
#include "tps.h"
#include "interpolation.h"
#include "adc_inputs.h"
#include "sensor.h"
#if EFI_PROD_CODE
#include "settings.h"
#endif /* EFI_PROD_CODE */
EXTERN_ENGINE;
/*
* Return current TPS position based on configured ADC levels, and adc
*
* */
static percent_t getTpsValue(int index, float adc DECLARE_ENGINE_PARAMETER_SUFFIX) {
DISPLAY_STATE(Engine)
DISPLAY_TAG(TPS_SECTION);
DISPLAY_SENSOR(TPS)
DISPLAY_TEXT(EOL)
DISPLAY_TEXT(Analog_MCU_reads);
engine->engineState.currentTpsAdc = adc;
#if !EFI_UNIT_TEST
engine->engineState.DISPLAY_FIELD(tpsVoltageMCU) = adcToVolts(adc);
#endif
DISPLAY_TEXT(Volts);
DISPLAY_TEXT(from_pin) DISPLAY(DISPLAY_CONFIG(tps1_1AdcChannel))
DISPLAY_TEXT(EOL);
DISPLAY_TEXT(Analog_ECU_reads);
engine->engineState.DISPLAY_FIELD(tpsVoltageBoard) =
DISPLAY_TEXT(Rdivider) engine->engineState.tpsVoltageMCU * CONFIG(DISPLAY_CONFIG(analogInputDividerCoefficient));
DISPLAY_TEXT(EOL);
if (engineConfiguration->tpsMin == engineConfiguration->tpsMax) {
warning(CUSTOM_INVALID_TPS_SETTING, "Invalid TPS configuration: same value %d", engineConfiguration->tpsMin);
return NAN;
}
DISPLAY_TEXT(Current_ADC)
DISPLAY(DISPLAY_FIELD(currentTpsAdc))
DISPLAY_TEXT(interpolate_between)
DISPLAY(DISPLAY_CONFIG(tpsMax))
DISPLAY_TEXT(and)
DISPLAY(DISPLAY_CONFIG(tpsMin))
int tpsMax = index == 0 ? CONFIG(tpsMax) : CONFIG(tps2Max);
int tpsMin = index == 0 ? CONFIG(tpsMin) : CONFIG(tps2Min);
const char *msg = index == 0 ? "TPS1" : "TPS2";
float result = interpolateMsg(msg, tpsMax, 100, tpsMin, 0, adc);
if (result < engineConfiguration->tpsErrorDetectionTooLow) {
#if EFI_PROD_CODE
// too much noise with simulator
warning(OBD_Throttle_Position_Sensor_Circuit_Malfunction, "TPS too low: %.2f", result);
#endif /* EFI_PROD_CODE */
}
if (result > engineConfiguration->tpsErrorDetectionTooHigh) {
#if EFI_PROD_CODE
// too much noise with simulator
warning(OBD_Throttle_Position_Sensor_Range_Performance_Problem, "TPS too high: %.2f", result);
#endif /* EFI_PROD_CODE */
}
// this would put the value into the 0-100 range
return maxF(0, minF(100, result));
}
/*
* Return TPS ADC readings.
* We need ADC value because TunerStudio has a nice TPS configuration wizard, and this wizard
* wants a TPS value.
* @param index [0, ETB_COUNT)
*/
static float getTPS10bitAdc(int index DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (engineConfiguration->tps1_1AdcChannel == EFI_ADC_NONE)
return -1;
#if EFI_PROD_CODE
if (index == 0) {
return convertVoltageTo10bitADC(getVoltageDivided("tps10", engineConfiguration->tps1_1AdcChannel));
} else {
return convertVoltageTo10bitADC(getVoltageDivided("tps20", engineConfiguration->tps2_1AdcChannel));
}
// return tpsFastAdc / 4;
#else
return 0;
#endif /* EFI_PROD_CODE */
}
void grabTPSIsClosed() {
#if EFI_PROD_CODE
printTPSInfo();
engineConfiguration->tpsMin = getTPS10bitAdc(0);
engineConfiguration->tpsMin = convertVoltageTo10bitADC(Sensor::getRaw(SensorType::Tps1));
printTPSInfo();
#endif /* EFI_PROD_CODE */
}
@ -106,48 +21,21 @@ void grabTPSIsClosed() {
void grabTPSIsWideOpen() {
#if EFI_PROD_CODE
printTPSInfo();
engineConfiguration->tpsMax = getTPS10bitAdc(0);
engineConfiguration->tpsMax = convertVoltageTo10bitADC(Sensor::getRaw(SensorType::Tps1));
printTPSInfo();
#endif /* EFI_PROD_CODE */
}
void grabPedalIsUp() {
#if EFI_PROD_CODE
float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel PASS_ENGINE_PARAMETER_SUFFIX);
engineConfiguration->throttlePedalUpVoltage = voltage;
engineConfiguration->throttlePedalUpVoltage = Sensor::getRaw(SensorType::AcceleratorPedal);
printTPSInfo();
#endif /* EFI_PROD_CODE */
}
void grabPedalIsWideOpen() {
#if EFI_PROD_CODE
float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel PASS_ENGINE_PARAMETER_SUFFIX);
engineConfiguration->throttlePedalWOTVoltage = voltage;
engineConfiguration->throttlePedalWOTVoltage = Sensor::getRaw(SensorType::AcceleratorPedal);
printTPSInfo();
#endif /* EFI_PROD_CODE */
}
/**
* @brief Position on physical primary TPS
*/
static percent_t getPrimaryRawTPS(int index DECLARE_ENGINE_PARAMETER_SUFFIX) {
float adcValue = getTPS10bitAdc(index PASS_ENGINE_PARAMETER_SUFFIX);
percent_t tpsValue = getTpsValue(index, adcValue PASS_ENGINE_PARAMETER_SUFFIX);
return tpsValue;
}
#define NO_TPS_MAGIC_VALUE 66.611
static bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engineConfiguration->tps1_1AdcChannel != EFI_ADC_NONE;
}
percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (!hasTpsSensor(PASS_ENGINE_PARAMETER_SIGNATURE))
return NO_TPS_MAGIC_VALUE;
// todo: if (config->isDualTps)
// todo: blah blah
// todo: if two TPS do not match - show OBD code via malfunction_central.c
return getPrimaryRawTPS(0 PASS_ENGINE_PARAMETER_SUFFIX);
}

View File

@ -15,13 +15,6 @@
// Scaled to 1000 counts = 5.0 volts
#define TPS_TS_CONVERSION 200
/**
* Throttle Position Sensor
* In case of dual TPS this function would return logical TPS position
* @return Current TPS position, percent of WOT. 0 means idle and 100 means Wide Open Throttle
*/
percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE);
constexpr inline int convertVoltageTo10bitADC(float voltage) {
return (int) (voltage * TPS_TS_CONVERSION);
}

View File

@ -1306,7 +1306,6 @@ end_struct
#define MOCK_IAT_COMMAND "mock_iat_voltage"
#define MOCK_CLT_COMMAND "mock_clt_voltage"
#define MOCK_MAP_COMMAND "mock_map_voltage"
#define MOCK_TPS_COMMAND "mock_tps_voltage"
#define MOCK_AFR_COMMAND "mock_afr_voltage"
#define MOCK_MAF_COMMAND "mock_maf_voltage"
! Pedal Position Sensor

View File

@ -29,7 +29,6 @@ EngineTestHelperBase::EngineTestHelperBase() {
}
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback) {
Sensor::resetRegistry();
unitTestWarningCodeState.clear();
testMafValue = 0;

View File

@ -7,8 +7,11 @@
#include "engine_test_helper.h"
#include "aux_valves.h"
#include "sensor.h"
TEST(misc, testAuxValves) {
Sensor::setMockValue(SensorType::DriverThrottleIntent, 0);
WITH_ENGINE_TEST_HELPER(NISSAN_PRIMERA);
engine->needTdcCallback = false;