From 45b0b71654fbb40cc7b40d9c472fd3bbd839190c Mon Sep 17 00:00:00 2001 From: Comerm28 Date: Sun, 20 Oct 2024 17:44:54 -0400 Subject: [PATCH] unfucked? --- test/test_systems/tc_mux_v2_testing.h | 238 ++++++++++++-------------- 1 file changed, 105 insertions(+), 133 deletions(-) diff --git a/test/test_systems/tc_mux_v2_testing.h b/test/test_systems/tc_mux_v2_testing.h index fab15902..46ca9e32 100644 --- a/test/test_systems/tc_mux_v2_testing.h +++ b/test/test_systems/tc_mux_v2_testing.h @@ -60,30 +60,30 @@ TEST(TorqueControllerMuxTesting, test_construction_bypass_limits) drivetrain_data.measuredSpeeds[i] = 500.0f; } //onlhy use mode 0 for the input state in all tests and then test if they would act the same, idk how to do that - SharedCarState_s mode_1_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}); + SharedCarState_s mode_1_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); auto drive_command = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, mode_1_input_state); - ASSERT_EQ(drive_command.torqueSetpoints[0], 30.0f); - ASSERT_EQ(drive_command.torqueSetpoints[1], 30.0f); - ASSERT_EQ(drive_command.torqueSetpoints[2], 30.0f); - ASSERT_EQ(drive_command.torqueSetpoints[3], 30.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[0], 30.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[1], 30.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[2], 30.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[3], 30.0f); ASSERT_EQ(test.get_tc_mux_status().output_is_bypassing_limits, true); - inst1.output.command.torqueSetpoints[0] = 5; + inst1.output.command.inverter_torque_limit[0] = 5; drive_command = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, mode_1_input_state); - ASSERT_EQ(drive_command.torqueSetpoints[0], 5.0f); - ASSERT_EQ(drive_command.torqueSetpoints[1], 30.0f); - ASSERT_EQ(drive_command.torqueSetpoints[2], 30.0f); - ASSERT_EQ(drive_command.torqueSetpoints[3], 30.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[0], 5.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[1], 30.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[2], 30.0f); + ASSERT_EQ(drive_command.inverter_torque_limit[3], 30.0f); ASSERT_EQ(test.get_tc_mux_status().output_is_bypassing_limits, true); } template void test_with_n_controllers() { - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); std::array controller_instances; std::array controller_ptrs; std::array error_flags{}; @@ -99,7 +99,7 @@ void test_with_n_controllers() { auto result = mux.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); // Assert no error has occurred - ASSERT_EQ(mux.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(mux.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); } // Test case for different numbers of controllers (hardcoded bc needs a const) TEST(TorqueControllerMuxTesting, test_variable_length_controllers) @@ -169,8 +169,8 @@ TEST(TorqueControllerMuxTesting, test_controller_output_swap_logic) out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_1); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_1); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); } TEST(TorqueControllerMuxTesting, simple_switch_many_active_modes) { @@ -180,35 +180,35 @@ TEST(TorqueControllerMuxTesting, simple_switch_many_active_modes) set_outputs(inst3, 0, 1); set_outputs(inst4, 0, 1); TorqueControllerMux<4> test({static_cast(&inst1), static_cast(&inst2), static_cast(&inst3), static_cast(&inst4)}, {false, false, false, false}); - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); set_four_outputs(state.drivetrain_data.measuredSpeeds, 2); state.pedals_data = {}; state.vn_data = {}; auto out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_0); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_1); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_1); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_2, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_2); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_2); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_3, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_3); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_3); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_2, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_2); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_2); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_0); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); } //TorqueControllerMuxError testing @@ -216,43 +216,43 @@ TEST(TorqueControllerMuxTesting, test_invalid_controller_request_error) { TestControllerType inst1, inst2; TorqueControllerMux<2> test({static_cast(&inst1), static_cast(&inst2)}, {false, false}); - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); //test positve out of bounds auto res = test.getDrivetrainCommand(ControllerMode_e::MODE_2, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::ERROR_CONTROLLER_INDEX_OUT_OF_BOUNDS); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::ERROR_CONTROLLER_INDEX_OUT_OF_BOUNDS); for (int i =0; i< 4; i++) { ASSERT_EQ(res.speeds_rpm[i], 0.0); - ASSERT_EQ(res.torqueSetpoints[i], 0.0); + ASSERT_EQ(res.inverter_torque_limit[i], 0.0); } //reset to no error res = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); //test negative out of bounds res = test.getDrivetrainCommand(static_cast(-1), TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::ERROR_CONTROLLER_INDEX_OUT_OF_BOUNDS); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::ERROR_CONTROLLER_INDEX_OUT_OF_BOUNDS); for (int i =0; i< 4; i++) { ASSERT_EQ(res.speeds_rpm[i], 0.0); - ASSERT_EQ(res.torqueSetpoints[i], 0.0); + ASSERT_EQ(res.inverter_torque_limit[i], 0.0); } } TEST(TorqueControllerMuxTesting, test_null_pointer_error_state) { TorqueControllerMux<1> test({nullptr}, {true}); - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); auto res = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, state); for (int i = 0; i < 4; i++) { - ASSERT_EQ(res.torqueSetpoints[i], 0.0f); + ASSERT_EQ(res.inverter_torque_limit[i], 0.0f); ASSERT_EQ(res.speeds_rpm[i], 0.0f); } - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::ERROR_CONTROLLER_NULL_POINTER); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::ERROR_CONTROLLER_NULL_POINTER); } TEST(TorqueControllerMuxTesting, test_torque_diff_swap_limit) { @@ -288,42 +288,14 @@ TEST(TorqueControllerMuxTesting, test_speed_diff_swap_limit) { TestControllerType inst1, inst2; TorqueControllerMux<2> test({static_cast(&inst1), static_cast(&inst2)}, {false, false}); - SharedCarState_s state({}, {}, {}, {}, {}, {}); - - auto out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::ERROR_TORQUE_DIFF_TOO_HIGH); - - // tick it a bunch of times - out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::ERROR_TORQUE_DIFF_TOO_HIGH); - - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); - - ASSERT_EQ(out1.torqueSetpoints[0], 1); - ASSERT_EQ(out1.torqueSetpoints[1], 1); - ASSERT_EQ(out1.torqueSetpoints[2], 1); - ASSERT_EQ(out1.torqueSetpoints[3], 1); -} -TEST(TorqueControllerMuxTesting, test_speed_diff_swap_limit) -{ - TestControllerType inst1, inst2; - TorqueControllerMux<2> test({static_cast(&inst1), static_cast(&inst2)}, {false, false}); - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); set_outputs(inst1, 0.1, 1); set_outputs(inst2, 3, 1); auto out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_1); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_1); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); state.drivetrain_data = { 0, { 3000, 0, 0, 0 }, {}, {}, {} }; @@ -336,14 +308,14 @@ TEST(TorqueControllerMuxTesting, test_speed_diff_swap_limit) out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); out1 = test.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::ERROR_SPEED_DIFF_TOO_HIGH); + ASSERT_EQ(test.get_tc_mux_status().active_error, TorqueControllerMuxError::ERROR_SPEED_DIFF_TOO_HIGH); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_0); - ASSERT_EQ(out1.torqueSetpoints[0], 1); - ASSERT_EQ(out1.torqueSetpoints[1], 1); - ASSERT_EQ(out1.torqueSetpoints[2], 1); - ASSERT_EQ(out1.torqueSetpoints[3], 1); + ASSERT_EQ(out1.inverter_torque_limit[0], 1); + ASSERT_EQ(out1.inverter_torque_limit[1], 1); + ASSERT_EQ(out1.inverter_torque_limit[2], 1); + ASSERT_EQ(out1.inverter_torque_limit[3], 1); } //Mode evaluation tests @@ -373,10 +345,10 @@ TEST(TorqueControllerMuxTesting, test_mode0_evaluation) SharedCarState_s mode_0_input_state({}, {}, {}, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); DrivetrainCommand_s out = torque_controller_mux.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, mode_0_input_state); - ASSERT_NEAR(out.torqueSetpoints[0], (max_torque / 2), 0.01); - ASSERT_NEAR(out.torqueSetpoints[1], (max_torque / 2), 0.01); - ASSERT_NEAR(out.torqueSetpoints[2], (max_torque / 2), 0.01); - ASSERT_NEAR(out.torqueSetpoints[3], (max_torque / 2), 0.01); + ASSERT_NEAR(out.inverter_torque_limit[0], (max_torque / 2), 0.01); + ASSERT_NEAR(out.inverter_torque_limit[1], (max_torque / 2), 0.01); + ASSERT_NEAR(out.inverter_torque_limit[2], (max_torque / 2), 0.01); + ASSERT_NEAR(out.inverter_torque_limit[3], (max_torque / 2), 0.01); } TEST(TorqueControllerMuxTesting, test_modeX_stationary) @@ -399,12 +371,12 @@ TEST(TorqueControllerMuxTesting, test_modeX_stationary) for (int i = 0; i <= 4; ++i) { ControllerMode_e mode = static_cast(static_cast(ControllerMode_e::MODE_0) + i); - SharedCarState_s mode_X_input_state({}, {}, {}, {}, {.accelPercent = 0.0f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}); + SharedCarState_s mode_X_input_state({}, {}, {}, {}, {.accelPercent = 0.0f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); DrivetrainCommand_s out = torque_controller_mux.getDrivetrainCommand(mode, TorqueLimit_e::TCMUX_FULL_TORQUE, mode_X_input_state); - ASSERT_EQ(out.torqueSetpoints[0], 0); - ASSERT_EQ(out.torqueSetpoints[1], 0); - ASSERT_EQ(out.torqueSetpoints[2], 0); - ASSERT_EQ(out.torqueSetpoints[3], 0); + ASSERT_EQ(out.inverter_torque_limit[0], 0); + ASSERT_EQ(out.inverter_torque_limit[1], 0); + ASSERT_EQ(out.inverter_torque_limit[2], 0); + ASSERT_EQ(out.inverter_torque_limit[3], 0); } } @@ -420,7 +392,7 @@ TEST(TorqueControllerMuxTesting, test_power_limit) { drivetrain_data.measuredSpeeds[i] = 500.0f; } - SharedCarState_s mode_1_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}); + SharedCarState_s mode_1_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); DrivetrainCommand_s res = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, mode_1_input_state); @@ -434,7 +406,7 @@ TEST(TorqueControllerMuxTesting, test_power_limit) } set_output_rpm(inst1, 20000, 21.0); - SharedCarState_s mode_1_input_state_high_power({}, {}, drivetrain_data, {}, {.accelPercent = 1.0f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}); + SharedCarState_s mode_1_input_state_high_power({}, {}, drivetrain_data, {}, {.accelPercent = 1.0f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); res = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, mode_1_input_state_high_power); for (int i = 0; i < 4; i++) @@ -458,7 +430,7 @@ TEST(TorqueControllerMuxTesting, test_torque_limit) drivetrain_data.measuredSpeeds[i] = 500.0f; } - SharedCarState_s mode_1_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}); + SharedCarState_s mode_1_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); auto drive_command = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, mode_1_input_state); @@ -488,39 +460,39 @@ TEST(TorqueControllerMuxTesting, test_apply_regen_limit) TestControllerType inst1; set_output_rpm(inst1, 300, 10.0); - inst1.output.command.torqueSetpoints[0] = 10; + inst1.output.command.inverter_torque_limit[0] = 10; TorqueControllerMux<1> test({static_cast(&inst1)}, {false}); - SharedCarState_s mode_1_input_state({}, {}, {}, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}); + SharedCarState_s mode_1_input_state({}, {}, {}, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); DrivetrainDynamicReport_s drivetrain_data_below_no_regen = {}; drivetrain_data_below_no_regen.measuredSpeeds[0] = 12.0f / RPM_TO_KILOMETERS_PER_HOUR; - inst1.output.command.torqueSetpoints[0] = 0.0f; + inst1.output.command.inverter_torque_limit[0] = 0.0f; auto command_below_no_regen = test.getDrivetrainCommand( ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, mode_1_input_state ); - ASSERT_EQ(command_below_no_regen.torqueSetpoints[0], 0.0f); + ASSERT_EQ(command_below_no_regen.inverter_torque_limit[0], 0.0f); DrivetrainDynamicReport_s drivetrain_data_above_no_regen = {}; drivetrain_data_above_no_regen.measuredSpeeds[0] = 15.0f / RPM_TO_KILOMETERS_PER_HOUR; - inst1.output.command.torqueSetpoints[0] = 10.0f; + inst1.output.command.inverter_torque_limit[0] = 10.0f; auto command_above_no_regen = test.getDrivetrainCommand( ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, mode_1_input_state ); - ASSERT_GT(command_above_no_regen.torqueSetpoints[0], 0.0f); + ASSERT_GT(command_above_no_regen.inverter_torque_limit[0], 0.0f); DrivetrainDynamicReport_s drivetrain_data_between_limits = {}; drivetrain_data_between_limits.measuredSpeeds[0] = 8.0f / RPM_TO_KILOMETERS_PER_HOUR; - inst1.output.command.torqueSetpoints[0] = 10.0f; + inst1.output.command.inverter_torque_limit[0] = 10.0f; auto command_between_limits = test.getDrivetrainCommand( ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, mode_1_input_state ); - ASSERT_LE(command_between_limits.torqueSetpoints[0], 10.0f); + ASSERT_LE(command_between_limits.inverter_torque_limit[0], 10.0f); } @@ -529,9 +501,9 @@ TEST(TorqueControllerMuxTesting, test_apply_positive_speed_limit) { TestControllerType inst1; set_output_rpm(inst1, -300, 10.0); - inst1.output.command.torqueSetpoints[0] = 5; + inst1.output.command.inverter_torque_limit[0] = 5; TorqueControllerMux<1> test({static_cast(&inst1)}, {false}); - SharedCarState_s mode_1_input_state({}, {}, {}, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}); + SharedCarState_s mode_1_input_state({}, {}, {}, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}); // apply speed limit happens in here auto drive_command = test.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_LOW_TORQUE, mode_1_input_state); @@ -557,16 +529,16 @@ TEST(TorqueControllerMuxTesting, test_tc_mux_status) TestControllerType inst1; set_outputs(inst1, 0, 1); TorqueControllerMux<1> test({static_cast(&inst1)}, { false }); - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); set_four_outputs(state.drivetrain_data.measuredSpeeds, 2); state.pedals_data = {}; state.vn_data = {}; auto out1 = test.getDrivetrainCommand(testMode, testTorqLim, state); - ASSERT_EQ(test.get_tc_mux_status().current_error, testErr); - ASSERT_EQ(test.get_tc_mux_status().current_controller_mode, testMode); - ASSERT_EQ(test.get_tc_mux_status().current_torque_limit_enum, testTorqLim); + ASSERT_EQ(test.get_tc_mux_status().active_error, testErr); + ASSERT_EQ(test.get_tc_mux_status().active_controller_mode, testMode); + ASSERT_EQ(test.get_tc_mux_status().active_torque_limit_enum, testTorqLim); } //set shared car state so that it does not randomly pass and not pass anymore TEST(TorqueControllerMuxTesting, test_real_controllers_output) @@ -596,34 +568,34 @@ TEST(TorqueControllerMuxTesting, test_real_controllers_output) static_cast(&simple_launch), static_cast(&slip_launch)}, {false, false, false, false, false}); - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); state.pedals_data = {}; state.vn_data = {}; state.drivetrain_data = { 0, {}, {}, {}, {} }; auto out1 = torque_controller_mux.getDrivetrainCommand(ControllerMode_e::MODE_3, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(static_cast(torque_controller_mux.get_tc_mux_status().current_error), static_cast(TorqueControllerMuxError::NO_ERROR)); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_3); + ASSERT_EQ(static_cast(torque_controller_mux.get_tc_mux_status().active_error), static_cast(TorqueControllerMuxError::NO_ERROR)); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_3); out1 = torque_controller_mux.getDrivetrainCommand(ControllerMode_e::MODE_4, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_4); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_4); out1 = torque_controller_mux.getDrivetrainCommand(ControllerMode_e::MODE_4, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_4); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_4); out1 = torque_controller_mux.getDrivetrainCommand(ControllerMode_e::MODE_3, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_3); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_3); out1 = torque_controller_mux.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_0); out1 = torque_controller_mux.getDrivetrainCommand(ControllerMode_e::MODE_1, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(torque_controller_mux.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_1); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(torque_controller_mux.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_1); } void set_state_mcu(SharedCarState_s & state) @@ -693,7 +665,7 @@ TEST(TorqueControllerMuxTesting, test_state_machine_progression_simple_controlle { //recreating environment in CAR_STATE::READY_TO_DRIVE in MCU //which is when the tc mux is used to request torque from active controller - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); set_state_mcu(state); //make tc mux to see if under these conditions it is sending out correct commands @@ -707,15 +679,15 @@ TEST(TorqueControllerMuxTesting, test_state_machine_progression_simple_controlle DrivetrainCommand_s expected = DrivetrainCommand_s { .speeds_rpm = { PhysicalParameters::AMK_MAX_RPM , PhysicalParameters::AMK_MAX_RPM , PhysicalParameters::AMK_MAX_RPM , PhysicalParameters::AMK_MAX_RPM }, - .torqueSetpoints = { 0 , 0 , 0 , 0 } + .inverter_torque_limit = { 0 , 0 , 0 , 0 } }; auto out1 = test_mux0.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test_mux0.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(test_mux0.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); + ASSERT_EQ(test_mux0.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test_mux0.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_0); for(int i = 0; i < 4; i++){ ASSERT_EQ(expected.speeds_rpm[i], out1.speeds_rpm[i]); - ASSERT_EQ(expected.torqueSetpoints[i], out1.torqueSetpoints[i]); + ASSERT_EQ(expected.inverter_torque_limit[i], out1.inverter_torque_limit[i]); } state.pedals_data.accelPercent = .5f; @@ -723,12 +695,12 @@ TEST(TorqueControllerMuxTesting, test_state_machine_progression_simple_controlle expected = DrivetrainCommand_s { .speeds_rpm = { PhysicalParameters::AMK_MAX_RPM , PhysicalParameters::AMK_MAX_RPM , PhysicalParameters::AMK_MAX_RPM , PhysicalParameters::AMK_MAX_RPM }, - .torqueSetpoints = { PhysicalParameters::AMK_MAX_TORQUE*.5 , PhysicalParameters::AMK_MAX_TORQUE*.5 , PhysicalParameters::AMK_MAX_TORQUE*.5 , PhysicalParameters::AMK_MAX_TORQUE*.5} + .inverter_torque_limit = { PhysicalParameters::AMK_MAX_TORQUE*.5 , PhysicalParameters::AMK_MAX_TORQUE*.5 , PhysicalParameters::AMK_MAX_TORQUE*.5 , PhysicalParameters::AMK_MAX_TORQUE*.5} }; out1 = test_mux0.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); for(int i = 0; i < 4; i++){ ASSERT_EQ(expected.speeds_rpm[i], out1.speeds_rpm[i]); - ASSERT_EQ(expected.torqueSetpoints[i], out1.torqueSetpoints[i]); + ASSERT_EQ(expected.inverter_torque_limit[i], out1.inverter_torque_limit[i]); } state.pedals_data.accelPercent = 0; @@ -737,19 +709,19 @@ TEST(TorqueControllerMuxTesting, test_state_machine_progression_simple_controlle expected = DrivetrainCommand_s { .speeds_rpm = { 0 , 0 , 0 , 0 }, - .torqueSetpoints = { 0 , 0 , 0 , 0} + .inverter_torque_limit = { 0 , 0 , 0 , 0} }; out1 = test_mux0.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); for(int i = 0; i < 4; i++){ ASSERT_EQ(expected.speeds_rpm[i], out1.speeds_rpm[i]); - ASSERT_EQ(expected.torqueSetpoints[i], out1.torqueSetpoints[i]); + ASSERT_EQ(expected.inverter_torque_limit[i], out1.inverter_torque_limit[i]); } } TEST(TorqueControllerMuxTesting, test_state_machine_progression_launch_controller) { //recreating environment in CAR_STATE::READY_TO_DRIVE in MCU //which is when the tc mux is used to request torque from active controller - SharedCarState_s state({}, {}, {}, {}, {}, {}); + SharedCarState_s state({}, {}, {}, {}, {}, {}, {}, {}); set_state_mcu(state); //make tc mux to see if under these conditions it is sending out correct commands @@ -763,29 +735,29 @@ TEST(TorqueControllerMuxTesting, test_state_machine_progression_launch_controlle DrivetrainCommand_s expected = DrivetrainCommand_s { .speeds_rpm = { 0 , 0 , 0 , 0 }, - .torqueSetpoints = { 0 , 0 , 0 , 0 } + .inverter_torque_limit = { 0 , 0 , 0 , 0 } }; //makes sure launch not ready state is initialized and it moves to next state while outputting command with no torque or speed ASSERT_EQ(tc_sl.get_launch_state(), LaunchStates_e::LAUNCH_NOT_READY); auto out1 = test_mux0.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test_mux0.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(test_mux0.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); + ASSERT_EQ(test_mux0.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test_mux0.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_0); ASSERT_EQ(tc_sl.get_launch_state(), LaunchStates_e::LAUNCH_READY); for(int i = 0; i < 4; i++){ ASSERT_EQ(expected.speeds_rpm[i], out1.speeds_rpm[i]); - ASSERT_EQ(expected.torqueSetpoints[i], out1.torqueSetpoints[i]); + ASSERT_EQ(expected.inverter_torque_limit[i], out1.inverter_torque_limit[i]); } //ensures that from this state, it transitions from launch ready to launching when accelerator is pressed, still outputs a command with no torque or speed state.pedals_data.accelPercent = .9; out1 = test_mux0.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); - ASSERT_EQ(test_mux0.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); - ASSERT_EQ(test_mux0.get_tc_mux_status().current_controller_mode, ControllerMode_e::MODE_0); + ASSERT_EQ(test_mux0.get_tc_mux_status().active_error, TorqueControllerMuxError::NO_ERROR); + ASSERT_EQ(test_mux0.get_tc_mux_status().active_controller_mode, ControllerMode_e::MODE_0); ASSERT_EQ(tc_sl.get_launch_state(), LaunchStates_e::LAUNCHING); for(int i = 0; i < 4; i++){ ASSERT_EQ(expected.speeds_rpm[i], out1.speeds_rpm[i]); - ASSERT_EQ(expected.torqueSetpoints[i], out1.torqueSetpoints[i]); + ASSERT_EQ(expected.inverter_torque_limit[i], out1.inverter_torque_limit[i]); } //ensures during launch that speed target increases and torque is requested @@ -793,13 +765,13 @@ TEST(TorqueControllerMuxTesting, test_state_machine_progression_launch_controlle { //calculated values for rpm based on time elapsed + algo .speeds_rpm = { 7989 , 7989 , 7989 , 7989 }, - .torqueSetpoints = { PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE} + .inverter_torque_limit = { PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE} }; state.systick.millis = 1000; out1 = test_mux0.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); for(int i = 0; i < 4; i++){ ASSERT_EQ(expected.speeds_rpm[i], out1.speeds_rpm[i]); - ASSERT_EQ(expected.torqueSetpoints[i], out1.torqueSetpoints[i]); + ASSERT_EQ(expected.inverter_torque_limit[i], out1.inverter_torque_limit[i]); } //again @@ -807,13 +779,13 @@ TEST(TorqueControllerMuxTesting, test_state_machine_progression_launch_controlle { //calculated values for rpm based on time elapsed + algo .speeds_rpm = { 14543 , 14543 , 14543 , 14543 }, - .torqueSetpoints = { PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE} + .inverter_torque_limit = { PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE , PhysicalParameters::AMK_MAX_TORQUE} }; state.systick.millis = 2000; out1 = test_mux0.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); for(int i = 0; i < 4; i++){ ASSERT_EQ(expected.speeds_rpm[i], out1.speeds_rpm[i]); - ASSERT_EQ(expected.torqueSetpoints[i], out1.torqueSetpoints[i]); + ASSERT_EQ(expected.inverter_torque_limit[i], out1.inverter_torque_limit[i]); } }