Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
get_current_pose_action.cpp
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 #include <string>
17 #include <memory>
18 #include <limits>
19 
20 #include "nav_msgs/msg/path.hpp"
21 #include "geometry_msgs/msg/pose_stamped.hpp"
22 #include "nav2_util/geometry_utils.hpp"
23 #include "behaviortree_cpp/decorator_node.h"
24 #include "nav2_ros_common/tf2_factories.hpp"
25 
26 #include "nav2_behavior_tree/plugins/action/get_current_pose_action.hpp"
27 
28 namespace nav2_behavior_tree
29 {
30 
32  const std::string & name,
33  const BT::NodeConfiguration & conf)
34 : BT::ActionNodeBase(name, conf)
35 {
36  auto node = config().blackboard->get<nav2::LifecycleNode::SharedPtr>("node");
37  tf_ = config().blackboard->get<nav2::TransformBuffer::SharedPtr>("tf_buffer");
38  node->get_parameter("transform_tolerance", transform_tolerance_);
39  global_frame_ = BT::deconflictPortAndParamFrame<std::string>(
40  node, "global_frame", this);
41  robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string>(
42  node, "robot_base_frame", this);
43 }
44 
45 inline BT::NodeStatus GetCurrentPoseAction::tick()
46 {
47  setStatus(BT::NodeStatus::RUNNING);
48  geometry_msgs::msg::PoseStamped current_pose;
49 
50  if (!nav2_util::getCurrentPose(
51  current_pose, *tf_, global_frame_, robot_base_frame_, transform_tolerance_))
52  {
53  RCLCPP_WARN(
54  config().blackboard->get<nav2::LifecycleNode::SharedPtr>("node")->get_logger(),
55  "Current robot pose is not available.");
56  return BT::NodeStatus::FAILURE;
57  }
58 
59  setOutput("current_pose", current_pose);
60  return BT::NodeStatus::SUCCESS;
61 }
62 
63 } // namespace nav2_behavior_tree
64 
65 #include "behaviortree_cpp/bt_factory.h"
66 BT_REGISTER_NODES(factory)
67 {
68  factory.registerNodeType<nav2_behavior_tree::GetCurrentPoseAction>("GetCurrentPose");
69 }
A BT::ActionNodeBase to shorten path by some distance.
GetCurrentPoseAction(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A nav2_behavior_tree::GetCurrentPoseAction constructor.