rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
redundant_ford_tps.cpp
Go to the documentation of this file.
1#include "pch.h"
2
4
6 : Sensor(outputType)
7 , m_first(first)
8 , m_second(second)
9{
10}
11
12void RedundantFordTps::configure(float maxDifference, float secondaryMaximum) {
13 m_maxDifference = maxDifference;
14 m_secondaryMaximum = secondaryMaximum;
15}
16
18 // Sensor 1 is "plain linear" and has the full range
19 auto tps1 = Sensor::get(m_first);
20
21 // Sensor 2 is compressed in to 0 -> 50%
23
24 // If either result is invalid, return invalid.
25 if (!tps1 || !tps2) {
26 return UnexpectedCode::Inconsistent;
27 }
28
29 // The "actual" position resolved by the second throttle - this tops out at m_secondaryMaximum instead of 100%
30 float tps2Actual = tps2.Value * m_secondaryMaximum / 100;
31
32 // Switch modes slightly below the maximum of the secondary, to avoid misbehavior near 100%
33 float avgThreshold = m_secondaryMaximum * 0.9f;
34
35 // Case 1: both sensors show low position, average result
36 if (tps1.Value < avgThreshold && tps2Actual < avgThreshold) {
37 // Check that the resolved positions are close
38 float delta = absF(tps1.Value - tps2Actual);
39 if (delta > m_maxDifference) {
40 return UnexpectedCode::Inconsistent;
41 }
42
43 return (tps1.Value + tps2Actual) / 2;
44 }
45
46 // Case 2: both sensors show high position, return "full scale" sensor's position
47 if (tps1.Value > avgThreshold && tps2Actual > (avgThreshold - 3)) {
48 return tps1;
49 }
50
51 // Any other condition indicates an mismatch, and therefore an error
52 return UnexpectedCode::Inconsistent;
53}
SensorResult get() const override
const SensorType m_first
const SensorType m_second
RedundantFordTps(SensorType outputType, SensorType firstSensor, SensorType secondSensor)
void configure(float maxDifference, float secondaryMaximum)
virtual SensorResult get() const =0
static RedundantPair tps2(tps2p, tps2s, SensorType::Tps2)
expected< float > SensorResult
Definition sensor.h:46
SensorType
Definition sensor_type.h:18