Nav2 Navigation Stack - rolling  main
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 "behaviortree_cpp/action_node.h"
23 #include "behaviortree_cpp/json_export.h"
24 #include "nav_msgs/msg/path.hpp"
25 #include "nav2_behavior_tree/bt_utils.hpp"
26 #include "nav2_behavior_tree/json_utils.hpp"
27 #include "nav2_ros_common/lifecycle_node.hpp"
28 
29 
30 namespace nav2_behavior_tree
31 {
32 
36 class TruncatePath : public BT::ActionNodeBase
37 {
38 public:
45  const std::string & xml_tag_name,
46  const BT::NodeConfiguration & conf);
47 
52  static BT::PortsList providedPorts()
53  {
54  // Register JSON definitions for the types used in the ports
55  BT::RegisterJsonDefinition<nav_msgs::msg::Path>();
56 
57  return {
58  BT::InputPort<nav_msgs::msg::Path>("input_path", "Original Path"),
59  BT::OutputPort<nav_msgs::msg::Path>("output_path", "Path truncated to a certain distance"),
60  BT::InputPort<double>("distance", 1.0, "distance"),
61  };
62  }
63 
64 private:
68  void halt() override {}
69 
74  BT::NodeStatus tick() override;
75 
76  double distance_;
77 };
78 
79 } // namespace nav2_behavior_tree
80 
81 #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.