implement `Minimum CLT` setting #6783
This commit is contained in:
parent
19003c22d2
commit
67d0923a29
|
@ -60,4 +60,5 @@ namespace engine_configuration_defaults {
|
|||
constexpr float NITROUS_LUA_GAUGE_ARMING_VALUE = 0.0f;
|
||||
|
||||
constexpr int NITROUS_MINIMUM_TPS = 0;
|
||||
constexpr uint8_t NITROUS_MINIMUM_CLT = 0;
|
||||
}
|
||||
|
|
|
@ -2,5 +2,6 @@ struct_no_prefix nitrous_control_state_s
|
|||
|
||||
bit isArmed
|
||||
bit isTpsConditionSatisfied
|
||||
bit isCltConditionSatisfied
|
||||
|
||||
end_struct
|
|
@ -11,6 +11,7 @@ void NitrousController::update() {
|
|||
if (engineConfiguration->nitrousControlEnabled) {
|
||||
updateArmingState();
|
||||
updateTpsConditionSatisfied();
|
||||
updateCltConditionSatisfied();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +41,15 @@ void NitrousController::updateTpsConditionSatisfied() {
|
|||
}
|
||||
}
|
||||
|
||||
void NitrousController::updateCltConditionSatisfied() {
|
||||
const expected<float> clt = Sensor::get(SensorType::Clt);
|
||||
if (engineConfiguration->nitrousMinimumClt != 0) {
|
||||
isCltConditionSatisfied = clt.Valid && (engineConfiguration->nitrousMinimumClt <= clt.Value);
|
||||
} else {
|
||||
isCltConditionSatisfied = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool NitrousController::checkTriggerPinState() const {
|
||||
bool result = false;
|
||||
#if !EFI_SIMULATOR
|
||||
|
|
|
@ -12,6 +12,7 @@ public:
|
|||
private:
|
||||
void updateArmingState();
|
||||
void updateTpsConditionSatisfied();
|
||||
void updateCltConditionSatisfied();
|
||||
|
||||
bool checkTriggerPinState() const;
|
||||
bool checkLuaGauge() const;
|
||||
|
|
|
@ -1785,8 +1785,9 @@ uint8_t autoscale knockFuelTrim;Fuel trim when knock, max 30%;"%", 1, 0, 0, 30,
|
|||
float nitrousLuaGaugeArmingValue;;"", 1, 0, -30000, 30000, 3
|
||||
|
||||
int nitrousMinimumTps;;"", 1, 0, 0, 20000, 0
|
||||
uint8_t nitrousMinimumClt;;"deg C", 1, 0, 0, @@CLT_UPPER_LIMIT@@, 0
|
||||
|
||||
#define END_OF_CALIBRATION_PADDING 90
|
||||
#define END_OF_CALIBRATION_PADDING 89
|
||||
uint8_t[END_OF_CALIBRATION_PADDING] unusedOftenChangesDuringFirmwareUpdate;;"units", 1, 0, 0, 1, 0
|
||||
|
||||
! end of engine_configuration_s
|
||||
|
|
|
@ -4991,6 +4991,7 @@ dialog = tcuControls, "Transmission Settings"
|
|||
|
||||
dialog = NitrousControlSettings, "Settings"
|
||||
field = "Minimum TPS", nitrousMinimumTps
|
||||
field = "Minimum CLT", nitrousMinimumClt
|
||||
|
||||
dialog = NitrousControlSettingsDialog, "", yAxis
|
||||
field = "Enable Nitrous Control", nitrousControlEnabled
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
//
|
||||
// Created by kifir on 11/28/24.
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include "util/test_base.h"
|
||||
|
||||
namespace {
|
||||
struct CltConditionTestData {
|
||||
const std::optional<float> clt;
|
||||
const bool expectedCltCondition;
|
||||
const char* const context;
|
||||
};
|
||||
|
||||
class NitrousCltConditionTest : public TestBase {
|
||||
protected:
|
||||
static constexpr uint8_t TEST_CLT = 51;
|
||||
|
||||
void checkCltCondition(const std::vector<CltConditionTestData>& testData);
|
||||
};
|
||||
|
||||
void NitrousCltConditionTest::checkCltCondition(const std::vector<CltConditionTestData>& testData) {
|
||||
for (const CltConditionTestData& item: testData) {
|
||||
updateClt(item.clt);
|
||||
EXPECT_EQ(engine->nitrousController.isCltConditionSatisfied, item.expectedCltCondition) << item.context;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(NitrousCltConditionTest, checkDefault) {
|
||||
checkCltCondition({
|
||||
{ {}, false, "default" },
|
||||
{ { 0 }, false, "0.0" },
|
||||
{ { TEST_CLT - EPS5D }, false, "TEST_CLT - EPS5D" },
|
||||
{ { TEST_CLT }, false, "TEST_CLT" },
|
||||
{ { TEST_CLT + EPS5D }, false, "TEST_CLT + EPS5D" },
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(NitrousCltConditionTest, checkDefaultWithDisabledNitrousControl) {
|
||||
setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ false }));
|
||||
checkCltCondition({
|
||||
{ {}, false, "default" },
|
||||
{ { 0.0f }, false, "0.0" },
|
||||
{ { TEST_CLT - EPS5D }, false, "TEST_CLT - EPS5D" },
|
||||
{ { TEST_CLT }, false, "TEST_CLT" },
|
||||
{ { TEST_CLT + EPS5D }, false, "TEST_CLT + EPS5D" },
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(NitrousCltConditionTest, checkDefaultWithEnabledNitrousControl) {
|
||||
setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ true }));
|
||||
checkCltCondition({
|
||||
{ {}, true, "default" },
|
||||
{ { 0.0f }, true, "0.0" },
|
||||
{ { TEST_CLT - EPS5D }, true, "TEST_CLT - EPS5D" },
|
||||
{ { TEST_CLT }, true, "TEST_CLT" },
|
||||
{ { TEST_CLT + EPS5D }, true, "TEST_CLT + EPS5D" },
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(NitrousCltConditionTest, checkZeroMinimumClt) {
|
||||
setUpEngineConfiguration(
|
||||
EngineConfig()
|
||||
.setNitrousControlEnabled({ true })
|
||||
.setNitrousMinimumClt(0)
|
||||
);
|
||||
checkCltCondition({
|
||||
{ {}, true, "default" },
|
||||
{ { 0.0f }, true, "0.0" },
|
||||
{ { TEST_CLT - EPS5D }, true, "TEST_CLT - EPS5D" },
|
||||
{ { TEST_CLT }, true, "TEST_CLT" },
|
||||
{ { TEST_CLT + EPS5D }, true, "TEST_CLT + EPS5D" },
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(NitrousCltConditionTest, checkMinimumClt) {
|
||||
setUpEngineConfiguration(
|
||||
EngineConfig()
|
||||
.setNitrousControlEnabled({ true })
|
||||
.setNitrousMinimumClt({ TEST_CLT })
|
||||
);
|
||||
checkCltCondition({
|
||||
{ {}, false, "default" },
|
||||
{ { 0.0f }, false, "0.0" },
|
||||
{ { TEST_CLT - EPS5D }, false, "TEST_CLT - EPS5D" },
|
||||
{ { TEST_CLT }, true, "TEST_CLT" },
|
||||
{ { TEST_CLT + EPS5D }, true, "TEST_CLT + EPS5D" },
|
||||
});
|
||||
}
|
||||
}
|
|
@ -73,6 +73,7 @@ TESTS_SRC_CPP = \
|
|||
tests/shift_torque_reduction/test_shift_torque_reduction_angle_advance.cpp \
|
||||
tests/nitrous_control/test_nitrous_arming.cpp \
|
||||
tests/nitrous_control/test_nitrous_tps_condition.cpp \
|
||||
tests/nitrous_control/test_nitrous_clt_condition.cpp \
|
||||
tests/test_fft.cpp \
|
||||
tests/lua/test_lua_basic.cpp \
|
||||
tests/lua/test_bit_range_msb.cpp \
|
||||
|
|
|
@ -223,3 +223,8 @@ EngineConfig EngineConfig::setNitrousMinimumTps(const std::optional<int> value)
|
|||
m_nitrousMinimumTps = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EngineConfig EngineConfig::setNitrousMinimumClt(const std::optional<uint8_t> value) {
|
||||
m_nitrousMinimumClt = value;
|
||||
return *this;
|
||||
}
|
|
@ -70,6 +70,7 @@ public:
|
|||
std::optional<float> getNitrousLuaGaugeArmingValue() const { return m_nitrousLuaGaugeArmingValue; }
|
||||
|
||||
std::optional<int> getNitrousMinimumTps() const { return m_nitrousMinimumTps; }
|
||||
std::optional<uint8_t> getNitrousMinimumClt() const { return m_nitrousMinimumClt; }
|
||||
|
||||
// We do not core about performance in tests, but we want to use builder-like style, so setters return new instance
|
||||
// of configuration:
|
||||
|
@ -129,6 +130,7 @@ public:
|
|||
EngineConfig setNitrousLuaGaugeArmingValue(std::optional<float> value);
|
||||
|
||||
EngineConfig setNitrousMinimumTps(std::optional<int> value);
|
||||
EngineConfig setNitrousMinimumClt(std::optional<uint8_t> value);
|
||||
private:
|
||||
// Launch Control
|
||||
std::optional<switch_input_pin_e> m_launchActivatePin;
|
||||
|
@ -184,6 +186,6 @@ private:
|
|||
std::optional<lua_gauge_meaning_e> m_nitrousLuaGaugeMeaning;
|
||||
std::optional<float> m_nitrousLuaGaugeArmingValue;
|
||||
|
||||
std::optional<float> m_nitrousMinimumTps;
|
||||
std::optional<int> m_nitrousMinimumTps;
|
||||
std::optional<uint8_t> m_nitrousMinimumClt;
|
||||
};
|
|
@ -88,6 +88,7 @@ void TestBase::setUpEngineConfiguration(const EngineConfig& config) {
|
|||
getTestEngineConfiguration().configureNitrousLuaGaugeArmingValue(config.getNitrousLuaGaugeArmingValue());
|
||||
|
||||
getTestEngineConfiguration().configureNitrousMinimumTps(config.getNitrousMinimumTps());
|
||||
getTestEngineConfiguration().configureNitrousMinimumClt(config.getNitrousMinimumClt());
|
||||
}
|
||||
|
||||
void TestBase::periodicFastCallback() {
|
||||
|
@ -108,6 +109,10 @@ void TestBase::updateApp(const std::optional<float> app) {
|
|||
updateSensor(SensorType::DriverThrottleIntent, app);
|
||||
}
|
||||
|
||||
void TestBase::updateClt(const std::optional<float> clt) {
|
||||
updateSensor(SensorType::Clt, clt);
|
||||
}
|
||||
|
||||
void TestBase::updateSensor(const SensorType sensor, const std::optional<float> sensorReading) {
|
||||
if (sensorReading.has_value()) {
|
||||
Sensor::setMockValue(sensor, sensorReading.value());
|
||||
|
|
|
@ -25,6 +25,7 @@ protected:
|
|||
|
||||
void updateRpm(float rpm);
|
||||
void updateApp(std::optional<float> app);
|
||||
void updateClt(std::optional<float> clt);
|
||||
|
||||
template<typename ModuleType> ModuleType& getModule();
|
||||
private:
|
||||
|
|
|
@ -488,6 +488,17 @@ void TestEngineConfiguration::configureNitrousMinimumTps(const std::optional<int
|
|||
}
|
||||
}
|
||||
|
||||
void TestEngineConfiguration::configureNitrousMinimumClt(const std::optional<uint8_t> nitrousMinimumClt) {
|
||||
if (nitrousMinimumClt.has_value()) {
|
||||
engineConfiguration->nitrousMinimumClt = nitrousMinimumClt.value();
|
||||
} else {
|
||||
ASSERT_EQ(
|
||||
engineConfiguration->nitrousMinimumClt,
|
||||
engine_configuration_defaults::NITROUS_MINIMUM_CLT
|
||||
); // check default value
|
||||
}
|
||||
}
|
||||
|
||||
TestEngineConfiguration::TestEngineConfiguration() {
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
void configureNitrousLuaGaugeArmingValue(std::optional<float> luaGaugeArmingValue);
|
||||
|
||||
void configureNitrousMinimumTps(std::optional<int> nitrousMinimumTps);
|
||||
void configureNitrousMinimumClt(std::optional<uint8_t> nitrousMinimumClt);
|
||||
private:
|
||||
TestEngineConfiguration();
|
||||
static TestEngineConfiguration instance;
|
||||
|
|
Loading…
Reference in New Issue