-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirIntake.cpp
More file actions
32 lines (27 loc) · 869 Bytes
/
AirIntake.cpp
File metadata and controls
32 lines (27 loc) · 869 Bytes
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
#include "AirIntake.h"
#include "Turbocharger.h"
#include <algorithm>
AirIntake::AirIntake()
: airMassFlow_(0.0), intakeTemperature_(25.0), mafVoltage_(0.0)
{
}
void AirIntake::update(double dt, const Sensors& sensors, const Turbocharger& turbo)
{
double throttle = std::clamp(sensors.readings().throttlePosition, 0.0, 1.0);
double boostFactor = std::clamp(turbo.boostPressure(), 0.0, 2.2);
airMassFlow_ = std::clamp(0.08 * throttle * (1.0 + boostFactor * 0.4) * 1.0, 0.0, 7.0);
intakeTemperature_ += ((25.0 + boostFactor * 20.0) - intakeTemperature_) * dt * 0.5;
mafVoltage_ = std::clamp(0.5 + airMassFlow_ * 0.35, 0.5, 5.0);
}
double AirIntake::airMassFlow() const
{
return airMassFlow_;
}
double AirIntake::intakeTemperature() const
{
return intakeTemperature_;
}
double AirIntake::mafVoltage() const
{
return mafVoltage_;
}