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 ()
 
 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 onEntry ()
 

Protected Member Functions

bool sendGoal (Goal &goal)
 
bool trackGoal (std::shared_future< typename GoalHandle::SharedPtr > goalHandleFuture)
 
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 ()
 
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
 

Protected Attributes

ActionClientComponent * actionClient_ = 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)
 
bool isOwnGoal (const WrappedResult &result)
 

Private Attributes

bool resultConnectionsInitialized_ = false
 
std::mutex ownGoalMutex_
 
std::shared_future< typename GoalHandle::SharedPtr > ownGoalHandleFuture_
 
std::atomic< bool > goalInFlight_ {false}
 
std::atomic< bool > goalActivitySeen_ {false}
 

Detailed Description

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

Definition at line 53 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 60 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 59 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 56 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 57 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 58 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 88 of file cb_action_client_behavior_base.hpp.

88{}

Member Function Documentation

◆ cancelGoal()

◆ dispatchActionAbort()

template<typename TAction >
void smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::dispatchActionAbort ( const WrappedResult & result)
inlineprivate

◆ dispatchActionFeedback()

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

◆ dispatchActionSuccess()

◆ isOwnGoal()

template<typename TAction >
bool smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::isOwnGoal ( const WrappedResult & result)
inlineprivate

Definition at line 255 of file cb_action_client_behavior_base.hpp.

256 {
257 std::shared_future<typename GoalHandle::SharedPtr> future;
258 {
259 std::lock_guard<std::mutex> lock(ownGoalMutex_);
260 future = ownGoalHandleFuture_;
261 }
262 // rclcpp_action resolves the goal response before it can deliver that goal's result.
263 const bool own = future.valid() &&
264 future.wait_for(std::chrono::seconds(0)) == std::future_status::ready &&
265 future.get() != nullptr && future.get()->get_goal_id() == result.goal_id;
266 if (!own)
267 {
268 RCLCPP_INFO(
269 getLogger(), "[%s] Ignoring the result of a goal this behavior did not send",
270 getName().c_str());
271 }
272 return own;
273 }
virtual rclcpp::Logger getLogger() const
std::shared_future< typename GoalHandle::SharedPtr > ownGoalHandleFuture_

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::ownGoalHandleFuture_, and smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::ownGoalMutex_.

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

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

◆ 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 211 of file cb_action_client_behavior_base.hpp.

211{}

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 196 of file cb_action_client_behavior_base.hpp.

197 {
198 actionResult_ = result.code;
199 RCLCPP_INFO(getLogger(), "[%s] Action succeeded, propagating success event", getName().c_str());
200 this->postSuccessEvent();
201 }

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 63 of file cb_action_client_behavior_base.hpp.

64 {
65 if (actionClientName_.empty())
66 {
68 }
69 else
70 {
71 // target a specific named instance when the client holds several
72 // CpActionClient components of the same action type
74 }
75
77 {
83 }
84
86 }
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 114 of file cb_action_client_behavior_base.hpp.

115 {
116 if (actionClient_ == nullptr || !actionClient_->isServerReady())
117 {
118 RCLCPP_ERROR(
119 getLogger(), "[%s] Action server not available, cannot send goal", getName().c_str());
120 this->postFailureEvent();
121 return false;
122 }
123
124 goalActivitySeen_ = false;
125 return this->trackGoal(actionClient_->sendGoal(goal));
126 }
bool trackGoal(std::shared_future< typename GoalHandle::SharedPtr > goalHandleFuture)
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_core_components::CpActionClient< ActionType >::isServerReady(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::client_core_components::CpActionClient< ActionType >::sendGoal(), and smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::trackGoal().

Here is the call graph for this function:

◆ setActionClientName()

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

◆ trackGoal()

template<typename TAction >
bool smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::trackGoal ( std::shared_future< typename GoalHandle::SharedPtr > goalHandleFuture)
inlineprotected

Definition at line 130 of file cb_action_client_behavior_base.hpp.

131 {
132 {
133 std::lock_guard<std::mutex> lock(ownGoalMutex_);
134 ownGoalHandleFuture_ = goalHandleFuture;
135 }
136
137 // wait for goal acceptance in short slices so a state exit is honored
138 auto deadline = std::chrono::steady_clock::now() + goalResponseTimeout_;
139 while (!this->isShutdownRequested() && std::chrono::steady_clock::now() < deadline)
140 {
141 // Feedback or a result arriving proves the goal was accepted even if
142 // the goal-response future hasn't been serviced yet: under spin_some, a
143 // high-rate feedback stream (NavigateToPose feeds back continuously
144 // from acceptance) can starve the action client's response processing
145 // for the whole execution. Rejected goals produce no feedback, so their
146 // response resolves the future promptly.
148 {
149 goalInFlight_ = true;
150 return true;
151 }
152
153 if (goalHandleFuture.wait_for(std::chrono::milliseconds(50)) == std::future_status::ready)
154 {
155 if (goalHandleFuture.get() != nullptr)
156 {
157 goalInFlight_ = true; // accepted; the result signals will finish the behavior
158 return true;
159 }
160
161 RCLCPP_ERROR(getLogger(), "[%s] Goal was rejected by the action server", getName().c_str());
162 this->postFailureEvent();
163 return false;
164 }
165 }
166
167 if (!this->isShutdownRequested())
168 {
169 // No response, no feedback, no result within the window: ambiguous, and
170 // observed only under executor starvation with an accepted goal - a
171 // genuine rejection resolves the future in milliseconds. Assume the
172 // goal is running and let the result signals finish the behavior
173 // (fire-and-forget, the pre-template behavior), rather than failing a
174 // healthy mission.
175 RCLCPP_WARN(
176 getLogger(),
177 "[%s] No goal response from the action server after %ld ms; assuming the goal was "
178 "accepted (a rejection responds promptly) - result signals will finish this behavior",
179 getName().c_str(), static_cast<long>(goalResponseTimeout_.count()));
180 goalInFlight_ = true;
181 }
182 return true;
183 }
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...

References 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::SmaccAsyncClientBehavior::isShutdownRequested(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::ownGoalHandleFuture_, smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::ownGoalMutex_, and smacc2::SmaccAsyncClientBehavior::postFailureEvent().

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

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

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

◆ ownGoalHandleFuture_

template<typename TAction >
std::shared_future<typename GoalHandle::SharedPtr> smacc2::client_behavior_bases::CbActionClientBehaviorBase< TAction >::ownGoalHandleFuture_
private

◆ ownGoalMutex_

◆ 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: