Fully switch acc pedal to new sensors (#1212)

* proxy sensor

* header

* idle

* can

* settings

* remove old mocking

* remove old impl

* etb

* oops, gotta actually register it

* fix test

* structured bindings ftw!

* driver intent for stepper

* tear out old

* oops too much
This commit is contained in:
Matthew Kennedy 2020-04-01 17:21:03 -07:00 committed by GitHub
parent 26f1ff996b
commit 50cd6549a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 79 deletions

View File

@ -76,6 +76,7 @@
#include "electronic_throttle.h"
#include "tps.h"
#include "sensor.h"
#include "io_pins.h"
#include "engine_configuration.h"
#include "pwm_generator_logic.h"
@ -108,8 +109,6 @@ static bool startupPositionError = false;
#define STARTUP_NEUTRAL_POSITION_ERROR_THRESHOLD 5
extern percent_t mockPedalPosition;
static percent_t directPwmValue = NAN;
static percent_t currentEtbDuty;
@ -180,6 +179,14 @@ void EtbController::PeriodicTask() {
return;
}
auto pedalPosition = Sensor::get(SensorType::AcceleratorPedal);
if (!pedalPosition.Valid) {
m_motor->set(0);
return;
}
percent_t actualThrottlePosition = getTPSWithIndex(m_myIndex PASS_ENGINE_PARAMETER_SUFFIX);
if (engine->etbAutoTune) {
@ -203,10 +210,8 @@ void EtbController::PeriodicTask() {
}
percent_t pedalPosition = getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE);
int rpm = GET_RPM();
engine->engineState.targetFromTable = pedal2tpsMap.getValue(rpm / RPM_1_BYTE_PACKING_MULT, pedalPosition);
engine->engineState.targetFromTable = pedal2tpsMap.getValue(rpm / RPM_1_BYTE_PACKING_MULT, pedalPosition.Value);
percent_t etbIdleAddition = CONFIG(useETBforIdleControl) ? engine->engineState.idle.etbIdleAddition : 0;
percent_t targetPosition = engine->engineState.targetFromTable + etbIdleAddition;
@ -305,12 +310,6 @@ static void showEthInfo(void) {
scheduleMsg(&logger, "etbAutoTune=%d",
engine->etbAutoTune);
scheduleMsg(&logger, "throttlePedal=%.2f %.2f/%.2f @%s",
getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE),
engineConfiguration->throttlePedalUpVoltage,
engineConfiguration->throttlePedalWOTVoltage,
getPinNameByAdcChannel("tPedal", engineConfiguration->throttlePedalPositionAdcChannel, pinNameBuffer));
scheduleMsg(&logger, "TPS=%.2f", getTPS(PASS_ENGINE_PARAMETER_SIGNATURE));
@ -371,8 +370,6 @@ static void etbReset() {
}
etbPidReset();
mockPedalPosition = MOCK_UNDEFINED;
}
#endif /* EFI_PROD_CODE */

View File

