Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
consecutive_counter_filter.cpp
Go to the documentation of this file.
2
3#include <map>
4
6Eigen::VectorXd ConsecutiveCounterFilter::filter(const Eigen::VectorXd& observations,
7 const Eigen::VectorXd& observation_confidences,
8 Eigen::VectorXi& associations) {
10 return observations; // No filtering needed
11 }
12
13 std::vector<int>
14 filter_to_global_observation_map; // TODO: change to more efficient data structure
15
16 Eigen::VectorXd unfiltered_new_observations;
18 for (int i = 0; i < associations.size(); i++) {
19 if (associations(i) < 0) {
20 unfiltered_new_observations.conservativeResize(unfiltered_new_observations.size() + 2);
27 associations(i) = -2; // Mark as not ready. Did not pass filter yet
29 }
30 }
31
32 // Associate the observations that are considered new with the map stored in this filter
33 Eigen::MatrixXd const map_covariance = Eigen::MatrixXd::Zero(this->map.size(), this->map.size());
34 Eigen::VectorXi new_associations =
35 this->_data_association_->associate(this->map, unfiltered_new_observations, map_covariance,
37 const int num_landmarks = this->map.size() / 2;
38 const int num_new_observations = unfiltered_new_observations.size() / 2;
39
40 // Calculate which observations should be added to this filter's map and which landmarks in the
41 // map were observed
42 std::vector<int> was_observed_as(num_landmarks, -1); // Map landmark index to observation index
43 Eigen::VectorXd to_be_added_to_map;
47 observation_index; // Map landmark index to observation index
48 } else if (new_associations(observation_index) == -1) {
49 to_be_added_to_map.conservativeResize(to_be_added_to_map.size() + 2);
50 to_be_added_to_map.segment(to_be_added_to_map.size() - 2, 2) =
52 }
53 }
54 // Update counter and set filtered observations
55 Eigen::VectorXd new_map;
56 Eigen::VectorXi new_counter;
57 Eigen::VectorXd filtered_observations;
60 continue;
61 }
63 filtered_observations.conservativeResize(filtered_observations.size() + 2);
64 filtered_observations.segment(filtered_observations.size() - 2, 2) =
67 -1; // Mark as new landmark ready to be added to the map
68 }
69 new_map.conservativeResize(new_map.size() + 2);
70 new_map.segment(new_map.size() - 2, 2) = this->map.segment(landmark_index * 2, 2);
71 new_counter.conservativeResize(new_counter.size() + 1);
72 new_counter(new_counter.size() - 1) = this->counter(landmark_index) + 1;
73 }
74 new_map.conservativeResize(new_map.size() + to_be_added_to_map.size());
76 new_counter.conservativeResize(new_counter.size() + to_be_added_to_map.size() / 2);
77 new_counter.tail(to_be_added_to_map.size() / 2).setOnes();
78 this->map = new_map;
79 this->counter = new_counter;
80
82}
83
84void ConsecutiveCounterFilter::delete_landmarks(const Eigen::VectorXd& some_landmarks) {
85 int map_size = this->map.size() / 2;
86 int num_landmarks = some_landmarks.size() / 2;
87 std::vector<bool> to_be_deleted(map_size, false);
88 Eigen::VectorXd new_map;
89 Eigen::VectorXi new_counter;
90 for (int i = 0; i < num_landmarks; i++) {
91 for (int j = 0; j < map_size; j++) {
92 if (std::hypot(this->map(j * 2) - some_landmarks(i * 2),
93 this->map(j * 2 + 1) - some_landmarks(i * 2 + 1)) < EQUALITY_TOLERANCE) {
94 to_be_deleted[j] = true;
95 }
96 }
97 }
98 for (int i = 0; i < map_size; i++) {
99 if (to_be_deleted[i]) {
100 continue;
101 }
102 new_map.conservativeResize(new_map.size() + 2);
103 new_map.segment(new_map.size() - 2, 2) = this->map.segment(i * 2, 2);
104 new_counter.conservativeResize(new_counter.size() + 1);
105 new_counter(new_counter.size() - 1) = this->counter(i);
106 }
107 this->map = new_map;
108 this->counter = new_counter;
109}
void delete_landmarks(const Eigen::VectorXd &some_landmarks) override
Used by SLAM to signal to the filter that the landmarks are already in SLAM's map,...
Eigen::VectorXd filter(const Eigen::VectorXd &observations, const Eigen::VectorXd &observation_confidences, Eigen::VectorXi &associations) override
This function receives a new set of observations and returns a filtered set of landmarks in global co...
std::shared_ptr< DataAssociationModel > _data_association_
LandmarkFilterParameters _params_
#define EQUALITY_TOLERANCE