MCU
Loading...
Searching...
No Matches
launch_controller_integration_testing.h
Go to the documentation of this file.
1// TODO put the launch controller testing in here with the tc mux
2
4#include "TorqueControllers.h"
6
7constexpr DrivetrainDynamicReport_s create_drive_report(float speed_fl, float speed_fr, float speed_rl, float speed_rr)
8{
10 .measuredInverterFLPackVoltage = 550,
11 .measuredSpeeds = {
12 speed_fl,
13 speed_fr,
14 speed_rl,
15 speed_rr},
16 .measuredTorques = {0.0, 0.0, 0.0, 0.0},
17 .measuredTorqueCurrents = {0.0, 0.0, 0.0, 0.0},
18 .measuredMagnetizingCurrents = {0.0, 0.0, 0.0, 0.0}};
20}
21
22constexpr PedalsSystemData_s create_pedals_data(float accel_percent, float brake_percent)
23{
24 PedalsSystemData_s pedals = {
25 .accelImplausible = false,
26 .brakeImplausible = false,
27 .brakePressed = false,
28 .brakeAndAccelPressedImplausibility = false,
29 .implausibilityExceededMaxDuration = false,
30 .accelPercent = accel_percent,
31 .brakePercent = brake_percent};
32 return pedals;
33}
34
44
45TEST(LaunchIntergationTesting, test_simple_launch_controller)
46{
47
48 SysClock clock = SysClock();
49 SysTick_s cur_tick;
50 cur_tick = clock.tick(0);
51 SharedCarState_s still_state(cur_tick, {}, simulated_slow_drivetrain_dynamics, {}, simulated_no_accel_press, {}, {}, {});
52 SharedCarState_s pedal_pressed_state(cur_tick, {}, simulated_slow_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
53 SharedCarState_s no_launch_allowed_state(cur_tick, {}, simulated_no_launch_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
54 SharedCarState_s barely_launch_state(cur_tick, {}, simulated_barely_launch_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
55 SharedCarState_s one_sec_passed_in_launch_state(clock.tick(1000000), {}, simulated_barely_launch_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
56 SharedCarState_s one_sec_passed_in_launch_state_w_error(clock.tick(1000000), {}, simulated_barely_launch_drivetrain_dynamics, {}, simulated_accel_and_brake_press, {}, {}, {});
57
58 // mode 0
60 // mode 1
62 // mode 2
64 CASESystem<DummyQueue_s> case_sys(&q, 100, 70, 550, {});
65 TorqueControllerCASEWrapper<DummyQueue_s> case_wrapper(&case_sys);
66
67 // mode 3
69 // mode 4
71
74 static_cast<Controller *>(&tc_vec),
75 static_cast<Controller *>(&case_wrapper),
76 static_cast<Controller *>(&simple_launch),
77 static_cast<Controller *>(&slip_launch)},
78 {false, false, true, false, false});
79
83 // tick again to calculate state switch
84
85 // tick again to calculate state switch
87
88 // press accelerator but with one wheel right at max speed threshold
91
92 // // go back to launch ready state
93
96
97 // press accel now with one wheelspeed barely under threshold
98
101
103 ASSERT_NEAR((float)((int)((res.speeds_rpm[0] - 1500) * RPM_TO_METERS_PER_SECOND * 100)) / 100, 11.76f, 0.02);
104
107}
108
109TEST(LaunchIntergationTesting, test_slip_launch_controller)
110{
111 SysClock clock = SysClock();
112 SysTick_s cur_tick;
113 cur_tick = clock.tick(0);
114
115 VectornavData_s vn_data{};
116 // mode 0
118 // mode 1
120 // mode 2
121 DummyQueue_s q;
122 CASESystem<DummyQueue_s> case_sys(&q, 100, 70, 550, {});
123 TorqueControllerCASEWrapper<DummyQueue_s> case_wrapper(&case_sys);
124
125 // mode 3
127 // mode 4
128 TorqueControllerSlipLaunch slip_launch;
129
132 static_cast<Controller *>(&tc_vec),
133 static_cast<Controller *>(&case_wrapper),
134 static_cast<Controller *>(&simple_launch),
135 static_cast<Controller *>(&slip_launch)},
136 {false, false, true, false, false});
137
138 SharedCarState_s still_state(cur_tick, {}, simulated_slow_drivetrain_dynamics, {}, simulated_no_accel_press, {}, {}, {});
139 SharedCarState_s pedal_pressed_state(cur_tick, {}, simulated_slow_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
140 SharedCarState_s no_launch_allowed_state(cur_tick, {}, simulated_no_launch_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
141 SharedCarState_s barely_launch_state(cur_tick, {}, simulated_barely_launch_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
142
144 // getting to slip launch (mode 4)
146 ASSERT_EQ(slip_launch.get_launch_state(), LaunchStates_e::LAUNCH_READY);
147
148 SharedCarState_s one_hundredth_sec_passed_in_launch_state(clock.tick(10000), {}, simulated_barely_launch_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
150
151 SharedCarState_s two_hundredth_sec_passed_in_launch_state(clock.tick(20000), {}, simulated_barely_launch_drivetrain_dynamics, {}, simulated_full_accel_press, {}, {}, {});
153
154 ASSERT_EQ(slip_launch.get_launch_state(), LaunchStates_e::LAUNCHING);
156
159
160 ASSERT_EQ(slip_launch.get_launch_state(), LaunchStates_e::LAUNCHING);
162
163 // // if velocity is less than the default speed, it should still go at launch speed
164 vn_data.velocity_x = 0; // m/s
167 printf("lower vx_body: %.2f\n", (float)res.speeds_rpm[0] * RPM_TO_METERS_PER_SECOND);
168 ASSERT_EQ(res.speeds_rpm[0], BaseLaunchControllerParams::DEFAULT_LAUNCH_SPEED_TARGET); // should still be at initial launch target
169
170 ASSERT_EQ(slip_launch.get_launch_state(), LaunchStates_e::LAUNCHING);
171 // // this is approx. the speed the car would be going at 1500 rpm
172 // // we should expect the next calculation to be approx. DEFAULT_SLIP_RATIO % higher than this
174
177
178 ASSERT_EQ(slip_launch.get_launch_state(), LaunchStates_e::LAUNCHING);
179 printf("launch vx_body: %.2f\n", (float)res.speeds_rpm[0] * RPM_TO_METERS_PER_SECOND);
180 ASSERT_EQ((int16_t)res.speeds_rpm[0] > (BaseLaunchControllerParams::DEFAULT_LAUNCH_SPEED_TARGET * RPM_TO_METERS_PER_SECOND), true);
181
182 // TODO this is actually failing, idk what is going on here @walker
183 // ASSERT_NEAR((float)((int)((res.speeds_rpm[0] - 1500) * RPM_TO_METERS_PER_SECOND * 100)) / 100, 11.76f, 0.02);
184}
constexpr const float RPM_TO_METERS_PER_SECOND
constexpr const float METERS_PER_SECOND_TO_RPM
LaunchStates_e get_launch_state()
this class with both take in sensor inputs as well as handle calculations for various derived states ...
Definition: CASESystem.h:97
Base class for all controllers, which define drivetrain command containing different variations of
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
TEST(LaunchIntergationTesting, test_simple_launch_controller)
constexpr DrivetrainDynamicReport_s create_drive_report(float speed_fl, float speed_fr, float speed_rl, float speed_rr)
constexpr auto simulated_fast_drivetrain_dynamics
constexpr float slow_speed
constexpr auto simulated_slow_drivetrain_dynamics
constexpr auto simulated_barely_launch_drivetrain_dynamics
constexpr float fast_speed
constexpr auto simulated_full_accel_press
constexpr auto simulated_no_accel_press
constexpr auto simulated_accel_and_brake_press
constexpr auto simulated_no_launch_drivetrain_dynamics
constexpr PedalsSystemData_s create_pedals_data(float accel_percent, float brake_percent)
constexpr const float MAX_SPEED_FOR_MODE_CHANGE
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
Definition: main.cpp:308
TorqueControllerSimpleLaunch simple_launch
Definition: main.cpp:313
car state struct that contains state of everything about the car including