SMACC2
Loading...
Searching...
No Matches
smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction > Class Template Reference

#include <cb_action_client_behavior_base.hpp>

Inheritance diagram for smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >:
Inheritance graph
Collaboration diagram for smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >:
Collaboration graph

Public Types

using Goal = typename TAction::Goal
 
using GoalHandle = rclcpp_action::ClientGoalHandle<TAction>
 
using WrappedResult = typename GoalHandle::WrappedResult
 
using Feedback = typename TAction::Feedback
 
using ActionClientComponent = smacc2::client_core_components::CpActionClient<TAction>
 

Public Member Functions

template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~CbActionClientBehaviorBase ()
 
void onExit () override
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
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 ()
 
ISmaccStateMachinegetStateMachine ()
 
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 (std::string name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
virtual void onEntry ()
 

Protected Member Functions

bool sendGoal (Goal &goal)
 
void cancelGoal ()
 
virtual void onActionSuccess (const WrappedResult &result)
 
virtual void onActionAbort (const WrappedResult &result)
 
virtual void onActionFeedback (const Feedback &)
 
void setActionClientName (std::string name)
 
- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual 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 ()
 
ISmaccStategetCurrentState ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 

Protected Attributes

ActionClientComponentactionClient_ = nullptr
 
std::string actionClientName_
 
rclcpp_action::ResultCode actionResult_ = rclcpp_action::ResultCode::UNKNOWN
 
std::chrono::milliseconds goalResponseTimeout_ = std::chrono::milliseconds(10000)
 

Private Member Functions

void dispatchActionSuccess (const WrappedResult &result)
 
void dispatchActionAbort (const WrappedResult &result)
 
void dispatchActionFeedback (const Feedback &feedback)
 

Private Attributes

bool resultConnectionsInitialized_ = false
 
std::atomic< boolgoalInFlight_ {false}
 
std::atomic< boolgoalActivitySeen_ {false}
 

Detailed Description

template<typename TAction>
class smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >

Definition at line 51 of file cb_action_client_behavior_base.hpp.

Member Typedef Documentation

◆ ActionClientComponent

template<typename TAction >
using smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::ActionClientComponent = smacc2::client_core_components::CpActionClient<TAction>

Definition at line 58 of file cb_action_client_behavior_base.hpp.

◆ Feedback

template<typename TAction >
using smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::Feedback = typename TAction::Feedback

Definition at line 57 of file cb_action_client_behavior_base.hpp.

◆ Goal

template<typename TAction >
using smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::Goal = typename TAction::Goal

Definition at line 54 of file cb_action_client_behavior_base.hpp.

◆ GoalHandle

template<typename TAction >
using smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::GoalHandle = rclcpp_action::ClientGoalHandle<TAction>

Definition at line 55 of file cb_action_client_behavior_base.hpp.

◆ WrappedResult

template<typename TAction >
using smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::WrappedResult = typename GoalHandle::WrappedResult

Definition at line 56 of file cb_action_client_behavior_base.hpp.

Constructor & Destructor Documentation

◆ ~CbActionClientBehaviorBase()

template<typename TAction >
virtual smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::~CbActionClientBehaviorBase ( )
inlinevirtual

Definition at line 86 of file cb_action_client_behavior_base.hpp.

86{}

Member Function Documentation

◆ cancelGoal()

◆ dispatchActionAbort()

◆ dispatchActionFeedback()

template<typename TAction >
void smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::dispatchActionFeedback ( const Feedback & feedback)
inlineprivate

◆ dispatchActionSuccess()

◆ onActionAbort()

template<typename TAction >
virtual void smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onActionAbort ( const WrappedResult & result)
inlineprotectedvirtual

◆ onActionFeedback()

template<typename TAction >
virtual void smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onActionFeedback ( const Feedback & )
inlineprotectedvirtual

Definition at line 199 of file cb_action_client_behavior_base.hpp.

199{}

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::dispatchActionFeedback().

Here is the caller graph for this function:

◆ onActionSuccess()

template<typename TAction >
virtual void smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onActionSuccess ( const WrappedResult & result)
inlineprotectedvirtual

Definition at line 184 of file cb_action_client_behavior_base.hpp.

185 {
186 actionResult_ = result.code;
187 RCLCPP_INFO(getLogger(), "[%s] Action succeeded, propagating success event", getName().c_str());
188 this->postSuccessEvent();
189 }

References smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::actionResult_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), and smacc2::SmaccAsyncClientBehavior::postSuccessEvent().

Referenced by smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::dispatchActionSuccess().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onExit()

◆ onStateOrthogonalAllocation()

template<typename TAction >
template<typename TOrthogonal , typename TSourceObject >
void smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::onStateOrthogonalAllocation ( )
inline

Definition at line 61 of file cb_action_client_behavior_base.hpp.

