* Add turbocharger speed converter class * Add turbocharger speed converter tests * Add turbocharger speed sensor initialization functions * Add turbocharger speed sensor to initialization Co-authored-by: alxrMironov <330OMcorporative> Co-authored-by: rusefillc <48498823+rusefillc@users.noreply.github.com>
This commit is contained in:
parent
cc0fcd32be
commit
bb341c4c07
|
@ -0,0 +1,17 @@
|
||||||
|
/**
|
||||||
|
* Frequency to RPM converter for turbocharger pin
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
#include "sensor_converter_func.h"
|
||||||
|
|
||||||
|
class TurbochargerSpeedConverter : public SensorConverter {
|
||||||
|
public:
|
||||||
|
DECLARE_ENGINE_PTR;
|
||||||
|
|
||||||
|
SensorResult convert(float frequency) const override {
|
||||||
|
auto speed = frequency * engineConfiguration->turboSpeedSensorMultiplier;
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -32,6 +32,7 @@ void initFuelLevel(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
void initBaro(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void initBaro(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
void initAuxSensors(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void initAuxSensors(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
void initVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void initVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
void initTurbochargerSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
// Sensor reconfiguration
|
// Sensor reconfiguration
|
||||||
void deinitVbatt();
|
void deinitVbatt();
|
||||||
|
@ -40,3 +41,4 @@ void deinitThermistors();
|
||||||
void reconfigureOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void reconfigureOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
void deInitFlexSensor();
|
void deInitFlexSensor();
|
||||||
void deInitVehicleSpeedSensor();
|
void deInitVehicleSpeedSensor();
|
||||||
|
void deinitTurbochargerSpeedSensor();
|
||||||
|
|
|
@ -13,3 +13,4 @@ INIT_SRC_CPP = $(PROJECT_DIR)/init/sensor/init_sensors.cpp \
|
||||||
$(PROJECT_DIR)/init/sensor/init_fuel_level.cpp \
|
$(PROJECT_DIR)/init/sensor/init_fuel_level.cpp \
|
||||||
$(PROJECT_DIR)/init/sensor/init_aux.cpp \
|
$(PROJECT_DIR)/init/sensor/init_aux.cpp \
|
||||||
$(PROJECT_DIR)/init/sensor/init_vehicle_speed_sensor.cpp \
|
$(PROJECT_DIR)/init/sensor/init_vehicle_speed_sensor.cpp \
|
||||||
|
$(PROJECT_DIR)/init/sensor/init_turbocharger_speed_sensor.cpp \
|
||||||
|
|
|
@ -64,6 +64,7 @@ void initNewSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
initBaro(PASS_CONFIG_PARAMETER_SIGNATURE);
|
initBaro(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||||
initAuxSensors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
initAuxSensors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||||
initVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
initTurbochargerSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
#if !EFI_UNIT_TEST
|
#if !EFI_UNIT_TEST
|
||||||
initFuelLevel(PASS_CONFIG_PARAMETER_SIGNATURE);
|
initFuelLevel(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||||
|
@ -84,6 +85,7 @@ void stopSensors(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||||
deinitThermistors();
|
deinitThermistors();
|
||||||
deInitFlexSensor();
|
deInitFlexSensor();
|
||||||
deInitVehicleSpeedSensor();
|
deInitVehicleSpeedSensor();
|
||||||
|
deinitTurbochargerSpeedSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
@ -94,6 +96,7 @@ void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
initThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
initThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||||
initFlexSensor(PASS_CONFIG_PARAMETER_SIGNATURE);
|
initFlexSensor(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||||
initVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
initTurbochargerSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
initOldAnalogInputs(PASS_CONFIG_PARAMETER_SIGNATURE);
|
initOldAnalogInputs(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
#include "init.h"
|
||||||
|
#include "frequency_sensor.h"
|
||||||
|
#include "turbocharger_speed_converter.h"
|
||||||
|
|
||||||
|
static FrequencySensor turbochargerSpeedSensor(SensorType::VehicleSpeed, MS2NT(500));
|
||||||
|
static TurbochargerSpeedConverter turbochargerSpeedConverter;
|
||||||
|
|
||||||
|
|
||||||
|
void initTurbochargerSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
INJECT_ENGINE_REFERENCE(&turbochargerSpeedConverter);
|
||||||
|
|
||||||
|
auto pin = CONFIG(turboSpeedSensorInputPin);
|
||||||
|
|
||||||
|
// Nothing to do if no sensor configured
|
||||||
|
if (!isBrainPinValid(pin)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
turbochargerSpeedSensor.setFunction(turbochargerSpeedConverter);
|
||||||
|
turbochargerSpeedSensor.init(pin, "tcss");
|
||||||
|
turbochargerSpeedSensor.Register();
|
||||||
|
}
|
||||||
|
|
||||||
|
void deinitTurbochargerSpeedSensor() {
|
||||||
|
turbochargerSpeedSensor.deInit();
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
#include "pch.h"
|
||||||
|
#include "turbocharger_speed_converter.h"
|
||||||
|
|
||||||
|
static constexpr engine_type_e ENGINE_TEST_HELPER = TEST_ENGINE;
|
||||||
|
|
||||||
|
class TurbochargerSpeedConverterTest : public ::testing::Test {
|
||||||
|
|
||||||
|
public:
|
||||||
|
TurbochargerSpeedConverter dut;
|
||||||
|
|
||||||
|
TurbochargerSpeedConverterTest(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetUp() override {
|
||||||
|
WITH_ENGINE_TEST_HELPER(ENGINE_TEST_HELPER);
|
||||||
|
INJECT_ENGINE_REFERENCE(&dut);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCoef(float new_coef) {
|
||||||
|
dut.engineConfiguration->turboSpeedSensorMultiplier = new_coef;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetFrequencyBySpeedAndCoef(float speed, float coef) {
|
||||||
|
return (speed / coef);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestForSpeedWithCoef(float expectedSpeed, float coef)
|
||||||
|
{
|
||||||
|
SetCoef(coef);
|
||||||
|
auto inputFreq = GetFrequencyBySpeedAndCoef(expectedSpeed, coef);
|
||||||
|
auto result = dut.convert(inputFreq);
|
||||||
|
ASSERT_TRUE(result.Valid);
|
||||||
|
ASSERT_NEAR(expectedSpeed, result.Value, 0.01f);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Converter must return valid and expected result for setted coef
|
||||||
|
*/
|
||||||
|
TEST_F(TurbochargerSpeedConverterTest, returnExpectedResultForSettedCoef) {
|
||||||
|
|
||||||
|
TestForSpeedWithCoef(0.0f, 0.5f);
|
||||||
|
TestForSpeedWithCoef(0.5f, 0.5f);
|
||||||
|
TestForSpeedWithCoef(10.0f, 0.5f);
|
||||||
|
TestForSpeedWithCoef(0.0f, 10.0f);
|
||||||
|
TestForSpeedWithCoef(0.5f, 10.0f);
|
||||||
|
TestForSpeedWithCoef(10.0f, 10.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Converter must always return strong float zero if coef == 0.0f
|
||||||
|
*/
|
||||||
|
TEST_F(TurbochargerSpeedConverterTest, zeroCoefReturnsZeroSpeedOnAnyInput) {
|
||||||
|
|
||||||
|
SetCoef(0.0f);
|
||||||
|
|
||||||
|
{
|
||||||
|
auto result = dut.convert(0.0f);
|
||||||
|
ASSERT_TRUE(result.Valid);
|
||||||
|
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto result = dut.convert(0.5f);
|
||||||
|
ASSERT_TRUE(result.Valid);
|
||||||
|
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto result = dut.convert(10.0f);
|
||||||
|
ASSERT_TRUE(result.Valid);
|
||||||
|
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -85,6 +85,8 @@ TESTS_SRC_CPP = \
|
||||||
tests/trigger/test_all_triggers.cpp \
|
tests/trigger/test_all_triggers.cpp \
|
||||||
tests/test_stepper.cpp \
|
tests/test_stepper.cpp \
|
||||||
tests/sensor/test_frequency_sensor.cpp \
|
tests/sensor/test_frequency_sensor.cpp \
|
||||||
|
tests/sensor/test_turbocharger_speed_converter.cpp \
|
||||||
tests/sensor/test_vehicle_speed_converter.cpp
|
tests/sensor/test_vehicle_speed_converter.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue