Skip to content
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

Add beam sensor model #160

Merged
merged 19 commits into from
May 5, 2023
Merged

Add beam sensor model #160

merged 19 commits into from
May 5, 2023

Conversation

serraramiro1
Copy link
Contributor

@serraramiro1 serraramiro1 commented Apr 4, 2023

Related to #99

Summary

  • Adds a brasenhaum raycasting function for casting rays on an occupancy grid.
  • Adds a beam sensor model implementation.
  • Adds beam sensor model to the runtime selection for the AMCL node.
  • Adds tests for both the raycasting and the model itself.

Checklist

  • Read the contributing guidelines.
  • Configured pre-commit and ran colcon test locally.
  • Signed all commits for DCO.
  • Added tests (regression tests for bugs, coverage of new code for features).
  • Updated documentation (as needed).
  • Checked that CI is passing.


int error = 0;
// Needed because of the way OccupancyGrid signals an out of bounds index.
std::size_t last_ok_index = steep ? grid.index(y * grid.resolution(), x * grid.resolution())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird but needed.
I think it'd be nice to provide an abstaction of index() that signals an out-of-bound cell differently, instead of the current approach that returns size()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking out loud, index() could return std::optional as a poor mans substitute to e.g. abseil::StatusOr.

beluga/include/beluga/sensor/beam_model.hpp Show resolved Hide resolved
beluga/include/beluga/sensor/beam_model.hpp Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga_amcl/src/amcl_node.cpp Outdated Show resolved Hide resolved
@nahueespinosa nahueespinosa added the do-not-land Do not merge these changes into the main branch label Apr 4, 2023
@nahueespinosa nahueespinosa changed the title [DO NOT MERGE] Add beam sensor model Add beam sensor model Apr 4, 2023
@nahueespinosa nahueespinosa added enhancement New feature or request cpp Related to C++ code labels Apr 4, 2023
@serraramiro1 serraramiro1 force-pushed the ramiro/beam_sensor_model branch from b05bb3f to 7596970 Compare April 4, 2023 14:28
Copy link
Collaborator

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start. It needs polishing but functionality is pretty much there.

beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved

int error = 0;
// Needed because of the way OccupancyGrid signals an out of bounds index.
std::size_t last_ok_index = steep ? grid.index(y * grid.resolution(), x * grid.resolution())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking out loud, index() could return std::optional as a poor mans substitute to e.g. abseil::StatusOr.

beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
Comment on lines +125 to +127
// TODO(Ramiro): We're converting from range + bearing to cartesian points in the ROS node, but we want range +
// bearing here. We might want to make that conversion in the likelihood model instead, and let the measurement
// type be range, bearing instead of x, y.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking out loud, measurement_type should perhaps be a proxy object to iterate over points in either cartesian or polar coordinate, which may or may not incur additional overhead depending on underlying data (e.g. in ROS, LaserScan messages use polar coordinates where PointCloud2 messages normally use cartesian coordinates).

beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
@hidmic hidmic self-assigned this Apr 14, 2023
@hidmic
Copy link
Collaborator

hidmic commented Apr 14, 2023

I'll give this a shot.

@@ -0,0 +1,186 @@
// Copyright 2022 Ekumen, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date

Copy link
Member

@nahueespinosa nahueespinosa May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to using 2023

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 875d382.

last_ok_index = index;
x += 1;
error += delta_y;
if (2 * error >= delta_x) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a source for this version of the algorithm? Isn't this comparison done before updating the error with delta_y?

serraramiro1 and others added 12 commits May 3, 2023 00:52
Signed-off-by: Ramiro Serra <[email protected]>
Signed-off-by: Ramiro Serra <[email protected]>
Signed-off-by: Ramiro Serra <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic hidmic force-pushed the ramiro/beam_sensor_model branch from 31d666c to c77b3d2 Compare May 3, 2023 13:51
@hidmic
Copy link
Collaborator

hidmic commented May 3, 2023

