Go to the documentation of this file.00001 #include "place_alg_node.h"
00002
00003 PlaceAlgNode::PlaceAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<PlaceAlgorithm>(),
00005 place_aserver_(public_node_handle_, "place")
00006 {
00007
00008
00009 place_pose_frame_id_ = "/wam_link0";
00010 place_action_success_ = false;
00011 place_action_status_ = 0;
00012
00013
00014
00015
00016
00017
00018
00019
00020 joints_move_client_ = this->public_node_handle_.serviceClient<iri_wam_common_msgs::joints_move>("joints_move");
00021 get_tcp_ik_client_ = this->public_node_handle_.serviceClient<iri_wam_common_msgs::wamInverseKinematics>("get_tcp_ik");
00022 bhand_cmd_client_ = this->public_node_handle_.serviceClient<iri_wam_common_msgs::bhand_cmd>("bhand_cmd");
00023
00024
00025 place_aserver_.registerStartCallback(boost::bind(&PlaceAlgNode::placeStartCallback, this, _1));
00026 place_aserver_.registerStopCallback(boost::bind(&PlaceAlgNode::placeStopCallback, this));
00027 place_aserver_.registerIsFinishedCallback(boost::bind(&PlaceAlgNode::placeIsFinishedCallback, this));
00028 place_aserver_.registerHasSucceedCallback(boost::bind(&PlaceAlgNode::placeHasSucceedCallback, this));
00029 place_aserver_.registerGetResultCallback(boost::bind(&PlaceAlgNode::placeGetResultCallback, this, _1));
00030 place_aserver_.registerGetFeedbackCallback(boost::bind(&PlaceAlgNode::placeGetFeedbackCallback, this, _1));
00031 place_aserver_.start();
00032
00033
00034 }
00035
00036 PlaceAlgNode::~PlaceAlgNode(void)
00037 {
00038
00039 }
00040
00041 void PlaceAlgNode::mainNodeThread(void)
00042 {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 }
00091
00092
00093
00094
00095
00096
00097 void PlaceAlgNode::placeStartCallback(const object_manipulation_msgs::PlaceGoalConstPtr& goal)
00098 {
00099
00100 ROS_INFO("Starting place action");
00101
00102 if(goal->place_locations[0].header.frame_id != place_pose_frame_id_){
00103 ROS_ERROR("frame_id mismatch");
00104 std::cout << goal->place_locations[0].header.frame_id << std::endl;
00105 std::cout << place_pose_frame_id_ << std::endl;
00106 alg_.lock();
00107 place_action_status_ = FINISH;
00108 alg_.unlock();
00109 return;
00110 }
00111
00112 alg_.lock();
00113 place_action_status_ = POSE_CHECKED;
00114 alg_.unlock();
00115
00116 get_tcp_ik_srv_.request.pose = goal->place_locations[0];
00117 if (get_tcp_ik_client_.call(get_tcp_ik_srv_)) {
00118 ROS_INFO("PlaceAlgNode:: Response %f %f %f %f %f %f %f", get_tcp_ik_srv_.response.joints.position[0], get_tcp_ik_srv_.response.joints.position[1], get_tcp_ik_srv_.response.joints.position[2], get_tcp_ik_srv_.response.joints.position[3], get_tcp_ik_srv_.response.joints.position[4], get_tcp_ik_srv_.response.joints.position[5], get_tcp_ik_srv_.response.joints.position[6]);
00119 } else {
00120 ROS_ERROR("PlaceAlgNode:: Failed to Call Server on topic %s", get_tcp_ik_client_.getService().c_str());
00121 alg_.lock();
00122 place_action_status_ = FINISH;
00123 alg_.unlock();
00124 return;
00125 }
00126
00127 joints_move_srv_.request.joints = get_tcp_ik_srv_.response.joints.position;
00128 ROS_INFO("Moving");
00129 if (joints_move_client_.call(joints_move_srv_)) {
00130 ROS_DEBUG("joints_move success %d", joints_move_srv_.response.success);
00131 } else {
00132 ROS_ERROR("Failed to call service %s", joints_move_client_.getService().c_str());
00133 alg_.lock();
00134 place_action_status_ = FINISH;
00135 alg_.unlock();
00136 return;
00137 }
00138
00139 alg_.lock();
00140 place_action_status_ = POSITION_REACHED;
00141 alg_.unlock();
00142
00143 ROS_INFO("Opening hand");
00144 bhand_cmd_srv_.request.bhandcmd = "GTO";
00145 if (bhand_cmd_client_.call(bhand_cmd_srv_))
00146 {
00147 ROS_DEBUG("bhand move success %d", bhand_cmd_srv_.response.success);
00148 } else {
00149 ROS_ERROR("Failed to call service %s", bhand_cmd_client_.getService().c_str());
00150 alg_.lock();
00151 place_action_status_ = FINISH;
00152 alg_.unlock();
00153 return;
00154 }
00155
00156 alg_.lock();
00157 place_action_status_ = HAND_OPENED;
00158 place_action_status_ = FINISH;
00159 place_action_success_ = true;
00160 alg_.unlock();
00161 ROS_INFO("Place action completed");
00162
00163 }
00164
00165 void PlaceAlgNode::placeStopCallback(void)
00166 {
00167 alg_.lock();
00168
00169 alg_.unlock();
00170 }
00171
00172 bool PlaceAlgNode::placeIsFinishedCallback(void)
00173 {
00174 bool ret = false;
00175
00176 alg_.lock();
00177
00178
00179 if(place_action_status_ == FINISH){
00180 ret = true;
00181 }
00182 alg_.unlock();
00183
00184 return ret;
00185 }
00186
00187 bool PlaceAlgNode::placeHasSucceedCallback(void)
00188 {
00189 bool ret = false;
00190
00191
00192 alg_.lock();
00193
00194
00195 last_place_action_success_ = place_action_success_;
00196 if(place_action_success_ == true){
00197 ret = true;
00198
00199 place_action_success_ = false;
00200 }
00201 alg_.unlock();
00202
00203 return ret;
00204 }
00205
00206 void PlaceAlgNode::placeGetResultCallback(object_manipulation_msgs::PlaceResultPtr& result)
00207 {
00208 alg_.lock();
00209
00210 if(last_place_action_success_){
00211 result->manipulation_result.value = object_manipulation_msgs::ManipulationResult::SUCCESS;
00212 }else{
00213 result->manipulation_result.value = object_manipulation_msgs::ManipulationResult::FAILED;
00214 }
00215 alg_.unlock();
00216 }
00217
00218 void PlaceAlgNode::placeGetFeedbackCallback(object_manipulation_msgs::PlaceFeedbackPtr& feedback)
00219 {
00220 alg_.lock();
00221
00222
00223 alg_.unlock();
00224 }
00225
00226
00227
00228 void PlaceAlgNode::node_config_update(Config &config, uint32_t level)
00229 {
00230
00231 ROS_INFO("Reconfigure called");
00232
00233 this->alg_.lock();
00234 place_pose_frame_id_ = config.pose_frame_id;
00235 this->alg_.unlock();
00236
00237 }
00238
00239 void PlaceAlgNode::addNodeDiagnostics(void)
00240 {
00241 }
00242
00243
00244 int main(int argc,char *argv[])
00245 {
00246 return algorithm_base::main<PlaceAlgNode>(argc, argv, "place_alg_node");
00247 }