Skip to content

Extending likelihood field to model unexplored spaces - #430

Merged
hidmic merged 7 commits into
mainfrom
davpr/likelihood-limitations
Oct 5, 2024
Merged

Extending likelihood field to model unexplored spaces#430
hidmic merged 7 commits into
mainfrom
davpr/likelihood-limitations

Conversation

@DPR00

@DPR00 DPR00 commented Aug 22, 2024

Copy link
Copy Markdown
Collaborator

Proposed changes

The following changes are proposed in order to enhance the Likelihood Field Model based on the suggestions described on #55:

  • First, a new function unknown_obstacle_data() is created to ideally replace the obstacle_data() function in beluga/sensor/data/OccupancyGrid.hpp. This new function will return a srd::tuple<bool, bool> containing the values which are occupied and unknown.
  • Then, this new function will be passed to calculate the distance map using a new function nearest_obstacle_unknown_distance_map. This new function will ideally replace the nearest_obstacle_distance_map function.
  • The value of the distance map for unknown values is assigned with a pre-computed value inside the nearest_obstacle_unknown_distance_map function. Based on this computed value, the likelihood will be $\frac{1}{z_{max}}$.

Some comments:

  • It passed the compilation steps and the beluga example was tested. It would be nice to make some maps testing the draft. How could I perform that?

Type of change

  • 🐛 Bugfix (change which fixes an issue)
  • 🚀 Feature (change which adds functionality)
  • 📚 Documentation (change which fixes or extends documentation)

💥 Breaking change! Explain why a non-backwards compatible change is necessary or remove this line entirely if not applicable.

Checklist

Put an x in the boxes that apply. This is simply a reminder of what we will require before merging your code.

  • Lint and unit tests (if any) pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All commits have been signed for DCO

Additional comments

@DPR00
DPR00 requested a review from hidmic August 22, 2024 23:27
@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch from 7e2e962 to 32867eb Compare August 23, 2024 03:40

@hidmic hidmic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

First pass!

It would be nice to make some maps testing the draft. How could I perform that?

I recommend extending the likelihood field model unit tests for this next.

Comment thread beluga/include/beluga/sensor/data/occupancy_grid.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/algorithm/distance_map.hpp Outdated
@DPR00

DPR00 commented Aug 27, 2024

Copy link
Copy Markdown
Collaborator Author

