MCU
Loading...
Searching...
No Matches
BaseLaunchController.cpp
Go to the documentation of this file.
2#include <stdlib.h> /* abs */
4 const SysTick_s &tick,
5 const PedalsSystemData_s &pedalsData,
6 const float wheel_rpms[],
7 const VectornavData_s &vn_data)
8{
9
10 if (tick.triggers.trigger100)
11 {
12
13 current_millis_ = tick.millis;
14
15 int16_t brake_torque_req = pedalsData.regenPercent * PhysicalParameters::MAX_REGEN_TORQUE;
16
17 float max_speed = 0;
18 for (int i = 0; i < 4; i++)
19 {
20 max_speed = std::max(max_speed, abs(wheel_rpms[i]));
21 }
22
23 writeout_.ready = true;
24
25 switch (launch_state_)
26 {
27 case LaunchStates_e::LAUNCH_NOT_READY:
28 // set torques and speed to 0
33
34 writeout_.command.inverter_torque_limit[FL] = brake_torque_req;
35 writeout_.command.inverter_torque_limit[FR] = brake_torque_req;
36 writeout_.command.inverter_torque_limit[RL] = brake_torque_req;
37 writeout_.command.inverter_torque_limit[RR] = brake_torque_req;
38
39 // init launch vars
41 time_of_launch_ = tick.millis;
42 // check speed is 0 and pedals not pressed
44 {
45 launch_state_ = LaunchStates_e::LAUNCH_READY;
46 }
47
48 break;
49 case LaunchStates_e::LAUNCH_READY:
50 // set torques and speed to 0
55
56 writeout_.command.inverter_torque_limit[FL] = brake_torque_req;
57 writeout_.command.inverter_torque_limit[FR] = brake_torque_req;
58 writeout_.command.inverter_torque_limit[RL] = brake_torque_req;
59 writeout_.command.inverter_torque_limit[RR] = brake_torque_req;
60
61 // init launch vars
64
65 // check speed is 0 and brake not pressed
67 {
68 launch_state_ = LaunchStates_e::LAUNCH_NOT_READY;
69 }
71 {
72
73 initial_ecef_x_ = vn_data.ecef_coords[0];
74 initial_ecef_y_ = vn_data.ecef_coords[1];
75 initial_ecef_z_ = vn_data.ecef_coords[2];
76
77 launch_state_ = LaunchStates_e::LAUNCHING;
78 }
79
80 // check accel above launch threshold and launch
81 break;
82 case LaunchStates_e::LAUNCHING:
83 { // use brackets to ignore 'cross initialization' of secs_since_launch
84 // check accel below launch threshold and brake above
86 {
87 launch_state_ = LaunchStates_e::LAUNCH_NOT_READY;
88 }
89
90 calc_launch_algo(vn_data);
91
96
101
102 break;
103 }
104 default:
105 break;
106 }
107 }
108}
109
111{
112 tick(state.systick, state.pedals_data, state.drivetrain_data.measuredSpeeds, state.vn_data);
113 return writeout_;
114}
const int RR
Definition: Utility.h:9
const int FL
Definition: Utility.h:6
const int FR
Definition: Utility.h:7
const int RL
Definition: Utility.h:8
TorqueControllerOutput_s evaluate(const SharedCarState_s &state) override
all launch controllers share the same evaluate method implemented in this class implementation.
TorqueControllerOutput_s writeout_
LaunchStates_e launch_state_
void tick(const SysTick_s &tick, const PedalsSystemData_s &pedalsData, const float wheel_rpms[], const VectornavData_s &vn_data)
ticks launch controller to progress through launch states when conditions are met....
virtual void calc_launch_algo(const VectornavData_s &vn_data)=0
calculates how speed target (the speed the car is trying to achieve during launch) is set and/or incr...
const float AMK_MAX_TORQUE
const float MAX_REGEN_TORQUE
float inverter_torque_limit[NUM_MOTORS]
float speeds_rpm[NUM_MOTORS]
speed_rpm measuredSpeeds[NUM_MOTORS]
car state struct that contains state of everything about the car including
PedalsSystemData_s pedals_data
DrivetrainDynamicReport_s drivetrain_data
VectornavData_s vn_data
Packages drivetrain command with ready boolean to give feedback on controller successfully evaluating...
DrivetrainCommand_s command
double ecef_coords[3]