ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
RosActionServer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 <copyright holder> <email>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 ROSEE::RosActionServer::RosActionServer (std::string topicForAction, ros::NodeHandle* nh) :
20  _actionServer(*nh, topicForAction, false) {
21 
22  this->nh = nh;
23  this->topicForAction = topicForAction;
24  goalInExecution = false;
25  newGoal = false;
26 
27  _actionServer.registerGoalCallback (boost::bind(&RosActionServer::goalReceivedCallback, this));
28  _actionServer.registerPreemptCallback (boost::bind (&RosActionServer::preemptReceivedCallback, this));
29 
30  _actionServer.start();
31 
32 }
33 
35  return goalInExecution;
36 }
37 
39  return newGoal;
40 }
41 
43  return wantedNormError;
44 }
45 
46 rosee_msg::ROSEEActionControl ROSEE::RosActionServer::getGoal() {
47  if (goalInExecution) {
48  newGoal = false;
49  return actionControlMsg;
50  } else {
51  ROS_WARN_STREAM ("ROSACTION SERVER no goal is in execution (no one has" <<
52  "arrived or the last one is already completed. EMPTY GOAL RETURNING");
53  return rosee_msg::ROSEEActionControl();
54  }
55 }
56 
57 
59 
60  //ROS_INFO_STREAM (goal_action.
61  goalInExecution = true;
62  newGoal = true;
63  this->actionControlMsg = _actionServer.acceptNewGoal()->goal_action;
64 
66 
67  ROS_INFO_STREAM ("ROSACTION SERVER received goal: '" << this->actionControlMsg.action_name << "'");
68 
69 
70 }
71 
73 
74  ROS_INFO_STREAM("ROSACTION SERVER Preempted old goal");
75  goalInExecution = false;
76  newGoal = false;
78  // set the action state to preempted
79  _actionServer.setPreempted();
80 
81 }
82 
83 void ROSEE::RosActionServer::abortGoal(std::string errorMsg) {
84  ROS_INFO_STREAM("ROSACTION SERVER Aborted goal");
85  rosee_msg::ROSEECommandResult result;
86  result.completed_action = actionControlMsg;
87  _actionServer.setAborted(result, errorMsg);
88  newGoal = false;
89  goalInExecution = false;
91 
92 
93 }
94 
95 void ROSEE::RosActionServer::sendFeedback(double completation_percentage, std::string currentAction) {
96 
97  ROS_INFO_STREAM("ROSACTION SERVER Sending feedback " << completation_percentage );
98 
99  rosee_msg::ROSEECommandFeedback feedback;
100  feedback.completation_percentage = completation_percentage;
101  if (currentAction.size() == 0) {
102  feedback.action_name_current = actionControlMsg.action_name;
103  } else {
104  feedback.action_name_current = currentAction;
105  }
106 
107  _actionServer.publishFeedback(feedback);
108 
109 }
110 
112 
113  ROS_INFO_STREAM("ROSACTION SERVER Sending final result completed ");
114  goalInExecution = false;
115  newGoal = false; //even if here should be already false
117 
118  rosee_msg::ROSEECommandResult result;
119  result.completed_action = actionControlMsg;
120 
121  _actionServer.setSucceeded ( result );
122  //TODO reinitialize actionControlMsg here or not?
123 
124 }
125 
void sendFeedback(double completation_percentage, std::string currentAction)
send Feedback to the client who has requested the goal.
double getWantedNormError() const
in message there is a field where norm error of joint position can be set If it is not present in the...
ros::NodeHandle * nh
RosActionServer(std::string topicForAction, ros::NodeHandle *nh)
rosee_msg::ROSEEActionControl actionControlMsg
void abortGoal(std::string errorMsg="")
rosee_msg::ROSEEActionControl getGoal()
actionlib::SimpleActionServer< rosee_msg::ROSEECommandAction > _actionServer
#define DEFAULT_ERROR_NORM