rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
deadband.h
Go to the documentation of this file.
1/**
2 * @file deadband.h
3 *
4 * @date April 6, 2020
5 * @author Matthew Kennedy, (c) 2020
6 */
7
8#pragma once
9
10#include "efilib.h"
11
12template <int TDeadband>
13class Deadband {
14public:
15 bool gt(float lhs, float rhs) {
16 // If we're within the deadband, be "sticky" with the previous value
17 float absError = std::abs(lhs - rhs);
18
19 // If there's enough error, actually compare values
20 if (absError > TDeadband) {
21 m_lastState = lhs > rhs;
22 }
23
24 return m_lastState;
25 }
26
27 // Deadband has no concept of equal - only greater and less, so to compute gt, we just swap args
28 bool lt(float lhs, float rhs) {
29 return gt(rhs, lhs);
30 }
31
32private:
33 bool m_lastState =false;
34};
bool m_lastState
Definition deadband.h:33
bool gt(float lhs, float rhs)
Definition deadband.h:15
bool lt(float lhs, float rhs)
Definition deadband.h:28