Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
no_slip_bicycle_model.cpp
Go to the documentation of this file.
2
4 const Eigen::VectorXd& cg_velocities) const {
5 const double vx = cg_velocities(0);
6 const double vy = cg_velocities(1);
7 const double omega = cg_velocities(2);
8 const double lr =
10 ->dist_cg_2_rear_axis; // distance from the center of mass to the rear wheels
11 const double lf =
12 this->car_parameters_->wheelbase -
13 this->car_parameters_
14 ->dist_cg_2_rear_axis; // distance from the center of mass to the front wheels
15
16 double rear_wheel_velocity = sqrt(pow(vx, 2) + pow(vy - omega * lr, 2));
17 double rear_wheels_rpm =
18 60 * rear_wheel_velocity / (M_PI * this->car_parameters_->wheel_diameter);
19 if (vx < 0) {
20 rear_wheels_rpm = -rear_wheels_rpm;
21 }
22
23 double front_wheel_velocity = sqrt(pow(vx, 2) + pow(vy + omega * lf, 2));
24 double front_wheels_rpm =
25 60 * front_wheel_velocity / (M_PI * this->car_parameters_->wheel_diameter);
26 if (vx < 0) {
27 front_wheels_rpm = -front_wheels_rpm;
28 }
29 double v = sqrt(pow(vx, 2) + pow(vy, 2));
30 double steering_angle =
31 (std::fabs(v) <= 1e-2) ? 0 : atan(omega * (this->car_parameters_->wheelbase) / v);
32 double motor_rpm = 60 * this->car_parameters_->gear_ratio * rear_wheel_velocity /
33 (M_PI * this->car_parameters_->wheel_diameter);
34 if (vx < 0) {
35 motor_rpm = -motor_rpm;
36 }
37
38 Eigen::VectorXd observations = Eigen::VectorXd::Zero(6);
39 observations << front_wheels_rpm, front_wheels_rpm, rear_wheels_rpm, rear_wheels_rpm,
40 steering_angle, motor_rpm;
41 return observations;
42}
43
45 const Eigen::VectorXd& cg_velocities) const {
46 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Zero(6, 3);
47 double vx = cg_velocities(0);
48 double vy = cg_velocities(1);
49 double omega = cg_velocities(2);
50 double lr = this->car_parameters_
51 ->dist_cg_2_rear_axis; // distance from the center of mass to the rear wheels
52 double lf = this->car_parameters_->wheelbase -
53 this->car_parameters_
54 ->dist_cg_2_rear_axis; // distance from the center of mass to the front wheels
55 double rear_wheel_velocity = sqrt(pow(vx, 2) + pow(vy - omega * lr, 2));
56 double front_wheel_velocity = sqrt(pow(vx, 2) + pow(vy + omega * lf, 2));
57
58 const double epsilon = 1e-2;
59 if (std::fabs(rear_wheel_velocity) < epsilon || std::fabs(front_wheel_velocity) < epsilon) {
60 jacobian(5, 0) = epsilon;
61 return jacobian;
62 }
63
64 double sign = (vx < 0) ? -1.0 : 1.0;
65 jacobian(0, 0) = std::max(
66 0.0, sign * 60 * vx / (M_PI * this->car_parameters_->wheel_diameter * front_wheel_velocity));
67 jacobian(0, 1) = sign * 60 * (vy + omega * lf) /
68 (M_PI * this->car_parameters_->wheel_diameter * front_wheel_velocity);
69 jacobian(0, 2) = sign * 60 * lf * (vy + omega * lf) /
70 (M_PI * this->car_parameters_->wheel_diameter * front_wheel_velocity);
71 jacobian(1, 0) = jacobian(0, 0);
72 jacobian(1, 1) = jacobian(0, 1);
73 jacobian(1, 2) = jacobian(0, 2);
74
75 jacobian(2, 0) =
76 sign * 60 * vx / (M_PI * this->car_parameters_->wheel_diameter * rear_wheel_velocity);
77 jacobian(2, 1) = sign * 60 * (vy - omega * lr) /
78 (M_PI * this->car_parameters_->wheel_diameter * rear_wheel_velocity);
79 jacobian(2, 2) = sign * 60 * (-lr) * (vy - omega * lr) /
80 (M_PI * this->car_parameters_->wheel_diameter * rear_wheel_velocity);
81 jacobian(3, 0) = jacobian(2, 0);
82 jacobian(3, 1) = jacobian(2, 1);
83 jacobian(3, 2) = jacobian(2, 2);
84
85 jacobian(5, 0) = sign * this->car_parameters_->gear_ratio * 60 * vx /
86 (M_PI * this->car_parameters_->wheel_diameter * rear_wheel_velocity);
87 jacobian(5, 1) = sign * this->car_parameters_->gear_ratio * 60 * (vy - omega * lr) /
88 (M_PI * this->car_parameters_->wheel_diameter * rear_wheel_velocity);
89 jacobian(5, 2) = sign * this->car_parameters_->gear_ratio * 60 * (-lr) * (vy - omega * lr) /
90 (M_PI * this->car_parameters_->wheel_diameter * rear_wheel_velocity);
91 double L = this->car_parameters_->wheelbase;
92 double v = sqrt(pow(vx, 2) + pow(vy, 2));
93 if (std::fabs(v) > epsilon) {
94 jacobian(4, 0) = -((omega * L) / (v * v + (omega * L) * (omega * L))) * (vx / v);
95 jacobian(4, 1) = -((omega * L) / (v * v + (omega * L) * (omega * L))) * (vy / v);
96 jacobian(4, 2) = (L * v) / (v * v + (omega * L) * (omega * L));
97 }
98
99 return jacobian;
100}
Eigen::VectorXd expected_observations(const Eigen::VectorXd &state) const override
Eigen::MatrixXd expected_observations_jacobian(const Eigen::VectorXd &state) const override
calculates the Jacobian of the expected_observations function with respect to the state.
std::shared_ptr< common_lib::car_parameters::CarParameters > car_parameters_