Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
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? | |||
7 | 1000558 | float ErrorAccumulator::accumulate(float error) { | ||
8 | // We only care about the absolute value of the error | |||
9 | 1000558 | 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 | 1000558 | float accumulationRate = error - m_ignoreError; | ||
16 | ||||
17 | 1000558 | float newIntegral = accumulationRate * m_dt + m_errorIntegral; | ||
18 | ||||
19 | // Don't allow less than 0 error | |||
20 |
2/2✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 558 times.
|
2/2✓ Decision 'true' taken 1000000 times.
✓ Decision 'false' taken 558 times.
|
1000558 | if (newIntegral < 0) { |
21 | 1000000 | newIntegral = 0; | ||
22 | } | |||
23 | ||||
24 | 1000558 | m_errorIntegral = newIntegral; | ||
25 | ||||
26 | 1000558 | return newIntegral; | ||
27 | } | |||
28 | ||||
29 | ✗ | void ErrorAccumulator::reset() { | ||
30 | ✗ | m_errorIntegral = 0; | ||
31 | ✗ | } | ||
32 |