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 #include <cstdio>
41 #include <string>
42 
43 namespace actionlib
44 {
45 
46 class RefServer : public ActionServer<TestAction>
47 {
48 public:
50 
51  RefServer(ros::NodeHandle & n, const std::string & name);
52 
53 private:
54  void goalCallback(GoalHandle gh);
55  void cancelCallback(GoalHandle gh);
56 };
57 
58 } // namespace actionlib
59 
60 using namespace actionlib;
61 
62 RefServer::RefServer(ros::NodeHandle & n, const std::string & name)
63 : ActionServer<TestAction>(n, name,
64  boost::bind(&RefServer::goalCallback, this, _1),
65  boost::bind(&RefServer::cancelCallback, this, _1),
66  false)
67 {
68  start();
69  printf("Creating ActionServer [%s]\n", name.c_str());
70 }
71 
73 {
74  TestGoal goal = *gh.getGoal();
75 
76  switch (goal.goal) {
77  case 1:
78  gh.setAccepted();
79  gh.setSucceeded(TestResult(), "The ref server has succeeded");
80  break;
81  case 2:
82  gh.setAccepted();
83  gh.setAborted(TestResult(), "The ref server has aborted");
84  break;
85  case 3:
86  gh.setRejected(TestResult(), "The ref server has rejected");
87  break;
88  default:
89  break;
90  }
91 }
92 
94 {
95 }
96 
97 
98 int main(int argc, char ** argv)
99 {
100  ros::init(argc, argv, "ref_server");
101 
102  ros::NodeHandle nh;
103 
104  RefServer ref_server(nh, "reference_action");
105 
106  ros::spin();
107 }
int main(int argc, char **argv)
Definition: ref_server.cpp:98
void goalCallback(GoalHandle gh)
Definition: ref_server.cpp:72
ServerGoalHandle< TestAction > GoalHandle
Definition: ref_server.cpp:49
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setRejected(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to rejected.
boost::shared_ptr< const Goal > getGoal() const
Accessor for the goal associated with the ServerGoalHandle.
void cancelCallback(GoalHandle gh)
Definition: ref_server.cpp:93
void setAccepted(const std::string &text=std::string(""))
Accept the goal referenced by the goal handle. This will transition to the ACTIVE state or the PREEMP...
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to succeeded.
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(""))
Set the status of the goal associated with the ServerGoalHandle to aborted.
RefServer(ros::NodeHandle &n, const std::string &name)
Definition: ref_server.cpp:62
void start()
Explicitly start the action server, used it auto_start is set to false.
The ActionServer is a helpful tool for managing goal requests to a node. It allows the user to specif...
Definition: action_server.h:72


actionlib
Author(s): Eitan Marder-Eppstein, Vijay Pradeep, Mikael Arguedas
autogenerated on Mon Feb 18 2019 03:59:59