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  boost::placeholders::_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 }
actionlib::ServerGoalHandle
Encapsulates a state machine for a given goal that the user can trigger transitions on....
Definition: server_goal_handle.h:98
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
actionlib::SimpleActionServer::start
void start()
Explicitly start the action server, used it auto_start is set to false.
Definition: simple_action_server_imp.h:439
ros.h
boost
main
int main(int argc, char **argv)
Definition: simple_execute_ref_server.cpp:100
actionlib::SimpleExecuteRefServer::nh_
ros::NodeHandle nh_
Definition: simple_execute_ref_server.cpp:116
actionlib::SimpleActionServer::isPreemptRequested
bool isPreemptRequested()
Allows polling implementations to query about preempt requests.
Definition: simple_action_server_imp.h:257
actionlib::SimpleActionServer::setSucceeded
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to succeeded.
Definition: simple_action_server_imp.h:274
simple_action_server.h
ROS_DEBUG_NAMED
#define ROS_DEBUG_NAMED(name,...)
actionlib::SimpleExecuteRefServer::GoalHandle
ServerGoalHandle< TestAction > GoalHandle
Definition: simple_execute_ref_server.cpp:111
actionlib::SimpleExecuteRefServer::executeCallback
void executeCallback(const TestGoalConstPtr &goal)
Definition: simple_execute_ref_server.cpp:69
actionlib::SimpleActionServer::setPreempted
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to preempted.
Definition: simple_action_server_imp.h:290
actionlib::SimpleExecuteRefServer
Definition: simple_execute_ref_server.cpp:76
actionlib::SimpleExecuteRefServer::as_
SimpleActionServer< TestAction > as_
Definition: simple_execute_ref_server.cpp:117
actionlib::SimpleExecuteRefServer::SimpleExecuteRefServer
SimpleExecuteRefServer()
Definition: simple_execute_ref_server.cpp:62
actionlib::SimpleActionServer::setAborted
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
Sets the status of the active goal to aborted.
Definition: simple_action_server_imp.h:282
actionlib::SimpleActionServer< TestAction >
actionlib
Definition: action_definition.h:40
ros::spin
ROSCPP_DECL void spin()
ros::Duration
ros::NodeHandle


actionlib
Author(s): Eitan Marder-Eppstein, Vijay Pradeep, Mikael Arguedas
autogenerated on Fri May 19 2023 02:36:55