-
Notifications
You must be signed in to change notification settings - Fork 0
Loop Closure #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DiogoProPrayer
wants to merge
16
commits into
dev
Choose a base branch
from
loop_closure
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Loop Closure #420
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0d16477
First iteration of loop closure based on distance and data association
DiogoProPrayer a90d8eb
Added loop closure to graph slam
DiogoProPrayer b73a367
added correct includes
DiogoProPrayer dfff9f8
Merge branch 'dev' into loop_closure
DiogoProPrayer 2998790
added interface, and lap counter to slam
DiogoProPrayer 5ffb3d1
redefined parameter types
DiogoProPrayer 076c268
everything put on slam
DiogoProPrayer 2863e13
modified parameters
DiogoProPrayer 22a15a4
Tested with slam and working
DiogoProPrayer 9a981b6
slam integration part1
DiogoProPrayer a529d99
Merge branch 'dev' into loop_closure
DiogoProPrayer 6b362ad
now loop closure has to match cones 3 times consecutively to output a…
DiogoProPrayer 6a5f409
everything using Eigen now
DiogoProPrayer 49033ed
resolved reviews
DiogoProPrayer 0482894
Added confidence to parameters
DiogoProPrayer 44a9150
Merge branch 'dev' into loop_closure
DiogoProPrayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule as-integration
deleted from
9147a3
Submodule hesai-lidar
deleted from
0329ec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/perception_sensor_lib/include/perception_sensor_lib/loop_closure/lap_counter.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "loop_closure.hpp" | ||
|
||
/** | ||
* @brief Implementation of LoopClosure that detects when the robot returns near | ||
* the origin and re‑observes any of the first X cones from the map. | ||
*/ | ||
class LapCounter : public LoopClosure { | ||
public: | ||
/** | ||
* @param threshold_dist distance (m) around origin to trigger closure | ||
* @param first_x_cones consider a loop if you see any of these first X cones | ||
* @param border_width distance to givve to start searching for loop closure again | ||
* @param minimum_confidence minimum number of observations to confirm loop closure | ||
*/ | ||
LapCounter(double threshold_dist, int first_x_cones, int border_width, int minimum_confidence); | ||
|
||
/** | ||
* @brief Detects loop closure when returning to origin and seeing initial cones | ||
* @param current_pose your latest pose in world frame | ||
* @param map_cones full map of cones (in insertion order) | ||
* @param associations one entry per observation: | ||
* >=3 → matched map_cones[(j-3)/2] | ||
* -1 → new landmark, -2 → no match | ||
* @param observations raw observations (unused in this implementation) | ||
* @return {true,0.0} once you re‑see any of map_cones[0..X-1] | ||
*/ | ||
Result detect( | ||
const Eigen::Vector3d& current_pose, | ||
const Eigen::VectorXi& map_cones, | ||
const Eigen::VectorXi& associations, | ||
const Eigen::VectorXd& observations) const override; | ||
|
||
private: | ||
double threshold_dist_; | ||
int first_x_cones_; | ||
int border_width_; | ||
int minimum_confidence_; | ||
mutable int confidence_ {0}; | ||
mutable bool searching_{false}; | ||
}; |
41 changes: 41 additions & 0 deletions
41
src/perception_sensor_lib/include/perception_sensor_lib/loop_closure/loop_closure.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <Eigen/Core> | ||
#include <common_lib/structures/cone.hpp> | ||
#include <vector> | ||
#include <utility> | ||
|
||
/** | ||
* @brief Interface for detecting loop closures | ||
*/ | ||
class LoopClosure { | ||
Davide64-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public: | ||
|
||
/** | ||
* @brief Result of loop closure detection | ||
* @param detected true if a loop closure was detected | ||
* @param offset offset in meters of the map deviation | ||
*/ | ||
struct Result{ | ||
bool detected; | ||
double offset; | ||
}; | ||
|
||
virtual ~LoopClosure() = default; | ||
|
||
/** | ||
* @brief Call every time you have new observations. | ||
* @param current_pose your latest pose in world frame | ||
* @param map_cones full map of cones (in insertion order) | ||
* @param associations one entry per observation: | ||
* >=3 → matched map_cones[(j-3)/2] | ||
DiogoProPrayer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* -1 → new landmark, -2 → no match | ||
* @param observations raw observations | ||
* @return result indicating if loop closure was detected | ||
*/ | ||
virtual Result detect( | ||
const Eigen::Vector3d& current_pose, | ||
const Eigen::VectorXi& map_cones, | ||
const Eigen::VectorXi& associations, | ||
const Eigen::VectorXd& observations) const = 0; | ||
}; |
61 changes: 61 additions & 0 deletions
61
src/perception_sensor_lib/src/loop_closure/lap_counter.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "perception_sensor_lib/loop_closure/lap_counter.hpp" | ||
#include <cmath> | ||
|
||
LapCounter::LapCounter(double threshold_dist, int first_x_cones, int border_width, int minimum_confidence) | ||
: threshold_dist_(threshold_dist), | ||
first_x_cones_(first_x_cones), | ||
border_width_(border_width), | ||
minimum_confidence_(minimum_confidence) | ||
{} | ||
|
||
LoopClosure::Result LapCounter::detect( | ||
const Eigen::Vector3d& current_pose, | ||
const Eigen::VectorXi& map_cones, | ||
const Eigen::VectorXi& associations, | ||
const Eigen::VectorXd& observations) const | ||
{ | ||
double dx = current_pose.x(); | ||
double dy = current_pose.y(); | ||
double dist = std::sqrt(dx * dx + dy * dy); | ||
|
||
// add a border to give some space until we start searching again | ||
if (!searching_) { | ||
if (dist > threshold_dist_ + border_width_) { | ||
searching_ = true; | ||
} else { | ||
return {false, 0.0}; | ||
} | ||
} | ||
|
||
// If we're still far from the origin, no closure | ||
if (dist > threshold_dist_) { | ||
return {false, 0.0}; | ||
} | ||
|
||
bool match_found = false; | ||
// Look for match with any of the first X cones | ||
for (int i = 0; i < associations.size(); ++i) { | ||
int j = associations[i]; | ||
if (j >= 3) { | ||
int map_idx = (j - 3) / 2; // Index into map_cones | ||
if (map_idx < first_x_cones_) { | ||
match_found = true; // Update the outer match_found variable | ||
break; // We found a match, no need to continue searching | ||
} | ||
} | ||
} | ||
|
||
if (match_found) { | ||
confidence_++; | ||
if (confidence_ >= minimum_confidence_) { | ||
// We found loop closure, reset confidence and return | ||
confidence_ = 0; | ||
searching_ = false; // Reset search flag | ||
return {true, 0.0}; | ||
} | ||
} else { | ||
confidence_ = 0; | ||
} | ||
|
||
return {false, 0.0}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.