Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
check_pose_occupancy_action.hpp
1 // Copyright (c) 2025 Maurice Alexander Purnawan
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__CHECK_POSE_OCCUPANCY_ACTION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__CHECK_POSE_OCCUPANCY_ACTION_HPP_
17 
18 #include <memory>
19 #include <string>
20 
21 #include "nav2_ros_common/lifecycle_node.hpp"
22 #include "behaviortree_cpp/action_node.h"
23 #include "behaviortree_cpp/json_export.h"
24 #include "geometry_msgs/msg/pose_stamped.hpp"
25 #include "nav2_msgs/srv/get_costs.hpp"
26 #include "nav2_ros_common/service_client.hpp"
27 #include "nav2_behavior_tree/bt_utils.hpp"
28 #include "nav2_behavior_tree/json_utils.hpp"
29 #include "nav2_behavior_tree/bt_service_node.hpp"
30 
31 namespace nav2_behavior_tree
32 {
33 
42 class CheckPoseOccupancy : public BtServiceNode<nav2_msgs::srv::GetCosts>
43 {
44 public:
51  const std::string & service_node_name,
52  const BT::NodeConfiguration & conf);
53 
58  void on_tick() override;
59 
65  BT::NodeStatus on_completion(std::shared_ptr<nav2_msgs::srv::GetCosts::Response> response)
66  override;
67 
72  static BT::PortsList providedPorts()
73  {
74  // Register JSON definitions for the types used in the ports
75  BT::RegisterJsonDefinition<geometry_msgs::msg::PoseStamped>();
76 
77  return providedBasicPorts(
78  {
79  BT::InputPort<geometry_msgs::msg::PoseStamped>("pose", "Pose to check if occupied"),
80  BT::InputPort<double>(
81  "cost_threshold", 254.0,
82  "Cost threshold for considering a pose occupied"),
83  BT::InputPort<bool>("use_footprint", true, "Whether to use footprint cost"),
84  BT::InputPort<bool>(
85  "consider_unknown_as_obstacle", false,
86  "Whether to consider unknown cost as obstacle")
87  });
88  }
89 
90 private:
91  bool use_footprint_;
92  bool consider_unknown_as_obstacle_;
93  double cost_threshold_;
94 };
95 
96 } // namespace nav2_behavior_tree
97 
98 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__CHECK_POSE_OCCUPANCY_ACTION_HPP_
Abstract class representing a service based BT node.
static BT::PortsList providedBasicPorts(BT::PortsList addition)
Any subclass of BtServiceNode that accepts parameters must provide a providedPorts method and call pr...
A nav2_behavior_tree::BtServiceNode class that checks if a pose is occupied by calling the GetCosts s...
BT::NodeStatus on_completion(std::shared_ptr< nav2_msgs::srv::GetCosts::Response > response) override
Function to perform some user-defined operation after receiving a result from the service.
void on_tick() override
The main override required by a BT service.
static BT::PortsList providedPorts()
Creates list of BT ports.
CheckPoseOccupancy(const std::string &service_node_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::CheckPoseOccupancy.