1 #ifndef RTT_SIMPLE_ACTION_SERVER_HPP 2 #define RTT_SIMPLE_ACTION_SERVER_HPP 5 #include <boost/bind.hpp> 6 #include <boost/function.hpp> 46 if (!owner_service)
throw std::invalid_argument(
"RTTSimpleActionServer: owner pointer must be valid.");
47 action_server.
addPorts(owner_service);
56 return action_server.
ready();
64 bool start(
bool publish_feedback =
false);
70 action_server.shutdown();
77 return goal_active.
isValid() && goal_active.
getGoalStatus().status == actionlib_msgs::GoalStatus::ACTIVE;
84 return goal_active.
isValid() && goal_active.
getGoalStatus().status == actionlib_msgs::GoalStatus::PREEMPTING;
91 return goal_pending.
isValid() && goal_pending.
getGoalStatus().status == actionlib_msgs::GoalStatus::PENDING;
118 bool acceptPending(
const Result& result,
const std::string& msg =
"");
126 bool rejectPending(
const Result& result,
const std::string& msg =
"");
142 bool abortActive(
const Result& result,
const std::string& msg =
"");
150 bool cancelActive(
const Result& result,
const std::string& msg =
"");
158 bool succeedActive(
const Result& result,
const std::string& msg =
"");
164 void setGoalHook(boost::function<
void(
const Goal&)> _newGoalHook) {
165 newGoalHook = _newGoalHook;
173 cancelGoalHook = _cancelGoalHook;
180 action_server.
start();
181 if (publish_feedback) action_server.
initialize();
192 case actionlib_msgs::GoalStatus::ACTIVE:
193 case actionlib_msgs::GoalStatus::PREEMPTING:
210 if (!goal_pending.
isValid())
return false;
212 case actionlib_msgs::GoalStatus::PENDING:
213 case actionlib_msgs::GoalStatus::RECALLING:
229 if (!goal_active.
isValid())
return false;
231 case actionlib_msgs::GoalStatus::ACTIVE:
232 case actionlib_msgs::GoalStatus::PREEMPTING:
241 if (!goal_active.
isValid())
return false;
243 case actionlib_msgs::GoalStatus::ACTIVE:
244 case actionlib_msgs::GoalStatus::PREEMPTING:
253 if (!goal_active.
isValid())
return false;
255 case actionlib_msgs::GoalStatus::ACTIVE:
256 case actionlib_msgs::GoalStatus::PREEMPTING:
267 case actionlib_msgs::GoalStatus::PENDING:
268 case actionlib_msgs::GoalStatus::RECALLING:
269 goal_pending.
setRejected(Result(),
"Pending goal is replaced by new received goal.");
282 case actionlib_msgs::GoalStatus::ACTIVE:
283 case actionlib_msgs::GoalStatus::PREEMPTING:
284 case actionlib_msgs::GoalStatus::PENDING:
285 case actionlib_msgs::GoalStatus::RECALLING:
286 if (goal_active == gh) {
290 else if (goal_pending == gh) {
291 gh.
setCanceled(Result(),
"Pending goal is canceled by client request.");
void publishFeedback(const Feedback &feedback)
Orocos RTT-Based Action Server.
bool addPorts(RTT::Service::shared_ptr service, const bool create_topics=false, const std::string &topic_namespace="")
Add actionlib ports to a given rtt service.
void setGoalHook(boost::function< void(const Goal &)> _newGoalHook)
Setup goal hook.
actionlib::ServerGoalHandle< ActionSpec > GoalHandle
bool succeedActive(const Result &result, const std::string &msg="")
Succeed active goal. Succeed active goal with given result, do nothing if there is no active goal...
void setRejected(const Result &result=Result(), const std::string &text=std::string(""))
boost::shared_ptr< const Goal > getGoal() const
bool publishFeedback(const Feedback &feedpack)
Publish feedback on active goal. Publish feedback on active goal, do nothing if there is no active go...
void setCancelHook(boost::function< void()> _cancelGoalHook)
Setup cancel hook.
boost::shared_ptr< const Goal > getActiveGoal() const
void setCanceled(const Result &result=Result(), const std::string &text=std::string(""))
void setAccepted(const std::string &text=std::string(""))
void registerGoalCallback(boost::function< void(GoalHandle)> cb)
RTTSimpleActionServer(boost::shared_ptr< RTT::Service > owner_service)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
bool start(bool publish_feedback=false)
bool ready()
Check if the server is ready to be started.
bool isPreempting() const
void registerCancelCallback(boost::function< void(GoalHandle)> cb)
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
boost::function< void(const Goal &)> newGoalHook
boost::function< void()> cancelGoalHook
virtual void initialize()
Set up status publishing timers.
RTTActionServer< ActionSpec > action_server
void goalCallback(GoalHandle gh)
boost::shared_ptr< const Goal > getPendingGoal() const
bool rejectPending(const Result &result, const std::string &msg="")
Reject pending goal. Reject pending goal with result, do nothing if there is no pending goal...
bool cancelActive(const Result &result, const std::string &msg="")
Cancel active goal. Cancel active goal with given result, do nothing if there is no active goal...
bool acceptPending(const Result &result, const std::string &msg="")
Accept pending goal. Accept pending goal, preempt the active goal with result if present. Do nothing if there is no pending goal.
ACTION_DEFINITION(ActionSpec)
void cancelCallback(GoalHandle gh)
actionlib_msgs::GoalStatus getGoalStatus() const
bool abortActive(const Result &result, const std::string &msg="")
Abort active goal. Abort active goal with given result, do nothing if there is no active goal...