Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
constant_velocity_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) * ::cos(previous_pose(2)) * delta_t;
12 pose_difference(1) = motion_data(0) * ::sin(previous_pose(2)) * delta_t;
13 } else {
14 pose_difference(0) =
15 motion_data(0) / motion_data(2) *
16 (::sin(motion_data(2) * delta_t + previous_pose(2)) - ::sin(previous_pose(2)));
17 pose_difference(1) =
18 motion_data(0) / motion_data(2) *
19 (-::cos(motion_data(2) * delta_t + previous_pose(2)) + ::cos(previous_pose(2)));
20 }
21 pose_difference(2) = common_lib::maths::normalize_angle(motion_data(2) * delta_t);
22 return pose_difference;
23}
24
26 const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data,
27 const double delta_t) {
28 Eigen::Matrix3d jacobian = Eigen::Matrix3d::Identity();
29 if (::abs(motion_data(2)) < 0.001) { // Avoid division by zero when car is going straight
30 jacobian(0, 2) = -motion_data(0) * ::sin(previous_pose(2)) * delta_t;
31 jacobian(1, 2) = motion_data(0) * ::cos(previous_pose(2)) * delta_t;
32 } else {
33 jacobian(0, 2) = motion_data(0) / motion_data(2) *
34 (::cos(motion_data(2) * delta_t + previous_pose(2)) - ::cos(previous_pose(2)));
35 jacobian(1, 2) = motion_data(0) / motion_data(2) *
36 (::sin(motion_data(2) * delta_t + previous_pose(2)) - ::sin(previous_pose(2)));
37 }
38 return jacobian;
39}
40
42 const Eigen::Vector3d &previous_pose, const Eigen::VectorXd &motion_data,
43 const double delta_t) {
44 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Zero(3, 4);
45 if (::abs(motion_data(2)) < 0.001) {
46 jacobian(0, 0) = ::cos(previous_pose(2)) * delta_t;
47 jacobian(1, 0) = ::sin(previous_pose(2)) * delta_t;
48 } else {
49 jacobian(0, 0) = 1 / motion_data(2) *
50 (::sin(motion_data(2) * delta_t + previous_pose(2)) - ::sin(previous_pose(2)));
51 jacobian(0, 2) =
52 -(motion_data(0) *
53 (::sin(motion_data(2) * delta_t + previous_pose(2)) -
54 motion_data(2) * delta_t * ::cos(motion_data(2) * delta_t + previous_pose(2)) -
55 ::sin(previous_pose(2))) /
56 (motion_data(2) * motion_data(2)));
57 jacobian(1, 0) =
58 1 / motion_data(2) *
59 (-::cos(motion_data(2) * delta_t + previous_pose(2)) + ::cos(previous_pose(2)));
60 jacobian(1, 2) =
61 (motion_data(0) *
62 (::cos(motion_data(2) * delta_t + previous_pose(2)) +
63 motion_data(2) * delta_t * ::sin(motion_data(2) * delta_t + previous_pose(2)) -
64 ::cos(previous_pose(2))) /
65 (motion_data(2) * motion_data(2)));
66 }
67 jacobian(2, 2) = delta_t;
68 return jacobian;
69}
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::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::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.