rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
controllers
sensors
redundant_sensor.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
3
#include "
redundant_sensor.h
"
4
5
RedundantSensor::RedundantSensor
(
SensorType
outputType,
SensorType
first,
SensorType
second)
6
:
Sensor
(outputType)
7
, m_first(first)
8
, m_second(second)
9
{
10
}
11
12
void
RedundantSensor::configure
(
float
/*split threshold*/
maxDifference,
bool
ignoreSecondSensor) {
13
m_maxDifference
= maxDifference;
14
m_ignoreSecond
= ignoreSecondSensor;
15
}
16
17
SensorResult
RedundantSensor::get
()
const
{
18
auto
sensor1 =
Sensor::get
(
m_first
);
19
20
// If we're set to disable redundancy, just pass thru the first sensor
21
if
(
m_ignoreSecond
) {
22
return
sensor1;
23
}
24
25
auto
sensor2 =
Sensor::get
(
m_second
);
26
27
// If either result is invalid, return invalid.
28
if
(!sensor1.Valid || !sensor2.Valid) {
29
return
UnexpectedCode::Inconsistent;
30
}
31
32
// If both are valid, check that they're near one another
33
float
delta = absF(sensor1.Value - sensor2.Value);
34
if
(delta >
m_maxDifference
) {
35
return
UnexpectedCode::Inconsistent;
36
}
37
38
// Both sensors are valid, and their readings are close. All is well.
39
// Return the average
40
return
(sensor1.Value + sensor2.Value) / 2;
41
}
RedundantSensor::m_first
const SensorType m_first
Definition
redundant_sensor.h:27
RedundantSensor::configure
void configure(float maxDifference, bool ignoreSecondSensor)
Definition
redundant_sensor.cpp:12
RedundantSensor::get
SensorResult get() const override
Definition
redundant_sensor.cpp:17
RedundantSensor::m_second
const SensorType m_second
Definition
redundant_sensor.h:28
RedundantSensor::RedundantSensor
RedundantSensor(SensorType outputType, SensorType firstSensor, SensorType secondSensor)
Definition
redundant_sensor.cpp:5
RedundantSensor::m_maxDifference
float m_maxDifference
Definition
redundant_sensor.h:31
RedundantSensor::m_ignoreSecond
bool m_ignoreSecond
Definition
redundant_sensor.h:34
Sensor
Definition
sensor.h:51
Sensor::get
virtual SensorResult get() const =0
pch.h
redundant_sensor.h
SensorResult
expected< float > SensorResult
Definition
sensor.h:46
SensorType
SensorType
Definition
sensor_type.h:18
Generated on Sat Sep 27 2025 00:10:06 for rusEFI by
1.9.8