Nav2 Navigation Stack - jazzy  jazzy
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 "nav2_behavior_tree/plugins/action/concatenate_paths_action.hpp"
16 
17 namespace nav2_behavior_tree
18 {
19 
21  const std::string & name,
22  const BT::NodeConfiguration & conf)
23 : BT::ActionNodeBase(name, conf)
24 {
25 }
26 
27 inline BT::NodeStatus ConcatenatePaths::tick()
28 {
29  setStatus(BT::NodeStatus::RUNNING);
30 
31  nav_msgs::msg::Path input_path1, input_path2;
32  getInput("input_path1", input_path1);
33  getInput("input_path2", input_path2);
34 
35  if (input_path1.poses.empty() && input_path2.poses.empty()) {
36  RCLCPP_ERROR(
37  config().blackboard->get<rclcpp::Node::SharedPtr>("node")->get_logger(),
38  "No input paths provided to concatenate. Both paths are empty.");
39  return BT::NodeStatus::FAILURE;
40  }
41 
42  nav_msgs::msg::Path output_path;
43  output_path = input_path1;
44  if (input_path1.header != std_msgs::msg::Header()) {
45  output_path.header = input_path1.header;
46  } else if (input_path2.header != std_msgs::msg::Header()) {
47  output_path.header = input_path2.header;
48  }
49 
50  output_path.poses.insert(
51  output_path.poses.end(),
52  input_path2.poses.begin(),
53  input_path2.poses.end());
54 
55  setOutput("output_path", output_path);
56  return BT::NodeStatus::SUCCESS;
57 }
58 
59 } // namespace nav2_behavior_tree
60 
61 #include "behaviortree_cpp/bt_factory.h"
62 BT_REGISTER_NODES(factory)
63 {
64  factory.registerNodeType<nav2_behavior_tree::ConcatenatePaths>("ConcatenatePaths");
65 }
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.