simple_execute_ref_server.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
36 
38 #include <actionlib/TestAction.h>
39 #include <ros/ros.h>
40 
41 namespace actionlib
42 {
43 
45 {
46 public:
48 
50 
51 private:
54 
55  void executeCallback(const TestGoalConstPtr & goal);
56 };
57 
58 } // namespace actionlib
59 
60 using namespace actionlib;
61 
63 : as_(nh_, "reference_action", boost::bind(&SimpleExecuteRefServer::executeCallback, this,
64  _1), false)
65 {
66  as_.start();
67 }
68 
69 void SimpleExecuteRefServer::executeCallback(const TestGoalConstPtr & goal)
70 {
71  ROS_DEBUG_NAMED("actionlib", "Got a goal of type [%u]", goal->goal);
72  switch (goal->goal) {
73  case 1:
74  ROS_DEBUG_NAMED("actionlib", "Got goal #1");
75  as_.setSucceeded(TestResult(), "The ref server has succeeded");
76  break;
77  case 2:
78  ROS_DEBUG_NAMED("actionlib", "Got goal #2");
79  as_.setAborted(TestResult(), "The ref server has aborted");
80  break;
81  case 4:
82  {
83  ROS_DEBUG_NAMED("actionlib", "Got goal #4");
84  ros::Duration sleep_dur(.1);
85  for (unsigned int i = 0; i < 100; i++) {
86  sleep_dur.sleep();
87  if (as_.isPreemptRequested()) {
88  as_.setPreempted();
89  return;
90  }
91  }
92  as_.setAborted();
93  break;
94  }
95  default:
96  break;
97  }
98 }
99 
100 int main(int argc, char ** argv)
101 {
102  ros::init(argc, argv, "ref_server");
103 
104  SimpleExecuteRefServer server;
105 
106  ros::spin();
107 
108  return 0;
109 }
int main(int argc, char **argv)
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to succeeded.
void start()
Explicitly start the action server, used if auto_start is set to false.
#define ROS_DEBUG_NAMED(name,...)
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to preempted.
void executeCallback(const TestGoalConstPtr &goal)
ServerGoalHandle< TestAction > GoalHandle
bool isPreemptRequested()
Allows polling implementations to query about preempt requests.
ROSCPP_DECL void spin()
Encapsulates a state machine for a given goal that the user can trigger transitions on...
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to aborted.
SimpleActionServer< TestAction > as_


actionlib
Author(s): Eitan Marder-Eppstein, Vijay Pradeep, Mikael Arguedas
autogenerated on Mon Aug 24 2020 03:40:47