SMACC
Loading...
Searching...
No Matches
cp_pose.cpp
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6
8
9
10namespace cl_move_base_z
11{
12 std::shared_ptr<tf::TransformListener> Pose::tfListener_ = nullptr;
13 std::mutex Pose::listenerMutex_;
14
15 Pose::Pose(std::string targetFrame, std::string referenceFrame)
16 : poseFrameName_(targetFrame),
17 referenceFrame_(referenceFrame),
18 isInitialized(false),
19 m_mutex_()
20 {
21 this->pose_.header.frame_id = referenceFrame_;
22 ROS_INFO("[Pose] Creating Pose tracker component to track %s in the reference frame %s", targetFrame.c_str(), referenceFrame.c_str());
23
24 {
25 //singleton
26 std::lock_guard<std::mutex> guard(listenerMutex_);
27 if (tfListener_ == nullptr)
28 tfListener_ = std::make_shared<tf::TransformListener>();
29 }
30 }
31
32 void Pose::waitTransformUpdate(ros::Rate r)
33 {
34 bool found = false;
35 while (ros::ok() && !found)
36 {
37 tf::StampedTransform transform;
38 try
39 {
40 {
41 std::lock_guard<std::mutex> lock(listenerMutex_);
43 ros::Time(0), transform);
44 }
45
46 {
47 std::lock_guard<std::mutex> guard(m_mutex_);
48 tf::poseTFToMsg(transform, this->pose_.pose);
49 this->pose_.header.stamp = transform.stamp_;
50 found = true;
51 this->isInitialized = true;
52 }
53 }
54 catch (tf::TransformException ex)
55 {
56 ROS_ERROR_STREAM_THROTTLE(1, "[Component pose] (" << poseFrameName_ << "/[" << referenceFrame_ << "] ) is failing on pose update : " << ex.what());
57 }
58
59 r.sleep();
60 ros::spinOnce();
61 }
62 }
63
65 {
66 tf::StampedTransform transform;
67 try
68 {
69 {
70 std::lock_guard<std::mutex> lock(listenerMutex_);
72 ros::Time(0), transform);
73 }
74
75 {
76 std::lock_guard<std::mutex> guard(m_mutex_);
77 tf::poseTFToMsg(transform, this->pose_.pose);
78 this->pose_.header.stamp = transform.stamp_;
79 this->isInitialized = true;
80 }
81 }
82 catch (tf::TransformException ex)
83 {
84 ROS_ERROR_STREAM_THROTTLE(1, "[Component pose] (" << poseFrameName_ << "/[" << referenceFrame_ << "] ) is failing on pose update : " << ex.what());
85 }
86 }
87} // namespace cl_move_base_z
static std::shared_ptr< tf::TransformListener > tfListener_
Definition: cp_pose.h:54
std::string poseFrameName_
Definition: cp_pose.h:57
void waitTransformUpdate(ros::Rate r=ros::Rate(20))
Definition: cp_pose.cpp:32
std::string referenceFrame_
Definition: cp_pose.h:58
std::mutex m_mutex_
Definition: cp_pose.h:60
geometry_msgs::PoseStamped pose_
Definition: cp_pose.h:52
Pose(std::string poseFrameName="base_link", std::string referenceFrame="odom")
Definition: cp_pose.cpp:15
virtual void update() override
Definition: cp_pose.cpp:64
static std::mutex listenerMutex_
Definition: cp_pose.h:55