MCU
Loading...
Searching...
No Matches
LaunchControllerAlgos.cpp
Go to the documentation of this file.
4
5
7{
8 /*
9 Stolen launch algo from HT07. This ramps up the speed target over time.
10 launch rate target is m/s^2 and is the target acceleration rate
11 secs_since_launch takes the milliseconds since launch started and converts to sec
12 This is then converted to RPM for a speed target
13 There is an initial speed target that is your iitial instant acceleration on the wheels
14 */
15 float secs_since_launch = (float)(current_millis_ - time_of_launch_) / 1000.0;
16 launch_speed_target_ = (int16_t)((float)secs_since_launch * launch_rate_target_ * METERS_PER_SECOND_TO_RPM);
19}
20
22{
23
25
26 double dx = vn_data.ecef_coords[0] - initial_ecef_x_;
27 double dy = vn_data.ecef_coords[1] - initial_ecef_y_;
28 double dz = vn_data.ecef_coords[2] - initial_ecef_z_;
29
30 double distance = sqrt((dx * dx) + (dy * dy) + (dz * dz));
31
32 /*
33 Distance-lookup launch algorithm. Takes in the vel_dist_lookup
34 generated from Luke's matlab/symlink to set speed targets based
35 on distance travelled from the start point.
36 This can also and may be better to replace with an integration
37 of body velocity.
38 */
39
40 uint32_t idx = (uint32_t)(distance * 10); // multiply by 10 to be used as index for meters in steps of 1/10
41 idx = std::min(idx, (uint32_t)(sizeof(vel_dist_lookup) / sizeof(float)));
42 float mps_target = vel_dist_lookup[idx];
43
44 float new_speed_target = mps_target * METERS_PER_SECOND_TO_RPM;
45 launch_speed_target_ = std::max(launch_speed_target_, new_speed_target);
46}
48{
49 // accelerate at constant speed for a period of time to get body velocity up
50 // may want to make this the ht07 launch algo
51
52 // makes sure that the car launches at the target launch speed
54
55 /*
56 New slip-ratio based launch algorithm by Luke Chen. The basic idea
57 is to always be pushing the car a certain 'slip_ratio_' faster than
58 the car is currently going, theoretically always keeping the car in slip
59 */
60 // m/s
61 float new_speed_target = (1 + slip_ratio_) * (vn_data.velocity_x);
62 // rpm
63 new_speed_target *= METERS_PER_SECOND_TO_RPM;
64 // makes sure the car target speed never goes lower than prev. target
65 // allows for the vn to 'spool' up and us to get reliable vx data
66 launch_speed_target_ = std::max(launch_speed_target_, new_speed_target);
67}
constexpr const float METERS_PER_SECOND_TO_RPM
const float vel_dist_lookup[750]
Definition: accel_lookup.h:6
void calc_launch_algo(const VectornavData_s &vn_data) override
increases speed target based on distance from start to ensure the speed target is progressing as the ...
void calc_launch_algo(const VectornavData_s &vn_data) override
Increases speed target during launch linearly based off launch rate provided in the constructor.
void calc_launch_algo(const VectornavData_s &vn_data) override
Increases speed target during launch linearly according to slip ratio to keep the cars wheels spinnin...
const int16_t DEFAULT_LAUNCH_SPEED_TARGET
double ecef_coords[3]