9 const Eigen::VectorXf &expected_state,
const ObservationData &observation_data)
const {
10 RCLCPP_DEBUG(rclcpp::get_logger(
"ekf_state_est"),
11 "Observation Model - Expected State: %f %f %f %f %f", expected_state(0),
12 expected_state(1), expected_state(2), expected_state(3), expected_state(4));
13 RCLCPP_DEBUG(rclcpp::get_logger(
"ekf_state_est"),
"Observation Model - Observation Data: (%f,%f)",
16 Eigen::Matrix3f transformation_matrix = Eigen::Matrix3f::Identity();
17 transformation_matrix(0, 0) = cos(expected_state(2));
18 transformation_matrix(0, 1) = -sin(expected_state(2));
19 transformation_matrix(0, 2) = expected_state(0);
20 transformation_matrix(1, 0) = sin(expected_state(2));
21 transformation_matrix(1, 1) = cos(expected_state(2));
22 transformation_matrix(1, 2) = expected_state(1);
24 Eigen::Vector3f observation =
26 Eigen::Vector3f observed_landmark_absolute_position = transformation_matrix * observation;
28 return Eigen::Vector2f(observed_landmark_absolute_position(0),
29 observed_landmark_absolute_position(1));
34 Eigen::MatrixXf gv(2, 3);
37 -observation_data.
position.
x * sin(expected_state(2)) -
38 observation_data.
position.
y * cos(expected_state(2)),
40 observation_data.
position.
x * cos(expected_state(2)) -
41 observation_data.
position.
y * sin(expected_state(2));
57 const unsigned int landmark_index)
const {
58 Eigen::Matrix3f transformation_matrix = Eigen::Matrix3f::Identity();
63 transformation_matrix(0, 0) = cos(-expected_state(2));
64 transformation_matrix(0, 1) = -sin(-expected_state(2));
65 transformation_matrix(0, 2) =
66 -expected_state(0) * cos(-expected_state(2)) + expected_state(1) * sin(-expected_state(2));
67 transformation_matrix(1, 0) = sin(-expected_state(2));
68 transformation_matrix(1, 1) = cos(-expected_state(2));
69 transformation_matrix(1, 2) =
70 -expected_state(0) * sin(-expected_state(2)) - expected_state(1) * cos(-expected_state(2));
71 Eigen::Vector3f observation =
72 transformation_matrix *
73 Eigen::Vector3f(
static_cast<float>(expected_state(landmark_index)),
74 static_cast<float>(expected_state(landmark_index + 1)), 1);
76 return Eigen::Vector2f(observation(0), observation(1));
80 const std::vector<Eigen::Vector2f> &observations)
const {
81 Eigen::VectorXf formatted_observation(2 * observations.size());
82 for (
int i = 0; i < static_cast<int>(observations.size()); i++) {
83 formatted_observation(2 * i) = observations[i](0);
84 formatted_observation(2 * i + 1) = observations[i](1);
86 return formatted_observation;
90 const Eigen::VectorXf ¤t_state,
const std::vector<int> &matched_ids)
const {
91 auto number_of_landmarks =
static_cast<int>(matched_ids.size());
92 Eigen::VectorXf expected_observation(2 * number_of_landmarks);
97 double cossine_minus_theta = cos(-current_state(2));
98 double sine_minus_theta = sin(-current_state(2));
101 -current_state(0) * cossine_minus_theta + current_state(1) * sine_minus_theta;
103 -current_state(0) * sine_minus_theta - current_state(1) * cossine_minus_theta;
106 for (
unsigned int i : matched_ids) {
107 expected_observation(2 * j) = cossine_minus_theta * current_state(i) -
108 sine_minus_theta * current_state(i + 1) + car_shift_x;
109 expected_observation(2 * j + 1) = sine_minus_theta * current_state(i) +
110 cossine_minus_theta * current_state(i + 1) + car_shift_y;
114 return expected_observation;
118 const Eigen::VectorXf ¤t_state,
const std::vector<int> &matched_ids)
const {
119 int number_of_landmarks = matched_ids.size();
120 double cossine_minus_theta = cos(-current_state(2));
121 double sine_minus_theta = sin(-current_state(2));
122 Eigen::MatrixXf jacobian = Eigen::MatrixXf::Zero(number_of_landmarks * 2, current_state.size());
123 for (
int i = 0; i < number_of_landmarks; i++) {
124 jacobian(2 * i, 0) = -cossine_minus_theta;
125 jacobian(2 * i + 1, 0) = -sine_minus_theta;
127 for (
int i = 0; i < number_of_landmarks; i++) {
128 jacobian(2 * i, 1) = sine_minus_theta;
129 jacobian(2 * i + 1, 1) = -cossine_minus_theta;
131 for (
int i = 0; i < number_of_landmarks; i++) {
133 sine_minus_theta * (current_state(matched_ids[i]) - current_state(0)) +
134 cossine_minus_theta * (current_state(matched_ids[i] + 1) - current_state(1));
135 jacobian(2 * i + 1, 2) =
136 -cossine_minus_theta * (current_state(matched_ids[i]) - current_state(0)) +
137 sine_minus_theta * (current_state(matched_ids[i] + 1) - current_state(1));
139 for (
int i = 0; i < number_of_landmarks; i++) {
140 jacobian(2 * i, matched_ids[i]) = cossine_minus_theta;
141 jacobian(2 * i, matched_ids[i] + 1) = -sine_minus_theta;
142 jacobian(2 * i + 1, matched_ids[i]) = sine_minus_theta;
143 jacobian(2 * i + 1, matched_ids[i] + 1) = cossine_minus_theta;
149 const Eigen::VectorXf &expected_state,
const unsigned int landmark_index,
150 const unsigned int state_size)
const {
152 Eigen::MatrixXf reformating_matrix = Eigen::MatrixXf::Zero(8, state_size);
153 reformating_matrix(0, 0) = 1;
154 reformating_matrix(1, 1) = 1;
155 reformating_matrix(2, 2) = 1;
156 reformating_matrix(3, 3) = 1;
157 reformating_matrix(4, 4) = 1;
158 reformating_matrix(5, 5) = 1;
159 reformating_matrix(6, landmark_index) = 1;
160 reformating_matrix(7, landmark_index + 1) = 1;
164 Eigen::MatrixXf low_jacobian = Eigen::MatrixXf::Zero(2, 8);
176 low_jacobian(0, 0) = -cos(-expected_state(2));
177 low_jacobian(0, 1) = sin(-expected_state(2));
178 low_jacobian(0, 2) = -expected_state(landmark_index) * sin(expected_state(2)) +
179 expected_state(landmark_index + 1) * cos(-expected_state(2)) +
180 expected_state(0) * sin(expected_state(2)) -
181 expected_state(1) * cos(-expected_state(2));
182 low_jacobian(0, 3) = 0;
183 low_jacobian(0, 4) = 0;
184 low_jacobian(0, 5) = 0;
185 low_jacobian(0, 6) = cos(-expected_state(2));
186 low_jacobian(0, 7) = -sin(-expected_state(2));
188 low_jacobian(1, 0) = -sin(-expected_state(2));
189 low_jacobian(1, 1) = -cos(-expected_state(2));
190 low_jacobian(1, 2) = -expected_state(landmark_index) * cos(-expected_state(2)) -
191 expected_state(landmark_index + 1) * sin(expected_state(2)) +
192 expected_state(0) * cos(-expected_state(2)) +
193 expected_state(1) * sin(expected_state(2));
194 low_jacobian(1, 3) = 0;
195 low_jacobian(1, 4) = 0;
196 low_jacobian(1, 5) = 0;
197 low_jacobian(1, 6) = sin(-expected_state(2));
198 low_jacobian(1, 7) = cos(-expected_state(2));
200 Eigen::MatrixXf validation_jacobian = low_jacobian * reformating_matrix;
202 return validation_jacobian;
Eigen::MatrixXf get_state_to_observation_matrix(const Eigen::VectorXf &expected_state, const unsigned int landmark_index, const unsigned int state_size) const
Get the state to observation matrix of the observation model (H in LaTeX documentation)