Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
lap_counter.cpp
Go to the documentation of this file.
2
3#include <cmath>
4
5LapCounter::LapCounter(double threshold_dist, int first_x_cones, int border_width,
6 int minimum_confidence)
7 : threshold_dist_(threshold_dist),
8 first_x_cones_(first_x_cones),
9 border_width_(border_width),
10 minimum_confidence_(minimum_confidence) {}
11
12// TODO: solve this, not using map_cones or observations
13LoopClosure::Result LapCounter::detect(const Eigen::Vector3d& current_pose,
14 const Eigen::VectorXd& map_cones,
15 const Eigen::VectorXi& associations,
16 const Eigen::VectorXd& observations) const {
17 double dx = current_pose.x();
18 double dy = current_pose.y();
19 double dist = std::sqrt(dx * dx + dy * dy);
20
21 // add a border to give some space until we start searching again
22 if (!searching_) {
23 if (dist > threshold_dist_ + border_width_) {
24 searching_ = true;
25 } else {
26 return {false, 0.0};
27 }
28 }
29
30 // If we're still far from the origin, no closure
31 if (dist > threshold_dist_) {
32 return {false, 0.0};
33 }
34
35 int confidence_ = 0;
36 // Look for match with any of the first X cones
37 for (int i = 0; i < associations.size(); ++i) {
38 int j = associations[i];
39 if (j >= 0 && j / 2 < first_x_cones_) { // If observation macthed with one of the first X cones
40 confidence_++; // increase the number of cones that have a match -> increase confidence
41 }
42 }
43
44 if (confidence_ >= minimum_confidence_) {
45 searching_ = false; // Reset search flag
46 return {true, 0.0};
47 }
48
49 return {false, 0.0};
50}
double threshold_dist_
Result detect(const Eigen::Vector3d &current_pose, const Eigen::VectorXd &map_cones, const Eigen::VectorXi &associations, const Eigen::VectorXd &observations) const override
Detects loop closure when returning to origin and seeing initial cones.
LapCounter(double threshold_dist, int first_x_cones, int border_width, int minimum_confidence)
int minimum_confidence_
Result of loop closure detection.