Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
is_path_valid_condition.hpp
1 // Copyright (c) 2021 Joshua Wallace
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__CONDITION__IS_PATH_VALID_CONDITION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_PATH_VALID_CONDITION_HPP_
17 
18 #include <string>
19 #include <memory>
20 
21 #include "rclcpp/rclcpp.hpp"
22 #include "behaviortree_cpp/condition_node.h"
23 #include "behaviortree_cpp/json_export.h"
24 #include "geometry_msgs/msg/pose_stamped.hpp"
25 #include "nav2_msgs/srv/is_path_valid.hpp"
26 #include "nav2_behavior_tree/json_utils.hpp"
27 
28 namespace nav2_behavior_tree
29 {
30 
40 class IsPathValidCondition : public BT::ConditionNode
41 {
42 public:
49  const std::string & condition_name,
50  const BT::NodeConfiguration & conf);
51 
52  IsPathValidCondition() = delete;
53 
58  BT::NodeStatus tick() override;
59 
63  void initialize();
64 
69  static BT::PortsList providedPorts()
70  {
71  // Register JSON definitions for the types used in the ports
72  BT::RegisterJsonDefinition<nav_msgs::msg::Path>();
73  BT::RegisterJsonDefinition<std::chrono::milliseconds>();
74 
75  return {
76  BT::InputPort<nav_msgs::msg::Path>("path", "Path to Check"),
77  BT::InputPort<std::chrono::milliseconds>("server_timeout")
78  };
79  }
80 
81 private:
82  rclcpp::Node::SharedPtr node_;
83  rclcpp::Client<nav2_msgs::srv::IsPathValid>::SharedPtr client_;
84  // The timeout value while waiting for a responce from the
85  // is path valid service
86  std::chrono::milliseconds server_timeout_;
87 };
88 
89 } // namespace nav2_behavior_tree
90 
91 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_PATH_VALID_CONDITION_HPP_
A BT::ConditionNode that returns SUCCESS when the IsPathValid service returns true and FAILURE otherw...
void initialize()
Function to read parameters and initialize class variables.
BT::NodeStatus tick() override
The main override required by a BT action.
static BT::PortsList providedPorts()
Creates list of BT ports.