Skip to content

Commit

Permalink
Map3D considered harmful FOME-Tech#421
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed May 4, 2024
1 parent a4897eb commit 044e575
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion firmware/controllers/actuators/electronic_throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class IEtbController : public ClosedLoopController<percent_t, percent_t> {
virtual void setWastegatePosition(percent_t pos) = 0;
virtual void update() = 0;
virtual void autoCalibrateTps() = 0;
virtual bool isEtbMode() = 0;
virtual bool isEtbMode() const = 0;

virtual const pid_state_s& getPidState() const = 0;

Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/actuators/electronic_throttle_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class EtbController : public IEtbController, public electronic_throttle_s {
* @return true if OK, false if should be disabled
*/
bool checkStatus();
bool isEtbMode() {
bool isEtbMode() const override {
return m_function == DC_Throttle1 || m_function == DC_Throttle2;
}

Expand Down
2 changes: 1 addition & 1 deletion unit_tests/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MockEtb : public IEtbController {

// IEtbController mocks
MOCK_METHOD(void, reset, (), (override));
MOCK_METHOD(bool, isEtbMode, (), (override));
MOCK_METHOD(bool, isEtbMode, (), (const, override));
MOCK_METHOD(void, update, (), (override));
MOCK_METHOD(bool, init, (dc_function_e function, DcMotor* motor, pid_s* pidParameters, const ValueProvider3D* pedalMap, bool initializeThrottles), (override));
MOCK_METHOD(void, setIdlePosition, (percent_t pos), (override));
Expand Down
19 changes: 10 additions & 9 deletions unit_tests/tests/actuators/test_etb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(etb, initializationSingleThrottle) {
StrictMock<MockEtb> mocks[ETB_COUNT];

EXPECT_CALL(mocks[0], isEtbMode())
.WillOnce(Return(TRUE));
.WillOnce(Return(true));

EngineTestHelper eth(engine_type_e::TEST_ENGINE, [](engine_configuration_s* cfg) {
engineConfiguration->etbFunctions[0] = DC_Throttle1;
Expand Down Expand Up @@ -89,7 +89,7 @@ TEST(etb, initializationSingleThrottleInSecondSlot) {
StrictMock<MockEtb> mocks[ETB_COUNT];

EXPECT_CALL(mocks[1], isEtbMode())
.WillOnce(Return(TRUE));
.WillOnce(Return(true));

EngineTestHelper eth(engine_type_e::TEST_ENGINE, [](engine_configuration_s* cfg) {
engineConfiguration->etbFunctions[0] = DC_None;
Expand Down Expand Up @@ -117,9 +117,9 @@ TEST(etb, initializationDualThrottle) {
StrictMock<MockEtb> mocks[ETB_COUNT];

EXPECT_CALL(mocks[0], isEtbMode())
.WillOnce(Return(TRUE));
.WillOnce(Return(true));
EXPECT_CALL(mocks[1], isEtbMode())
.WillOnce(Return(TRUE));
.WillOnce(Return(true));

EngineTestHelper eth(engine_type_e::TEST_ENGINE);

Expand Down Expand Up @@ -339,18 +339,19 @@ TEST(etb, setpointSecondThrottleTrim) {
return y;
});

// Should get called with the un-adjusted setpoint
StrictMock<MockVp3d> throttleTrimTable;
EXPECT_CALL(throttleTrimTable, getValue(0, 47))
.WillOnce(Return(4));
struct MockEtb2 : EtbController2 {
MOCK_METHOD(percent_t, getThrottleTrim, (float rpm, percent_t targetPosition), (const, override));
};

// Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);

EtbController2 etb(throttleTrimTable);
StrictMock<MockEtb2> etb;
etb.init(DC_Throttle1, nullptr, nullptr, &pedalMap, true);
// Should get called with the un-adjusted setpoint
EXPECT_CALL(etb, getThrottleTrim(0, 47)).WillOnce(Return(4));

Sensor::setMockValue(SensorType::AcceleratorPedal, 47, true);
EXPECT_EQ(51, etb.getSetpoint().value_or(-1));
Expand Down

0 comments on commit 044e575

Please sign in to comment.