1#ifndef __TC_MUX_V2_TESTING_H__
2#define __TC_MUX_V2_TESTING_H__
7#include "gtest/gtest.h"
13template <
typename quad_array_type>
22template <
typename controller_type>
23void set_outputs(controller_type &controller,
float mps,
float torque)
29 controller.output.command.inverter_torque_limit[0] = torque;
30 controller.output.command.inverter_torque_limit[1] = torque;
31 controller.output.command.inverter_torque_limit[2] = torque;
32 controller.output.command.inverter_torque_limit[3] = torque;
34template <
typename controller_type>
37 controller.output.command.speeds_rpm[0] = rpm;
38 controller.output.command.speeds_rpm[1] = rpm;
39 controller.output.command.speeds_rpm[2] = rpm;
40 controller.output.command.speeds_rpm[3] = rpm;
41 controller.output.command.inverter_torque_limit[0] = torque;
42 controller.output.command.inverter_torque_limit[1] = torque;
43 controller.output.command.inverter_torque_limit[2] = torque;
44 controller.output.command.inverter_torque_limit[3] = torque;
46TEST(TorqueControllerMuxTesting, test_construction)
52TEST(TorqueControllerMuxTesting, test_invalid_controller_request_error)
60 for (
int i =0; i< 4; i++)
63 ASSERT_EQ(res.speeds_rpm[i], 0.0);
64 ASSERT_EQ(res.inverter_torque_limit[i], 0.0);
71TEST(TorqueControllerMuxTesting, test_controller_output_swap_logic)
80 state.pedals_data = {};
101TEST(TorqueControllerMuxTesting, test_torque_diff_swap_limit)
126 ASSERT_EQ(out1.inverter_torque_limit[0], 1);
127 ASSERT_EQ(out1.inverter_torque_limit[1], 1);
128 ASSERT_EQ(out1.inverter_torque_limit[2], 1);
129 ASSERT_EQ(out1.inverter_torque_limit[3], 1);
132TEST(TorqueControllerMuxTesting, test_construction_with_new_controller_orgs)
154 {
false,
false,
true,
false,
false});
157TEST(TorqueControllerMuxTesting, test_mode0_evaluation)
160 float max_torque = 21.42;
179 {
false,
true,
false,
false,
false});
180 SharedCarState_s mode_0_input_state({}, {}, {}, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {});
183 ASSERT_NEAR(out.inverter_torque_limit[0], (max_torque / 2), 0.01);
184 ASSERT_NEAR(out.inverter_torque_limit[1], (max_torque / 2), 0.01);
185 ASSERT_NEAR(out.inverter_torque_limit[2], (max_torque / 2), 0.01);
186 ASSERT_NEAR(out.inverter_torque_limit[3], (max_torque / 2), 0.01);
188 mode_0_input_state = {{}, {}, {}, {}, {.accelPercent = 0.0f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {}};
190 ASSERT_EQ(out.inverter_torque_limit[0], 0);
191 ASSERT_EQ(out.inverter_torque_limit[1], 0);
192 ASSERT_EQ(out.inverter_torque_limit[2], 0);
193 ASSERT_EQ(out.inverter_torque_limit[3], 0);
198TEST(TorqueControllerMuxTesting, test_power_limit)
205 for (
int i = 0; i < 4; i++)
207 drivetrain_data.measuredSpeeds[i] = 500.0f;
209 SharedCarState_s mode_0_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {} , {});
213 for (
int i = 0; i < 4; i++)
215 ASSERT_EQ(res.inverter_torque_limit[i], 10.0f);
217 for (
int i = 0; i < 4; i++)
219 drivetrain_data.measuredSpeeds[i] = 20000.0f;
223 SharedCarState_s mode_0_input_state_high_power({}, {}, drivetrain_data, {}, {.accelPercent = 1.0f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {});
226 for (
int i = 0; i < 4; i++)
228 ASSERT_LT(res.inverter_torque_limit[i], 7.6);
232TEST(TorqueControllerMuxTesting, test_torque_limit)
242 for (
int i = 0; i < 4; i++)
244 drivetrain_data.measuredSpeeds[i] = 500.0f;
247 SharedCarState_s mode_0_input_state({}, {}, drivetrain_data, {}, {.accelPercent = 0.5f, .brakePercent = 0.0f, .regenPercent = 0.0}, {}, {}, {});
251 ASSERT_EQ(drive_command.inverter_torque_limit[0], 5.0f);
252 ASSERT_EQ(drive_command.inverter_torque_limit[1], 10.0f);
253 ASSERT_EQ(drive_command.inverter_torque_limit[2], 10.0f);
254 ASSERT_EQ(drive_command.inverter_torque_limit[3], 10.0f);
261 ASSERT_LT(drive_command.inverter_torque_limit[0], 3.5f);
262 ASSERT_LT(drive_command.inverter_torque_limit[1], 12.5f);
263 ASSERT_LT(drive_command.inverter_torque_limit[2], 12.5f);
264 ASSERT_LT(drive_command.inverter_torque_limit[3], 12.5f);
266 printf(
"torque 1: %.2f\n", drive_command.inverter_torque_limit[0]);
267 printf(
"torque 2: %.2f\n", drive_command.inverter_torque_limit[1]);
268 printf(
"torque 3: %.2f\n", drive_command.inverter_torque_limit[2]);
269 printf(
"torque 4: %.2f\n", drive_command.inverter_torque_limit[3]);
272TEST(TorqueControllerMuxTesting, test_null_pointer_error_state)
277 for (
int i = 0; i < 4; i++)
279 ASSERT_EQ(res.inverter_torque_limit[i], 0.0f);
280 ASSERT_EQ(res.speeds_rpm[i], 0.0f);
constexpr const float METERS_PER_SECOND_TO_RPM
@ ERROR_CONTROLLER_NULL_POINTER
@ ERROR_CONTROLLER_INDEX_OUT_OF_BOUNDS
@ ERROR_SPEED_DIFF_TOO_HIGH
@ ERROR_TORQUE_DIFF_TOO_HIGH
this class with both take in sensor inputs as well as handle calculations for various derived states ...
Base class for all controllers, which define drivetrain command containing different variations of
TorqueControllerOutput_s output
makes CASE system a part of Controller hierarchy for use in TC Mux
DrivetrainCommand_s getDrivetrainCommand(ControllerMode_e requested_controller_type, TorqueLimit_e controller_command_torque_limit, const SharedCarState_s &input_state)
function that evaluates the mux, controllers and gets the active command
TorqueControllerSimple tc_simple(1.0f, 1.0f)
TCMuxType torque_controller_mux({static_cast< Controller * >(&tc_simple), static_cast< Controller * >(&tc_vec), static_cast< Controller * >(&case_wrapper), static_cast< Controller * >(&simple_launch), static_cast< Controller * >(&db_controller)}, {false, false, true, false, true})
TorqueControllerLoadCellVectoring tc_vec
TorqueControllerSimpleLaunch simple_launch
Stores setpoints for a command to the Drivetrain, containing speed and torque setpoints for each moto...
float inverter_torque_limit[NUM_MOTORS]
car state struct that contains state of everything about the car including
DrivetrainCommand_s command
void set_outputs(controller_type &controller, float mps, float torque)
void set_output_rpm(controller_type &controller, float rpm, float torque)
void set_four_outputs(quad_array_type &out, float val)
TEST(TorqueControllerMuxTesting, test_construction)