rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
error_accumulator.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "error_accumulator.h"
4
5// todo: shall we rename to StatsIntegrator or SomethingIntegrator assuming we see not "Error Accumulator" usages?
6// todo: ValueIntegrator maybe?
7float ErrorAccumulator::accumulate(float error) {
8 // We only care about the absolute value of the error
9 error = absF(error);
10
11 // If m_ignoreError is 5, for example:
12 // 0 error -> bleeds down at 5 per second
13 // 5 error -> integral stays where it is
14 // 10 error -> integral grows at 5 per second
15 float accumulationRate = error - m_ignoreError;
16
17 float newIntegral = accumulationRate * m_dt + m_errorIntegral;
18
19 // Don't allow less than 0 error
20 if (newIntegral < 0) {
21 newIntegral = 0;
22 }
23
24 m_errorIntegral = newIntegral;
25
26 return newIntegral;
27}
28
float accumulate(float error)