simple_action_server.h
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2008, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Eitan Marder-Eppstein
36 *********************************************************************/
37 #ifndef ACTIONLIB__SERVER__SIMPLE_ACTION_SERVER_H_
38 #define ACTIONLIB__SERVER__SIMPLE_ACTION_SERVER_H_
39 
40 #include <boost/thread/condition.hpp>
41 #include <ros/ros.h>
44 
45 #include <string>
46 
47 namespace actionlib
48 {
59 template<class ActionSpec>
61 {
62 public:
63  // generates typedefs that we'll use to make our lives easier
64  ACTION_DEFINITION(ActionSpec);
65 
67  typedef boost::function<void (const GoalConstPtr &)> ExecuteCallback;
68 
77  SimpleActionServer(std::string name, ExecuteCallback execute_callback, bool auto_start);
78 
84  SimpleActionServer(std::string name, bool auto_start);
85 
93  ROS_DEPRECATED SimpleActionServer(std::string name, ExecuteCallback execute_callback = NULL);
94 
104  SimpleActionServer(ros::NodeHandle n, std::string name, ExecuteCallback execute_callback,
105  bool auto_start);
106 
113  SimpleActionServer(ros::NodeHandle n, std::string name, bool auto_start);
114 
124  ExecuteCallback execute_callback = NULL);
125 
127 
140 
145  bool isNewGoalAvailable();
146 
147 
152  bool isPreemptRequested();
153 
158  bool isActive();
159 
165  void setSucceeded(const Result & result = Result(), const std::string & text = std::string(""));
166 
172  void setAborted(const Result & result = Result(), const std::string & text = std::string(""));
173 
174 
179  void publishFeedback(const FeedbackConstPtr & feedback);
180 
185  void publishFeedback(const Feedback & feedback);
186 
192  void setPreempted(const Result & result = Result(), const std::string & text = std::string(""));
193 
198  void registerGoalCallback(boost::function<void()> cb);
199 
204  void registerPreemptCallback(boost::function<void()> cb);
205 
209  void start();
210 
214  void shutdown();
215 
216 private:
220  void goalCallback(GoalHandle goal);
221 
225  void preemptCallback(GoalHandle preempt);
226 
230  void executeLoop();
231 
233 
235 
237 
239 
240  boost::recursive_mutex lock_;
241 
242  boost::function<void()> goal_callback_;
243  boost::function<void()> preempt_callback_;
244  ExecuteCallback execute_callback_;
245 
246  boost::condition execute_condition_;
247  boost::thread * execute_thread_;
248 
249  boost::mutex terminate_mutex_;
251 };
252 
253 } // namespace actionlib
254 
255 // include the implementation here
257 #endif // ACTIONLIB__SERVER__SIMPLE_ACTION_SERVER_H_
boost::shared_ptr< const Goal > acceptNewGoal()
Accepts a new goal when one is available. The status of this goal is set to active upon acceptance...
void publishFeedback(const FeedbackConstPtr &feedback)
Publishes feedback for a given goal.
boost::function< void()> goal_callback_
void preemptCallback(GoalHandle preempt)
Callback for when the ActionServer receives a new preempt and passes it on.
void goalCallback(GoalHandle goal)
Callback for when the ActionServer receives a new goal and passes it on.
void executeLoop()
Called from a separate thread to call blocking execute calls.
SimpleActionServer(std::string name, ExecuteCallback execute_callback, bool auto_start)
Constructor for a SimpleActionServer.
bool isActive()
Allows polling implementations to query about the status of the current goal.
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to succeeded.
void shutdown()
Explicitly shutdown the action server.
boost::function< void(const GoalConstPtr &)> ExecuteCallback
void start()
Explicitly start the action server, used it auto_start is set to false.
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to preempted.
boost::function< void()> preempt_callback_
void registerPreemptCallback(boost::function< void()> cb)
Allows users to register a callback to be invoked when a new preempt request is available.
bool isPreemptRequested()
Allows polling implementations to query about preempt requests.
Encapsulates a state machine for a given goal that the user can trigger transitions on...
#define ROS_DEPRECATED
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to aborted.
ActionServer< ActionSpec >::GoalHandle GoalHandle
boost::shared_ptr< ActionServer< ActionSpec > > as_
void registerGoalCallback(boost::function< void()> cb)
Allows users to register a callback to be invoked when a new goal is available.
bool isNewGoalAvailable()
Allows polling implementations to query about the availability of a new goal.


actionlib
Author(s): Eitan Marder-Eppstein, Vijay Pradeep, Mikael Arguedas
autogenerated on Mon Feb 28 2022 21:34:38