Skip to content

Commit

Permalink
Native SENT TPS input #5079
Browse files Browse the repository at this point in the history
only:alphax-4chan
  • Loading branch information
rusefillc committed Feb 22, 2023
1 parent eed7521 commit 5a735c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 8 additions & 1 deletion firmware/controllers/actuators/electronic_throttle.cpp
Expand Up @@ -108,6 +108,13 @@ static SensorType functionToPositionSensor(dc_function_e func) {
}
}

static SensorType functionToTpsSensor(dc_function_e func) {
switch(func) {
case DC_Throttle1: return SensorType::Tps1;
default: return SensorType::Tps2;
}
}

static SensorType functionToTpsSensorPrimary(dc_function_e func) {
switch(func) {
case DC_Throttle1: return SensorType::Tps1Primary;
Expand Down Expand Up @@ -177,7 +184,7 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam
}

// If no sensor is configured for this throttle, skip initialization.
if (!Sensor::hasSensor(functionToTpsSensorPrimary(function))) {
if (!Sensor::hasSensor(functionToTpsSensor(function))) {
etbErrorCode = (int8_t)TpsState::TpsError;
return false;
}
Expand Down
9 changes: 3 additions & 6 deletions unit_tests/tests/actuators/test_etb.cpp
Expand Up @@ -210,21 +210,18 @@ TEST(etb, initializationNotRedundantPedal) {
EXPECT_FATAL_ERROR(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true));
}

TEST(etb, initializationNoPrimarySensor) {
TEST(etb, initializationNoSensor) {
Sensor::resetAllMocks();

EtbController dut;

// Needs pedal for init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);

// Redundant, but no primary configured
Sensor::setMockValue(SensorType::Tps1, /*value*/0, /*mockRedundant*/true);

EXPECT_FALSE(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true));

// Now configure primary TPS
Sensor::setMockValue(SensorType::Tps1Primary, 0);
// Redundant
Sensor::setMockValue(SensorType::Tps1, /*value*/0, /*mockRedundant*/true);

// With primary TPS, should return true (ie, throttle was configured)
EXPECT_TRUE(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true));
Expand Down

0 comments on commit 5a735c9

Please sign in to comment.