62 {
63 if (actionClientName_.empty())
64 {
66 }
67 else
68 {
69 // target a specific named instance when the client holds several
70 // CpActionClient components of the same action type
72 }
73
75 {
81 }
82
84 }
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
smacc2::SmaccSignalConnection onSucceeded(void(T::*callback)(const WrappedResult &), T *object)
smacc2::SmaccSignalConnection onFeedback(void(T::*callback)(const Feedback &), T *object)
smacc2::SmaccSignalConnection onAborted(void(T::*callback)(const WrappedResult &), T *object)
smacc2::SmaccSignalConnection onCancelled(void(T::*callback)(const WrappedResult &), T *object)

References smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::actionClient_, smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::actionClientName_, smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::dispatchActionAbort(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::dispatchActionFeedback(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::dispatchActionSuccess(), smacc2::HARD, smacc2::client_core_components::CpActionClient< ActionType >::onAborted(), smacc2::client_core_components::CpActionClient< ActionType >::onCancelled(), smacc2::client_core_components::CpActionClient< ActionType >::onFeedback(), smacc2::SmaccAsyncClientBehavior::onStateOrthogonalAllocation(), smacc2::client_core_components::CpActionClient< ActionType >::onSucceeded(), smacc2::ISmaccClientBehavior::requiresComponent(), and smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::resultConnectionsInitialized_.

Here is the call graph for this function:

◆ sendGoal()

template<typename TAction >
bool smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::sendGoal ( Goal & goal)
inlineprotected

Definition at line 112 of file cb_action_client_behavior_base.hpp.

113 {
114 if (actionClient_ == nullptr || !actionClient_->isServerReady())
115 {
116 RCLCPP_ERROR(
117 getLogger(), "[%s] Action server not available, cannot send goal", getName().c_str());
118 this->postFailureEvent();
119 return false;
120 }
121
122 goalActivitySeen_ = false;
123 auto goalHandleFuture = actionClient_->sendGoal(goal);
124
125 // wait for goal acceptance in short slices so a state exit is honored
126 auto deadline = std::chrono::steady_clock::now() + goalResponseTimeout_;
127 while (!this->isShutdownRequested() && std::chrono::steady_clock::now() < deadline)
128 {
129 // Feedback or a result arriving proves the goal was accepted even if
130 // the goal-response future hasn't been serviced yet: under spin_some, a
131 // high-rate feedback stream (NavigateToPose feeds back continuously
132 // from acceptance) can starve the action client's response processing
133 // for the whole execution. Rejected goals produce no feedback, so their
134 // response resolves the future promptly.
136 {
137 goalInFlight_ = true;
138 return true;
139 }
140
141 if (goalHandleFuture.wait_for(std::chrono::milliseconds(50)) == std::future_status::ready)
142 {
143 if (goalHandleFuture.get() != nullptr)
144 {
145 goalInFlight_ = true; // accepted; the result signals will finish the behavior
146 return true;
147 }
148
149 RCLCPP_ERROR(getLogger(), "[%s] Goal was rejected by the action server", getName().c_str());
150 this->postFailureEvent();
151 return false;
152 }
153 }
154
155 if (!this->isShutdownRequested())
156 {
157 // No response, no feedback, no result within the window: ambiguous, and
158 // observed only under executor starvation with an accepted goal - a
159 // genuine rejection resolves the future in milliseconds. Assume the
160 // goal is running and let the result signals finish the behavior
161 // (fire-and-forget, the pre-template behavior), rather than failing a
162 // healthy mission.
163 RCLCPP_WARN(
164 getLogger(),
165 "[%s] No goal response from the action server after %ld ms; assuming the goal was "
166 "accepted (a rejection responds promptly) - result signals will finish this behavior",
167 getName().c_str(), static_cast<long>(goalResponseTimeout_.count()));
168 goalInFlight_ = true;
169 }
170 return true;
171 }
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal, typename smacc2::SmaccSignal< void(const WrappedResult &)>::WeakPtr resultCallback=typename smacc2::SmaccSignal< void(const WrappedResult &)>::WeakPtr())

References smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::actionClient_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::goalActivitySeen_, smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::goalInFlight_, smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::goalResponseTimeout_, smacc2::client_core_components::CpActionClient< ActionType >::isServerReady(), smacc2::SmaccAsyncClientBehavior::isShutdownRequested(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), and smacc2::client_core_components::CpActionClient< ActionType >::sendGoal().

Here is the call graph for this function:

◆ setActionClientName()

template<typename TAction >
void smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::setActionClientName ( std::string name)
inlineprotected

Member Data Documentation

◆ actionClient_

◆ actionClientName_

◆ actionResult_

template<typename TAction >
rclcpp_action::ResultCode smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::actionResult_ = rclcpp_action::ResultCode::UNKNOWN
protected

◆ goalActivitySeen_

◆ goalInFlight_

◆ goalResponseTimeout_

template<typename TAction >
std::chrono::milliseconds smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::goalResponseTimeout_ = std::chrono::milliseconds(10000)
protected

◆ resultConnectionsInitialized_

template<typename TAction >
bool smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::resultConnectionsInitialized_ = false
private

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