@glpuga @nahueespinosa @serraramiro1 PTAL

hidmic added 3 commits May 3, 2023 14:13
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
* - Give possibly const values `x` and `y` of type `double`, `g.index(x, y)` returns a `std::size`,
* representing the index of the cell.
* - Give a possibly const `Eigen::Vector2d` `p`, `g.index(p)` is equivalent to `g.index(p.x(), p.y())`.
* - Give possibly const values `x` and `y` of type `int`, `g.index(x, y)` returns a `std::size`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - Give possibly const values `x` and `y` of type `int`, `g.index(x, y)` returns a `std::size`,
* - Given possibly const values `x` and `y` of type `int`, `g.index(x, y)` returns a `std::size`,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this and concluded this is error prone.

Let's say an user defines its own Grid, that defines the double variant of this method, i.e. index(double x , double y) , this will still compile and produce incorrect results.

How do we feel about enforcing this through an abstract interface? Or removing the builtin type variants in favor of Eigen::Vector2 ones that prevent this from happening.

I'd also be happy coming up with a different name for continous vs discrete methods to prevent this from happening.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say an user defines its own Grid, that defines the double variant of this method, i.e. index(double x , double y) , this will still compile and produce incorrect results.

That is possible, yes.

How do we feel about enforcing this through an abstract interface? Or removing the builtin type variants in favor of Eigen::Vector2 ones that prevent this from happening.
I'd also be happy coming up with a different name for continous vs discrete methods to prevent this from happening.

I think the OccupancyGrid concept needs to be reworked, but I didn't want to do it here. Better method naming is perhaps best. I'd suggest deferring it to a follow-up PR though, where we can address semantics and code reuse.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed typos in aa3f86c.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another aspect of the current changes to the OccupancyGrid that is perhaps more controversial is the use of plain ints.

I understand why std::size_t was used but arithmetic with unsigned numeric types is error prone even when defined, and thus why you normally don't see unsigned scalars in vector types. I'd also argue that the current API is unnecessarily low level. Storage layout details can be abstracted without compromising performance.

beluga_system_tests/test/test_system.cpp Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic hidmic removed the do-not-land Do not merge these changes into the main branch label May 3, 2023
@serraramiro1
Copy link
Contributor Author

LGTM

@hidmic hidmic requested a review from glpuga May 3, 2023 18:30
@hidmic hidmic mentioned this pull request May 3, 2023
2 tasks
Copy link
Collaborator

@glpuga glpuga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/raycasting.hpp Outdated Show resolved Hide resolved
beluga_amcl/src/amcl_node.cpp Show resolved Hide resolved
beluga_amcl/src/amcl_node.cpp Show resolved Hide resolved
beluga_example/config/params.yaml Outdated Show resolved Hide resolved
Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic
Copy link
Collaborator

hidmic commented May 5, 2023

Anything else here @glpuga @nahueespinosa ?

Copy link
Member

@nahueespinosa nahueespinosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -0,0 +1,186 @@
// Copyright 2022 Ekumen, Inc.
Copy link
Member

@nahueespinosa nahueespinosa May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to using 2023

@glpuga
Copy link
Collaborator

glpuga commented May 5, 2023

@hidmic Nop, it GO on my side. 🟢🟢🟢

Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic hidmic merged commit 966b3ed into main May 5, 2023
@hidmic hidmic deleted the ramiro/beam_sensor_model branch May 5, 2023 13:25
@nahueespinosa nahueespinosa mentioned this pull request May 9, 2023
1 task
@olmerg
Copy link
Collaborator

olmerg commented May 12, 2023

Which tasks of Make beluga_amcl a drop-in replacement of nav2_amcl was implemented? @hidmic

@hidmic
Copy link
Collaborator

hidmic commented May 12, 2023

It would say (in terms of parameters):

  • lambda_short
  • z_max
  • z_short

Beam skip parameters have not been implemented. It's a rather simple variation though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp Related to C++ code enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants