2020-02-03 22:54:05 -08:00
|
|
|
#include "adc_subscription.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "error_handling.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "functional_sensor.h"
|
2020-05-18 11:32:00 -07:00
|
|
|
#include "redundant_sensor.h"
|
2020-03-22 14:29:01 -07:00
|
|
|
#include "proxy_sensor.h"
|
2020-02-03 22:54:05 -08:00
|
|
|
#include "linear_func.h"
|
|
|
|
#include "tps.h"
|
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
2020-03-22 14:09:46 -07:00
|
|
|
LinearFunc tpsFunc1p(TPS_TS_CONVERSION);
|
2020-05-18 11:32:00 -07:00
|
|
|
LinearFunc tpsFunc1s(TPS_TS_CONVERSION);
|
2020-03-22 14:09:46 -07:00
|
|
|
LinearFunc tpsFunc2p(TPS_TS_CONVERSION);
|
2020-05-18 11:32:00 -07:00
|
|
|
LinearFunc tpsFunc2s(TPS_TS_CONVERSION);
|
2020-02-03 22:54:05 -08:00
|
|
|
|
2020-05-18 11:32:00 -07:00
|
|
|
FunctionalSensor tpsSens1p(SensorType::Tps1Primary, MS2NT(10));
|
|
|
|
FunctionalSensor tpsSens1s(SensorType::Tps1Secondary, MS2NT(10));
|
|
|
|
FunctionalSensor tpsSens2p(SensorType::Tps2Primary, MS2NT(10));
|
|
|
|
FunctionalSensor tpsSens2s(SensorType::Tps2Secondary, MS2NT(10));
|
|
|
|
|
|
|
|
RedundantSensor tps1(SensorType::Tps1, SensorType::Tps1Primary, SensorType::Tps1Secondary);
|
|
|
|
RedundantSensor tps2(SensorType::Tps2, SensorType::Tps2Primary, SensorType::Tps2Secondary);
|
2020-02-03 22:54:05 -08:00
|
|
|
|
2020-05-23 16:48:32 -07:00
|
|
|
LinearFunc pedalFuncPrimary;
|
|
|
|
LinearFunc pedalFuncSecondary;
|
|
|
|
FunctionalSensor pedalSensorPrimary(SensorType::AcceleratorPedalPrimary, MS2NT(10));
|
|
|
|
FunctionalSensor pedalSensorSecondary(SensorType::AcceleratorPedalSecondary, MS2NT(10));
|
|
|
|
|
|
|
|
RedundantSensor pedal(SensorType::AcceleratorPedal, SensorType::AcceleratorPedalPrimary, SensorType::AcceleratorPedalSecondary);
|
2020-03-22 14:09:46 -07:00
|
|
|
|
2020-03-22 14:29:01 -07:00
|
|
|
// This sensor indicates the driver's throttle intent - Pedal if we have one, TPS if not.
|
|
|
|
ProxySensor driverIntent(SensorType::DriverThrottleIntent);
|
|
|
|
|
2020-04-05 06:10:08 -07:00
|
|
|
static void configureTps(LinearFunc& func, float closed, float open, float min, float max) {
|
2020-02-03 22:54:05 -08:00
|
|
|
func.configure(
|
2020-03-22 14:09:46 -07:00
|
|
|
closed, 0,
|
|
|
|
open, 100,
|
2020-04-05 06:10:08 -07:00
|
|
|
min, max
|
2020-02-03 22:54:05 -08:00
|
|
|
);
|
2020-02-08 01:22:23 -08:00
|
|
|
}
|
|
|
|
|
2020-05-18 11:32:00 -07:00
|
|
|
static bool initTpsFunc(LinearFunc& func, FunctionalSensor& sensor, adc_channel_e channel, float closed, float open, float min, float max) {
|
2020-02-08 01:22:23 -08:00
|
|
|
// Only register if we have a sensor
|
|
|
|
if (channel == EFI_ADC_NONE) {
|
2020-05-18 11:32:00 -07:00
|
|
|
return false;
|
2020-02-08 01:22:23 -08:00
|
|
|
}
|
|
|
|
|
2020-04-05 06:10:08 -07:00
|
|
|
configureTps(func, closed, open, min, max);
|
2020-02-03 22:54:05 -08:00
|
|
|
|
|
|
|
sensor.setFunction(func);
|
|
|
|
|
|
|
|
AdcSubscription::SubscribeSensor(sensor, channel);
|
|
|
|
|
|
|
|
if (!sensor.Register()) {
|
2020-04-02 05:02:44 -07:00
|
|
|
firmwareError(CUSTOM_INVALID_TPS_SETTING, "Duplicate registration for sensor \"%s\"", sensor.getSensorName());
|
2020-05-18 11:32:00 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initTpsFuncAndRedund(RedundantSensor& redund, LinearFunc& func, FunctionalSensor& sensor, adc_channel_e channel, float closed, float open, float min, float max) {
|
|
|
|
bool hasSecond = initTpsFunc(func, sensor, channel, closed, open, min, max);
|
|
|
|
|
|
|
|
redund.configure(5.0f, !hasSecond);
|
|
|
|
|
|
|
|
if (!redund.Register()) {
|
|
|
|
firmwareError(CUSTOM_INVALID_TPS_SETTING, "Duplicate registration for sensor \"%s\"", redund.getSensorName());
|
2020-02-03 22:54:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 06:10:08 -07:00
|
|
|
void initTps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|
|
|
float min = CONFIG(tpsErrorDetectionTooLow);
|
|
|
|
float max = CONFIG(tpsErrorDetectionTooHigh);
|
|
|
|
|
|
|
|
initTpsFunc(tpsFunc1p, tpsSens1p, CONFIG(tps1_1AdcChannel), CONFIG(tpsMin), CONFIG(tpsMax), min, max);
|
2020-05-18 11:32:00 -07:00
|
|
|
initTpsFuncAndRedund(tps1, tpsFunc1s, tpsSens1s, CONFIG(tps1_2AdcChannel), CONFIG(tps1SecondaryMin), CONFIG(tps1SecondaryMax), min, max);
|
2020-04-05 06:10:08 -07:00
|
|
|
initTpsFunc(tpsFunc2p, tpsSens2p, CONFIG(tps2_1AdcChannel), CONFIG(tps2Min), CONFIG(tps2Max), min, max);
|
2020-05-18 11:32:00 -07:00
|
|
|
initTpsFuncAndRedund(tps2, tpsFunc2s, tpsSens2s, CONFIG(tps2_2AdcChannel), CONFIG(tps2SecondaryMin), CONFIG(tps2SecondaryMax), min, max);
|
2020-05-23 16:48:32 -07:00
|
|
|
initTpsFunc(pedalFuncPrimary, pedalSensorPrimary, CONFIG(throttlePedalPositionAdcChannel), CONFIG(throttlePedalUpVoltage), CONFIG(throttlePedalWOTVoltage), min, max);
|
|
|
|
initTpsFuncAndRedund(pedal, pedalFuncSecondary, pedalSensorSecondary, CONFIG(throttlePedalPositionSecondAdcChannel), CONFIG(throttlePedalSecondaryUpVoltage), CONFIG(throttlePedalSecondaryWOTVoltage), min, max);
|
2020-03-22 14:29:01 -07:00
|
|
|
|
|
|
|
// Route the pedal or TPS to driverIntent as appropriate
|
|
|
|
if (CONFIG(throttlePedalPositionAdcChannel) != EFI_ADC_NONE) {
|
|
|
|
driverIntent.setProxiedSensor(SensorType::AcceleratorPedal);
|
|
|
|
} else {
|
|
|
|
driverIntent.setProxiedSensor(SensorType::Tps1);
|
|
|
|
}
|
2020-04-01 17:21:03 -07:00
|
|
|
|
|
|
|
if (!driverIntent.Register()) {
|
2020-04-02 05:02:44 -07:00
|
|
|
firmwareError(CUSTOM_INVALID_TPS_SETTING, "Duplicate registration for driver acc intent sensor");
|
2020-04-01 17:21:03 -07:00
|
|
|
}
|
2020-02-03 22:54:05 -08:00
|
|
|
}
|
2020-02-08 01:22:23 -08:00
|
|
|
|
2020-04-05 06:10:08 -07:00
|
|
|
void reconfigureTps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|
|
|
float min = CONFIG(tpsErrorDetectionTooLow);
|
|
|
|
float max = CONFIG(tpsErrorDetectionTooHigh);
|
|
|
|
|
|
|
|
configureTps(tpsFunc1p, CONFIG(tpsMin), CONFIG(tpsMax), min, max);
|
2020-05-18 11:32:00 -07:00
|
|
|
configureTps(tpsFunc1s, CONFIG(tps1SecondaryMin), CONFIG(tps1SecondaryMax), min, max);
|
2020-04-05 06:10:08 -07:00
|
|
|
configureTps(tpsFunc2p, CONFIG(tps2Min), CONFIG(tps2Max), min, max);
|
2020-05-18 11:32:00 -07:00
|
|
|
configureTps(tpsFunc2s, CONFIG(tps2SecondaryMin), CONFIG(tps2SecondaryMax), min, max);
|
|
|
|
|
2020-05-23 16:48:32 -07:00
|
|
|
configureTps(pedalFuncPrimary, CONFIG(throttlePedalUpVoltage), CONFIG(throttlePedalWOTVoltage), min, max);
|
|
|
|
configureTps(pedalFuncSecondary, CONFIG(throttlePedalSecondaryUpVoltage), CONFIG(throttlePedalSecondaryWOTVoltage), min, max);
|
2020-02-08 01:22:23 -08:00
|
|
|
}
|