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

Explicit assignment operators for Observation, default assignment is a bug here #2413

Merged
merged 3 commits into from
Jun 28, 2021

Conversation

topin89
Copy link
Contributor

@topin89 topin89 commented Jun 17, 2021

Also move constructor. Default copy assignment is not just a shortcut to copy constructor, sadly


Basic Info

Info Please fill out this column
Ticket this addresses #2412)
Primary OS tested on Ubuntu under WSL1
Robotic platform tested on N/A

Description of contribution in a few bullet points

  • Fixed bug with copy assignment being just a copy of all class fields, without proper new call for sensor_msgs::msg::PointCloud2 * cloud_
  • Added move assignment and move constructor, because it's they are called inside std::vector with less (de)allocations

Description of documentation updates required from your changes

Teeeny changes:

  • Changed description for copy assignment
  • Added description for move assignment and move constructor

Future work that may be required in bullet points

  • I guess similar pulls for crystal and main braches should be done
  • Maybe check if any other default defined functions really shouldn't be

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 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

Also move constructor. Default copy assignment is not just a shortcut to copy constructor, sadly
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.

Overall, I don't see the value in this PR. What are you trying to accomplish that was not possible prior, specifically?

nav2_costmap_2d/include/nav2_costmap_2d/observation.hpp Outdated Show resolved Hide resolved
nav2_costmap_2d/include/nav2_costmap_2d/observation.hpp Outdated Show resolved Hide resolved
@topin89
Copy link
Contributor Author

topin89 commented Jun 18, 2021

I guess there's an alternative to those verbose constructors/assignments. I didn't try to compile it, but it looks like
sensor_msgs::msg::PointCloud2 * cloud_; can easily be replaced with sensor_msgs::msg::PointCloud2::UniquePtr cloud_;.

EDIT:

Checked. It would still require this:

  Observation & operator=(const Observation & obs){
    origin_ = obs.origin_;
    cloud_.reset(new sensor_msgs::msg::PointCloud2(*(obs.cloud_)));
    obstacle_range_ = obs.obstacle_range_;
    raytrace_range_ = obs.raytrace_range_;

    return *this;
  }

But move functions could easily be defined as:

Observation(Observation && obs) = default;
Observation & operator=(Observation && obs) = default;

@SteveMacenski
Copy link
Member

SteveMacenski commented Jun 18, 2021

Yes, a unique pointer would also work. I'd accept a PR to do that if you like. But please do remove the other unnecessary changes and lets just focus on the copy operator that isn't handling the PC2 correctly. This PR also has linting issues, please make sure to run the test suite, especially ament_uncrustify and ament_cpplint. We also need these changes made to Galactic and main to merge into Foxy

@topin89
Copy link
Contributor Author

topin89 commented Jun 20, 2021

Not sure what exactly should I do, so for now just removed functions unrelated to the bug and fixed linting issues. If I should replace the pointer with unique_ptr, I'll change to that. I could also port this to any branches you think it should be ported to, just not sure what to port, how many PRs to do (I mean, I still want to add those move functions). As I understand it, there should be two requests. one for assignment (with or without unique_ptr) and another for move stuff, for every branch.

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.

Please submit against Galactic and Main branches and I can merge the full set of 3 together

If you wished to switch to a unique pointer as well, that would be fine, but not required. I'm OK with it either way. It can be included in this PR not a new one.

You will also need to submit a PR https://github.com/ros-planning/navigation.ros.org/blob/master/migration/Galactic.rst against this file adding a new section about this change to the migration guide.

@topin89
Copy link
Contributor Author

topin89 commented Jun 23, 2021

OK, two followup PRs are done: #2425 #2424

You will also need to submit a PR https://github.com/ros-planning/navigation.ros.org/blob/master/migration/Galactic.rst against this file adding a new section about this change to the migration guide.

But what to submit there? This is just a bugfix, and there's no difference between observation.hpp in galactic and main branches.

I can think of only

  • Various bug fixes

or

  • Fixed a double free bug

to "Major Improvements", but that's not exactly major.

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.

2 participants