SMACC2
Loading...
Searching...
No Matches
cl_nav2z::CbWaitTransform Class Reference

#include <cb_wait_transform.hpp>

Inheritance diagram for cl_nav2z::CbWaitTransform:
Inheritance graph
Collaboration diagram for cl_nav2z::CbWaitTransform:
Collaboration graph

Public Member Functions

 CbWaitTransform (std::string targetFrame, std::string referenceFrame, rclcpp::Duration timeout)
 
 ~CbWaitTransform () override
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
void onEntry () override
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
 SmaccAsyncClientBehavior ()=default
 
 ~SmaccAsyncClientBehavior () override
 
 SmaccAsyncClientBehavior (const SmaccAsyncClientBehavior &)=delete
 
SmaccAsyncClientBehavior & operator= (const SmaccAsyncClientBehavior &)=delete
 
 SmaccAsyncClientBehavior (SmaccAsyncClientBehavior &&)=delete
 
SmaccAsyncClientBehavior & operator= (SmaccAsyncClientBehavior &&)=delete
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
 ISmaccClientBehavior (const ISmaccClientBehavior &)=delete
 
ISmaccClientBehavior & operator= (const ISmaccClientBehavior &)=delete
 
 ISmaccClientBehavior (ISmaccClientBehavior &&)=delete
 
ISmaccClientBehavior & operator= (ISmaccClientBehavior &&)=delete
 
ISmaccStateMachine * getStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
virtual void onExit ()
 

Protected Attributes

std::shared_ptr< tf2_ros::Buffer > tfBuffer_
 
std::shared_ptr< tf2_ros::TransformListener > tfListener_
 
std::string targetFrame_
 
std::string referenceFrame_
 
rclcpp::Duration timeout_
 
std::optional< tf2::Stamped< tf2::Transform > > result_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccState * getCurrentState ()
 
void postInitializationFailureEvent (const std::string &what)
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
std::string getTraceStateName () const
 
std::string getTraceOrthogonalName () const
 

Detailed Description

Definition at line 34 of file cb_wait_transform.hpp.

Constructor & Destructor Documentation

◆ CbWaitTransform()

cl_nav2z::CbWaitTransform::CbWaitTransform ( std::string targetFrame,
std::string referenceFrame,
rclcpp::Duration timeout )

Definition at line 24 of file cb_wait_transform.cpp.

26: targetFrame_(targetFrame), referenceFrame_(referenceFrame), timeout_(timeout)
27{
28}

◆ ~CbWaitTransform()

cl_nav2z::CbWaitTransform::~CbWaitTransform ( )
override

Definition at line 30 of file cb_wait_transform.cpp.

30{}

Member Function Documentation

◆ onEntry()

void cl_nav2z::CbWaitTransform::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 32 of file cb_wait_transform.cpp.

33{
34 RCLCPP_INFO(
35 getLogger(), "[CbWaitTransform] ref %s -> target %s", referenceFrame_.c_str(),
36 targetFrame_.c_str());
37
38 tfBuffer_ = std::make_shared<tf2_ros::Buffer>(getNode()->get_clock());
39 tfListener_ = std::make_shared<tf2_ros::TransformListener>(*tfBuffer_);
40
41 tf2::Stamped<tf2::Transform> transform;
42 try
43 {
44 // the latest transform: this buffer is new, so it never holds data for the time of this call
45 auto transformstamped =
46 tfBuffer_->lookupTransform(targetFrame_, referenceFrame_, rclcpp::Time(0), timeout_);
47 tf2::fromMsg(transformstamped, transform);
48
49 result_ = transform;
50
51 RCLCPP_INFO(
52 getLogger(), "[CbWaitTransform] Success wait transform ref %s -> target %s",
53 referenceFrame_.c_str(), targetFrame_.c_str());
54 this->postSuccessEvent();
55 }
56 catch (tf2::TransformException & ex)
57 {
58 RCLCPP_ERROR_STREAM(
59 getLogger(), "[CbWaitTransform] Failure waiting transform ( ref "
60 << referenceFrame_ << "/ target " << targetFrame_ << " - " << ex.what());
61 this->postFailureEvent();
62 }
63}
std::shared_ptr< tf2_ros::TransformListener > tfListener_
std::shared_ptr< tf2_ros::Buffer > tfBuffer_
std::optional< tf2::Stamped< tf2::Transform > > result_
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getNode(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), referenceFrame_, result_, targetFrame_, tfBuffer_, tfListener_, and timeout_.

Here is the call graph for this function:

◆ onStateOrthogonalAllocation()

template<typename TOrthogonal , typename TSourceObject >
void cl_nav2z::CbWaitTransform::onStateOrthogonalAllocation ( )
inline

Member Data Documentation

◆ referenceFrame_

std::string cl_nav2z::CbWaitTransform::referenceFrame_
protected

Definition at line 55 of file cb_wait_transform.hpp.

Referenced by onEntry().

◆ result_

std::optional<tf2::Stamped<tf2::Transform> > cl_nav2z::CbWaitTransform::result_
protected

Definition at line 58 of file cb_wait_transform.hpp.

Referenced by onEntry().

◆ targetFrame_

std::string cl_nav2z::CbWaitTransform::targetFrame_
protected

Definition at line 54 of file cb_wait_transform.hpp.

Referenced by onEntry().

◆ tfBuffer_

std::shared_ptr<tf2_ros::Buffer> cl_nav2z::CbWaitTransform::tfBuffer_
protected

Definition at line 51 of file cb_wait_transform.hpp.

Referenced by onEntry().

◆ tfListener_

std::shared_ptr<tf2_ros::TransformListener> cl_nav2z::CbWaitTransform::tfListener_
protected

Definition at line 52 of file cb_wait_transform.hpp.

Referenced by onEntry().

◆ timeout_

rclcpp::Duration cl_nav2z::CbWaitTransform::timeout_
protected

Definition at line 56 of file cb_wait_transform.hpp.

Referenced by onEntry().


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