Proxy sensor for extra magic (#1210)

* proxy sensor

* header
This commit is contained in:
Matthew Kennedy 2020-03-22 14:29:01 -07:00 committed by GitHub
parent 21b1bc9612
commit f587b9f555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/**
* @file proxy_sensor.h
* @brief A sensor to duplicate a sensor to an additional SensorType.
*
* This was built for the use case of "driver throttle intent" where we care what the driver's
* right foot is doing, but that might mean TPS (cable throttle) or pedal (electronic throttle).
*
* @date March 22, 2020
* @author Matthew Kennedy, (c) 2019
*/
#pragma once
#include "sensor.h"
class ProxySensor final : public Sensor {
public:
explicit ProxySensor(SensorType type) : Sensor(type) {}
void setProxiedSensor(SensorType proxiedSensor) {
m_proxiedSensor = proxiedSensor;
}
private:
SensorResult get() const {
return Sensor::get(m_proxiedSensor);
}
SensorType m_proxiedSensor = SensorType::Invalid;
};

View File

@ -37,6 +37,9 @@ enum class SensorType : unsigned char {
AcceleratorPedalPrimary,
AcceleratorPedalSecondary,
// This maps to the pedal if we have one, and Tps1 if not.
DriverThrottleIntent,
// Leave me at the end!
PlaceholderLast
};

View File

@ -3,6 +3,7 @@
#include "error_handling.h"
#include "global.h"
#include "functional_sensor.h"
#include "proxy_sensor.h"
#include "linear_func.h"
#include "tps.h"
@ -21,6 +22,9 @@ FunctionalSensor tpsSens2p(SensorType::Tps2, MS2NT(10));
LinearFunc pedalFunc;
FunctionalSensor pedalSensor(SensorType::AcceleratorPedal, MS2NT(10));
// This sensor indicates the driver's throttle intent - Pedal if we have one, TPS if not.
ProxySensor driverIntent(SensorType::DriverThrottleIntent);
static void configureTps(LinearFunc& func, float closed, float open) {
func.configure(
closed, 0,
@ -51,6 +55,13 @@ void initTps() {
initTpsFunc(tpsFunc1p, tpsSens1p, CONFIG(tps1_1AdcChannel), CONFIG(tpsMin), CONFIG(tpsMax));
initTpsFunc(tpsFunc2p, tpsSens2p, CONFIG(tps2_1AdcChannel), CONFIG(tps2Min), CONFIG(tps2Max));
initTpsFunc(pedalFunc, pedalSensor, CONFIG(throttlePedalPositionAdcChannel), CONFIG(throttlePedalUpVoltage), CONFIG(throttlePedalWOTVoltage));
// Route the pedal or TPS to driverIntent as appropriate
if (CONFIG(throttlePedalPositionAdcChannel) != EFI_ADC_NONE) {
driverIntent.setProxiedSensor(SensorType::AcceleratorPedal);
} else {
driverIntent.setProxiedSensor(SensorType::Tps1);
}
}
void reconfigureTps() {