From ad1b97f444c8adb9b92fa730c72ce14a9e1d12c9 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 01:26:47 -0400 Subject: [PATCH 1/8] broken intentially tests. needs fixing asap --- lib/systems/include/PedalsSystem.h | 2 - lib/systems/src/PedalsSystem.cpp | 25 +++--- test/test_systems/pedals_system_test.h | 118 ++++++++++++++----------- 3 files changed, 74 insertions(+), 71 deletions(-) diff --git a/lib/systems/include/PedalsSystem.h b/lib/systems/include/PedalsSystem.h index c2ad19045..43ec5f02e 100644 --- a/lib/systems/include/PedalsSystem.h +++ b/lib/systems/include/PedalsSystem.h @@ -115,8 +115,6 @@ class PedalsSystem PedalsParams brakeParams_{}; unsigned long implausibilityStartTime_; - bool both_pedals_implausible; - float remove_deadzone_(float conversion_input, float deadzone); bool max_duration_of_implausibility_exceeded_(unsigned long curr_time); diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index 440e958cb..383c92574 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -40,8 +40,9 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.brakePercent = brake.conversion; out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); - out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); out.mechBrakeActive = out.brakePercent > brakeParams_.mechanical_activation_percentage; + out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); + out.brakePressed = out.brakePercent > brakeParams_.activation_percentage; out.implausibilityExceededMaxDuration = max_duration_of_implausibility_exceeded_(curr_time); return out; } @@ -70,12 +71,14 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; out.brakePercent = (brake1.conversion + brake2.conversion) / 2.0; + out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); + out.brakePressed = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_.activation_percentage); - out.mechBrakeActive = out.brakePercent > brakeParams_.mechanical_activation_percentage; + out.mechBrakeActive = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_.mechanical_activation_percentage); out.implausibilityExceededMaxDuration = max_duration_of_implausibility_exceeded_(curr_time); return out; @@ -97,17 +100,7 @@ bool PedalsSystem::max_duration_of_implausibility_exceeded_(unsigned long curr_t // only checks implaus based on first min / max bool PedalsSystem::evaluate_pedal_implausibilities_(const AnalogConversion_s &pedalData, const PedalsParams ¶ms) { - bool pedal1_min_max_implaus = evaluate_min_max_pedal_implausibilities_(pedalData, params.min_pedal_1, params.max_pedal_1, params.implausibility_margin); - - - if (pedal1_min_max_implaus) - { - return true; - } - else - { - return false; - } + return evaluate_min_max_pedal_implausibilities_(pedalData, params.min_pedal_1, params.max_pedal_1, params.implausibility_margin); } bool PedalsSystem::evaluate_pedal_implausibilities_(const AnalogConversion_s &pedalData1, @@ -197,6 +190,7 @@ bool PedalsSystem::evaluate_brake_and_accel_pressed_(const AnalogConversion_s &a bool accel_pressed = pedal_is_active_(accel_pedal1_real, accel_pedal2_real, accelParams_.activation_percentage); // .1 bool brake_pressed = brake_pedal_real >= brakeParams_.mechanical_activation_percentage; + bool both_pedals_implausible; if (accel_pressed && brake_pressed) { both_pedals_implausible = true; } @@ -221,8 +215,9 @@ bool PedalsSystem::evaluate_brake_and_accel_pressed_(const AnalogConversion_s &a float brake_pedal2_real = remove_deadzone_(brakePedalData2.conversion, brakeParams_.deadzone_margin); bool accel_pressed = pedal_is_active_(accel_pedal1_real, accel_pedal2_real, accelParams_.activation_percentage); // .1 bool brake_pressed = pedal_is_active_(brake_pedal1_real, brake_pedal2_real, brakeParams_.mechanical_activation_percentage); // 0.05 - - if (accel_pressed && brake_pressed) { + + bool both_pedals_implausible; + if (accel_pressed && brake_pressed) { both_pedals_implausible = true; } diff --git a/test/test_systems/pedals_system_test.h b/test/test_systems/pedals_system_test.h index fd3b5601d..5b4bf7084 100644 --- a/test/test_systems/pedals_system_test.h +++ b/test/test_systems/pedals_system_test.h @@ -105,60 +105,69 @@ TEST(PedalsSystemTesting, test_accel_and_brake_percentages_implausibility) EXPECT_FALSE(data.accelImplausible); } -// TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) -// { -// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - -// PedalsParams params2; -// params2.min_pedal_1 = 100; -// params2.min_pedal_2 = 100; -// params2.max_pedal_1 = 3000; -// params2.max_pedal_2 = 3000; -// params2.activation_percentage = 0.1; -// params2.mechanical_activation_percentage = 0.6; -// params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; -// params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - -// PedalsSystem pedals(params2, params2); -// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); -// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); -// EXPECT_TRUE(data.brakePressed); - -// test_brake_val.conversion = 0.0; - -// data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - -// EXPECT_FALSE(data.brakeAndAccelPressedImplausibility); -// EXPECT_FALSE(data.brakePressed); -// } - -// TEST(PedalsSystemTesting, test_implausibility_duration) -// { -// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - -// PedalsParams params2; -// params2.min_pedal_1 = 100; -// params2.max_pedal_1 = 100; -// params2.min_pedal_2 = 3000; -// params2.max_pedal_2 = 3000; -// params2.activation_percentage = 0.1; -// params2.mechanical_activation_percentage = 0.6; -// params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; -// params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - -// PedalsSystem pedals(params2, params2); -// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); -// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); -// EXPECT_TRUE(data.brakePressed); -// EXPECT_FALSE(data.implausibilityExceededMaxDuration); - -// data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1200); - - -// EXPECT_TRUE(data.implausibilityExceededMaxDuration); -// } +TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) +{ + AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + PedalsParams params2; + params2.min_pedal_1 = 100; + params2.min_pedal_2 = 100; + params2.max_pedal_1 = 3100; + params2.max_pedal_2 = 3100; + params2.activation_percentage = 0.1; + params2.mechanical_activation_percentage = 0.6; + params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; + params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; + + PedalsSystem pedals(params2, params2); + auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); + EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data.brakePressed); + + test_brake_val.conversion = 0.0; + + data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); + data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1300); + EXPECT_FALSE(data.brakeAndAccelPressedImplausibility); + EXPECT_FALSE(data.brakePressed); + // an implausibility should still be present + EXPECT_TRUE(data.a) + EXPECT_TRUE(data.implausibilityExceededMaxDuration); +} + +TEST(PedalsSystemTesting, test_implausibility_duration) +{ + AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + PedalsParams params2; + params2.min_pedal_1 = 100; + params2.max_pedal_1 = 100; + params2.min_pedal_2 = 3000; + params2.max_pedal_2 = 3000; + params2.activation_percentage = 0.1; + params2.mechanical_activation_percentage = 0.6; + params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; + params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; + + PedalsSystem pedals(params2, params2); + auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); + EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data.brakePressed); + EXPECT_FALSE(data.implausibilityExceededMaxDuration); + + data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1200); + EXPECT_TRUE(data.implausibilityExceededMaxDuration); + + auto data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1000); + EXPECT_TRUE(data2.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data2.brakePressed); + EXPECT_FALSE(data2.implausibilityExceededMaxDuration); + + data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1200); + EXPECT_TRUE(data2.implausibilityExceededMaxDuration); +} TEST(PedalsSystemTesting, single_brake_pedal_test_limits) { // accel min and max on raw @@ -183,4 +192,5 @@ TEST(PedalsSystemTesting, single_brake_pedal_test_limits) { } + #endif /* PEDALS_SYSTEM_TEST */ From eb23bb11b881274d43bd15aceb3092c58270b9d5 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 01:28:10 -0400 Subject: [PATCH 2/8] yuh --- lib/systems/include/PedalsSystem.h | 2 - lib/systems/src/PedalsSystem.cpp | 25 +++--- test/test_systems/pedals_system_test.h | 118 ++++++++++++++----------- 3 files changed, 74 insertions(+), 71 deletions(-) diff --git a/lib/systems/include/PedalsSystem.h b/lib/systems/include/PedalsSystem.h index c2ad19045..43ec5f02e 100644 --- a/lib/systems/include/PedalsSystem.h +++ b/lib/systems/include/PedalsSystem.h @@ -115,8 +115,6 @@ class PedalsSystem PedalsParams brakeParams_{}; unsigned long implausibilityStartTime_; - bool both_pedals_implausible; - float remove_deadzone_(float conversion_input, float deadzone); bool max_duration_of_implausibility_exceeded_(unsigned long curr_time); diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index 440e958cb..383c92574 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -40,8 +40,9 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.brakePercent = brake.conversion; out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); - out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); out.mechBrakeActive = out.brakePercent > brakeParams_.mechanical_activation_percentage; + out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); + out.brakePressed = out.brakePercent > brakeParams_.activation_percentage; out.implausibilityExceededMaxDuration = max_duration_of_implausibility_exceeded_(curr_time); return out; } @@ -70,12 +71,14 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; out.brakePercent = (brake1.conversion + brake2.conversion) / 2.0; + out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); + out.brakePressed = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_.activation_percentage); - out.mechBrakeActive = out.brakePercent > brakeParams_.mechanical_activation_percentage; + out.mechBrakeActive = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_.mechanical_activation_percentage); out.implausibilityExceededMaxDuration = max_duration_of_implausibility_exceeded_(curr_time); return out; @@ -97,17 +100,7 @@ bool PedalsSystem::max_duration_of_implausibility_exceeded_(unsigned long curr_t // only checks implaus based on first min / max bool PedalsSystem::evaluate_pedal_implausibilities_(const AnalogConversion_s &pedalData, const PedalsParams ¶ms) { - bool pedal1_min_max_implaus = evaluate_min_max_pedal_implausibilities_(pedalData, params.min_pedal_1, params.max_pedal_1, params.implausibility_margin); - - - if (pedal1_min_max_implaus) - { - return true; - } - else - { - return false; - } + return evaluate_min_max_pedal_implausibilities_(pedalData, params.min_pedal_1, params.max_pedal_1, params.implausibility_margin); } bool PedalsSystem::evaluate_pedal_implausibilities_(const AnalogConversion_s &pedalData1, @@ -197,6 +190,7 @@ bool PedalsSystem::evaluate_brake_and_accel_pressed_(const AnalogConversion_s &a bool accel_pressed = pedal_is_active_(accel_pedal1_real, accel_pedal2_real, accelParams_.activation_percentage); // .1 bool brake_pressed = brake_pedal_real >= brakeParams_.mechanical_activation_percentage; + bool both_pedals_implausible; if (accel_pressed && brake_pressed) { both_pedals_implausible = true; } @@ -221,8 +215,9 @@ bool PedalsSystem::evaluate_brake_and_accel_pressed_(const AnalogConversion_s &a float brake_pedal2_real = remove_deadzone_(brakePedalData2.conversion, brakeParams_.deadzone_margin); bool accel_pressed = pedal_is_active_(accel_pedal1_real, accel_pedal2_real, accelParams_.activation_percentage); // .1 bool brake_pressed = pedal_is_active_(brake_pedal1_real, brake_pedal2_real, brakeParams_.mechanical_activation_percentage); // 0.05 - - if (accel_pressed && brake_pressed) { + + bool both_pedals_implausible; + if (accel_pressed && brake_pressed) { both_pedals_implausible = true; } diff --git a/test/test_systems/pedals_system_test.h b/test/test_systems/pedals_system_test.h index fd3b5601d..5b4bf7084 100644 --- a/test/test_systems/pedals_system_test.h +++ b/test/test_systems/pedals_system_test.h @@ -105,60 +105,69 @@ TEST(PedalsSystemTesting, test_accel_and_brake_percentages_implausibility) EXPECT_FALSE(data.accelImplausible); } -// TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) -// { -// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - -// PedalsParams params2; -// params2.min_pedal_1 = 100; -// params2.min_pedal_2 = 100; -// params2.max_pedal_1 = 3000; -// params2.max_pedal_2 = 3000; -// params2.activation_percentage = 0.1; -// params2.mechanical_activation_percentage = 0.6; -// params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; -// params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - -// PedalsSystem pedals(params2, params2); -// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); -// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); -// EXPECT_TRUE(data.brakePressed); - -// test_brake_val.conversion = 0.0; - -// data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - -// EXPECT_FALSE(data.brakeAndAccelPressedImplausibility); -// EXPECT_FALSE(data.brakePressed); -// } - -// TEST(PedalsSystemTesting, test_implausibility_duration) -// { -// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - -// PedalsParams params2; -// params2.min_pedal_1 = 100; -// params2.max_pedal_1 = 100; -// params2.min_pedal_2 = 3000; -// params2.max_pedal_2 = 3000; -// params2.activation_percentage = 0.1; -// params2.mechanical_activation_percentage = 0.6; -// params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; -// params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - -// PedalsSystem pedals(params2, params2); -// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); -// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); -// EXPECT_TRUE(data.brakePressed); -// EXPECT_FALSE(data.implausibilityExceededMaxDuration); - -// data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1200); - - -// EXPECT_TRUE(data.implausibilityExceededMaxDuration); -// } +TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) +{ + AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + PedalsParams params2; + params2.min_pedal_1 = 100; + params2.min_pedal_2 = 100; + params2.max_pedal_1 = 3100; + params2.max_pedal_2 = 3100; + params2.activation_percentage = 0.1; + params2.mechanical_activation_percentage = 0.6; + params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; + params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; + + PedalsSystem pedals(params2, params2); + auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); + EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data.brakePressed); + + test_brake_val.conversion = 0.0; + + data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); + data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1300); + EXPECT_FALSE(data.brakeAndAccelPressedImplausibility); + EXPECT_FALSE(data.brakePressed); + // an implausibility should still be present + EXPECT_TRUE(data.a) + EXPECT_TRUE(data.implausibilityExceededMaxDuration); +} + +TEST(PedalsSystemTesting, test_implausibility_duration) +{ + AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + PedalsParams params2; + params2.min_pedal_1 = 100; + params2.max_pedal_1 = 100; + params2.min_pedal_2 = 3000; + params2.max_pedal_2 = 3000; + params2.activation_percentage = 0.1; + params2.mechanical_activation_percentage = 0.6; + params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; + params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; + + PedalsSystem pedals(params2, params2); + auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); + EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data.brakePressed); + EXPECT_FALSE(data.implausibilityExceededMaxDuration); + + data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1200); + EXPECT_TRUE(data.implausibilityExceededMaxDuration); + + auto data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1000); + EXPECT_TRUE(data2.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data2.brakePressed); + EXPECT_FALSE(data2.implausibilityExceededMaxDuration); + + data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1200); + EXPECT_TRUE(data2.implausibilityExceededMaxDuration); +} TEST(PedalsSystemTesting, single_brake_pedal_test_limits) { // accel min and max on raw @@ -183,4 +192,5 @@ TEST(PedalsSystemTesting, single_brake_pedal_test_limits) { } + #endif /* PEDALS_SYSTEM_TEST */ From 22455dd2fa8614214cd803d7297bf1e7a1b180c8 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 13:16:20 -0400 Subject: [PATCH 3/8] adding in test refactor --- lib/systems/include/PedalsSystem.h | 17 +- lib/systems/src/PedalsSystem.cpp | 78 +++--- test/test_systems/pedals_system_test.h | 333 +++++++++++++------------ 3 files changed, 228 insertions(+), 200 deletions(-) diff --git a/lib/systems/include/PedalsSystem.h b/lib/systems/include/PedalsSystem.h index 43ec5f02e..9cef0dbfd 100644 --- a/lib/systems/include/PedalsSystem.h +++ b/lib/systems/include/PedalsSystem.h @@ -12,6 +12,7 @@ struct PedalsSystemData_s bool accelImplausible : 1; bool brakeImplausible : 1; bool brakePressed : 1; + bool accelPressed : 1; bool mechBrakeActive : 1; bool brakeAndAccelPressedImplausibility : 1; bool implausibilityExceededMaxDuration : 1; @@ -42,10 +43,16 @@ class PedalsSystem /// @param brakeParams brake pedal params. when used with only one pedal sensor, the pedal parameter evaluation for brakes only looks at the min and max for min_pedal_1 / max_pedal_1 PedalsSystem(const PedalsParams &accelParams, const PedalsParams &brakeParams) + { + setParams(accelParams, brakeParams); + implausibilityStartTime_ = 0; + } + + void setParams(const PedalsParams &accelParams, + const PedalsParams &brakeParams) { accelParams_ = accelParams; brakeParams_ = brakeParams; - implausibilityStartTime_ = 0; } const PedalsSystemData_s &getPedalsSystemData() @@ -177,7 +184,13 @@ class PedalsSystem int max, float implaus_margin_scale); - bool pedal_is_active_(float pedal1ConvertedData, float pedal2ConvertedData, float percent_threshold); + /// @brief check whether or not pedal is active according to input parameters. returns true if either pedal is over threshold. removes the deadzone before checking. + /// @param pedal1ConvertedData the value 0 to 1 of the first pedal without deadzone removed + /// @param pedal2ConvertedData ... second pedal 0 to 1 val + /// @param params the pedal parameters for this specific pedal + /// @param check_mech_activation if this is true, function will check percentages against the mechanical activation percentage + /// @return true or false accordingly + bool pedal_is_active_(float pedal1ConvertedData, float pedal2ConvertedData, const PedalsParams ¶ms, bool check_mech_activation); }; #endif /* PEDALSSYSTEM */ diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index 383c92574..17484ba45 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -14,6 +14,10 @@ void PedalsSystem::tick(const SysTick_s &tick, const AnalogConversion_s &accel1, data_ = evaluate_pedals(accel1, accel2, brake, tick.millis); } + +// TODO make it to where only when the pedal is released fully that the implausibility clears + + PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake, @@ -43,6 +47,8 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.mechBrakeActive = out.brakePercent > brakeParams_.mechanical_activation_percentage; out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); out.brakePressed = out.brakePercent > brakeParams_.activation_percentage; + + out.implausibilityExceededMaxDuration = max_duration_of_implausibility_exceeded_(curr_time); return out; } @@ -55,6 +61,7 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel { PedalsSystemData_s out; + out.accelPressed = pedal_is_active_(accel1.conversion, accel2.conversion, accelParams_, false); out.accelImplausible = evaluate_pedal_implausibilities_(accel1, accel2, accelParams_, 0.1); out.brakeImplausible = evaluate_pedal_implausibilities_(brake1, brake2, brakeParams_, 0.25); out.brakeAndAccelPressedImplausibility = evaluate_brake_and_accel_pressed_(accel1, accel2, brake1, brake2); @@ -64,21 +71,21 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel { implausibilityStartTime_ = curr_time; } - else if (!implausibility) + else if ((!implausibility) && (!out.accelPressed)) { implausibilityStartTime_ = 0; } - out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; + out.brakePercent = (brake1.conversion + brake2.conversion) / 2.0; - out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); + out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); - out.brakePressed = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_.activation_percentage); - out.mechBrakeActive = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_.mechanical_activation_percentage); + out.brakePressed = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_, false); + out.mechBrakeActive = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_, true); out.implausibilityExceededMaxDuration = max_duration_of_implausibility_exceeded_(curr_time); return out; @@ -184,23 +191,13 @@ bool PedalsSystem::evaluate_brake_and_accel_pressed_(const AnalogConversion_s &a const AnalogConversion_s &brakePedalData) { - float accel_pedal1_real = remove_deadzone_(accelPedalData1.conversion, accelParams_.deadzone_margin); - float accel_pedal2_real = remove_deadzone_(accelPedalData2.conversion, accelParams_.deadzone_margin); + + + bool accel_pressed = pedal_is_active_(accelPedalData1.conversion, accelPedalData2.conversion, accelParams_, false); // .1 float brake_pedal_real = remove_deadzone_(brakePedalData.conversion, brakeParams_.deadzone_margin); - bool accel_pressed = pedal_is_active_(accel_pedal1_real, accel_pedal2_real, accelParams_.activation_percentage); // .1 - bool brake_pressed = brake_pedal_real >= brakeParams_.mechanical_activation_percentage; - - bool both_pedals_implausible; - if (accel_pressed && brake_pressed) { - both_pedals_implausible = true; - } - - // make sure that implausibility does not clear until both pedals are completely depressed - if (!accel_pressed && !brake_pressed) { - both_pedals_implausible = false; - } - - return (both_pedals_implausible); + bool mech_brake_pressed = brake_pedal_real >= brakeParams_.mechanical_activation_percentage; + bool both_pedals_implausible = (accel_pressed && mech_brake_pressed); + return both_pedals_implausible; } bool PedalsSystem::evaluate_brake_and_accel_pressed_(const AnalogConversion_s &accelPedalData1, @@ -209,29 +206,28 @@ bool PedalsSystem::evaluate_brake_and_accel_pressed_(const AnalogConversion_s &a const AnalogConversion_s &brakePedalData2) { - float accel_pedal1_real = remove_deadzone_(accelPedalData1.conversion, accelParams_.deadzone_margin); - float accel_pedal2_real = remove_deadzone_(accelPedalData2.conversion, accelParams_.deadzone_margin); - float brake_pedal1_real = remove_deadzone_(brakePedalData1.conversion, brakeParams_.deadzone_margin); - float brake_pedal2_real = remove_deadzone_(brakePedalData2.conversion, brakeParams_.deadzone_margin); - bool accel_pressed = pedal_is_active_(accel_pedal1_real, accel_pedal2_real, accelParams_.activation_percentage); // .1 - bool brake_pressed = pedal_is_active_(brake_pedal1_real, brake_pedal2_real, brakeParams_.mechanical_activation_percentage); // 0.05 - - bool both_pedals_implausible; - if (accel_pressed && brake_pressed) { - both_pedals_implausible = true; - } - - // make sure that implausibility does not clear until both pedals are completely depressed - if (!accel_pressed && !brake_pressed) { - both_pedals_implausible = false; - } - return (both_pedals_implausible); + bool accel_pressed = pedal_is_active_(accelPedalData1.conversion, accelPedalData2.conversion, accelParams_, false); // .1 + bool mech_brake_pressed = pedal_is_active_(brakePedalData1.conversion, brakePedalData2.conversion, brakeParams_, true); // 0.40 + + + bool both_pedals_implausible = (accel_pressed && mech_brake_pressed); + return both_pedals_implausible; } -bool PedalsSystem::pedal_is_active_(float pedal1ConvertedData, float pedal2ConvertedData, float percent_threshold) +bool PedalsSystem::pedal_is_active_(float pedal1ConvertedData, float pedal2ConvertedData, const PedalsParams& params, bool check_mech_activation) { - bool pedal_1_is_active = pedal1ConvertedData >= percent_threshold; - bool pedal_2_is_active = pedal2ConvertedData >= percent_threshold; + float val1_deadzone_removed = remove_deadzone_(pedal1ConvertedData, params.deadzone_margin); + float val2_deadzone_removed = remove_deadzone_(pedal2ConvertedData, params.deadzone_margin); + bool pedal_1_is_active; + bool pedal_2_is_active; + if(check_mech_activation) + { + pedal_1_is_active = val1_deadzone_removed >= params.mechanical_activation_percentage; + pedal_2_is_active = val2_deadzone_removed >= params.mechanical_activation_percentage; + } else { + pedal_1_is_active = val1_deadzone_removed >= params.activation_percentage; + pedal_2_is_active = val2_deadzone_removed >= params.activation_percentage; + } return (pedal_1_is_active || pedal_2_is_active); } \ No newline at end of file diff --git a/test/test_systems/pedals_system_test.h b/test/test_systems/pedals_system_test.h index 5b4bf7084..2853daea4 100644 --- a/test/test_systems/pedals_system_test.h +++ b/test/test_systems/pedals_system_test.h @@ -5,7 +5,6 @@ rough draft author: Lucas Plant */ - #ifndef PEDALS_SYSTEM_TEST #define PEDALS_SYSTEM_TEST #include @@ -14,183 +13,203 @@ author: Lucas Plant #include #include "MCU_rev15_defs.h" - - -TEST(PedalsSystemTesting, test_accel_and_brake_limits_plausibility) +PedalsParams gen_positive_and_negative_slope_params() { - // accel min and max on raw - AnalogConversion_s test_accel1_val = {0, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_accel2_val = {200, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_brake_val = {200, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + PedalsParams params; + params.min_pedal_1 = 2000; + params.max_pedal_1 = 1000; + params.min_pedal_2 = 1000; + params.max_pedal_2 = 2000; + params.activation_percentage = 0.25; + params.mechanical_activation_percentage = 0.4; + params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; // .05 + params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; // 0.1 + return params; +} +PedalsParams gen_positive_slope_only_params() +{ PedalsParams params; params.min_pedal_1 = 1000; params.max_pedal_1 = 2000; params.min_pedal_2 = 1000; params.max_pedal_2 = 2000; - params.activation_percentage = 0.1; - params.mechanical_activation_percentage = 0.6; - params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; - params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - PedalsSystem pedals(params, params); - - // this should be implausible since test accel1 and accel2 have values less than the min (1000) - auto data = pedals.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake_val, test_brake_val, 1000); - EXPECT_TRUE(data.accelImplausible); - // ensuring that both accel in either position (since they have the same config, this should fail too) - data = pedals.evaluate_pedals(test_accel2_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - EXPECT_TRUE(data.accelImplausible); - - - // testing accel raw greater than max - test_accel1_val.raw = 4000; - data = pedals.evaluate_pedals(test_accel2_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - EXPECT_TRUE(data.accelImplausible); - - // brake min and max on raw. testing that if accel is implaus and brake implaus (less than min) we still guchi - test_accel1_val.raw = 300; - test_brake_val.raw = 0; - data = pedals.evaluate_pedals(test_accel2_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - EXPECT_TRUE(data.brakeImplausible); - - // testing brake greater than max - test_brake_val.raw = 40000; - data = pedals.evaluate_pedals(test_accel2_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - EXPECT_TRUE(data.brakeImplausible); - - // testing good values still good - test_accel1_val.raw = 1300; - test_brake_val.raw = 1300; - - data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - - EXPECT_FALSE(data.brakeImplausible); - EXPECT_FALSE(data.accelImplausible); + params.activation_percentage = 0.25; + params.mechanical_activation_percentage = 0.4; + params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; // .05 + params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; // 0.1 + return params; } -TEST(PedalsSystemTesting, test_accel_and_brake_percentages_implausibility) +bool get_result_of_double_brake_test(PedalsSystem &pedals, const AnalogConversion_s &a1, const AnalogConversion_s &a2, const AnalogConversion_s &b1, const AnalogConversion_s &b2) { - // accel percentage outside of range - AnalogConversion_s test_accel1_val = {200, 0.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_accel2_val = {200, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_brake_val = {200, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - - PedalsParams params2; - params2.min_pedal_1 = 100; - params2.min_pedal_2 = 100; - params2.max_pedal_1 = 3000; - params2.max_pedal_2 = 3000; - params2.activation_percentage = 0.1; - params2.mechanical_activation_percentage = 0.6; - params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; - params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - - PedalsSystem pedals(params2, params2); - auto data = pedals.evaluate_pedals(test_accel2_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - - EXPECT_FALSE(data.brakeImplausible); - EXPECT_TRUE(data.accelImplausible); - - // brake percentage outside of range - test_brake_val.conversion = 0.5; - auto test_b2 = test_brake_val; - test_b2.conversion = 0.0; - data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_b2, test_brake_val, 1000); - EXPECT_TRUE(data.brakeImplausible); - EXPECT_FALSE(data.accelImplausible); - - data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - - EXPECT_FALSE(data.brakeImplausible); - EXPECT_FALSE(data.accelImplausible); + auto data = pedals.evaluate_pedals(a1, a2, b1, b2, 1000); + data = pedals.evaluate_pedals(a1, a2, b1, b2, 1110); + return data.implausibilityExceededMaxDuration; } -TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) +bool get_result_of_single_brake_test(PedalsSystem &pedals, const AnalogConversion_s &a1, const AnalogConversion_s &a2, const AnalogConversion_s &b1) { - AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - - PedalsParams params2; - params2.min_pedal_1 = 100; - params2.min_pedal_2 = 100; - params2.max_pedal_1 = 3100; - params2.max_pedal_2 = 3100; - params2.activation_percentage = 0.1; - params2.mechanical_activation_percentage = 0.6; - params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; - params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - - PedalsSystem pedals(params2, params2); - auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); - EXPECT_TRUE(data.brakePressed); - - test_brake_val.conversion = 0.0; - - data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1300); - EXPECT_FALSE(data.brakeAndAccelPressedImplausibility); - EXPECT_FALSE(data.brakePressed); - // an implausibility should still be present - EXPECT_TRUE(data.a) - EXPECT_TRUE(data.implausibilityExceededMaxDuration); + auto data = pedals.evaluate_pedals(a1, a2, b1, 1000); + data = pedals.evaluate_pedals(a1, a2, b1, 1110); + return data.implausibilityExceededMaxDuration; } -TEST(PedalsSystemTesting, test_implausibility_duration) +// resets the implaus time to zero by ticking with plausible data. should return true always. +bool reset_pedals_system_implaus_time(PedalsSystem &pedals) { - AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - - PedalsParams params2; - params2.min_pedal_1 = 100; - params2.max_pedal_1 = 100; - params2.min_pedal_2 = 3000; - params2.max_pedal_2 = 3000; - params2.activation_percentage = 0.1; - params2.mechanical_activation_percentage = 0.6; - params2.deadzone_margin = DEFAULT_PEDAL_DEADZONE; - params2.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; - - PedalsSystem pedals(params2, params2); - auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); - EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); - EXPECT_TRUE(data.brakePressed); - EXPECT_FALSE(data.implausibilityExceededMaxDuration); - - data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1200); - EXPECT_TRUE(data.implausibilityExceededMaxDuration); - - auto data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1000); - EXPECT_TRUE(data2.brakeAndAccelPressedImplausibility); - EXPECT_TRUE(data2.brakePressed); - EXPECT_FALSE(data2.implausibilityExceededMaxDuration); - - data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1200); - EXPECT_TRUE(data2.implausibilityExceededMaxDuration); + AnalogConversion_s test_accel_good_val = {1010, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_good_val = {1010, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + auto data = pedals.evaluate_pedals(test_accel_good_val, test_accel_good_val, test_brake_good_val, 1000); + data = pedals.evaluate_pedals(test_accel_good_val, test_accel_good_val, test_brake_good_val, 1110); + return (!data.implausibilityExceededMaxDuration); } -TEST(PedalsSystemTesting, single_brake_pedal_test_limits) { - // accel min and max on raw - AnalogConversion_s test_accel1_val = {0, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_accel2_val = {200, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_brake1_val = {200, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_brake2_val = {500, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - - PedalsParams params; - params.min_pedal_1 = 1000; - params.max_pedal_1 = 2000; - params.min_pedal_2 = 200; - params.max_pedal_2 = 300; - params.activation_percentage = 0.1; - params.mechanical_activation_percentage = 0.6; - params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; - params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; +// T.4.3.4, T.4.2.7, T.4.2.9, T.4.2.10 FSAE rules 2024 v1 +TEST(PedalsSystemTesting, test_accel_and_brake_limits_plausibility) +{ + auto params = gen_positive_and_negative_slope_params(); PedalsSystem pedals(params, params); - auto data = pedals.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake1_val, test_brake2_val, 1000); - EXPECT_TRUE(data.brakeImplausible); - + AnalogConversion_s test_pedal_bad_val_min = {0, 0.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_bad_val_max = {4000, 2.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val = {1200, 0.2, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + std::vector> pedal_pairs; + + // check the possibilities of all min/max pairs for accel and good brake + pedal_pairs.push_back({test_pedal_bad_val_min, test_pedal_bad_val_min}); + pedal_pairs.push_back({test_pedal_bad_val_min, test_pedal_bad_val_max}); + pedal_pairs.push_back({test_pedal_bad_val_max, test_pedal_bad_val_min}); + pedal_pairs.push_back({test_pedal_bad_val_max, test_pedal_bad_val_max}); + + // T.4.2.7 , T.4.2.9 and T.4.2.10 (accel out of ranges min/max) testing + for (auto pair : pedal_pairs) + { + auto p1 = std::get<0>(pair); + auto p2 = std::get<1>(pair); + bool t_4_2_7 = get_result_of_double_brake_test(pedals, p1, p2, test_pedal_good_val, test_pedal_good_val); + EXPECT_TRUE(t_4_2_7); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + + t_4_2_7 = get_result_of_single_brake_test(pedals, p1, p2, test_pedal_good_val); + EXPECT_TRUE(t_4_2_7); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + } + + // ensure that all good is still good for d.p. brake + bool t_4_2_7 = get_result_of_double_brake_test(pedals, test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, test_pedal_good_val); + EXPECT_FALSE(t_4_2_7); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + // ensure that all good is still good for s.p. brake + t_4_2_7 = get_result_of_single_brake_test(pedals, test_pedal_good_val, test_pedal_good_val, test_pedal_good_val); + EXPECT_FALSE(t_4_2_7); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + + + // T.4.3.4 brake testing + for (auto pair : pedal_pairs) + { + auto p1 = std::get<0>(pair); + auto p2 = std::get<1>(pair); + bool t_4_3_4 = get_result_of_double_brake_test(pedals, test_pedal_good_val, test_pedal_good_val, p1, p2); + EXPECT_TRUE(t_4_3_4); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + + t_4_3_4 = get_result_of_single_brake_test(pedals, test_pedal_good_val, test_pedal_good_val, p1); + EXPECT_TRUE(t_4_3_4); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + } +} + +// T.4.2.4 FSAE rules 2024 v1 (accel vals not within 10 percent of each other) +TEST(PedalsSystemTesting, test_accel_and_brake_percentages_implausibility) +{ + // accel percentage outside of range + AnalogConversion_s test_pedal_pos_slope_val_not_pressed = {1000, 0.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_neg_slope_val_not_pressed = {2000, 0.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_val_half_pressed = {1500, 0.5, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + // the pos / neg slop gens pedal sens 1 with neg, and sensor 2 with pos. slope + auto accel_params = gen_positive_and_negative_slope_params(); + auto brake_params = gen_positive_slope_only_params(); + PedalsSystem pedals(accel_params, brake_params); + // bool is true if it is supposed to error, false otherwise + std::vector> pedal_pairs_w_expected_val; + + // check the possibilities of all half pressed and not pressed with aligned slopes for sensor values + pedal_pairs_w_expected_val.push_back({test_pedal_neg_slope_val_not_pressed, test_pedal_val_half_pressed, true}); + pedal_pairs_w_expected_val.push_back({test_pedal_val_half_pressed, test_pedal_pos_slope_val_not_pressed, true}); + pedal_pairs_w_expected_val.push_back({test_pedal_neg_slope_val_not_pressed, test_pedal_pos_slope_val_not_pressed, false}); + pedal_pairs_w_expected_val.push_back({test_pedal_val_half_pressed, test_pedal_val_half_pressed, false}); + + for(auto set : pedal_pairs_w_expected_val) + { + auto p1 = std::get<0>(set); + auto p2 = std::get<1>(set); + // test accel + bool res = get_result_of_double_brake_test(pedals, p1, p2, test_pedal_pos_slope_val_not_pressed, test_pedal_pos_slope_val_not_pressed); + EXPECT_EQ(res, std::get<2>(set)); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + // TODO test double brake res (brakes not within req percentage) (not required by rules, still good to have) + + // testing single brake accel mode + res = get_result_of_single_brake_test(pedals, p1, p2, test_pedal_pos_slope_val_not_pressed); + EXPECT_EQ(res, std::get<2>(set)); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + + } + } +// EV.4.7.1 FSAE rules 2024 v1 +// TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) +// { +// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// auto params = gen_params(); +// PedalsSystem pedals(params, params); +// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); +// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); +// EXPECT_TRUE(data.brakePressed); +// } + +// // T.4.2.5 FSAE rules 2024 v1 +// TEST(PedalsSystemTesting, test_implausibility_duration) +// { +// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// auto params = gen_params(); +// PedalsSystem pedals(params, params); +// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); +// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); +// EXPECT_TRUE(data.brakePressed); +// EXPECT_FALSE(data.implausibilityExceededMaxDuration); + +// data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1200); +// EXPECT_TRUE(data.implausibilityExceededMaxDuration); + +// auto data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1000); +// EXPECT_TRUE(data2.brakeAndAccelPressedImplausibility); +// EXPECT_TRUE(data2.brakePressed); +// EXPECT_FALSE(data2.implausibilityExceededMaxDuration); + +// data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1200); +// EXPECT_TRUE(data2.implausibilityExceededMaxDuration); +// } + +// TEST(PedalsSystemTesting, single_brake_pedal_test_limits) +// { +// // accel min and max on raw +// AnalogConversion_s test_accel1_val = {0, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// AnalogConversion_s test_accel2_val = {200, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// AnalogConversion_s test_brake1_val = {200, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// AnalogConversion_s test_brake2_val = {500, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; +// auto params = gen_params(); +// PedalsSystem pedals(params, params); + +// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake1_val, test_brake2_val, 1000); +// EXPECT_TRUE(data.brakeImplausible); +// } #endif /* PEDALS_SYSTEM_TEST */ From 4fa4005df6ca27dbf566d5c51ece8993bfe7f37a Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 17:42:05 -0400 Subject: [PATCH 4/8] pushing more tests --- include/MCU_rev15_defs.h | 6 +- lib/systems/src/PedalsSystem.cpp | 17 +- test/test_systems/pedals_system_test.h | 209 ++++++++++++++++++------- 3 files changed, 171 insertions(+), 61 deletions(-) diff --git a/include/MCU_rev15_defs.h b/include/MCU_rev15_defs.h index 426afe6c6..0582dc04e 100644 --- a/include/MCU_rev15_defs.h +++ b/include/MCU_rev15_defs.h @@ -54,9 +54,9 @@ const int BRAKE2_PEDAL_MIN = 867; const float DEFAULT_PEDAL_DEADZONE = 0.05f; const float DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN = 0.10f; -const float APPS_ACTIVATION_PERCENTAGE = 0.1; -const float BRAKE_ACTIVATION_PERCENTAGE = 0.05; -const float BRAKE_MECH_THRESH = 0.40; +const float APPS_ACTIVATION_PERCENTAGE = 0.1f; +const float BRAKE_ACTIVATION_PERCENTAGE = 0.05f; +const float BRAKE_MECH_THRESH = 0.40f; // Load Cell Defs to convert raw to lbs // lbs = (scale)*raw + offset diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index 17484ba45..d5090191c 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -24,6 +24,10 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel unsigned long curr_time) { PedalsSystemData_s out; + + out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; + out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); + out.accelImplausible = evaluate_pedal_implausibilities_(accel1, accel2, accelParams_, 0.1); out.brakeImplausible = evaluate_pedal_implausibilities_(brake, brakeParams_); out.brakeAndAccelPressedImplausibility = evaluate_brake_and_accel_pressed_(accel1, accel2, brake); @@ -33,13 +37,11 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel { implausibilityStartTime_ = curr_time; } - else if (!implausibility) + else if ((!implausibility) && (!(out.accelPercent > 0.05))) { implausibilityStartTime_ = 0; } - out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; - out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); out.brakePercent = brake.conversion; out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); @@ -63,6 +65,12 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel PedalsSystemData_s out; out.accelPressed = pedal_is_active_(accel1.conversion, accel2.conversion, accelParams_, false); out.accelImplausible = evaluate_pedal_implausibilities_(accel1, accel2, accelParams_, 0.1); + + out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; + out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); + + + out.brakeImplausible = evaluate_pedal_implausibilities_(brake1, brake2, brakeParams_, 0.25); out.brakeAndAccelPressedImplausibility = evaluate_brake_and_accel_pressed_(accel1, accel2, brake1, brake2); bool implausibility = (out.brakeAndAccelPressedImplausibility || out.brakeImplausible || out.accelImplausible); @@ -71,14 +79,13 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel { implausibilityStartTime_ = curr_time; } - else if ((!implausibility) && (!out.accelPressed)) + else if ((!implausibility) && (!(out.accelPercent > 0.05))) { implausibilityStartTime_ = 0; } out.brakePercent = (brake1.conversion + brake2.conversion) / 2.0; - out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); diff --git a/test/test_systems/pedals_system_test.h b/test/test_systems/pedals_system_test.h index 2853daea4..019706fea 100644 --- a/test/test_systems/pedals_system_test.h +++ b/test/test_systems/pedals_system_test.h @@ -13,6 +13,11 @@ author: Lucas Plant #include #include "MCU_rev15_defs.h" +float get_pedal_conversion_val(float min, float max, float data) +{ + float scale = 1.0f / (max - min); + return ((data - min) * scale); +} PedalsParams gen_positive_and_negative_slope_params() { PedalsParams params; @@ -27,6 +32,34 @@ PedalsParams gen_positive_and_negative_slope_params() return params; } +// +PedalsParams get_real_accel_pedal_params() +{ + PedalsParams params; + params.min_pedal_1 = ACCEL1_PEDAL_MIN; + params.max_pedal_1 = ACCEL1_PEDAL_MAX; + params.min_pedal_2 = ACCEL2_PEDAL_MIN; + params.max_pedal_2 = ACCEL2_PEDAL_MAX; + params.activation_percentage = APPS_ACTIVATION_PERCENTAGE; + params.mechanical_activation_percentage = APPS_ACTIVATION_PERCENTAGE; + params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; // .05 + params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; // 0.1 + return params; +} +PedalsParams get_real_brake_pedal_params() +{ + PedalsParams params; + params.min_pedal_1 = BRAKE1_PEDAL_MIN; + params.max_pedal_1 = BRAKE1_PEDAL_MAX; + params.min_pedal_2 = BRAKE2_PEDAL_MIN; + params.max_pedal_2 = BRAKE2_PEDAL_MAX; + params.activation_percentage = APPS_ACTIVATION_PERCENTAGE; + params.mechanical_activation_percentage = BRAKE_MECH_THRESH; + params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; // .05 + params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; // 0.1 + return params; +} + PedalsParams gen_positive_slope_only_params() { PedalsParams params; @@ -106,7 +139,6 @@ TEST(PedalsSystemTesting, test_accel_and_brake_limits_plausibility) EXPECT_FALSE(t_4_2_7); EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); - // T.4.3.4 brake testing for (auto pair : pedal_pairs) { @@ -128,10 +160,10 @@ TEST(PedalsSystemTesting, test_accel_and_brake_percentages_implausibility) // accel percentage outside of range AnalogConversion_s test_pedal_pos_slope_val_not_pressed = {1000, 0.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; AnalogConversion_s test_pedal_neg_slope_val_not_pressed = {2000, 0.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_pedal_val_half_pressed = {1500, 0.5, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_val_half_pressed = {1500, 0.4, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; // the pos / neg slop gens pedal sens 1 with neg, and sensor 2 with pos. slope - auto accel_params = gen_positive_and_negative_slope_params(); + auto accel_params = gen_positive_and_negative_slope_params(); auto brake_params = gen_positive_slope_only_params(); PedalsSystem pedals(accel_params, brake_params); // bool is true if it is supposed to error, false otherwise @@ -143,7 +175,7 @@ TEST(PedalsSystemTesting, test_accel_and_brake_percentages_implausibility) pedal_pairs_w_expected_val.push_back({test_pedal_neg_slope_val_not_pressed, test_pedal_pos_slope_val_not_pressed, false}); pedal_pairs_w_expected_val.push_back({test_pedal_val_half_pressed, test_pedal_val_half_pressed, false}); - for(auto set : pedal_pairs_w_expected_val) + for (auto set : pedal_pairs_w_expected_val) { auto p1 = std::get<0>(set); auto p2 = std::get<1>(set); @@ -152,64 +184,135 @@ TEST(PedalsSystemTesting, test_accel_and_brake_percentages_implausibility) EXPECT_EQ(res, std::get<2>(set)); EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); // TODO test double brake res (brakes not within req percentage) (not required by rules, still good to have) - + // testing single brake accel mode res = get_result_of_single_brake_test(pedals, p1, p2, test_pedal_pos_slope_val_not_pressed); EXPECT_EQ(res, std::get<2>(set)); EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); - } - } // EV.4.7.1 FSAE rules 2024 v1 -// TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) -// { -// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// auto params = gen_params(); -// PedalsSystem pedals(params, params); -// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); -// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); -// EXPECT_TRUE(data.brakePressed); -// } +TEST(PedalsSystemTesting, test_accel_and_brake_pressed_at_same_time_and_activation) +{ + // test with example data + AnalogConversion_s test_pedal_val_half_pressed = {1500, 0.5, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + // the pos / neg slop gens pedal sens 1 with neg, and sensor 2 with pos. slope + auto accel_params = gen_positive_and_negative_slope_params(); + auto brake_params = gen_positive_slope_only_params(); + PedalsSystem pedals(accel_params, brake_params); + // + EXPECT_TRUE(get_result_of_double_brake_test(pedals, test_pedal_val_half_pressed, test_pedal_val_half_pressed, test_pedal_val_half_pressed, test_pedal_val_half_pressed)); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + EXPECT_TRUE(get_result_of_single_brake_test(pedals, test_pedal_val_half_pressed, test_pedal_val_half_pressed, test_pedal_val_half_pressed)); + EXPECT_TRUE(reset_pedals_system_implaus_time(pedals)); + + // test with real data (accel = ~37%) accel pressed + float accel1 = 2583; + float accel2 = 1068; + float brake = 1510; + pedals.setParams({ACCEL1_PEDAL_MIN, ACCEL2_PEDAL_MIN, ACCEL1_PEDAL_MAX, ACCEL2_PEDAL_MAX, APPS_ACTIVATION_PERCENTAGE, DEFAULT_PEDAL_DEADZONE, DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN, APPS_ACTIVATION_PERCENTAGE}, + {BRAKE1_PEDAL_MIN, BRAKE2_PEDAL_MIN, BRAKE1_PEDAL_MAX, BRAKE2_PEDAL_MAX, BRAKE_ACTIVATION_PERCENTAGE, DEFAULT_PEDAL_DEADZONE, DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN, BRAKE_MECH_THRESH}); + float conv1 = get_pedal_conversion_val(ACCEL1_PEDAL_MIN, ACCEL1_PEDAL_MAX, accel1); + float conv2 = get_pedal_conversion_val(ACCEL2_PEDAL_MIN, ACCEL2_PEDAL_MAX, accel2); + float convb = get_pedal_conversion_val(BRAKE1_PEDAL_MIN, BRAKE1_PEDAL_MAX, brake); + + std::cout << conv1 << " " << conv2 << " " << convb << std::endl; + AnalogConversion_s accel1_data = {accel1, conv1, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s accel2_data = {accel1, conv2, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s brake_data = {brake, convb, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + EXPECT_TRUE(get_result_of_single_brake_test(pedals, test_pedal_val_half_pressed, test_pedal_val_half_pressed, test_pedal_val_half_pressed)); +} // // T.4.2.5 FSAE rules 2024 v1 -// TEST(PedalsSystemTesting, test_implausibility_duration) -// { -// AnalogConversion_s test_accel1_val = {2000, 0.6, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake_val = {3000, 1.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// auto params = gen_params(); -// PedalsSystem pedals(params, params); -// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); -// EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); -// EXPECT_TRUE(data.brakePressed); -// EXPECT_FALSE(data.implausibilityExceededMaxDuration); - -// data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1200); -// EXPECT_TRUE(data.implausibilityExceededMaxDuration); - -// auto data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1000); -// EXPECT_TRUE(data2.brakeAndAccelPressedImplausibility); -// EXPECT_TRUE(data2.brakePressed); -// EXPECT_FALSE(data2.implausibilityExceededMaxDuration); - -// data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1200); -// EXPECT_TRUE(data2.implausibilityExceededMaxDuration); -// } - -// TEST(PedalsSystemTesting, single_brake_pedal_test_limits) -// { -// // accel min and max on raw -// AnalogConversion_s test_accel1_val = {0, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_accel2_val = {200, 0.3, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake1_val = {200, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// AnalogConversion_s test_brake2_val = {500, 0.01, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; -// auto params = gen_params(); -// PedalsSystem pedals(params, params); - -// auto data = pedals.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake1_val, test_brake2_val, 1000); -// EXPECT_TRUE(data.brakeImplausible); -// } +TEST(PedalsSystemTesting, test_implausibility_duration) +{ + AnalogConversion_s test_accel1_val = {2583, 0.37, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_accel2_val = {1068, 0.37, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_val = {1510, get_pedal_conversion_val(BRAKE1_PEDAL_MIN, BRAKE1_PEDAL_MAX, 1510), AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + PedalsSystem pedals(get_real_accel_pedal_params(), get_real_brake_pedal_params()); + + auto data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1000); + EXPECT_TRUE(data.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data.brakePressed); + EXPECT_FALSE(data.implausibilityExceededMaxDuration); + + data = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, test_brake_val, 1110); + EXPECT_TRUE(data.implausibilityExceededMaxDuration); + + // testing the single brake pedal vals + auto data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1000); + EXPECT_TRUE(data2.brakeAndAccelPressedImplausibility); + EXPECT_TRUE(data2.brakePressed); + EXPECT_FALSE(data2.implausibilityExceededMaxDuration); + + data2 = pedals.evaluate_pedals(test_accel1_val, test_accel1_val, test_brake_val, 1110); + EXPECT_TRUE(data2.implausibilityExceededMaxDuration); +} + +// EV.4.7.2 b FSAE rules 2024 v1 +TEST(PedalsSystemTesting, implausibility_latching_until_accel_released_double_brake) +{ + AnalogConversion_s test_accel1_val = {2583, 0.37, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_accel2_val = {1068, 0.37, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_val = {1510, get_pedal_conversion_val(BRAKE1_PEDAL_MIN, BRAKE1_PEDAL_MAX, 1510), AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + PedalsSystem pedals(get_real_accel_pedal_params(), get_real_brake_pedal_params()); + + // should stay im + EXPECT_TRUE(get_result_of_double_brake_test(pedals, test_accel1_val, test_accel2_val, test_brake_val, test_brake_val)); + + test_brake_val.raw = 870; + test_brake_val.conversion = 0.0; + auto data = pedals.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake_val, test_brake_val, 1600); + // this should still be implause since accel is still pressed + EXPECT_TRUE(data.implausibilityExceededMaxDuration); + + // reset accel to zero and try again this time it should pass + test_accel1_val.raw = ACCEL1_PEDAL_MIN; + test_accel2_val.raw = ACCEL2_PEDAL_MIN; + test_accel1_val.conversion = 0.0; + test_accel2_val.conversion = 0.0; + data = pedals.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake_val, test_brake_val, 1650); + + EXPECT_FALSE(data.implausibilityExceededMaxDuration); + + +} + +TEST(PedalsSystemTesting, implausibility_latching_until_accel_released_single_brake) +{ + //////////////////// + // repeat above with single pedal brake test: + //////////////////// + AnalogConversion_s test_accel1_val = {2583, 0.37, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_accel2_val = {1068, 0.37, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_brake_val = {1510, get_pedal_conversion_val(BRAKE1_PEDAL_MIN, BRAKE1_PEDAL_MAX, 1510), AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + PedalsSystem pedals2(get_real_accel_pedal_params(), get_real_brake_pedal_params()); + + // first we fail + EXPECT_TRUE(get_result_of_single_brake_test(pedals2, test_accel1_val, test_accel2_val, test_brake_val)); + + test_brake_val.raw = 870; + test_brake_val.conversion = 0.0; + auto data2 = pedals2.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake_val, 1600); + // this should still be implause since accel is still pressed + EXPECT_TRUE(data2.implausibilityExceededMaxDuration); + + // now we reset throttle back to 0 + test_accel1_val.raw = ACCEL1_PEDAL_MIN+10; + test_accel2_val.raw = ACCEL2_PEDAL_MIN+30; + test_accel1_val.conversion = 0.01; + test_accel2_val.conversion = 0.05; + data2 = pedals2.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake_val, 1710); + EXPECT_FALSE(data2.implausibilityExceededMaxDuration); + + +} + +// TEST(PedalsSystemTesting, deadzone_removal_calc) #endif /* PEDALS_SYSTEM_TEST */ From 8f00a176cf0ff491d04046e445801bc6348ed686 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 18:26:20 -0400 Subject: [PATCH 5/8] adding new tests --- lib/systems/src/PedalsSystem.cpp | 8 +- test/test_systems/pedals_system_test.h | 147 ++++++++++++++++++++++++- 2 files changed, 145 insertions(+), 10 deletions(-) diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index d5090191c..9d8072429 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -25,9 +25,9 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel { PedalsSystemData_s out; - out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; + out.accelPercent = ((accel1.conversion + accel2.conversion) / 2.0); out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); - + out.accelPercent = std::max(out.accelPercent, 0.0f); out.accelImplausible = evaluate_pedal_implausibilities_(accel1, accel2, accelParams_, 0.1); out.brakeImplausible = evaluate_pedal_implausibilities_(brake, brakeParams_); out.brakeAndAccelPressedImplausibility = evaluate_brake_and_accel_pressed_(accel1, accel2, brake); @@ -46,7 +46,7 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.brakePercent = brake.conversion; out.brakePercent = remove_deadzone_(out.brakePercent, brakeParams_.deadzone_margin); - out.mechBrakeActive = out.brakePercent > brakeParams_.mechanical_activation_percentage; + out.mechBrakeActive = out.brakePercent >= brakeParams_.mechanical_activation_percentage; out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); out.brakePressed = out.brakePercent > brakeParams_.activation_percentage; @@ -68,7 +68,7 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); - + out.accelPercent = std::max(out.accelPercent, 0.0f); out.brakeImplausible = evaluate_pedal_implausibilities_(brake1, brake2, brakeParams_, 0.25); diff --git a/test/test_systems/pedals_system_test.h b/test/test_systems/pedals_system_test.h index 019706fea..869d06f08 100644 --- a/test/test_systems/pedals_system_test.h +++ b/test/test_systems/pedals_system_test.h @@ -67,7 +67,7 @@ PedalsParams gen_positive_slope_only_params() params.max_pedal_1 = 2000; params.min_pedal_2 = 1000; params.max_pedal_2 = 2000; - params.activation_percentage = 0.25; + params.activation_percentage = 0.1; params.mechanical_activation_percentage = 0.4; params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; // .05 params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; // 0.1 @@ -278,8 +278,6 @@ TEST(PedalsSystemTesting, implausibility_latching_until_accel_released_double_br data = pedals.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake_val, test_brake_val, 1650); EXPECT_FALSE(data.implausibilityExceededMaxDuration); - - } TEST(PedalsSystemTesting, implausibility_latching_until_accel_released_single_brake) @@ -303,16 +301,153 @@ TEST(PedalsSystemTesting, implausibility_latching_until_accel_released_single_br EXPECT_TRUE(data2.implausibilityExceededMaxDuration); // now we reset throttle back to 0 - test_accel1_val.raw = ACCEL1_PEDAL_MIN+10; - test_accel2_val.raw = ACCEL2_PEDAL_MIN+30; + test_accel1_val.raw = ACCEL1_PEDAL_MIN + 10; + test_accel2_val.raw = ACCEL2_PEDAL_MIN + 30; test_accel1_val.conversion = 0.01; test_accel2_val.conversion = 0.05; data2 = pedals2.evaluate_pedals(test_accel1_val, test_accel2_val, test_brake_val, 1710); EXPECT_FALSE(data2.implausibilityExceededMaxDuration); +} + +TEST(PedalsSystemTesting, deadzone_removal_calc_double_brake_ped) +{ + // accel value testing (0, 100 percent, 50 percent) + AnalogConversion_s test_pedal_good_val = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + PedalsSystem pedals(gen_positive_slope_only_params(), gen_positive_slope_only_params()); + auto data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1000); + EXPECT_NEAR(data.accelPercent, 0, .001); + test_pedal_good_val.raw = 2059; + test_pedal_good_val.conversion = 1.05; + data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1100); + EXPECT_NEAR(data.accelPercent, 1, .001); + test_pedal_good_val.raw = 1500; + test_pedal_good_val.conversion = 0.5; + data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1200); + EXPECT_NEAR(data.accelPercent, 0.5, .001); + + // brake value testing (0, 100 percent, 50 percent) + AnalogConversion_s test_pedal_good_val_accel = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1300); + EXPECT_NEAR(data.brakePercent, 0, .001); + test_pedal_good_val_brake.raw = 2059; + test_pedal_good_val_brake.conversion = 1.05; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1400); + EXPECT_NEAR(data.brakePercent, 1, .001); + test_pedal_good_val_brake.raw = 1500; + test_pedal_good_val_brake.conversion = 0.5; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1500); + EXPECT_NEAR(data.brakePercent, 0.5, .001); +} + +TEST(PedalsSystemTesting, deadzone_removal_calc_single_brake_ped) +{ + // accel value testing (0, 100 percent, 50 percent) + AnalogConversion_s test_pedal_good_val = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + PedalsSystem pedals(gen_positive_slope_only_params(), gen_positive_slope_only_params()); + auto data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1000); + EXPECT_NEAR(data.accelPercent, 0, .001); + test_pedal_good_val.raw = 2059; + test_pedal_good_val.conversion = 1.05; + data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1100); + EXPECT_NEAR(data.accelPercent, 1, .001); + test_pedal_good_val.raw = 1500; + test_pedal_good_val.conversion = 0.5; + data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1200); + EXPECT_NEAR(data.accelPercent, 0.5, .001); + + // brake value testing (0, 100 percent, 50 percent) + AnalogConversion_s test_pedal_good_val_accel = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1300); + EXPECT_NEAR(data.brakePercent, 0, .001); + test_pedal_good_val_brake.raw = 2059; + test_pedal_good_val_brake.conversion = 1.05; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1400); + EXPECT_NEAR(data.brakePercent, 1, .001); + test_pedal_good_val_brake.raw = 1500; + test_pedal_good_val_brake.conversion = 0.5; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1500); + EXPECT_NEAR(data.brakePercent, 0.5, .001); +} + +// testing mechanical brake and brake activation +TEST(PedalsSystemTesting, brake_value_testing_double) +{ + AnalogConversion_s test_pedal_good_val_accel = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1200, 0.2, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + auto params = gen_positive_slope_only_params(); + // taking out deadzone margin to ensure that brake vals are good + params.deadzone_margin = 0; + PedalsSystem pedals(params, params); + auto data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1300); + EXPECT_NEAR(data.brakePercent, 0.2, .02); + EXPECT_NEAR(data.regenPercent, 0.5, .02); + + EXPECT_TRUE(data.brakePressed); + EXPECT_FALSE(data.mechBrakeActive); + + test_pedal_good_val_brake.raw = 1400; + test_pedal_good_val_brake.conversion = .4; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1500); + EXPECT_NEAR(data.brakePercent, 0.4, .03); + EXPECT_TRUE(data.brakePressed); + EXPECT_TRUE(data.mechBrakeActive); + EXPECT_NEAR(data.regenPercent, 1, .03); } -// TEST(PedalsSystemTesting, deadzone_removal_calc) +TEST(PedalsSystemTesting, brake_value_testing_single) +{ + AnalogConversion_s test_pedal_good_val_accel = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1200, 0.2, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + auto params = gen_positive_slope_only_params(); + // taking out deadzone margin to ensure that brake vals are good + params.deadzone_margin = 0; + PedalsSystem pedals(params, params); + auto data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1300); + EXPECT_NEAR(data.brakePercent, 0.2, .02); + EXPECT_NEAR(data.regenPercent, 0.5, .02); + + EXPECT_TRUE(data.brakePressed); + EXPECT_FALSE(data.mechBrakeActive); + + test_pedal_good_val_brake.raw = 1400; + test_pedal_good_val_brake.conversion = .4; + data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1500); + EXPECT_NEAR(data.brakePercent, 0.4, .03); + EXPECT_TRUE(data.brakePressed); + EXPECT_TRUE(data.mechBrakeActive); + EXPECT_NEAR(data.regenPercent, 1, .03); +} + +TEST(PedalsSystemTesting, check_accel_never_negative_single) +{ + AnalogConversion_s test_pedal_good_val_accel = {930, -0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1200, 0.2, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + auto params = gen_positive_slope_only_params(); + // taking out deadzone margin to ensure that brake vals are good + params.deadzone_margin = 0; + PedalsSystem pedals(params, params); + auto data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1300); + EXPECT_FALSE(data.accelImplausible); + EXPECT_EQ(data.accelPercent, 0); + +} + +TEST(PedalsSystemTesting, check_accel_never_negative_double) +{ + AnalogConversion_s test_pedal_good_val_accel = {930, -0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1200, 0.2, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + auto params = gen_positive_slope_only_params(); + // taking out deadzone margin to ensure that brake vals are good + params.deadzone_margin = 0; + PedalsSystem pedals(params, params); + auto data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1300); + EXPECT_FALSE(data.accelImplausible); + EXPECT_EQ(data.accelPercent, 0); + +} #endif /* PEDALS_SYSTEM_TEST */ From 859ed24c64e526d71a0d04a345aabb7f7edd9814 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 19:26:48 -0400 Subject: [PATCH 6/8] fixed de-latch of car when mc error reset --- include/MCU_rev15_defs.h | 2 +- lib/state_machine/include/MCUStateMachine.tpp | 8 +++++--- lib/systems/src/PedalsSystem.cpp | 2 +- src/main.cpp | 1 - 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/MCU_rev15_defs.h b/include/MCU_rev15_defs.h index 0582dc04e..97e232d0b 100644 --- a/include/MCU_rev15_defs.h +++ b/include/MCU_rev15_defs.h @@ -51,7 +51,7 @@ const int BRAKE2_PEDAL_MAX = 2198; const int BRAKE1_PEDAL_MIN = 867; const int BRAKE2_PEDAL_MIN = 867; -const float DEFAULT_PEDAL_DEADZONE = 0.05f; +const float DEFAULT_PEDAL_DEADZONE = 0.03f; const float DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN = 0.10f; const float APPS_ACTIVATION_PERCENTAGE = 0.1f; diff --git a/lib/state_machine/include/MCUStateMachine.tpp b/lib/state_machine/include/MCUStateMachine.tpp index 415e72f6a..6cbdcbf42 100644 --- a/lib/state_machine/include/MCUStateMachine.tpp +++ b/lib/state_machine/include/MCUStateMachine.tpp @@ -39,12 +39,14 @@ void MCUStateMachine::tick_state_machine(unsigned long curren // Serial.print(" "); // Serial.print(data.brakeAndAccelPressedImplausibility); // Serial.print(" "); - // Serial.print(data.implausibilityExceededMaxDuration); - // Serial.println(); + + // Serial.println("accel, brake:"); // Serial.print(data.accelPercent); // Serial.print(" "); // Serial.print(data.brakePercent); - // Serial.print(" "); + // Serial.print(" \n"); + // Serial.print(data.implausibilityExceededMaxDuration); + // Serial.println(); // if TS is above HV threshold, move to Tractive System Active diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index 10010ccf0..bda7f3d0f 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -37,7 +37,7 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel { implausibilityStartTime_ = curr_time; } - else if ((!implausibility) && (!(out.accelPercent > 0.05))) + else if ((!implausibility) && ((out.accelPercent <= 0.05))) { implausibilityStartTime_ = 0; } diff --git a/src/main.cpp b/src/main.cpp index 334d4b0f0..5430f00ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -195,7 +195,6 @@ void loop() // reset inverters if (dashboard.inverterResetButtonPressed() && drivetrain.drivetrain_error_occured()) { - hal_println("resetting errored drivetrain"); drivetrain.reset_drivetrain(); } // tick state machine From adb6d1c17a43d103632006e251ab34cb0c9c0ceb Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 19:35:47 -0400 Subject: [PATCH 7/8] fixing small number skill issues --- lib/systems/src/PedalsSystem.cpp | 4 ++-- test/test_systems/pedals_system_test.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index bda7f3d0f..63faa83cb 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -67,8 +67,8 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.accelPressed = pedal_is_active_(accel1.conversion, accel2.conversion, accelParams_, false); out.accelImplausible = evaluate_pedal_implausibilities_(accel1, accel2, accelParams_, 0.1); - out.accelPercent = (accel1.conversion + accel2.conversion) / 2.0; - out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); + auto percent = (accel1.conversion + accel2.conversion) / 2.0; + out.accelPercent = remove_deadzone_(percent, accelParams_.deadzone_margin); out.accelPercent = std::max(out.accelPercent, 0.0f); diff --git a/test/test_systems/pedals_system_test.h b/test/test_systems/pedals_system_test.h index c9374bf98..e4dc8e54b 100644 --- a/test/test_systems/pedals_system_test.h +++ b/test/test_systems/pedals_system_test.h @@ -27,7 +27,7 @@ PedalsParams gen_positive_and_negative_slope_params() params.max_pedal_2 = 2000; params.activation_percentage = 0.25; params.mechanical_activation_percentage = 0.4; - params.deadzone_margin = DEFAULT_PEDAL_DEADZONE; // .05 + params.deadzone_margin = .03; // .05 params.implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN; // 0.1 return params; } @@ -312,7 +312,7 @@ TEST(PedalsSystemTesting, implausibility_latching_until_accel_released_single_br TEST(PedalsSystemTesting, deadzone_removal_calc_double_brake_ped) { // accel value testing (0, 100 percent, 50 percent) - AnalogConversion_s test_pedal_good_val = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val = {1010, 0.03, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; PedalsSystem pedals(gen_positive_slope_only_params(), gen_positive_slope_only_params()); auto data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1000); EXPECT_NEAR(data.accelPercent, 0, .001); @@ -326,8 +326,8 @@ TEST(PedalsSystemTesting, deadzone_removal_calc_double_brake_ped) EXPECT_NEAR(data.accelPercent, 0.5, .001); // brake value testing (0, 100 percent, 50 percent) - AnalogConversion_s test_pedal_good_val_accel = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_pedal_good_val_brake = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_accel = {1050, 0.03, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1050, 0.03, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1300); EXPECT_NEAR(data.brakePercent, 0, .001); test_pedal_good_val_brake.raw = 2059; @@ -343,7 +343,7 @@ TEST(PedalsSystemTesting, deadzone_removal_calc_double_brake_ped) TEST(PedalsSystemTesting, deadzone_removal_calc_single_brake_ped) { // accel value testing (0, 100 percent, 50 percent) - AnalogConversion_s test_pedal_good_val = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val = {1010, 0.03, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; PedalsSystem pedals(gen_positive_slope_only_params(), gen_positive_slope_only_params()); auto data = pedals.evaluate_pedals(test_pedal_good_val, test_pedal_good_val, test_pedal_good_val, 1000); EXPECT_NEAR(data.accelPercent, 0, .001); @@ -357,10 +357,10 @@ TEST(PedalsSystemTesting, deadzone_removal_calc_single_brake_ped) EXPECT_NEAR(data.accelPercent, 0.5, .001); // brake value testing (0, 100 percent, 50 percent) - AnalogConversion_s test_pedal_good_val_accel = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; - AnalogConversion_s test_pedal_good_val_brake = {1050, 0.05, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_accel = {1010, 0.03, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1010, 0.03, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1300); - EXPECT_NEAR(data.brakePercent, 0, .001); + EXPECT_NEAR(data.brakePercent, 0, .01); test_pedal_good_val_brake.raw = 2059; test_pedal_good_val_brake.conversion = 1.05; data = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1400); From bb794f28ded34fdc6bce38f3587de99fe85ac1fd Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Wed, 10 Apr 2024 20:12:52 -0400 Subject: [PATCH 8/8] resolving https://github.com/hytech-racing/MCU/pull/69#discussion_r1560185606 --- lib/systems/src/PedalsSystem.cpp | 2 +- test/test_systems/pedals_system_test.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/systems/src/PedalsSystem.cpp b/lib/systems/src/PedalsSystem.cpp index 63faa83cb..701cd633c 100644 --- a/lib/systems/src/PedalsSystem.cpp +++ b/lib/systems/src/PedalsSystem.cpp @@ -28,6 +28,7 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.accelPercent = ((accel1.conversion + accel2.conversion) / 2.0); out.accelPercent = remove_deadzone_(out.accelPercent, accelParams_.deadzone_margin); out.accelPercent = std::max(out.accelPercent, 0.0f); + out.accelPressed = pedal_is_active_(accel1.conversion, accel2.conversion, accelParams_, false); out.accelImplausible = evaluate_pedal_implausibilities_(accel1, accel2, accelParams_, 0.1); out.brakeImplausible = evaluate_pedal_implausibilities_(brake, brakeParams_); out.brakeAndAccelPressedImplausibility = evaluate_brake_and_accel_pressed_(accel1, accel2, brake); @@ -49,7 +50,6 @@ PedalsSystemData_s PedalsSystem::evaluate_pedals(const AnalogConversion_s &accel out.mechBrakeActive = out.brakePercent >= brakeParams_.mechanical_activation_percentage; out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f); - out.brakePressed = out.brakePercent > brakeParams_.activation_percentage; out.implausibilityExceededMaxDuration = max_duration_of_implausibility_exceeded_(curr_time); diff --git a/test/test_systems/pedals_system_test.h b/test/test_systems/pedals_system_test.h index e4dc8e54b..708175e70 100644 --- a/test/test_systems/pedals_system_test.h +++ b/test/test_systems/pedals_system_test.h @@ -450,5 +450,19 @@ TEST(PedalsSystemTesting, check_accel_never_negative_double) } +TEST(PedalsSystemTesting, check_accel_pressed) +{ + AnalogConversion_s test_pedal_good_val_accel = {1200, 0.2, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + AnalogConversion_s test_pedal_good_val_brake = {1001, 0.0, AnalogSensorStatus_e::ANALOG_SENSOR_GOOD}; + + auto params = gen_positive_slope_only_params(); + PedalsSystem pedals(params, params); + PedalsSystem pedals_single(params, params); + auto data_double = pedals.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, test_pedal_good_val_brake, 1300); + EXPECT_TRUE(data_double.accelPressed); + auto data_single = pedals_single.evaluate_pedals(test_pedal_good_val_accel, test_pedal_good_val_accel, test_pedal_good_val_brake, 1300); + EXPECT_TRUE(data_single.accelPressed); +} + #endif /* PEDALS_SYSTEM_TEST */