Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
truncate_path_action.hpp
1 // Copyright (c) 2018 Intel Corporation
2 // Copyright (c) 2020 Francisco Martin Rico
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__TRUNCATE_PATH_ACTION_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__TRUNCATE_PATH_ACTION_HPP_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "nav_msgs/msg/path.hpp"
23 
24 #include "behaviortree_cpp/action_node.h"
25 #include "behaviortree_cpp/json_export.h"
26 #include "nav2_behavior_tree/json_utils.hpp"
27 
28 namespace nav2_behavior_tree
29 {
30 
39 class TruncatePath : public BT::ActionNodeBase
40 {
41 public:
48  const std::string & xml_tag_name,
49  const BT::NodeConfiguration & conf);
50 
55  static BT::PortsList providedPorts()
56  {
57  // Register JSON definitions for the types used in the ports
58  BT::RegisterJsonDefinition<nav_msgs::msg::Path>();
59 
60  return {
61  BT::InputPort<nav_msgs::msg::Path>("input_path", "Original Path"),
62  BT::OutputPort<nav_msgs::msg::Path>("output_path", "Path truncated to a certain distance"),
63  BT::InputPort<double>("distance", 1.0, "distance"),
64  };
65  }
66 
67 private:
71  void halt() override {}
72 
77  BT::NodeStatus tick() override;
78 
79  double distance_;
80 };
81 
82 } // namespace nav2_behavior_tree
83 
84 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__TRUNCATE_PATH_ACTION_HPP_
A BT::ActionNodeBase to shorten path by some distance.
TruncatePath(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A nav2_behavior_tree::TruncatePath constructor.
static BT::PortsList providedPorts()
Creates list of BT ports.