Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
concatenate_paths_action.cpp
1 // Copyright (c) 2025 Open Navigation LLC
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 #include <string>
16 #include <memory>
17 #include <limits>
18 
19 #include "nav_msgs/msg/path.hpp"
20 #include "geometry_msgs/msg/pose_stamped.hpp"
21 #include "nav2_util/geometry_utils.hpp"
22 #include "behaviortree_cpp/decorator_node.h"
23 
24 #include "nav2_behavior_tree/plugins/action/concatenate_paths_action.hpp"
25 
26 namespace nav2_behavior_tree
27 {
28 
30  const std::string & name,
31  const BT::NodeConfiguration & conf)
32 : BT::ActionNodeBase(name, conf)
33 {
34 }
35 
36 inline BT::NodeStatus ConcatenatePaths::tick()
37 {
38  setStatus(BT::NodeStatus::RUNNING);
39 
40  nav_msgs::msg::Path input_path1, input_path2;
41  getInput("input_path1", input_path1);
42  getInput("input_path2", input_path2);
43 
44  if (input_path1.poses.empty() && input_path2.poses.empty()) {
45  RCLCPP_ERROR(
46  config().blackboard->get<rclcpp::Node::SharedPtr>("node")->get_logger(),
47  "No input paths provided to concatenate. Both paths are empty.");
48  return BT::NodeStatus::FAILURE;
49  }
50 
51  nav_msgs::msg::Path output_path;
52  output_path = input_path1;
53  if (input_path1.header != std_msgs::msg::Header()) {
54  output_path.header = input_path1.header;
55  } else if (input_path2.header != std_msgs::msg::Header()) {
56  output_path.header = input_path2.header;
57  }
58 
59  output_path.poses.insert(
60  output_path.poses.end(),
61  input_path2.poses.begin(),
62  input_path2.poses.end());
63 
64  setOutput("output_path", output_path);
65  return BT::NodeStatus::SUCCESS;
66 }
67 
68 } // namespace nav2_behavior_tree
69 
70 #include "behaviortree_cpp/bt_factory.h"
71 BT_REGISTER_NODES(factory)
72 {
73  factory.registerNodeType<nav2_behavior_tree::ConcatenatePaths>("ConcatenatePaths");
74 }
A BT::ActionNodeBase to shorten path by some distance.
ConcatenatePaths(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A nav2_behavior_tree::ConcatenatePaths constructor.