Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
get_current_pose_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/get_current_pose_action.hpp"
16 
17 namespace nav2_behavior_tree
18 {
19 
21  const std::string & xml_tag_name,
22  const BT::NodeConfiguration & conf)
23 : BT::ActionNodeBase(xml_tag_name, conf)
24 {
25  auto node = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
26  tf_ = config().blackboard->get<std::shared_ptr<tf2_ros::Buffer>>("tf_buffer");
27  node->get_parameter("transform_tolerance", transform_tolerance_);
28  global_frame_ = BT::deconflictPortAndParamFrame<std::string>(
29  node, "global_frame", this);
30  robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string>(
31  node, "robot_base_frame", this);
32 }
33 
34 BT::NodeStatus GetCurrentPoseAction::tick()
35 {
36  setStatus(BT::NodeStatus::RUNNING);
37  geometry_msgs::msg::PoseStamped current_pose;
38 
39  if (!nav2_util::getCurrentPose(
40  current_pose, *tf_, global_frame_, robot_base_frame_, transform_tolerance_))
41  {
42  RCLCPP_WARN(
43  config().blackboard->get<rclcpp::Node::SharedPtr>("node")->get_logger(),
44  "Current robot pose is not available.");
45  return BT::NodeStatus::FAILURE;
46  }
47 
48  setOutput("current_pose", current_pose);
49  return BT::NodeStatus::SUCCESS;
50 }
51 
52 } // namespace nav2_behavior_tree
53 
54 #include "behaviortree_cpp/bt_factory.h"
55 BT_REGISTER_NODES(factory)
56 {
57  factory.registerNodeType<nav2_behavior_tree::GetCurrentPoseAction>("GetCurrentPose");
58 }
Action Node to get the current robot pose from TF.
GetCurrentPoseAction(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
Constructor.