Conversation
nav2_costmap_2d/include/nav2_costmap_2d/costmap_2d_publisher.hpp
Outdated
Show resolved
Hide resolved
nav2_costmap_2d/include/nav2_costmap_2d/costmap_2d_publisher.hpp
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| void Costmap2DPublisher::publishCostmap() | ||
| std::unique_ptr<nav2_msgs::msg::CostmapUpdate> Costmap2DPublisher::get_raw_costmap_update_msg() |
There was a problem hiding this comment.
I was just wondering if you could kindly explain why you use std::unique_ptr for the return type.
Returning the variable with std::unique_ptr is unnecessary due to Return Value Optimization (RVO).
There was a problem hiding this comment.
Publishing the std::unique_ptr instead of raw msg is a principle adopted in this project, so that is why I've decided to create msg in unique_ptr directly.
Change publishers to publish unique ptrs
I believe that the cause for that is related with Publisher class implementation.
When calling publish(const T & msg) additional copy of msg is made when using the intra-process communication
publisher.hpp:L278, and in the end you have a copy stored in the unique_ptr and pass the ownership further.
When using publish(std::unique_ptr<MessageT, MessageDeleter> msg) you are omitting this copy. Also please take a look at the comments describing each of the overloaded methods.
SteveMacenski
left a comment
There was a problem hiding this comment.
Overall, very few notes, well done!
This does require some unit testing to make sure it works as expected 😄
| costmap_update_pub_->publish(std::move(update)); | ||
| } | ||
| if (costmap_raw_update_pub_->get_subscription_count() > 0) { | ||
| costmap_raw_update_pub_->publish(createRawCostmapUpdateMsg()); |
There was a problem hiding this comment.
Always do std::move() on unique pointers when publishing for explicit ownership semantics. It helps with topic jitter, especially for larger topics like this
There was a problem hiding this comment.
In this case, I believe that using std::move() explicitly might cause an unnecessary call to the move constructor of unique_ptr.
I have run a toy example which showed that due to RVO/NRVO optimization, no additional call to the constructor was made. However, when calling std::move() I triggered the move constructor.
When I turned off the optimization I also had a call to move constructor.
So to sum up, we are ending up with the move constructor call in the worst-case scenario, but when calling move, it is more likely, because it seems like it blocks RVO.
Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
…ation2 into 3732_costmap_raw_update_msgs
|
@emsko please don't hit "resolve" on things that haven't been pushed / completed yet. I went through and unresolved a number of items that haven't been addressed yet. It helps with my tracking of status 😄 |
|
Try rebasing and pushing a new PR with a new branch. Something is not quite right here the fact that some of your commits are not appearing on github's diff UX. Everytime that's happened in the past and I overlooked it as a quirk of github messing something up, there ended up being real issues that bit us in the butt later. I agree the commits you link to in the github review comments appear to fix it, but the fact that I can't see that points to something being a little fishy which I want to make sure is resolved. |
|
@SteveMacenski I have opened a new PR with rebased changes as you asked: #3965 , so hopefully the issues with Github are resolved now. |
|
Yes, sounds good! I see things properly now in the new PR |
…) (#3965) * Adding CostmapUpdate msg * CostmapRawUpdate Publisher * remove test logs and typos * change data type to uint8 * pass unique ptr to raw costmap update publisher * adding subsriber for updates * -Werror=type-limits for update lower bounds checking * copy update msg * change code formatting * adding lock guards on costmap in footprint_collision_checker.cpp * adding lock guards for costmap subscriber clients * review suggestions implementation * fixing gtests errors * changes after second round of review * Update nav2_msgs/msg/CostmapUpdate.msg Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> * Integration test for costmap subscriber draft * Change the current grid parameters in separate method * WIP int test * adding method in PublisherCostmap2D for OccupancyGridUpdate population * test full costmap and updates while generating results * Integration tests for subscribers * Expected number of msgs related to number of mapchanges in tests * next round of reviews * refactor names of Costmap2DPublisher * remove unnecessary costmap_received_ flag form CostmapSubscriber --------- Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
…-navigation#3948) (ros-navigation#3965) * Adding CostmapUpdate msg * CostmapRawUpdate Publisher * remove test logs and typos * change data type to uint8 * pass unique ptr to raw costmap update publisher * adding subsriber for updates * -Werror=type-limits for update lower bounds checking * copy update msg * change code formatting * adding lock guards on costmap in footprint_collision_checker.cpp * adding lock guards for costmap subscriber clients * review suggestions implementation * fixing gtests errors * changes after second round of review * Update nav2_msgs/msg/CostmapUpdate.msg Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> * Integration test for costmap subscriber draft * Change the current grid parameters in separate method * WIP int test * adding method in PublisherCostmap2D for OccupancyGridUpdate population * test full costmap and updates while generating results * Integration tests for subscribers * Expected number of msgs related to number of mapchanges in tests * next round of reviews * refactor names of Costmap2DPublisher * remove unnecessary costmap_received_ flag form CostmapSubscriber --------- Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> Signed-off-by: gg <josho.wallace@gmail.com>
…-navigation#3948) (ros-navigation#3965) * Adding CostmapUpdate msg * CostmapRawUpdate Publisher * remove test logs and typos * change data type to uint8 * pass unique ptr to raw costmap update publisher * adding subsriber for updates * -Werror=type-limits for update lower bounds checking * copy update msg * change code formatting * adding lock guards on costmap in footprint_collision_checker.cpp * adding lock guards for costmap subscriber clients * review suggestions implementation * fixing gtests errors * changes after second round of review * Update nav2_msgs/msg/CostmapUpdate.msg Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> * Integration test for costmap subscriber draft * Change the current grid parameters in separate method * WIP int test * adding method in PublisherCostmap2D for OccupancyGridUpdate population * test full costmap and updates while generating results * Integration tests for subscribers * Expected number of msgs related to number of mapchanges in tests * next round of reviews * refactor names of Costmap2DPublisher * remove unnecessary costmap_received_ flag form CostmapSubscriber --------- Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> Signed-off-by: enricosutera <enricosutera@outlook.com>
…-navigation#3948) (ros-navigation#3965) * Adding CostmapUpdate msg * CostmapRawUpdate Publisher * remove test logs and typos * change data type to uint8 * pass unique ptr to raw costmap update publisher * adding subsriber for updates * -Werror=type-limits for update lower bounds checking * copy update msg * change code formatting * adding lock guards on costmap in footprint_collision_checker.cpp * adding lock guards for costmap subscriber clients * review suggestions implementation * fixing gtests errors * changes after second round of review * Update nav2_msgs/msg/CostmapUpdate.msg Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> * Integration test for costmap subscriber draft * Change the current grid parameters in separate method * WIP int test * adding method in PublisherCostmap2D for OccupancyGridUpdate population * test full costmap and updates while generating results * Integration tests for subscribers * Expected number of msgs related to number of mapchanges in tests * next round of reviews * refactor names of Costmap2DPublisher * remove unnecessary costmap_received_ flag form CostmapSubscriber --------- Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
…-navigation#3948) (ros-navigation#3965) * Adding CostmapUpdate msg * CostmapRawUpdate Publisher * remove test logs and typos * change data type to uint8 * pass unique ptr to raw costmap update publisher * adding subsriber for updates * -Werror=type-limits for update lower bounds checking * copy update msg * change code formatting * adding lock guards on costmap in footprint_collision_checker.cpp * adding lock guards for costmap subscriber clients * review suggestions implementation * fixing gtests errors * changes after second round of review * Update nav2_msgs/msg/CostmapUpdate.msg Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> * Integration test for costmap subscriber draft * Change the current grid parameters in separate method * WIP int test * adding method in PublisherCostmap2D for OccupancyGridUpdate population * test full costmap and updates while generating results * Integration tests for subscribers * Expected number of msgs related to number of mapchanges in tests * next round of reviews * refactor names of Costmap2DPublisher * remove unnecessary costmap_received_ flag form CostmapSubscriber --------- Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Basic Info
Description of contribution in a few bullet points
Description of documentation updates required from your changes
Future work that may be required in bullet points
For Maintainers: