Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00056
00057
00058
00059
00060 #include <unistd.h>
00061 #include <boost/bind.hpp>
00062
00063
00064
00065
00066 #include "ros/ros.h"
00067
00068
00069
00070
00071 #include "std_msgs/String.h"
00072 #include "hekateros_control/HekOpState.h"
00073 #include "hekateros_control/HekJointStateExtended.h"
00074
00075
00076
00077
00078 #include "actionlib/server/simple_action_server.h"
00079 #include "hekateros_control/CalibrateAction.h"
00080
00081
00082
00083
00084 #include "Hekateros/hekateros.h"
00085 #include "Hekateros/hekJoint.h"
00086 #include "Hekateros/hekRobot.h"
00087
00088
00089
00090
00091 #include "hekateros_control.h"
00092 #include "hekateros_as_calib.h"
00093
00094
00095 using namespace std;
00096 using namespace hekateros;
00097 using namespace hekateros_control;
00098
00099
00100 void ASCalibrate::execute_cb(const CalibrateGoalConstPtr &goal)
00101 {
00102 HekRobot &robot(node_.getRobot());
00103 HekJointStatePoint state;
00104 int rc;
00105
00106 ROS_INFO("%s: Executing calibrate action - please standby.",
00107 action_name_.c_str());
00108
00109
00110
00111
00112 rc = robot.calibrateAsync(goal->force_recalib? true: false);
00113
00114 if( rc != HEK_OK )
00115 {
00116 ROS_ERROR("%s: Failed to initiate calibration.", action_name_.c_str());
00117 result_.op.calib_state = HekOpState::UNCALIBRATED;
00118 as_.setAborted(result_);
00119 return;
00120 }
00121
00122 ros::Rate r(2);
00123
00124 while( robot.getAsyncState() == HekAsyncTaskStateWorking )
00125 {
00126
00127
00128
00129 if( as_.isPreemptRequested() || !ros::ok() )
00130 {
00131 ROS_INFO("%s: Execution preempted.", action_name_.c_str());
00132 result_.op.calib_state = HekOpState::UNCALIBRATED;
00133 as_.setPreempted(result_);
00134 return;
00135 }
00136
00137
00138
00139
00140 else
00141 {
00142 robot.getJointState(state);
00143 node_.updateExtendedJointStateMsg(state, feedback_.joint);
00144 as_.publishFeedback(feedback_);
00145 r.sleep();
00146 }
00147 }
00148
00149
00150 rc = robot.getAsyncRc();
00151
00152
00153 if( (rc == HEK_OK) && robot.isCalibrated() )
00154 {
00155 ROS_INFO("%s: Calibration succeeded.", action_name_.c_str());
00156 result_.op.calib_state = HekOpState::CALIBRATED;
00157 as_.setSucceeded(result_);
00158 }
00159
00160 else if( as_.isPreemptRequested() || !ros::ok() )
00161 {
00162 ROS_INFO("%s: Calibration preempted.", action_name_.c_str());
00163 result_.op.calib_state = HekOpState::UNCALIBRATED;
00164 as_.setPreempted(result_);
00165 }
00166
00167 else
00168 {
00169 ROS_ERROR("Calibration failed with error code %d.", rc);
00170 result_.op.calib_state = HekOpState::UNCALIBRATED;
00171 as_.setAborted(result_);
00172 }
00173 }
00174
00175 void ASCalibrate::preempt_cb()
00176 {
00177 ROS_INFO("%s: Preempt calibration.", action_name_.c_str());
00178 node_.getRobot().cancelAsyncTask();
00179 }