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

#include <cb_abort_navigation.hpp>

Inheritance diagram for cl_nav2z::CbAbortNavigation:
Inheritance graph
Collaboration diagram for cl_nav2z::CbAbortNavigation:
Collaboration graph

Public Member Functions

 CbAbortNavigation ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
void onEntry () override
 
void onExit () 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)
 

Private Member Functions

void onNavigationResult (const components::CpNav2ActionInterface::WrappedResult &result)
 

Private Attributes

components::CpNav2ActionInterface * nav2ActionInterface_ = nullptr
 
std::atomic< bool > goalFinished_ {false}
 

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 36 of file cb_abort_navigation.hpp.

Constructor & Destructor Documentation

◆ CbAbortNavigation()

cl_nav2z::CbAbortNavigation::CbAbortNavigation ( )

Definition at line 35 of file cb_abort_navigation.cpp.

35{}

Member Function Documentation

◆ onEntry()

void cl_nav2z::CbAbortNavigation::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 37 of file cb_abort_navigation.cpp.

38{
39 // connected before the request, so the result of the cancelled goal cannot be missed
40 goalFinished_ = false;
44
46 {
47 RCLCPP_INFO(getLogger(), "[CbAbortNavigation] no navigation goal in flight");
48 this->postSuccessEvent();
49 return;
50 }
51
52 const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
53 while (!goalFinished_)
54 {
55 // the state was left first: no event
56 if (this->isShutdownRequested()) return;
57 if (std::chrono::steady_clock::now() >= deadline)
58 {
59 RCLCPP_ERROR(getLogger(), "[CbAbortNavigation] no result for the cancelled goal after 5 s");
60 this->postFailureEvent();
61 return;
62 }
63 std::this_thread::sleep_for(std::chrono::milliseconds(10));
64 }
65
66 RCLCPP_INFO(getLogger(), "[CbAbortNavigation] the cancelled goal has finished");
67 this->postSuccessEvent();
68}
void onNavigationResult(const components::CpNav2ActionInterface::WrappedResult &result)
components::CpNav2ActionInterface * nav2ActionInterface_
smacc2::SmaccSignalConnection onNavigationSucceeded(void(T::*callback)(const WrappedResult &), T *object)
smacc2::SmaccSignalConnection onNavigationAborted(void(T::*callback)(const WrappedResult &), T *object)
smacc2::SmaccSignalConnection onNavigationCancelled(void(T::*callback)(const WrappedResult &), T *object)
virtual rclcpp::Logger getLogger() const
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...

References cl_nav2z::components::CpNav2ActionInterface::cancelNavigation(), smacc2::ISmaccClientBehavior::getLogger(), goalFinished_, smacc2::SmaccAsyncClientBehavior::isShutdownRequested(), nav2ActionInterface_, cl_nav2z::components::CpNav2ActionInterface::onNavigationAborted(), cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelled(), onNavigationResult(), cl_nav2z::components::CpNav2ActionInterface::onNavigationSucceeded(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), and smacc2::SmaccAsyncClientBehavior::postSuccessEvent().

Here is the call graph for this function:

◆ onExit()

void cl_nav2z::CbAbortNavigation::onExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 76 of file cb_abort_navigation.cpp.

76{}

◆ onNavigationResult()

void cl_nav2z::CbAbortNavigation::onNavigationResult ( const components::CpNav2ActionInterface::WrappedResult & result)
private

Definition at line 70 of file cb_abort_navigation.cpp.

72{
73 goalFinished_ = true;
74}

References goalFinished_.

Referenced by onEntry().

Here is the caller graph for this function:

◆ onStateOrthogonalAllocation()

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

Definition at line 42 of file cb_abort_navigation.hpp.

43 {
44 this->requiresComponent(nav2ActionInterface_, ComponentRequirement::HARD);
46 }
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References nav2ActionInterface_, smacc2::SmaccAsyncClientBehavior::onStateOrthogonalAllocation(), and smacc2::ISmaccClientBehavior::requiresComponent().

Here is the call graph for this function:

Member Data Documentation

◆ goalFinished_

std::atomic<bool> cl_nav2z::CbAbortNavigation::goalFinished_ {false}
private

Definition at line 55 of file cb_abort_navigation.hpp.

55{false};

Referenced by onEntry(), and onNavigationResult().

◆ nav2ActionInterface_

components::CpNav2ActionInterface* cl_nav2z::CbAbortNavigation::nav2ActionInterface_ = nullptr
private

Definition at line 54 of file cb_abort_navigation.hpp.

Referenced by onEntry(), and onStateOrthogonalAllocation().


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