Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
slam_base_observation_model.cpp
Go to the documentation of this file.
2
4
6 const Eigen::VectorXd& state, const std::vector<int> matched_landmarks) const {
7 Eigen::VectorXd matched_landmarks_coordinates(matched_landmarks.size() * 2);
8 for (int i = 0; i < static_cast<int>(matched_landmarks.size()); i++) {
9 matched_landmarks_coordinates(2 * i) = state(matched_landmarks[i]);
10 matched_landmarks_coordinates(2 * i + 1) = state(matched_landmarks[i] + 1);
11 }
12 return common_lib::maths::global_to_local_coordinates(state.segment(0, 3),
13 matched_landmarks_coordinates);
14}
15
17 const Eigen::VectorXd& state, const Eigen::VectorXd& observations) const {
18 return common_lib::maths::local_to_global_coordinates(state.segment(0, 3), observations);
19}
20
22 const Eigen::VectorXd& state, const std::vector<int>& matched_landmarks) const {
23 Eigen::MatrixXd jacobian = Eigen::MatrixXd::Zero(matched_landmarks.size() * 2, state.size());
24 double car_x = state(0);
25 double car_y = state(1);
26 double car_orientation = state(2);
27
28 int num_landmarks = static_cast<int>(matched_landmarks.size());
29
30 for (int i = 0; i < num_landmarks; ++i) {
31 jacobian(2 * i, 0) = -cos(car_orientation);
32 jacobian(2 * i + 1, 0) = sin(car_orientation);
33 jacobian(2 * i, 1) = -sin(car_orientation);
34 jacobian(2 * i + 1, 1) = -cos(car_orientation);
35 jacobian(2 * i, 2) = -sin(car_orientation) * (state(matched_landmarks[i]) - car_x) +
36 cos(car_orientation) * (state(matched_landmarks[i] + 1) - car_y);
37 jacobian(2 * i + 1, 2) = -cos(car_orientation) * (state(matched_landmarks[i]) - car_x) -
38 sin(car_orientation) * (state(matched_landmarks[i] + 1) - car_y);
39 jacobian(2 * i, matched_landmarks[i]) = cos(car_orientation);
40 jacobian(2 * i + 1, matched_landmarks[i]) = -sin(car_orientation);
41 jacobian(2 * i, matched_landmarks[i] + 1) = sin(car_orientation);
42 jacobian(2 * i + 1, matched_landmarks[i] + 1) = cos(car_orientation);
43 }
44 return jacobian;
45}
46
48 const Eigen::VectorXd& state, const Eigen::VectorXd& new_landmarks) const {
49 int num_landmarks = new_landmarks.size() / 2;
50 Eigen::MatrixXd gv = Eigen::MatrixXd::Zero(num_landmarks * 2, 3);
51 for (int i = 0; i < num_landmarks; i++) {
52 gv(2 * i, 0) = 1;
53 gv(2 * i, 1) = 0;
54 gv(2 * i, 2) = -new_landmarks(2 * i) * sin(state(2)) - new_landmarks(2 * i + 1) * cos(state(2));
55 gv(2 * i + 1, 0) = 0;
56 gv(2 * i + 1, 1) = 1;
57 gv(2 * i + 1, 2) =
58 new_landmarks(2 * i) * cos(state(2)) - new_landmarks(2 * i + 1) * sin(state(2));
59 }
60 return gv;
61}
62
64 const Eigen::VectorXd& state, const Eigen::VectorXd& new_landmarks) const {
65 int num_landmarks = new_landmarks.size() / 2;
66 Eigen::MatrixXd gz = Eigen::MatrixXd::Zero(num_landmarks * 2, num_landmarks * 2);
67 for (int i = 0; i < num_landmarks; i++) {
68 gz(2 * i, 2 * i) = cos(state(2));
69 gz(2 * i, 2 * i + 1) = -sin(state(2));
70 gz(2 * i + 1, 2 * i) = sin(state(2));
71 gz(2 * i + 1, 2 * i + 1) = cos(state(2));
72 }
73 return gz;
74}
virtual Eigen::MatrixXd inverse_observation_model_jacobian_landmarks(const Eigen::VectorXd &state, const Eigen::VectorXd &new_landmarks) const
get the Gz matrix used in the state augmentation function of the EKF, calculated as the jacobian of t...
virtual Eigen::MatrixXd observation_model_jacobian(const Eigen::VectorXd &state, const std::vector< int > &matched_landmarks) const
jacobian of the observation model
virtual Eigen::VectorXd inverse_observation_model(const Eigen::VectorXd &state, const Eigen::VectorXd &observations) const
transforms the landmarks' coordinates from the car's frame to the global frame
virtual Eigen::VectorXd observation_model(const Eigen::VectorXd &state, const std::vector< int > matched_landmarks) const
transform landmarks' positions from global frame to the car's frame
virtual Eigen::MatrixXd inverse_observation_model_jacobian_pose(const Eigen::VectorXd &state, const Eigen::VectorXd &new_landmarks) const
get the Gv matrix used in the state augmentation function, calculated as the jacobian of the inverse ...
Eigen::VectorXd global_to_local_coordinates(const Eigen::Vector3d &local_reference_frame, const Eigen::VectorXd &global_points)
Transform points from a global reference frame to a local reference frame.
Eigen::VectorXd local_to_global_coordinates(const Eigen::Vector3d &local_reference_frame, const Eigen::VectorXd &local_points)
Transform points from a local reference frame to a global reference frame.