@ -39,6 +39,7 @@
#include "engine.h"
#include "periodic_task.h"
#include "allsensors.h"
#include "sensor.h"
#if ! EFI_UNIT_TEST
#include "stepper.h"
@ -217,15 +218,14 @@ static bool isOutOfAutomaticIdleCondition(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return !engine->engineState.idle.throttlePedalUpState;
}
percent_t inputPosition;
const auto [valid, pos] = Sensor::get(SensorType::DriverThrottleIntent);
if (hasPedalPositionSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
inputPosition = getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE);
} else {
inputPosition = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
// Disable auto idle in case of TPS/Pedal failure
if (!valid) {
return true;
}
return inputPosition > CONFIG(idlePidDeactivationTpsThreshold);
return pos > CONFIG(idlePidDeactivationTpsThreshold);
}
/**

View File

@ -27,7 +27,6 @@ static void printPacket(const CANRxFrame& rx, Logging* logger) {
}
volatile float aemXSeriesLambda = 0;
volatile float canPedal = 0;
volatile float canMap = 0;
static CanSensorBase* s_head = nullptr;
@ -58,9 +57,6 @@ void processCanRxMessage(const CANRxFrame& frame, Logging* logger, efitick_t now
// AEM x-series lambda sensor reports in 0.0001 lambda per bit
uint16_t lambdaInt = SWAP_UINT16(frame.data16[0]);
aemXSeriesLambda = 0.0001f * lambdaInt;
} else if (frame.EID == CONFIG(verboseCanBaseAddress) + CAN_PEDAL_TPS_OFFSET) {
int16_t pedalScaled = *reinterpret_cast<const int16_t*>(&frame.data8[0]);
canPedal = pedalScaled / (1.0 * PACK_MULT_PERCENT);
} else if (frame.EID == CONFIG(verboseCanBaseAddress) + CAN_SENSOR_1_OFFSET) {
int16_t mapScaled = *reinterpret_cast<const int16_t*>(&frame.data8[0]);
canMap = mapScaled / (1.0 * PACK_MULT_PRESSURE);

View File

@ -81,7 +81,7 @@ struct PedalAndTps {
static void populateFrame(PedalAndTps& msg)
{
msg.pedal = getPedalPosition();
msg.pedal = Sensor::get(SensorType::AcceleratorPedal).value_or(-1);
msg.tps1 = Sensor::get(SensorType::Tps1).value_or(-1);
msg.tps2 = Sensor::get(SensorType::Tps2).value_or(-1);
}

View File

@ -28,7 +28,6 @@ void setMockVBattVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockMapVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
// throttle body sensor
void setMockThrottlePositionSensorVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockThrottlePedalSensorVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockAfrVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockMafVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockIatVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -48,10 +48,6 @@ void setMockAfrVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) {
setMockVoltage(engineConfiguration->afr.hwChannel, voltage PASS_ENGINE_PARAMETER_SUFFIX);
}
void setMockThrottlePedalSensorVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) {
setMockVoltage(engineConfiguration->throttlePedalPositionAdcChannel, voltage PASS_ENGINE_PARAMETER_SUFFIX);
}
void setMockThrottlePositionSensorVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) {
setMockVoltage(engineConfiguration->tps1_1AdcChannel, voltage PASS_ENGINE_PARAMETER_SUFFIX);
}

View File

@ -11,12 +11,6 @@
EXTERN_ENGINE;
/**
* set mock_pedal_position X
* See also directPwmValue
*/
percent_t mockPedalPosition = MOCK_UNDEFINED;
#if !EFI_PROD_CODE
/**
* this allows unit tests to simulate TPS position
@ -30,11 +24,6 @@ void setMockTpsValue(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX) {
}
#endif /* EFI_PROD_CODE */
// see also setMockThrottlePedalSensorVoltage
void setMockThrottlePedalPosition(percent_t value DECLARE_ENGINE_PARAMETER_SUFFIX) {
mockPedalPosition = value;
}
/**
* We are using one instance for read and another for modification, this is how we get lock-free thread-safety
*
@ -214,33 +203,6 @@ bool hasSecondThrottleBody(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engineConfiguration->tps2_1AdcChannel != EFI_ADC_NONE;
}
extern float canPedal;
percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_CANBUS_SLAVE
return canPedal;
#endif
if (mockPedalPosition != MOCK_UNDEFINED) {
return mockPedalPosition;
}
// Don't choke without a pedal set
if (CONFIG(throttlePedalPositionAdcChannel) == EFI_ADC_NONE) {
return 0;
}
DISPLAY_TAG(PEDAL_SECTION);
DISPLAY_TEXT(Analog_MCU_reads);
float voltage = getVoltageDivided("pPS", CONFIG(DISPLAY_CONFIG(throttlePedalPositionAdcChannel)) PASS_ENGINE_PARAMETER_SUFFIX);
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));
}
static bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engineConfiguration->tps1_1AdcChannel != EFI_ADC_NONE;
}

View File

@ -16,7 +16,6 @@
#define TPS_TS_CONVERSION 200
bool hasPedalPositionSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_SIGNATURE);
/**
* Throttle Position Sensor
* In case of dual TPS this function would return logical TPS position
@ -29,7 +28,6 @@ bool hasSecondThrottleBody(DECLARE_ENGINE_PARAMETER_SIGNATURE);
percent_t getTpsValue(int index, float adc DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockTpsAdc(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockTpsValue(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX);
void setMockThrottlePedalPosition(percent_t value DECLARE_ENGINE_PARAMETER_SUFFIX);
void grabTPSIsClosed();
void grabTPSIsWideOpen();
void grabPedalIsUp();

View File

@ -1177,8 +1177,6 @@ const command_f_s commandsF[] = {
#if EFI_ENGINE_CONTROL
#if EFI_ENABLE_MOCK_ADC
{MOCK_IAT_COMMAND, setMockIatVoltage},
{MOCK_PPS_POSITION_COMMAND, setMockThrottlePedalPosition},
{MOCK_PPS_VOLTAGE_COMMAND, setMockThrottlePedalSensorVoltage},
{MOCK_TPS_COMMAND, setMockThrottlePositionSensorVoltage},
{MOCK_MAF_COMMAND, setMockMafVoltage},
{MOCK_AFR_COMMAND, setMockAfrVoltage},

View File

@ -13,9 +13,9 @@
#if EFI_PROD_CODE || EFI_SIMULATOR
#include "stepper.h"
#include "pin_repository.h"
#include "tps.h"
#include "engine_controller.h"
#include "adc_inputs.h"
#include "sensor.h"
EXTERN_ENGINE;
@ -55,10 +55,11 @@ void StepperMotor::ThreadTask() {
bool isRunning = false;
#endif /* EFI_SHAFT_POSITION_INPUT */
// now check if stepper motor re-initialization is requested - if the throttle pedal is pressed at startup
bool forceStepperParking = !isRunning && getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > STEPPER_PARKING_TPS;
auto tpsPos = Sensor::get(SensorType::DriverThrottleIntent).value_or(0);
bool forceStepperParking = !isRunning && tpsPos > STEPPER_PARKING_TPS;
if (CONFIG(stepperForceParkingEveryRestart))
forceStepperParking = true;
scheduleMsg(logger, "Stepper: savedStepperPos=%d forceStepperParking=%d (tps=%.2f)", m_currentPosition, (forceStepperParking ? 1 : 0), getTPS(PASS_ENGINE_PARAMETER_SIGNATURE));
scheduleMsg(logger, "Stepper: savedStepperPos=%d forceStepperParking=%d (tps=%.2f)", m_currentPosition, (forceStepperParking ? 1 : 0), tpsPos);
if (m_currentPosition < 0 || forceStepperParking) {
// reset saved value

View File

@ -62,6 +62,10 @@ void initTps() {
} else {
driverIntent.setProxiedSensor(SensorType::Tps1);
}
if (!driverIntent.Register()) {
firmwareError(CUSTOM_INVALID_TPS_SETTING, "Duplicate TPS registration for TPS sensor");
}
}
void reconfigureTps() {

View File

@ -9,7 +9,7 @@
#include "electronic_throttle.h"
#include "dc_motor.h"
#include "engine_controller.h"
#include "tps.h"
#include "sensor.h"
class MockEtb : public IEtbController {
public:
@ -75,16 +75,15 @@ TEST(etb, testTargetTpsIsFloatBug945) {
engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_0;
setMockThrottlePedalSensorVoltage(3 PASS_ENGINE_PARAMETER_SUFFIX);
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f);
engine->etbControllers[0]->PeriodicTask();
ASSERT_NEAR(50, engine->engineState.targetFromTable, EPS4D);
setMockThrottlePedalSensorVoltage(3.05 PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_NEAR(50.8302, getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE), EPS4D);
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.8302f);
engine->etbControllers[0]->PeriodicTask();
ASSERT_NEAR(50.8302, engine->engineState.targetFromTable, EPS4D);
setMockThrottlePedalSensorVoltage(3.1 PASS_ENGINE_PARAMETER_SUFFIX);
Sensor::setMockValue(SensorType::AcceleratorPedal, 51.6605f);
engine->etbControllers[0]->PeriodicTask();
ASSERT_NEAR(51.6605, engine->engineState.targetFromTable, EPS4D);
}