00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <srs_assisted_arm_navigation/assisted_arm_navigation/arm_manip_node.h>
00029
00030 using namespace srs_assisted_arm_navigation;
00031 using namespace planning_scene_utils;
00032 using namespace srs_assisted_arm_navigation_msgs;
00033
00034
00035 std::string CArmManipulationEditor::add_coll_obj_bb(t_det_obj &obj) {
00036
00037 std::string ret = "";
00038
00039 ROS_INFO("Trying to add BB of detected object (%s) to collision map",obj.name.c_str());
00040
00041 stringstream ss;
00042
00043 ss << coll_obj_det.size();
00044
00045 std::string oname = obj.name + "_" + ss.str();
00046
00047 std_msgs::ColorRGBA color;
00048
00049 color.r = 0;
00050 color.g = 0;
00051 color.b = 1.0;
00052 color.a = 0.25;
00053
00054 bool transf = false;
00055
00056 geometry_msgs::PoseStamped mpose;
00057
00058
00059
00060 std::string target = collision_objects_frame_id_;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 if (obj.pose.header.frame_id != target) {
00072
00074 ros::Time now = ros::Time::now();
00075
00076
00077 obj.pose.header.stamp = now;
00078
00079
00080
00081 ROS_INFO("Trying to transform detected object BB from %s to %s frame",obj.pose.header.frame_id.c_str(),target.c_str());
00082
00083 ROS_INFO("Waiting for transformation between %s and %s",obj.pose.header.frame_id.c_str(),target.c_str());
00084
00085 try {
00086
00087 if (tfl_->waitForTransform(target, obj.pose.header.frame_id, now, ros::Duration(2.0))) {
00088
00089 tfl_->transformPose(target,obj.pose,mpose);
00090
00091 } else {
00092
00093 obj.pose.header.stamp = ros::Time(0);
00094 tfl_->transformPose(target,obj.pose,mpose);
00095 ROS_WARN("Using latest transform available, may be wrong.");
00096
00097 }
00098
00099 transf = true;
00100
00101 }
00102
00103
00104 catch(tf::TransformException& ex){
00105 std::cerr << "Transform error: " << ex.what() << std::endl;
00106 transf = false;
00107 }
00108
00109
00110
00111 } else {
00112
00113 ROS_INFO("BB of detected object is already in correct frame_id (%s). No need to transform.",obj.pose.header.frame_id.c_str());
00114 mpose = obj.pose;
00115 transf=true;
00116
00117 }
00118
00119 if (transf) {
00120
00121 mpose.pose.position.z += obj.bb_lwh.z/2;
00122
00123 ret = createCollisionObject(oname,
00124 mpose.pose,
00125 PlanningSceneEditor::Box,
00126 (obj.bb_lwh.x)*inflate_bb_,
00127 (obj.bb_lwh.y)*inflate_bb_,
00128 (obj.bb_lwh.z)*inflate_bb_,
00129 color,
00130 coll_objects_selectable_);
00131
00132
00133
00134 if (obj.attached) {
00135
00136 attachCollisionObject(ret, end_eff_link_, links_);
00137 ROS_INFO("Attached coll. obj. name=%s, id=%s has been created.",oname.c_str(),ret.c_str());
00138
00139 } else {
00140
00141 ROS_INFO("Coll. obj. name=%s, id=%s has been created.",oname.c_str(),ret.c_str());
00142
00143 }
00144
00145
00146 }
00147 else {
00148
00149 ROS_ERROR("Error on transforming - cannot add object %s to scene!",oname.c_str());
00150
00151 }
00152
00153
00154 if (obj.allow_collision) {
00155
00156 ROS_INFO("Allowing collisions of gripper with object: %s (NOT IMPLEMENTED YET)", obj.name.c_str());
00157
00158
00159 }
00160
00161
00162
00163 if (obj.allow_pregrasps && (!obj.attached) && ros::service::exists("/interaction_primitives/clickable_positions",true)) {
00164
00165 srs_interaction_primitives::ClickablePositions srv;
00166
00167 std_msgs::ColorRGBA c;
00168 c.r = 0.0;
00169 c.g = 0.0;
00170 c.b = 1.0;
00171 c.a = 0.6;
00172
00173 srv.request.color = c;
00174 srv.request.frame_id = world_frame_;
00175
00176 std::vector<geometry_msgs::Point> points;
00177
00178 double offset = 0.3;
00179
00180 geometry_msgs::Point tmp;
00181
00182 tmp.x = mpose.pose.position.x + offset;
00183 tmp.y = mpose.pose.position.y;
00184 tmp.z = mpose.pose.position.z;
00185
00186 points.push_back(tmp);
00187
00188 tmp.x = mpose.pose.position.x - offset;
00189 tmp.y = mpose.pose.position.y;
00190 tmp.z = mpose.pose.position.z;
00191
00192 points.push_back(tmp);
00193
00194 tmp.x = mpose.pose.position.x;
00195 tmp.y = mpose.pose.position.y + offset;
00196 tmp.z = mpose.pose.position.z;
00197
00198 points.push_back(tmp);
00199
00200 tmp.x = mpose.pose.position.x;
00201 tmp.y = mpose.pose.position.y - offset;
00202 tmp.z = mpose.pose.position.z;
00203
00204 points.push_back(tmp);
00205
00206
00207 srv.request.positions = points;
00208 srv.request.radius = 0.05;
00209 srv.request.topic_suffix = obj.name;
00210
00211 if (ros::service::call("/interaction_primitives/clickable_positions",srv)) {
00212
00213 obj.topic_name = srv.response.topic;
00214
00215 sub_click_ = nh_.subscribe(obj.topic_name,1,&CArmManipulationEditor::subClick,this);
00216
00217
00218 } else {
00219
00220 ROS_ERROR("Can't add clickable positions for object (%s).",obj.name.c_str());
00221 obj.topic_name = "";
00222
00223 }
00224
00225
00226 }
00227
00228
00229 return ret;
00230
00231 }
00232
00233 void CArmManipulationEditor::subClick(const srs_interaction_primitives::PositionClickedConstPtr &msg) {
00234
00235
00236 std::string topic = sub_click_.getTopic();
00237
00238 sub_click_.shutdown();
00239
00240 if (inited && !planned_) {
00241
00242
00243 ArmNavMovePalmLink::Request req;
00244 ArmNavMovePalmLink::Response resp;
00245
00246 req.sdh_palm_link_pose.pose.position.x = msg->position.x;
00247 req.sdh_palm_link_pose.pose.position.y = msg->position.y;
00248 req.sdh_palm_link_pose.pose.position.z = msg->position.z;
00249
00250
00251
00252
00253 req.sdh_palm_link_pose.pose.orientation = tf::createQuaternionMsgFromRollPitchYaw(-M_PI/2.0,0.0,M_PI/2.0);
00254
00255 req.sdh_palm_link_pose.header.frame_id = world_frame_;
00256 req.sdh_palm_link_pose.header.stamp = ros::Time::now();
00257
00258 ArmNavMovePalmLink(req,resp);
00259
00260 } else {
00261
00262 ROS_WARN("Ops... We can't move gripper IM right now.");
00263
00264 }
00265
00266 }
00267
00268 std::string CArmManipulationEditor::add_coll_obj_attached(double x, double y, double z, double scx, double scz) {
00269
00270 std::string ret = "";
00271 ros::Time now = ros::Time::now();
00272
00273 std::string target = collision_objects_frame_id_;
00274
00275 geometry_msgs::PoseStamped pose;
00276 pose.header.frame_id = aco_link_;
00277
00278 pose.header.stamp = now;
00279 pose.pose.position.x = x;
00280 pose.pose.position.y = y;
00281 pose.pose.position.z = z;
00282 pose.pose.orientation.x = 0;
00283 pose.pose.orientation.y = 0;
00284 pose.pose.orientation.z = 0;
00285 pose.pose.orientation.w = 1;
00286
00287 ROS_INFO("Trying to add coll. obj., frame=%s, x=%f,y=%f,z=%f",pose.header.frame_id.c_str(),x,y,z);
00288
00289 bool transf = false;
00290
00291 ROS_INFO("Waiting for transformation between %s and %s",pose.header.frame_id.c_str(),target.c_str());
00292
00293 try {
00294
00295 if (tfl_->waitForTransform(target, pose.header.frame_id, now, ros::Duration(2.0))) {
00296
00297 tfl_->transformPose(target,pose,pose);
00298
00299 } else {
00300
00301 pose.header.stamp = ros::Time(0);
00302 tfl_->transformPose(target,pose,pose);
00303 ROS_WARN("Using latest transform available, may be wrong.");
00304
00305 }
00306
00307 transf = true;
00308
00309 }
00310
00311
00312 catch(tf::TransformException& ex){
00313 std::cerr << "Transform error: " << ex.what() << std::endl;
00314 transf = false;
00315 }
00316
00317
00318 if (transf) {
00319
00320 ROS_INFO("Transformation succeeded");
00321
00322 stringstream ss;
00323
00324 ss << coll_obj_attached_id.size();
00325
00326 std::string name = "gripper_co_" + ss.str();
00327
00328 std_msgs::ColorRGBA color;
00329
00330 color.r = 1.0;
00331 color.g = 0;
00332 color.b = 0;
00333 color.a = 0.25;
00334
00335 ret = createCollisionObject(name,
00336 pose.pose,
00337 PlanningSceneEditor::Cylinder,
00338 scx,
00339 0,
00340 scz,
00341 color,
00342 coll_objects_selectable_);
00343
00344 ROS_INFO("Coll. obj. name=%s, id=%s",name.c_str(),ret.c_str());
00345
00346 if (ret!="") {
00347
00348 ROS_INFO("Attaching object to robot.");
00349
00350 attachCollisionObject(ret,
00351 aco_link_,
00352 links_);
00353
00354
00355
00356 } else {
00357
00358 ROS_ERROR("Gripper collision object was not created successfully");
00359
00360 }
00361
00362 }
00363
00364
00365 return ret;
00366
00367 }
00368
00369