SMACC2
Loading...
Searching...
No Matches
cp_pose.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
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/*****************************************************************************************************************
16 *-2020
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20#pragma once
21
22#include <mutex>
23
24#include <geometry_msgs/msg/pose_stamped.h>
25#include <tf2/transform_datatypes.h>
26#include <tf2/utils.h>
27#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
28#include <tf2_ros/buffer.h>
29#include <tf2_ros/transform_listener.h>
30#include <geometry_msgs/msg/quaternion_stamped.hpp>
31
32#include <smacc2/component.hpp>
34
35namespace cl_nav2z
36{
38{
39 Map,
41};
42
44{
45public:
46 Pose(std::string poseFrameName = "base_link", std::string referenceFrame = "odom");
47
48 Pose(StandardReferenceFrames referenceFrame);
49
50 void onInitialize() override;
51
52 void update() override;
53
54 // synchronously waits a transform in the current thread
55 void waitTransformUpdate(rclcpp::Rate r = rclcpp::Rate(20));
56
57 inline geometry_msgs::msg::Pose toPoseMsg()
58 {
59 std::lock_guard<std::mutex> guard(m_mutex_);
60 return this->pose_.pose;
61 }
62
63 inline geometry_msgs::msg::PoseStamped toPoseStampedMsg()
64 {
65 std::lock_guard<std::mutex> guard(m_mutex_);
66 return this->pose_;
67 }
68
69 // get yaw in radians
70 float getYaw();
71
72 float getX();
73 float getY();
74 float getZ();
75
76 inline const std::string & getReferenceFrame() const { return referenceFrame_; }
77
78 inline const std::string & getFrameId() const { return poseFrameName_; }
79
81
82private:
83 geometry_msgs::msg::PoseStamped pose_;
84
85 static std::shared_ptr<tf2_ros::Buffer> tfBuffer_;
86 static std::shared_ptr<tf2_ros::TransformListener> tfListener_;
87
88 static std::mutex listenerMutex_;
89
90 std::string poseFrameName_;
91 std::string referenceFrame_;
92
93 std::mutex m_mutex_;
94};
95} // namespace cl_nav2z
float getX()
Definition: cp_pose.cpp:120
static std::mutex listenerMutex_
Definition: cp_pose.hpp:88
static std::shared_ptr< tf2_ros::Buffer > tfBuffer_
Definition: cp_pose.hpp:85
void update() override
Definition: cp_pose.cpp:124
static std::shared_ptr< tf2_ros::TransformListener > tfListener_
Definition: cp_pose.hpp:86
float getY()
Definition: cp_pose.cpp:121
std::mutex m_mutex_
Definition: cp_pose.hpp:93
const std::string & getFrameId() const
Definition: cp_pose.hpp:78
float getYaw()
Definition: cp_pose.cpp:118
geometry_msgs::msg::PoseStamped toPoseStampedMsg()
Definition: cp_pose.hpp:63
const std::string & getReferenceFrame() const
Definition: cp_pose.hpp:76
void onInitialize() override
Definition: cp_pose.cpp:60
bool isInitialized
Definition: cp_pose.hpp:80
std::string referenceFrame_
Definition: cp_pose.hpp:91
geometry_msgs::msg::Pose toPoseMsg()
Definition: cp_pose.hpp:57
void waitTransformUpdate(rclcpp::Rate r=rclcpp::Rate(20))
Definition: cp_pose.cpp:77
geometry_msgs::msg::PoseStamped pose_
Definition: cp_pose.hpp:83
float getZ()
Definition: cp_pose.cpp:122
std::string poseFrameName_
Definition: cp_pose.hpp:90
StandardReferenceFrames
Definition: cp_pose.hpp:38