rusefi-1/unit_tests/tests/test_sensors.cpp

86 lines
2.2 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file test_sensors.cpp
*
* @date Dec 7, 2013
2018-01-20 17:42:19 -08:00
* @author Andrey Belomutskiy, (c) 2012-2018
2015-07-10 06:01:56 -07:00
*/
2018-09-16 19:39:46 -07:00
#include "global.h"
2015-07-10 06:01:56 -07:00
#include "thermistors.h"
#include "allsensors.h"
#include "engine_test_helper.h"
2015-07-10 06:01:56 -07:00
2019-01-08 19:10:54 -08:00
TEST(sensors, mapDecoding) {
2019-01-19 17:42:29 -08:00
WITH_ENGINE_TEST_HELPER(FORD_INLINE_6_1995);
2015-07-10 06:01:56 -07:00
air_pressure_sensor_config_s s;
s.type = MT_DENSO183;
2017-05-15 20:28:49 -07:00
assertEqualsM("denso 0 volts", -6.64, decodePressure(0, &s PASS_ENGINE_PARAMETER_SUFFIX));
2019-01-14 15:20:20 -08:00
ASSERT_FLOAT_EQ(31.244, decodePressure(1, &s PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
s.type = MT_MPX4250;
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 8, decodePressure(0, &s PASS_ENGINE_PARAMETER_SUFFIX)) << "MPX_4250 0 volts";
2019-01-14 15:20:20 -08:00
ASSERT_FLOAT_EQ(58.4, decodePressure(1, &s PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
}
2019-01-08 19:10:54 -08:00
TEST(sensors, tps) {
2015-07-10 06:01:56 -07:00
print("************************************************** testTps\r\n");
2019-01-19 17:42:29 -08:00
WITH_ENGINE_TEST_HELPER(DODGE_RAM);
2015-07-10 06:01:56 -07:00
2016-06-16 21:01:42 -07:00
engineConfiguration->tpsMax = 193;
engineConfiguration->tpsMin = 43;
2015-07-10 06:01:56 -07:00
2019-12-09 21:07:46 -08:00
ASSERT_NEAR(49.3333, getTpsValue(0, 4 * 117 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D);
2015-07-10 06:01:56 -07:00
2016-06-16 21:01:42 -07:00
engineConfiguration->tpsMax = 43;
engineConfiguration->tpsMin = 193;
2019-12-09 21:07:46 -08:00
assertEqualsM("test#2", 50.6667, getTpsValue(0, 4 * 117 PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
}
2019-01-14 12:31:56 -08:00
TEST(sensors, testTpsRateOfChange) {
2015-07-10 06:01:56 -07:00
print("************************************************** testTpsRateOfChange\r\n");
2016-02-04 11:01:38 -08:00
// saveTpsState(0, 0);
// saveTpsState(CH_FREQUENCY, 50);
// assertEquals(50, getTpsRateOfChange());
//
// saveTpsState(2 * CH_FREQUENCY, 50);
// assertEquals(0, getTpsRateOfChange());
//
// saveTpsState(3 * CH_FREQUENCY, 75);
// assertEquals(25, getTpsRateOfChange());
2015-07-10 06:01:56 -07:00
}
TEST(sensors, Thermistor1) {
ThermistorMath tm;
thermistor_conf_s tc = {32, 75, 120, 9500, 2100, 1000, 0};
tm.setConfig(&tc);
float t = tm.getKelvinTemperatureByResistance(2100);
ASSERT_FLOAT_EQ(75 + KELV, t);
2015-07-10 06:01:56 -07:00
ASSERT_NEAR(-0.003, tm.s_h_a, EPS4D);
ASSERT_NEAR(0.001, tm.s_h_b, EPS4D);
ASSERT_NEAR(0.0, tm.s_h_c, EPS5D);
}
TEST(sensors, ThermistorNeon)
{
2015-07-10 06:01:56 -07:00
ThermistorMath tm;
// 2003 Neon sensor
thermistor_conf_s tc = {0, 30, 100, 32500, 7550, 700, 0};
tm.setConfig(&tc);
float t = tm.getKelvinTemperatureByResistance(38000);
ASSERT_NEAR(-2.7983, t - KELV, EPS4D);
assertEqualsM("A", 0.0009, tm.s_h_a);
assertEqualsM("B", 0.0003, tm.s_h_b);
ASSERT_NEAR(0.0, tm.s_h_c, EPS4D);
2015-07-10 06:01:56 -07:00
}