12#include <boost/optional/optional_io.hpp>
20template <
typename ActionType>
27 typedef actionlib::SimpleActionClient<ActionType>
GoalHandle;
35 name_(actionServerName)
47 auto type = TypeInfo::getTypeInfoFromType<ActionType>();
48 return type->getNonTemplatedTypeName();
80 template <
typename EvType>
83 auto *ev =
new EvType();
85 ev->resultMessage = *result;
86 ROS_INFO(
"Posting EVENT %s",
demangleSymbol(
typeid(ev).name()).c_str());
90 template <
typename TOrthogonal,
typename TSourceObject>
94 postSuccessEvent = [=](
auto msg) { this->postResultEvent<EvActionSucceeded<TSourceObject, TOrthogonal>>(msg); };
95 postAbortedEvent = [=](
auto msg) { this->postResultEvent<EvActionAborted<TSourceObject, TOrthogonal>>(msg); };
96 postPreemptedEvent = [=](
auto msg) { this->postResultEvent<EvActionPreempted<TSourceObject, TOrthogonal>>(msg); };
97 postRejectedEvent = [=](
auto msg) { this->postResultEvent<EvActionRejected<TSourceObject, TOrthogonal>>(msg); };
100 actionFeedbackEvent->client =
this;
101 actionFeedbackEvent->feedbackMessage = *msg;
103 ROS_DEBUG(
"[%s] FEEDBACK EVENT",
demangleType(
typeid(*
this)).c_str());
111 template <
typename T>
112 boost::signals2::connection
onSucceeded(
void (T::*callback)(ResultConstPtr &), T *
object)
117 template <
typename T>
118 boost::signals2::connection
onSucceeded(std::function<
void(ResultConstPtr &)> callback)
123 template <
typename T>
124 boost::signals2::connection
onAborted(
void (T::*callback)(ResultConstPtr &), T *
object)
129 template <
typename T>
130 boost::signals2::connection
onAborted(std::function<
void(ResultConstPtr &)> callback)
135 template <
typename T>
136 boost::signals2::connection
onPreempted(
void (T::*callback)(ResultConstPtr &), T *
object)
141 template <
typename T>
142 boost::signals2::connection
onPreempted(std::function<
void(ResultConstPtr &)> callback)
147 template <
typename T>
148 boost::signals2::connection
onRejected(
void (T::*callback)(ResultConstPtr &), T *
object)
153 template <
typename T>
154 boost::signals2::connection
onRejected(std::function<
void(ResultConstPtr &)> callback)
161 if (
client_->isServerConnected())
163 ROS_INFO(
"Cancelling goal of %s", this->
getName().c_str());
168 ROS_ERROR(
"%s [at %s]: not connected with actionserver, skipping cancel goal ...",
getName().c_str(),
getNamespace().c_str());
179 ROS_INFO_STREAM(
"[ActionClient<"<< demangledTypeName<ActionType>() <<
">] Sending goal to actionserver located in " << this->name_ <<
"\"");
181 if (
client_->isServerConnected())
183 ROS_INFO_STREAM(
getName() <<
": Goal Value: " << std::endl
189 ROS_ERROR(
"%s [at %s]: not connected with actionserver, skipping goal request ...",
getName().c_str(),
getNamespace().c_str());
202 void onResult(
const SimpleClientGoalState &state,
const ResultConstPtr &result_msg)
208 const auto &resultType = this->
getState();
209 ROS_INFO(
"[%s] request result: %s", this->
getName().c_str(), resultType.toString().c_str());
211 if (resultType == actionlib::SimpleClientGoalState::SUCCEEDED)
213 ROS_INFO(
"[%s] request result: Success", this->
getName().c_str());
217 else if (resultType == actionlib::SimpleClientGoalState::ABORTED)
219 ROS_INFO(
"[%s] request result: Aborted", this->
getName().c_str());
223 else if (resultType == actionlib::SimpleClientGoalState::REJECTED)
225 ROS_INFO(
"[%s] request result: Rejected", this->
getName().c_str());
229 else if (resultType == actionlib::SimpleClientGoalState::PREEMPTED)
231 ROS_INFO(
"[%s] request result: Preempted", this->
getName().c_str());
237 ROS_INFO(
"[%s] request result: NOT HANDLED TYPE: %s", this->
getName().c_str(), resultType.toString().c_str());
242#define SMACC_ACTION_CLIENT_DEFINITION(ActionType) ACTION_DEFINITION(ActionType); typedef smacc::client_bases::SmaccActionClientBase<ActionType> Base;
virtual std::string getName() const
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
std::string getNamespace() const
std::function< void(ResultConstPtr)> postRejectedEvent
ActionClient::SimpleFeedbackCallback SimpleFeedbackCallback
smacc::SmaccSignal< void(const ResultConstPtr &)> onPreempted_
static std::string getEventLabel()
ACTION_DEFINITION(ActionType)
boost::signals2::connection onPreempted(std::function< void(ResultConstPtr &)> callback)
void onResult(const SimpleClientGoalState &state, const ResultConstPtr &result_msg)
SimpleDoneCallback done_cb
actionlib::SimpleActionClient< ActionType > GoalHandle
boost::signals2::connection onRejected(void(T::*callback)(ResultConstPtr &), T *object)
smacc::SmaccSignal< void(const ResultConstPtr &)> onRejected_
ActionClient::SimpleDoneCallback SimpleDoneCallback
void onFeedback(const FeedbackConstPtr &feedback_msg)
boost::signals2::connection onAborted(std::function< void(ResultConstPtr &)> callback)
virtual void initialize() override
boost::signals2::connection onAborted(void(T::*callback)(ResultConstPtr &), T *object)
boost::signals2::connection onPreempted(void(T::*callback)(ResultConstPtr &), T *object)
std::string name_
rosnamespace path
SimpleActiveCallback active_cb
boost::signals2::connection onSucceeded(std::function< void(ResultConstPtr &)> callback)
void onOrthogonalAllocation()
std::function< void(ResultConstPtr)> postPreemptedEvent
virtual SimpleClientGoalState getState() override
SimpleFeedbackCallback feedback_cb
void sendGoal(Goal &goal)
std::function< void(ResultConstPtr)> postAbortedEvent
virtual ~SmaccActionClientBase()
actionlib::SimpleActionClient< ActionType > ActionClient
std::shared_ptr< ActionClient > client_
std::function< void(FeedbackConstPtr)> postFeedbackEvent
ActionClient::SimpleActiveCallback SimpleActiveCallback
void postResultEvent(ResultConstPtr result)
smacc::SmaccSignal< void(const ResultConstPtr &)> onAborted_
virtual void cancelGoal() override
SmaccActionClientBase(std::string actionServerName)
boost::signals2::connection onSucceeded(void(T::*callback)(ResultConstPtr &), T *object)
boost::signals2::connection onRejected(std::function< void(ResultConstPtr &)> callback)
smacc::SmaccSignal< void(const ResultConstPtr &)> onSucceeded_
std::function< void(ResultConstPtr)> postSuccessEvent
std::string demangleType(const std::type_info *tinfo)
std::string demangleSymbol()