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);
132 this->postResultEvent<EvActionAborted<TSourceObject, TOrthogonal>>(msg);
136 this->postResultEvent<EvActionCancelled<TSourceObject, TOrthogonal>>(msg);
140 actionFeedbackEvent->client =
this;
141 actionFeedbackEvent->feedbackMessage = msg;
152 template <
typename T>
158 template <
typename T>
164 template <
typename T>
170 template <
typename T>
176 template <
typename T>
182 template <
typename T>
222 << rclcpp_action::to_string(req->get_goal_id()));
223 auto cancelresult =
client_->async_cancel_goal(req);
226 rclcpp::spin_until_future_complete(
getNode(), cancelresult);
233 getLogger(),
"%s [at %s]: not connected with actionserver, skipping cancel goal ...",
239 std::shared_future<typename GoalHandle::SharedPtr>
sendGoal(
Goal & goal)
257 options.result_callback =
262 RCLCPP_INFO_STREAM(
getLogger(),
getName() <<
": Result callback, getting shared future");
265 if (this->goalHandle_->get_goal_id() == result.goal_id)
269 RCLCPP_INFO_STREAM(
getLogger(),
getName() <<
": Result CB Goal id matches");
274 RCLCPP_INFO_STREAM(
getLogger(),
getName() <<
": Result CB Goal id DOES NOT match");
290 this->lastRequest_ = this->
client_->async_send_goal(goal, options);
293 getLogger(),
"[" <<
getName() <<
"] Action goal sent to " << this->action_endpoint_
294 <<
"\": " << std::endl
306 << this->
client_->get_number_of_ready_clients());
309 "[" <<
getName() <<
"] Waiting it is ready? " <<
client_->action_server_is_ready());
343 typename GoalHandle::SharedPtr ,
344 const std::shared_ptr<const Feedback> feedback_msg)
356 const auto & resultType = result_msg.code;
360 << rclcpp_action::to_string(result_msg.goal_id) <<
"]: " << (
int)resultType);
362 if (resultType == rclcpp_action::ResultCode::SUCCEEDED)
364 RCLCPP_INFO(
getLogger(),
"[%s] request result: Success", this->
getName().c_str());
368 else if (resultType == rclcpp_action::ResultCode::ABORTED)
370 RCLCPP_INFO(
getLogger(),
"[%s] request result: Aborted", this->
getName().c_str());
374 else if (resultType == rclcpp_action::ResultCode::CANCELED)
376 RCLCPP_INFO(
getLogger(),
"[%s] request result: Cancelled", this->
getName().c_str());
396 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
Base::WrappedResult WrappedResult
std::string demangleType(const std::type_info *tinfo)
std::string demangleSymbol(const std::string &name)
void callback(const image_tools::ROSCvMatContainer &img)