-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[costmap_filters] Add ZoneParameterFilter — config-driven per-zone parameter overrides #6104
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
Open
aki1770-del
wants to merge
22
commits into
ros-navigation:main
Choose a base branch
from
aki1770-del:feat/zone-parameter-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ea7408f
WIP: ZoneParameterFilter — plugin scaffold + test scaffold (slice 1, …
aki1770-del 4bb6fee
fix(zone_parameter_filter): uncrustify lint nits (Path C build verifi…
aki1770-del ac3d503
test(zone_parameter_filter): add TestZpf lifecycle fixture + first re…
aki1770-del 9b63594
test(zone_parameter_filter): add 3 lifecycle cases + #3796 regression…
aki1770-del bfcb13f
fix(zone_parameter_filter): YAML-declared nominal_defaults for state-…
aki1770-del 8aa04c3
fix(zone_parameter_filter): apply CI lint feedback (codespell + uncru…
aki1770-del 8e9a594
fix(zone_parameter_filter): explicit target_nodes + 4 audit-driven tests
aki1770-del e61099a
[costmap_filters] ZoneParameterFilter: always throw on unknown mask s…
aki1770-del 983e3a2
[costmap_filters] ZoneParameterFilter: scrub TMI comments
aki1770-del db32b3c
[costmap_filters] ZoneParameterFilter: default state_event_topic to "…
aki1770-del 1cf64e4
[costmap_filters] ZoneParameterFilter: flip on_param_set_failure defa…
aki1770-del a2c3a3b
[costmap_filters] ZoneParameterFilter: header restructure (protected …
aki1770-del c2f6976
[costmap_filters] ZoneParameterFilter: init-time param clients + drop…
aki1770-del d387a48
[costmap_filters] ZoneParameterFilter: replace colon-encoded keys wit…
aki1770-del c0fa9eb
[costmap_filters] ZoneParameterFilter: expand test coverage 13 → 30 c…
aki1770-del 864d49b
[costmap_filters] ZoneParameterFilter resets N-only params on N→M
aki1770-del 72b7009
[costmap_filters] ZoneParameterFilter: simplify exception flow + scop…
aki1770-del d094ede
[costmap_filters] ZoneParameterFilter: trim redundant comments + rename
aki1770-del 21a753e
[costmap_filters] ZoneParameterFilter: remove TODO dev-note from test…
aki1770-del 0828ff9
[costmap_filters] ZoneParameterFilter: compress test suite 30 -> 16
aki1770-del a9beccd
[costmap_filters] ZoneParameterFilter: fix lint findings on test comp…
aki1770-del 8c58cc8
[costmap_filters] ZoneParameterFilter: avoid codespell lets-let's mis…
aki1770-del File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
153 changes: 153 additions & 0 deletions
153
nav2_costmap_2d/include/nav2_costmap_2d/costmap_filters/zone_parameter_filter.hpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| // Copyright (c) 2026 Komada (aki1770-del) | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef NAV2_COSTMAP_2D__COSTMAP_FILTERS__ZONE_PARAMETER_FILTER_HPP_ | ||
| #define NAV2_COSTMAP_2D__COSTMAP_FILTERS__ZONE_PARAMETER_FILTER_HPP_ | ||
|
|
||
| #include <map> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "geometry_msgs/msg/pose.hpp" | ||
| #include "nav_msgs/msg/occupancy_grid.hpp" | ||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "std_msgs/msg/u_int8.hpp" | ||
|
|
||
| #include "nav2_costmap_2d/costmap_filters/costmap_filter.hpp" | ||
| #include "nav2_msgs/msg/costmap_filter_info.hpp" | ||
|
|
||
| namespace nav2_costmap_2d | ||
| { | ||
|
|
||
| /** | ||
| * @class ZoneParameterFilter | ||
| * @brief Costmap filter that applies a configured set of ROS parameters | ||
| * based on the mask value at the robot's pose. | ||
| * | ||
| * The filter mask uses occupancy-grid values. State 0 is the reset state; | ||
| * each non-zero state ID maps via configuration to a list of parameter | ||
| * overrides on configured target nodes. | ||
| */ | ||
| class ZoneParameterFilter : public CostmapFilter | ||
| { | ||
| public: | ||
| ZoneParameterFilter(); | ||
|
|
||
| /** | ||
| * @brief Initialise filter, subscribe to filter info / mask, build | ||
| * per-target-node async parameter clients. | ||
| */ | ||
| void initializeFilter(const std::string & filter_info_topic) override; | ||
|
|
||
| /** | ||
| * @brief Sample the mask at the robot pose; if the state changed, | ||
| * apply the new state's parameter set via async client and, | ||
| * if configured, publish the state event. | ||
| */ | ||
| void process( | ||
| nav2_costmap_2d::Costmap2D & master_grid, | ||
| int min_i, int min_j, int max_i, int max_j, | ||
| const geometry_msgs::msg::Pose & pose) override; | ||
|
|
||
| /** | ||
| * @brief Reset filter — drop subscriptions, reset publisher, clear | ||
| * nominal-defaults capture. | ||
| */ | ||
| void resetFilter() override; | ||
|
|
||
| /** | ||
| * @brief Whether the filter has received its mask and is operational. | ||
| */ | ||
| bool isActive(); | ||
|
|
||
| protected: | ||
| /** | ||
| * @brief Subscriber callback for the filter info topic. | ||
| */ | ||
| void filterInfoCallback( | ||
| const nav2_msgs::msg::CostmapFilterInfo::ConstSharedPtr & msg); | ||
|
|
||
| /** | ||
| * @brief Subscriber callback for the filter mask topic. | ||
| */ | ||
| void maskCallback( | ||
| const nav_msgs::msg::OccupancyGrid::ConstSharedPtr & msg); | ||
|
|
||
| /** | ||
| * @brief Parse the per-state parameter map and nominal_defaults from | ||
| * YAML overrides. | ||
| */ | ||
| void loadStateConfig(); | ||
|
|
||
| /** | ||
| * @brief Apply the parameter set associated with the given state. | ||
| * State 0 restores nominal_defaults; throws on unknown state. | ||
| */ | ||
| void applyState(uint8_t new_state); | ||
|
|
||
| /** | ||
| * @brief Restore all overridden parameters to their nominal_defaults | ||
| * values via async set_parameters. | ||
| */ | ||
| void resetToNominal(); | ||
|
|
||
| /** | ||
| * @brief Issue an async set_parameters call to the named target node. | ||
| */ | ||
| void issueAsyncSetParameters( | ||
| const std::string & target_node, | ||
| const std::vector<rclcpp::Parameter> & params); | ||
|
|
||
| /** | ||
| * @brief Drain completed set_parameters futures non-blockingly. Called | ||
| * at the start of every process() to guard future lifetimes. | ||
| */ | ||
| void drainPendingFutures(); | ||
|
|
||
| nav2::Subscription<nav2_msgs::msg::CostmapFilterInfo>::SharedPtr filter_info_sub_; | ||
| nav2::Subscription<nav_msgs::msg::OccupancyGrid>::SharedPtr mask_sub_; | ||
| nav2::Publisher<std_msgs::msg::UInt8>::SharedPtr state_event_pub_; | ||
|
|
||
| nav_msgs::msg::OccupancyGrid::ConstSharedPtr filter_mask_; | ||
| std::string global_frame_; | ||
|
|
||
| uint8_t current_state_{0}; | ||
| bool state_initialized_{false}; | ||
|
|
||
| // One per-state-override or per-nominal-default entry. | ||
| struct StateParamEntry | ||
| { | ||
| std::string target_node; | ||
| rclcpp::Parameter param; | ||
| }; | ||
| std::map<uint8_t, std::vector<StateParamEntry>> state_param_map_; | ||
| // Keyed by target_node; values are bare-named Parameters to restore. | ||
| std::map<std::string, std::vector<rclcpp::Parameter>> nominal_defaults_; | ||
| std::map<std::string, rclcpp::AsyncParametersClient::SharedPtr> param_clients_; | ||
|
|
||
| std::vector<std::shared_future< | ||
| std::vector<rcl_interfaces::msg::SetParametersResult>>> pending_futures_; | ||
|
|
||
| std::string state_event_topic_; | ||
|
|
||
| enum class ParamSetFailurePolicy { kWarn, kThrow }; | ||
| ParamSetFailurePolicy param_set_failure_policy_{ParamSetFailurePolicy::kThrow}; | ||
|
|
||
| bool filter_info_received_{false}; | ||
| }; | ||
|
|
||
| } // namespace nav2_costmap_2d | ||
|
|
||
| #endif // NAV2_COSTMAP_2D__COSTMAP_FILTERS__ZONE_PARAMETER_FILTER_HPP_ | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.