SMACC
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes | List of all members
cl_move_base_z::Pose Class Reference

#include <cp_pose.h>

Inheritance diagram for cl_move_base_z::Pose:
Inheritance graph
Collaboration diagram for cl_move_base_z::Pose:
Collaboration graph

Public Member Functions

 Pose (std::string poseFrameName="base_link", std::string referenceFrame="odom")
 
virtual void update () override
 
void waitTransformUpdate (ros::Rate r=ros::Rate(20))
 
geometry_msgs::Pose toPoseMsg ()
 
geometry_msgs::PoseStamped toPoseStampedMsg ()
 
const std::string & getReferenceFrame () const
 
const std::string & getFrameId () const
 
- Public Member Functions inherited from smacc::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 
- Public Member Functions inherited from smacc::ISmaccUpdatable
 ISmaccUpdatable ()
 
 ISmaccUpdatable (ros::Duration duration)
 
void executeUpdate ()
 
void setUpdatePeriod (ros::Duration duration)
 

Public Attributes

bool isInitialized
 

Private Attributes

geometry_msgs::PoseStamped pose_
 
std::string poseFrameName_
 
std::string referenceFrame_
 
std::mutex m_mutex_
 

Static Private Attributes

static std::shared_ptr< tf::TransformListener > tfListener_ = nullptr
 
static std::mutex listenerMutex_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc::ISmaccComponent
virtual void initialize (ISmaccClient *owner)
 
void setStateMachine (ISmaccStateMachine *stateMachine)
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
virtual void onInitialize ()
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
virtual void update ()=0
 
- Protected Attributes inherited from smacc::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

Definition at line 18 of file cp_pose.h.

Constructor & Destructor Documentation

◆ Pose()

cl_move_base_z::Pose::Pose ( std::string  poseFrameName = "base_link",
std::string  referenceFrame = "odom" 
)

Definition at line 15 of file cp_pose.cpp.

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 }
static std::shared_ptr< tf::TransformListener > tfListener_
Definition: cp_pose.h:54
std::string poseFrameName_
Definition: cp_pose.h:57
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
static std::mutex listenerMutex_
Definition: cp_pose.h:55

References listenerMutex_, pose_, referenceFrame_, and tfListener_.

Member Function Documentation

◆ getFrameId()

const std::string & cl_move_base_z::Pose::getFrameId ( ) const
inline

Definition at line 44 of file cp_pose.h.

45 {
46 return poseFrameName_;
47 }

References poseFrameName_.

◆ getReferenceFrame()

const std::string & cl_move_base_z::Pose::getReferenceFrame ( ) const
inline

◆ toPoseMsg()

geometry_msgs::Pose cl_move_base_z::Pose::toPoseMsg ( )
inline

Definition at line 27 of file cp_pose.h.

28 {
29 std::lock_guard<std::mutex> guard(m_mutex_);
30 return this->pose_.pose;
31 }

References m_mutex_, and pose_.

Referenced by cl_move_base_z::CbUndoPathBackwards2::onEntry(), and cl_move_base_z::CbUndoPathBackwards2::update().

Here is the caller graph for this function:

◆ toPoseStampedMsg()

geometry_msgs::PoseStamped cl_move_base_z::Pose::toPoseStampedMsg ( )
inline

Definition at line 33 of file cp_pose.h.

34 {
35 std::lock_guard<std::mutex> guard(m_mutex_);
36 return this->pose_;
37 }

References m_mutex_, and pose_.

◆ update()

void cl_move_base_z::Pose::update ( )
overridevirtual

Implements smacc::ISmaccUpdatable.

Definition at line 64 of file cp_pose.cpp.

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 }

References isInitialized, listenerMutex_, m_mutex_, pose_, poseFrameName_, referenceFrame_, and tfListener_.

◆ waitTransformUpdate()

void cl_move_base_z::Pose::waitTransformUpdate ( ros::Rate  r = ros::Rate(20))

Definition at line 32 of file cp_pose.cpp.

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 }

References isInitialized, listenerMutex_, m_mutex_, pose_, poseFrameName_, referenceFrame_, and tfListener_.

Member Data Documentation

◆ isInitialized

bool cl_move_base_z::Pose::isInitialized

Definition at line 49 of file cp_pose.h.

Referenced by update(), and waitTransformUpdate().

◆ listenerMutex_

std::mutex cl_move_base_z::Pose::listenerMutex_
staticprivate

Definition at line 55 of file cp_pose.h.

Referenced by Pose(), update(), and waitTransformUpdate().

◆ m_mutex_

std::mutex cl_move_base_z::Pose::m_mutex_
private

Definition at line 60 of file cp_pose.h.

Referenced by toPoseMsg(), toPoseStampedMsg(), update(), and waitTransformUpdate().

◆ pose_

geometry_msgs::PoseStamped cl_move_base_z::Pose::pose_
private

Definition at line 52 of file cp_pose.h.

Referenced by Pose(), toPoseMsg(), toPoseStampedMsg(), update(), and waitTransformUpdate().

◆ poseFrameName_

std::string cl_move_base_z::Pose::poseFrameName_
private

Definition at line 57 of file cp_pose.h.

Referenced by getFrameId(), update(), and waitTransformUpdate().

◆ referenceFrame_

std::string cl_move_base_z::Pose::referenceFrame_
private

Definition at line 58 of file cp_pose.h.

Referenced by getReferenceFrame(), Pose(), update(), and waitTransformUpdate().

◆ tfListener_

std::shared_ptr< tf::TransformListener > cl_move_base_z::Pose::tfListener_ = nullptr
staticprivate

Definition at line 54 of file cp_pose.h.

Referenced by Pose(), update(), and waitTransformUpdate().


The documentation for this class was generated from the following files: