Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
utils.cpp
Go to the documentation of this file.
1#include "utils/utils.hpp"
2
3std::pair<double, double> wheels_velocities_to_cg(std::shared_ptr<common_lib::car_parameters::CarParameters> car_parameters,
4 double rl_rpm, [[maybe_unused]] double fl_rpm, double rr_rpm, [[maybe_unused]] double fr_rpm,
5 double steering_angle) {
6 std::pair<double, double> velocities = {0, 0};
7 double rl_velocity =
8 common_lib::maths::get_wheel_velocity_from_rpm(rl_rpm, car_parameters->wheel_diameter);
9 double rr_velocity =
10 common_lib::maths::get_wheel_velocity_from_rpm(rr_rpm, car_parameters->wheel_diameter);
11 if (steering_angle == 0) { // If no steering angle, moving straight
12 velocities.first = (rl_velocity + rr_velocity) / 2;
13 } else if (steering_angle > 0) {
14 double rear_axis_center_rotation_radius = car_parameters->wheelbase / std::tan(steering_angle);
15 velocities.second =
16 rl_velocity / (rear_axis_center_rotation_radius - (car_parameters->track_width / 2));
17 velocities.first = std::sqrt(std::pow(rear_axis_center_rotation_radius, 2) +
18 std::pow(car_parameters->dist_cg_2_rear_axis, 2)) *
19 std::fabs(velocities.second);
20 } else {
21 double rear_axis_center_rotation_radius = car_parameters->wheelbase / std::tan(steering_angle);
22 velocities.second =
23 rr_velocity / (rear_axis_center_rotation_radius + (car_parameters->track_width / 2));
24 velocities.first = std::sqrt(std::pow(rear_axis_center_rotation_radius, 2) +
25 std::pow(car_parameters->dist_cg_2_rear_axis, 2)) *
26 std::fabs(velocities.second);
27 }
28 return velocities;
29}
std::pair< double, double > wheels_velocities_to_cg(std::shared_ptr< common_lib::car_parameters::CarParameters > car_parameters, double rl_rpm, double fl_rpm, double rr_rpm, double fr_rpm, double steering_angle)
Calculates the translational and rotational velocities of the vehicle from wheel rotations and steeri...
Definition utils.cpp:3
double get_wheel_velocity_from_rpm(const double rpm, const double wheel_diameter)
Function to get the translational velocity of a wheel from rpm and wheel diameter.