Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
constant_acceleration_turnrate_model.cpp
Go to the documentation of this file.
1
3
5
7 const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data,
8 const double delta_t) {
9 Eigen::Vector3d pose_difference;
10 if (::abs(motion_data(2)) < 0.0001) { // Avoid division by zero when car is going straight
11 pose_difference(0) = (motion_data(0) * delta_t + motion_data(3) * ::pow(delta_t, 2) / 2) *
12 ::cos(previous_pose(2));
13 pose_difference(1) = (motion_data(0) * delta_t + motion_data(3) * ::pow(delta_t, 2) / 2) *
14 ::sin(previous_pose(2));
15 } else {
16 pose_difference(0) =
17 ((motion_data(0) * motion_data(2) + motion_data(3) * motion_data(2) * delta_t) *
18 ::sin(previous_pose(2) + motion_data(2) * delta_t) +
19 motion_data(3) * ::cos(previous_pose(2) + motion_data(2) * delta_t) -
20 motion_data(0) * motion_data(2) * ::sin(previous_pose(2)) -
21 motion_data(3) * ::cos(previous_pose(2))) /
22 ::pow(motion_data(2), 2);
23 pose_difference(1) =
24 ((-motion_data(0) * motion_data(2) - motion_data(3) * motion_data(2) * delta_t) *
25 ::cos(previous_pose(2) + motion_data(2) * delta_t) +
26 motion_data(3) * ::sin(previous_pose(2) + motion_data(2) * delta_t) +
27 motion_data(0) * motion_data(2) * ::cos(previous_pose(2)) -
28 motion_data(3) * ::sin(previous_pose(2))) /
29 ::pow(motion_data(2), 2);
30 }
31 pose_difference(2) = common_lib::maths::normalize_angle(motion_data(2) * delta_t);
32 return pose_difference;
33}
34
36 const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data,
37 const double delta_t) {
38 Eigen::Matrix3d jacobian = Eigen::Matrix3d::Identity();
39 if (::abs(motion_data(2)) < 0.001) { // Avoid division by zero when car is going straight
40 jacobian(0, 2) = -(motion_data(0) * delta_t + motion_data(3) * ::pow(delta_t, 2) / 2) *
41 ::sin(previous_pose(2));
42 jacobian(1, 2) = (motion_data(0) * delta_t + motion_data(3) * ::pow(delta_t, 2) / 2) *
43 ::cos(previous_pose(2));
44 } else {
45 jacobian(0, 2) =
46 (-motion_data(3) * ::sin(previous_pose(2) + motion_data(2) * delta_t) +
47 (motion_data(0) * motion_data(2) + motion_data(3) * motion_data(2) * delta_t) *
48 ::cos(previous_pose(2) + motion_data(2) * delta_t) +
49 motion_data(3) * ::sin(previous_pose(2)) -
50 motion_data(0) * motion_data(2) * ::cos(previous_pose(2))) /
51 (motion_data(2) * motion_data(2));
52 jacobian(1, 2) = ((motion_data(0) + motion_data(3) * delta_t) * motion_data(2) *
53 ::sin(previous_pose(2) + motion_data(2) * delta_t) +
54 motion_data(3) * ::cos(previous_pose(2) + motion_data(2) * delta_t) -
55 motion_data(0) * motion_data(2) * ::sin(previous_pose(2)) -
56 motion_data(3) * ::cos(previous_pose(2))) /
57 (motion_data(2) * motion_data(2));
58 }
59 return jacobian;
60}
61
63 const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data,
64 const double delta_t) {
65 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Zero(3, 4);
66 if (::abs(motion_data(2)) < 0.001) {
67 jacobian(0, 0) = ::cos(previous_pose(2)) * delta_t;
68 jacobian(0, 3) = ::cos(previous_pose(2)) * ::pow(delta_t, 2) / 2;
69 jacobian(1, 0) = ::sin(previous_pose(2)) * delta_t;
70 jacobian(1, 3) = ::sin(previous_pose(2)) * ::pow(delta_t, 2) / 2;
71 } else {
72 jacobian(0, 0) =
73 (::sin(motion_data(2) * delta_t + previous_pose(2)) - ::sin(previous_pose(2))) /
74 motion_data(2);
75 jacobian(0, 2) = -(((-delta_t * motion_data(0) - ::pow(delta_t, 2) * motion_data(3)) *
76 ::pow(motion_data(2), 2) +
77 2 * motion_data(3)) *
78 ::cos(motion_data(2) * delta_t + previous_pose(2)) +
79 (motion_data(0) + 2 * motion_data(3) * delta_t) * motion_data(2) *
80 ::sin(delta_t * motion_data(2) + previous_pose(2)) -
81 ::sin(previous_pose(2)) * motion_data(0) * motion_data(2) -
82 2 * motion_data(3) * ::cos(previous_pose(2))) /
83 ::pow(motion_data(2), 3);
84 jacobian(0, 3) = delta_t * motion_data(2) * ::sin(motion_data(2) * delta_t + previous_pose(2)) +
85 ::cos(motion_data(2) * delta_t + previous_pose(2) - ::cos(previous_pose(2))) /
86 ::pow(motion_data(2), 2);
87 jacobian(1, 0) =
88 -(::cos(motion_data(2) * delta_t + previous_pose(2)) - ::cos(previous_pose(2))) /
89 motion_data(2);
90 jacobian(1, 2) = (((delta_t * motion_data(0) + ::pow(delta_t, 2) * motion_data(3)) *
91 ::pow(motion_data(2), 2) -
92 2 * motion_data(3)) *
93 ::sin(motion_data(2) * delta_t + previous_pose(2)) +
94 (motion_data(0) + 2 * motion_data(3) * delta_t) * motion_data(2) *
95 ::cos(delta_t * motion_data(2) + previous_pose(2)) -
96 ::cos(previous_pose(2)) * motion_data(0) * motion_data(2) +
97 2 * motion_data(3) * ::sin(previous_pose(2))) /
98 ::pow(motion_data(2), 3);
99 jacobian(1, 3) = delta_t * motion_data(2) * ::cos(motion_data(2) * delta_t + previous_pose(2)) +
100 ::sin(motion_data(2) * delta_t + previous_pose(2) - ::sin(previous_pose(2))) /
101 ::pow(motion_data(2), 2);
102 }
103 jacobian(2, 2) = delta_t;
104 return jacobian;
105}
Eigen::MatrixXd get_jacobian_motion_data(const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data, const double delta_t) override
Get the Jacobian matrix of the motion model in relation to motion data (commands)
Eigen::Vector3d get_pose_difference(const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data, const double delta_t) override
Gives the increments to the pose instead of the next pose.
Eigen::Matrix3d get_jacobian_pose(const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data, const double delta_t) override
Get the Jacobian matrix of the motion model in relation to the pose (state)
double normalize_angle(double angle)
Function to keep angle in [-Pi, Pi[ radians.