Hi @hidmic! I'm trying to replicate locally the 'build_and_test.sh' file, since it is failing in the pipeline. I wanted to tested first before updating the draft PR. However, I'm getting the following error (similar to #422, but it actually build when using -colcon build --packages-up-to beluga_example --cmake-args -DBUILD_TESTING=OFF as indicated in Documentation):

-- Configuring incomplete, errors occurred!
---
--- stderr: beluga
CMake Error at test/CMakeLists.txt:30 (find_package):
  By not providing "Findbenchmark.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "benchmark", but CMake did not find one.

  Could not find a package configuration file provided by "benchmark" with
  any of the following names:

    benchmarkConfig.cmake
    benchmark-config.cmake

  Add the installation prefix of "benchmark" to CMAKE_PREFIX_PATH or set
  "benchmark_DIR" to a directory containing one of the above files.  If
  "benchmark" provides a separate development package or SDK, be sure it has
  been installed.
---

This is happening in jazzy distro, but it actually works on humble. I also tried running it from the main branch, but it keeps throwing that error. Should I arise an issue?

@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch 2 times, most recently from fa79f0b to e591f1e Compare August 31, 2024 19:01

@hidmic hidmic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codecov isn't happy because we are lacking tests :)

Comment thread beluga/test/beluga/include/beluga/test/static_occupancy_grid.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/sensor/data/occupancy_grid.hpp Outdated
Comment thread beluga/include/beluga/sensor/data/occupancy_grid.hpp Outdated
Comment thread beluga/include/beluga/algorithm/distance_map.hpp Outdated
@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch 2 times, most recently from 9e8b397 to eec92a5 Compare September 7, 2024 02:34
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/sensor/data/occupancy_grid.hpp Outdated
Comment thread beluga/include/beluga/algorithm/distance_map.hpp Outdated
@hidmic

hidmic commented Sep 7, 2024

Copy link
Copy Markdown
Collaborator

@DPR00 we should update the PR title.

@DPR00 DPR00 changed the title First draft to address #55 Extending likelihood field to model unexplored spaces #55 Sep 9, 2024
@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch from 6804e7f to 0e3fff9 Compare September 11, 2024 03:09

@hidmic hidmic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is amazing @DPR00, great job!

We should add tests now though, for the likelihood model and for the action we just added.

Comment thread beluga/include/beluga/sensor/data/occupancy_grid.hpp Outdated
Comment thread beluga/include/beluga/sensor/data/occupancy_grid.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
@hidmic
hidmic marked this pull request as ready for review September 11, 2024 21:59
@hidmic

hidmic commented Sep 11, 2024

Copy link
Copy Markdown
Collaborator

This is no draft anymore, it's solid PR material.

@DPR00

DPR00 commented Sep 11, 2024

Copy link
Copy Markdown
Collaborator Author

Awesome @hidmic, thanks! I will be addressing the comments during the following days and adding tests, as well.
I also want to test it in a simulated world. Any recommendations of a world different than turtlebot_world?

@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch from 1f913d5 to 6612d46 Compare September 22, 2024 04:06

@hidmic hidmic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Third pass I think. Really good work @DPR00.

Comment thread beluga/include/beluga/actions/overlay.hpp
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp
Comment thread beluga/test/beluga/actions/test_overlay.cpp Outdated
Comment thread beluga/test/beluga/actions/test_overlay.cpp Outdated
Comment thread beluga/test/beluga/include/beluga/test/general_occupancy_grid.hpp Outdated
Comment thread beluga/test/beluga/sensor/test_lfm_with_unknown_space.cpp Outdated
Comment thread beluga/test/beluga/sensor/test_lfm_with_unknown_space.cpp Outdated
Comment thread beluga/test/beluga/sensor/test_lfm_with_unknown_space.cpp
@hidmic

hidmic commented Sep 24, 2024

Copy link
Copy Markdown
Collaborator

This PR needs a rebase after #433.

@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch 2 times, most recently from aebeaf6 to 2911f92 Compare September 26, 2024 04:55
@DPR00

DPR00 commented Sep 26, 2024

Copy link
Copy Markdown
Collaborator Author

I did the rebase and reduce all the changes to one commit. The latter was due there were a lot of commits where the changes are no longer valid.

@hidmic hidmic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I left a few more comments and CI is not happy, but this is a great piece of work @DPR00.

I'm happy with it once the missing bits are addressed and CI goes green (looks like clang-tidy is not happy).

Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/test/beluga/include/beluga/test/static_occupancy_grid.hpp Outdated
Comment thread beluga/test/beluga/include/beluga/test/static_occupancy_grid.hpp
Comment thread beluga/test/beluga/sensor/data/test_occupancy_grid.cpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated
@nahueespinosa nahueespinosa changed the title Extending likelihood field to model unexplored spaces #55 Extending likelihood field to model unexplored spaces Oct 2, 2024

@hidmic hidmic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Plain amazing. I'm good with this PR as-is. @nahueespinosa ?

Comment thread beluga/include/beluga/actions/overlay.hpp Outdated

@nahueespinosa nahueespinosa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! After fixing forwarding references.

Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/include/beluga/actions/overlay.hpp Outdated
Comment thread beluga/test/beluga/actions/test_overlay.cpp
@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch from 78f0239 to ceee341 Compare October 4, 2024 21:26
Comment thread beluga/include/beluga/actions/overlay.hpp
Comment thread beluga/include/beluga/sensor/likelihood_field_model.hpp Outdated

@nahueespinosa nahueespinosa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Signed-off-by: Diego Palma <dpalma@symbotic.com>
Signed-off-by: Diego Palma <dpalma@symbotic.com>
Signed-off-by: Diego Palma <dpalma@symbotic.com>
Signed-off-by: Diego Palma <dpalma@symbotic.com>
Signed-off-by: Diego Palma <dpalma@symbotic.com>
Signed-off-by: Diego Palma <dpalma@symbotic.com>
Signed-off-by: Diego Palma <dpalma@symbotic.com>
@DPR00
DPR00 force-pushed the davpr/likelihood-limitations branch from 3542c38 to 287453b Compare October 5, 2024 16:45

@hidmic hidmic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@DPR00 go go go 🚀

@DPR00

DPR00 commented Oct 5, 2024

Copy link
Copy Markdown
Collaborator Author

I am not able to merge it because I need to be an authorized user. Could you merge it @hidmic, pls? 🚀

@hidmic
hidmic merged commit 64026d9 into main Oct 5, 2024
@hidmic
hidmic deleted the davpr/likelihood-limitations branch October 5, 2024 19:05
auto distance_map = nearest_obstacle_distance_map(grid.obstacle_mask(), squared_distance, neighborhood);

if (params.model_unknown_space) {
const double inverse_max_distance = 1 / params.max_laser_distance;

@glpuga-eka glpuga-eka Sep 2, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@DPR00 @hidmic I'm going through this code to help rodrigo with #577, but I can't fully make sense of this.

After a while of thinking this go a long way around assigning 1 / params.max_laser_distance likelihood to any unknown cell. The latest version of this blurs this even more because that value may be overriden here, which may be right or may be wrong depending what we model here.

So my question is: why 1 / params.max_laser_distance? That models a uniform distribution over the lenght of the lidar assuming with 100% certainty that this is a random measurement in that range. Why is this not offset = params.z_random / params.max_laser_distance which is the overall probability of a random measurement falling here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

IIRC this was took from this part of Probabilistic Robotics book (Section 6.4.2, page 173):
image

@hidmic hidmic Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That. IIUC the idea is that the probability of a hit for any given measurement is uniform: $z \in [0, z_{max}]$, then $p(z) = \frac{1}{z_{max}}$). Mixing parameters are not applicable because those presume knowledge we don't have (well, kinda, we could still model failure and unexpected objects, I think, but they didn't and we don't).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think that's right, and I explain why.

The problem is that that causes the likelihood map to implement different likelihood functions depending on the lidar happens to hit, causing non-uniform weight scales. Depending on the lidar range the likelihood might be higher through an open window than 20cm away from an actually mapped obstacle.

Mixing parameters are not applicable because those presume knowledge we don't have

I think that not mixing assumes a knowledge we don't have. It asummes we know with 100% certainty that the measurement IS a random hit, which we can't know. Where a hit falls does not depend as much on the measurement as much as on the hyphotesis/particle you are tracing it from, so a hit on unknown area behind a wall surface or through a window most likely just means a hyphotesis which is 5 cm closer to the wall than the actual pose of the lidar. That hypothesis is not wrong, it's just part of the internal representation of the distribution that the filter uses for the pose.

If we assign 1 / params.max_laser_distance, we are overweighing particles with beams that hit within unknown areas, because z_random < 1.0,

If we assign a weight params.z_random / params.max_laser_distance to that case, that's the weight we assign to random impacts everywhere, and indeed that's how we model "random obstacles that are not mapped", which makes sense for unknown areas.

Notice that while I think that using params.z_random / params.max_laser_distance is at least in line with the larger model and does not distort the likelihood distribution value scale, I still don't think it is right.

That's because the likelihood model only really models known obstacles; more than a probabilistic model, LF is a "scan correlator". In fact, the z_random term is not really there to decide on the "goodness" of an impact over another, since it's the same everywhere; it's just there to avoid the likelihood product going to zero too fast if we hit unmapped obstacles.

In ignoring the z_hit term behind a wall we are biasing the estimation solution towards the external side of the wall by truncating the natural symmetry of the distance-likelihood distribution on both sides of the surface. In closed quarters this may not make much of a difference, but if you only see a straight wall on your left, this alone may add you a few centimeters of error due to that bias this causes in the particle distribution.

@hidmic hidmic Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we assign a weight params.z_random / params.max_laser_distance to that case, that's the weight we assign to random impacts everywhere, and indeed that's how we model "random obstacles that are not mapped", which makes sense for unknown areas.

Hmm, but random hit != unknown hit. Random hits have lower probability because it is implied they are transient. Thrun mentions cross-talk and echoes as potential sources.

That said...

In ignoring the z_hit term behind a wall we are biasing the estimation solution towards the external side of the wall by truncating the natural symmetry of the distance-likelihood distribution on both sides of the surface.

Yeah, I see the problem now 🤔

(stream of consciousness ahead)

IIUC we are folding both unobservable and unmapped as unknown, and we are overpowering the base likelihood model when we shouldn't. Assigning a higher likelihood to hits within internal walls or past external walls just gives us bias. Assigning a higher likelihood to hits within an unmapped but otherwise visible region does prevent us from excessively penalizing hypothesis close to such regions when those regions happen to be occupied. If the unmapped space is within a room that had its door closed during mapping, we do want hits within that unexplored space not be ruled out as highly unlikely.

Hmm, what if we let the user configure a distance threshold? Unexplored space that is within that distance from occupied cells decays normally, while unexplored space past that distance gets the truncated likelihood to signal we don't really know if a hit in that region is likely or not. We cover for the variance in the estimate while not (excessively) penalizing hitting a car parked out the window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants