28#include <rclcpp_action/rclcpp_action.hpp>
36template <
typename ActionType>
49 using Goal =
typename ActionClient::Goal;
50 using Feedback =
typename ActionClient::Feedback;
51 using GoalHandle = rclcpp_action::ClientGoalHandle<ActionType>;
56 std::function<void(std::shared_future<typename GoalHandle::SharedPtr>)>;
59 using CancelRequest =
typename ActionType::Impl::CancelGoalService::Request;
60 using CancelResponse =
typename ActionType::Impl::CancelGoalService::Response;
61 using CancelCallback = std::function<void(
typename CancelResponse::SharedPtr)>;
87 auto type = TypeInfo::getTypeInfoFromType<ActionType>();
88 return type->getNonTemplatedTypeName();
91 std::optional<std::shared_future<typename GoalHandle::SharedPtr>>
lastRequest_;
113 template <
typename EvType>
116 auto * ev =
new EvType();
124 template <
typename TOrthogonal,
typename TSourceObject>
129 { this->postResultEvent<EvActionSucceeded<TSourceObject, TOrthogonal>>(msg); };
131 { this->postResultEvent<EvActionAborted<TSourceObject, TOrthogonal>>(msg); };
134 { this->postResultEvent<EvActionCancelled<TSourceObject, TOrthogonal>>(msg); };
138 actionFeedbackEvent->client =
this;
139 actionFeedbackEvent->feedbackMessage = msg;
150 template <
typename T>
156 template <
typename T>
162 template <
typename T>
168 template <
typename T>
174 template <
typename T>
180 template <
typename T>
220 << rclcpp_action::to_string(req->get_goal_id()));
221 auto cancelresult =
client_->async_cancel_goal(req);
224 rclcpp::spin_until_future_complete(
getNode(), cancelresult);
231 getLogger(),
"%s [at %s]: not connected with actionserver, skipping cancel goal ...",
237 std::shared_future<typename GoalHandle::SharedPtr>
sendGoal(
Goal & goal)
255 options.result_callback =
256 [
this](
const typename rclcpp_action::ClientGoalHandle<ActionType>::WrappedResult & result)
261 RCLCPP_INFO_STREAM(
getLogger(),
getName() <<
": Result callback, getting shared future");
264 if (this->goalHandle_->get_goal_id() == result.goal_id)
268 RCLCPP_INFO_STREAM(
getLogger(),
getName() <<
": Result CB Goal id matches");
273 RCLCPP_INFO_STREAM(
getLogger(),
getName() <<
": Result CB Goal id DOES NOT match");
289 this->lastRequest_ = this->
client_->async_send_goal(goal, options);
292 getLogger(),
"[" <<
getName() <<
"] Action goal sent to " << this->action_endpoint_
293 <<
"\": " << std::endl
305 << this->
client_->get_number_of_ready_clients());
308 "[" <<
getName() <<
"] Waiting it is ready? " <<
client_->action_server_is_ready());
342 typename GoalHandle::SharedPtr ,
343 const std::shared_ptr<const Feedback> feedback_msg)
355 const auto & resultType = result_msg.code;
359 << rclcpp_action::to_string(result_msg.goal_id) <<
"]: " << (
int)resultType);
361 if (resultType == rclcpp_action::ResultCode::SUCCEEDED)
363 RCLCPP_INFO(
getLogger(),
"[%s] request result: Success", this->
getName().c_str());
367 else if (resultType == rclcpp_action::ResultCode::ABORTED)
369 RCLCPP_INFO(
getLogger(),
"[%s] request result: Aborted", this->
getName().c_str());
373 else if (resultType == rclcpp_action::ResultCode::CANCELED)
375 RCLCPP_INFO(
getLogger(),
"[%s] request result: Cancelled", this->
getName().c_str());
395 getLogger(),
"[%s] request result: NOT HANDLED TYPE: %d", this->
getName().c_str(),
rclcpp::Node::SharedPtr getNode()
ISmaccStateMachine * getStateMachine()
rclcpp::Logger getLogger()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
std::string getNamespace() const
virtual std::string getName() const
typename ActionType::Impl::CancelGoalService::Response CancelResponse
typename ActionClient::Feedback Feedback
typename ActionType::Impl::CancelGoalService::Request CancelRequest
boost::signals2::connection onAborted(void(T::*callback)(WrappedResult &), T *object)
std::function< void(std::shared_future< typename GoalHandle::SharedPtr >)> GoalResponseCallback
std::function< void(typename CancelResponse::SharedPtr)> CancelCallback
std::string action_endpoint_
typename ActionClient::SendGoalOptions SendGoalOptions
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal)
virtual ~SmaccActionClientBase()
static std::string getEventLabel()
void onFeedback(typename GoalHandle::SharedPtr, const std::shared_ptr< const Feedback > feedback_msg)
virtual std::shared_ptr< rclcpp_action::ClientBase > getClientBase() override
rclcpp_action::Client< ActionType > ActionClient
std::function< void(WrappedResult)> postCancelledEvent
smacc2::SmaccSignal< void(const WrappedResult &)> onSucceeded_
std::function< void(WrappedResult)> postSuccessEvent
boost::signals2::connection onSucceeded(std::function< void(WrappedResult &)> callback)
boost::signals2::connection onSucceeded(void(T::*callback)(WrappedResult &), T *object)
void onOrthogonalAllocation()
FeedbackCallback feedback_cb
smacc2::SmaccSignal< void(const WrappedResult &)> onAborted_
void onInitialize() override
ActionClient::SharedPtr client_
boost::signals2::connection onCancelled(std::function< void(WrappedResult &)> callback)
rclcpp_action::ClientGoalHandle< ActionType > GoalHandle
SmaccActionClientBase(std::string actionServerName)
std::function< void(WrappedResult)> postAbortedEvent
void onResult(const WrappedResult &result_msg)
std::function< void(const Feedback &)> postFeedbackEvent
typename ActionClient::Goal Goal
smacc2::SmaccSignal< void(const WrappedResult &)> onCancelled_
GoalHandle::WrappedResult WrappedResult
boost::signals2::connection onCancelled(void(T::*callback)(WrappedResult &), T *object)
virtual bool cancelGoal() override
GoalHandle::SharedPtr goalHandle_
typename GoalHandle::ResultCallback ResultCallback
void postResultEvent(WrappedResult &)
boost::signals2::connection onAborted(std::function< void(WrappedResult &)> callback)
std::optional< std::shared_future< typename GoalHandle::SharedPtr > > lastRequest_
typename GoalHandle::FeedbackCallback FeedbackCallback
std::string demangleSymbol()
std::string demangleType(const std::type_info *tinfo)