feat(grid_map_visualization): convert GridMapVisualization to rclcpp_lifecycle::LifecycleNode#532
Open
Lakshya-04 wants to merge 1 commit intoANYbotics:humblefrom
Open
Conversation
on_configure: reads parameters, creates VisualizationFactory and all configured visualizations on_activate: creates grid map subscription and starts processing on_deactivate: resets subscription to stop processing and save CPU on_cleanup/on_shutdown: teardown visualizations and factory Removes the wall-timer-based lazy subscription mechanism — lifecycle state transitions now control when the node subscribes to the grid map topic, giving external controllers explicit management of visualization CPU cost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
GridMapVisualizationruns continuously even when no operator has RViz open, paying the full cost of deserializing every incomingGridMapmessage and converting it to point clouds / marker arrays for nobody. The existing implementation works around this with a 2 Hz wall timer that polls subscriber counts and lazily subscribes/unsubscribes — but this is inherently racy and adds its own timer overhead.A lifecycle node solves this cleanly: an external lifecycle manager (e.g.
nav2_lifecycle_manager, a mission controller, or a simple launch-timeros2 lifecycle setcall) activates the visualization only when a human is monitoring and deactivates it when not needed.Changes
GridMapVisualization— inherits fromrclcpp_lifecycle::LifecycleNodeinstead of owning an internalrclcpp::Node:on_configure: reads parameters, constructsVisualizationFactoryand all configured visualizationson_activate: creates theGridMapsubscription and starts processing incoming mapson_deactivate: resets the subscription — zero CPU spent on visualization when inactiveon_cleanup/on_shutdown: tears down visualizations and factoryRemoves:
activityCheckTimer_,isSubscribed_,updateSubscriptionCallback(), and the publicnodePtrmember.VisualizationBase,VisualizationFactory, and all concrete visualization classes are unchanged — they acceptrclcpp::Node::SharedPtrand receive one viastd::static_pointer_castfrom the lifecycle node.grid_map_visualization_node.cpp— spins viaget_node_base_interface()(standard lifecycle node spin pattern).package.xml/CMakeLists.txt— addrclcpp_lifecycledependency.Behaviour change
The node now starts in the
unconfiguredstate. It must be transitioned toactivebefore it processes any messages:Or managed automatically via
nav2_lifecycle_managerin a launch file.Test plan
configure → active → inactive → cleanupviaros2 lifecycle set