-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathECU.cpp
More file actions
45 lines (36 loc) · 1.17 KB
/
ECU.cpp
File metadata and controls
45 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "ECU.h"
#include <algorithm>
ECU::ECU()
: faultActive_(false)
{
}
void ECU::update(double dt, const Sensors::Readings& sensors, double currentRpm)
{
(void)dt;
double baseLoad = std::clamp(sensors.throttlePosition, 0.0, 1.0);
command_.pulseWidthMs = lookupFuelPulseWidth(currentRpm, baseLoad);
double boostCorrection = 1.0 + sensors.boostPressure * 0.05;
command_.pulseWidthMs *= boostCorrection;
command_.pulseWidthMs = std::clamp(command_.pulseWidthMs, 0.05, 8.2);
command_.targetRpm = std::clamp(800.0 + sensors.throttlePosition * 5200.0, 800.0, 6000.0);
command_.clearFaults = false;
if (sensors.coolantTemp > 118.0 || sensors.oilTemp > 140.0) {
faultActive_ = true;
command_.pulseWidthMs *= 0.75;
} else if (faultActive_ && sensors.coolantTemp < 105.0) {
faultActive_ = false;
}
unburntFuelInExhaust_ = std::clamp(((0.2 * sensors.exhaustTemp) / sensors.dieselContentPPM), 0.0, 255.0);
}
const ECU::FuelCommand& ECU::fuelCommand() const
{
return command_;
}
bool ECU::faultActive() const
{
return faultActive_;
}
double ECU::unburntFuelInExhaust() const
{
return unburntFuelInExhaust_;
}