2019-12-13 11:55:20 -08:00
|
|
|
/*
|
|
|
|
* @file test_etb.cpp
|
|
|
|
*
|
|
|
|
* @date Dec 13, 2019
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2019-12-13 11:55:20 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engine_test_helper.h"
|
|
|
|
#include "electronic_throttle.h"
|
|
|
|
#include "dc_motor.h"
|
2020-03-03 14:56:50 -08:00
|
|
|
#include "engine_controller.h"
|
2020-04-01 17:21:03 -07:00
|
|
|
#include "sensor.h"
|
2019-12-13 11:55:20 -08:00
|
|
|
|
|
|
|
class MockEtb : public IEtbController {
|
|
|
|
public:
|
|
|
|
// todo: somehow I am failinig to figure out GMOCK syntax here?
|
|
|
|
// todo: convert to GMOCK
|
|
|
|
int resetCount = 0;
|
|
|
|
int startCount = 0;
|
|
|
|
int initCount = 0;
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
resetCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Start() override {
|
|
|
|
startCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(DcMotor *motor, int ownIndex, pid_s *pidParameters) {
|
|
|
|
initCount++;
|
|
|
|
};
|
|
|
|
|
|
|
|
void PeriodicTask() {
|
|
|
|
};
|
|
|
|
|
|
|
|
int getPeriodMs() {
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(etb, singleEtbInitialization) {
|
|
|
|
|
|
|
|
MockEtb mocks[ETB_COUNT];
|
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
}
|
|
|
|
|
2020-04-02 05:04:12 -07:00
|
|
|
// Must have a sensor configured before init
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
|
2019-12-13 11:55:20 -08:00
|
|
|
|
|
|
|
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
|
|
|
// assert that 1st ETB is initialized and started
|
|
|
|
ASSERT_EQ(1, mocks[0].initCount) << "1st init";
|
|
|
|
ASSERT_EQ(1, mocks[0].startCount);
|
|
|
|
|
2020-03-03 14:56:50 -08:00
|
|
|
// assert that 2nd ETB is neither initialized nor started
|
|
|
|
ASSERT_EQ(0, mocks[1].initCount) << "2nd init";
|
2019-12-13 11:55:20 -08:00
|
|
|
ASSERT_EQ(0, mocks[1].startCount) << "2nd start";
|
|
|
|
|
|
|
|
|
2020-02-22 20:18:02 -08:00
|
|
|
// todo: set mock pedal position
|
|
|
|
// todo: set mock ETB throttle position
|
|
|
|
// todo: invoke EtbController#PeriodicTask a few times and assert that duty cycle changes
|
2019-12-13 11:55:20 -08:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:02:49 -07:00
|
|
|
TEST(etb, testTargetTpsIsFloatBug945) {
|
2020-03-03 14:56:50 -08:00
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
2020-04-02 05:04:12 -07:00
|
|
|
// Must have a sensor configured before init
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
|
2020-04-02 18:33:49 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0);
|
2020-03-03 14:56:50 -08:00
|
|
|
|
2020-04-02 05:04:12 -07:00
|
|
|
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-03-19 17:02:49 -07:00
|
|
|
|
2020-04-01 17:21:03 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f);
|
2020-03-03 14:56:50 -08:00
|
|
|
engine->etbControllers[0]->PeriodicTask();
|
|
|
|
ASSERT_NEAR(50, engine->engineState.targetFromTable, EPS4D);
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-04-01 17:21:03 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.8302f);
|
2020-03-03 14:56:50 -08:00
|
|
|
engine->etbControllers[0]->PeriodicTask();
|
|
|
|
ASSERT_NEAR(50.8302, engine->engineState.targetFromTable, EPS4D);
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-04-01 17:21:03 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 51.6605f);
|
2020-03-03 14:56:50 -08:00
|
|
|
engine->etbControllers[0]->PeriodicTask();
|
|
|
|
ASSERT_NEAR(51.6605, engine->engineState.targetFromTable, EPS4D);
|
|
|
|
}
|
2020-04-19 14:18:47 -07:00
|
|
|
|
|
|
|
TEST(etb, etbTpsSensor) {
|
|
|
|
// Throw some distinct values on the TPS sensors so we can identify that we're getting the correct one
|
|
|
|
Sensor::setMockValue(SensorType::Tps1, 25.0f);
|
|
|
|
Sensor::setMockValue(SensorType::Tps2, 75.0f);
|
|
|
|
|
|
|
|
// Test first throttle
|
|
|
|
{
|
|
|
|
EtbController etb;
|
|
|
|
etb.init(nullptr, 0, nullptr);
|
|
|
|
EXPECT_EQ(etb.observePlant().Value, 25.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test second throttle
|
|
|
|
{
|
|
|
|
EtbController etb;
|
|
|
|
etb.init(nullptr, 1, nullptr);
|
|
|
|
EXPECT_EQ(etb.observePlant().Value, 75.0f);
|
|
|
|
}
|
|
|
|
}
|