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

[collision monitor] Select the observation sources used with each polygon #4227

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anaelle-sw
Copy link
Contributor

Basic Info

Info Please fill out this column
Ticket(s) this addresses #4197
Primary OS tested on Ubuntu
Robotic platform tested on RobOcc's robot
Does this PR contain AI generated software? No

Description of contribution in a few bullet points

New string vector parameter <polygon_name>.sources_names. Only the sources which names are specified in parameter are used to check collision with current polygon. If the parameter is not set, all the observation sources are used.

Description of documentation updates required from your changes

Add new parameter <polygon_name>.sources_names to default configs, documentation page, and migration guide


Future work that may be required in bullet points

For Maintainers:

  • Check that any new parameters added are updated in navigation.ros.org
  • Check that any significant change is added to the migration guide
  • Check that any new features OR changes to existing behaviors are reflected in the tuning guide
  • Check that any new functions have Doxygen added
  • Check that any new features have test coverage
  • Check that any new plugins is added to the plugins page
  • If BT Node, Additionally: add to BT's XML index of nodes for groot, BT package's readme table, and BT library lists

Copy link
Contributor

mergify bot commented Mar 28, 2024

@anaelle-sw, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Signed-off-by: asarazin <anaelle.sarazin@robocc.com>
@anaelle-sw anaelle-sw force-pushed the collision_monitor_specific_observation_sources_for_polygon branch from f8d2bef to 95174e9 Compare March 28, 2024 17:00
Copy link
Contributor

mergify bot commented Mar 28, 2024

@anaelle-sw, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

I think we can do this more efficiently and straight forward

  • Create the unordered map
  • Adjust the current for (std::shared_ptr<Source> source : sources_) { loop to contain (1) creating an entry for a source name key with an empty vector as the value. (2) Capture the return of insert will give you an iterator to that pair in the map
  • Pass into getData the reference to the value (vector) to populate. That eliminates an entire data copy. It also eliminates multiple calls to getData to populate both the vector and map separately
  • Adjust the processStopSlowdownLimit / processApproach / etc functions to take in this map. The vector of points should no longer exist
  • Pass the map to the isPointInside
  • When iterating through the sources, use the sources names to decide if you want to use that one or not

This eliminates any extra looping and a bunch of data copies (and not parallel populating a map and a vector of data). Speed here is really key and copying pointclouds and laserscans is a pretty worst-case situation

@@ -405,7 +405,14 @@ void CollisionMonitor::process(const Velocity & cmd_vel_in, const std_msgs::msg:
}

// Points array collected from different data sources in a robot base frame
std::vector<Point> collision_points;
Copy link
Member

Choose a reason for hiding this comment

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

This variable is no longer defined but appears to still be used. Does this compile / work?

std::unordered_map<std::string, std::vector<Point>> sources_collision_points_map;

// Fill collision_points array from different data sources
for (std::shared_ptr<Source> source : sources_) {
Copy link
Member

Choose a reason for hiding this comment

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

The source data population happens below, I don't think you should be adding a new duplicate but adjusting the old one, no?

If you create the map element, you can pass in the reference to that vector to getData() so that it populates the map in-line rather than copying it twice (once from the source, another to the map).

  // Fill collision_points array from different data sources
  for (std::shared_ptr<Source> source : sources_) {
    if (source->getEnabled()) {
      if (!source->getData(curr_time, collision_points) &&  // <-- Right here populate an element of the map rather than the vector (that is no longer defined)
        source->getSourceTimeout().seconds() != 0.0)
      {
        action_polygon = nullptr;
        robot_action.polygon_name = "invalid source";
        robot_action.action_type = STOP;
        robot_action.req_vel.x = 0.0;
        robot_action.req_vel.y = 0.0;
        robot_action.req_vel.tw = 0.0;
        break;
      }
    }
  }

Copy link
Member

Choose a reason for hiding this comment

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

It seems like this for loop should be deleted and the block of code below needs to be adjusted

@@ -468,6 +475,28 @@ void CollisionMonitor::process(const Velocity & cmd_vel_in, const std_msgs::msg:
// Update polygon coordinates
polygon->updatePolygon(cmd_vel_in);

// Get collision points for sources associated to polygon
std::vector<std::string> sources_names = polygon->getSourcesNames();
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me to be more sensible to pass in a reference to the map of collision points to isPointsInside function for each of the polygons and let each of the polygons use its own internal getSourcesNames when iterating through the map to decide if it wants to use it or not.

In that case, this block of code would be removed and we just pass in the map of collision points rather than the vector of collision points to the processXYZ() functions

Copy link
Contributor

mergify bot commented Apr 24, 2024

This pull request is in conflict. Could you fix it @anaelle-sw?

@SteveMacenski
Copy link
Member

SteveMacenski commented Apr 24, 2024

@anaelle-sw looks like some small changes needed from merging your other PR 😄 Can we get this one in next?

I do really appreciate your time and effort to contribute this work back to Nav2, it is very useful and thank you!

@SteveMacenski
Copy link
Member

@anaelle-sw Hi! Any update here?

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.

[collision monitor] Select the observation sources used with each polygon
2 participants