00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "romeo_moveit_actions/evaluation.hpp"
00018 #include "romeo_moveit_actions/toolsForObject.hpp"
00019
00020 namespace moveit_simple_actions
00021 {
00022
00023 Evaluation::Evaluation(const bool &verbose, const std::string &base_frame):
00024 verbose_(verbose),
00025 base_frame_(base_frame)
00026 {
00027 pose_zero_.position.x = 0.0;
00028 pose_zero_.position.y = 0.0;
00029 pose_zero_.position.z = 0.0;
00030 pose_zero_.orientation.x = -1.0;
00031 pose_zero_.orientation.y = 0.0;
00032 pose_zero_.orientation.z = 0.0;
00033 pose_zero_.orientation.w = 0.0;
00034 }
00035
00036 void Evaluation::init(const double &test_step,
00037 const double &block_size_x,
00038 const double &block_size_y,
00039 const double floor_to_base_height,
00040 const double &x_min,
00041 const double &x_max,
00042 const double &y_min,
00043 const double &y_max,
00044 const double &z_min,
00045 const double &z_max)
00046 {
00047 test_step_ = test_step;
00048 block_size_x_ = block_size_x;
00049 block_size_y_ = block_size_y;
00050 floor_to_base_height_ = floor_to_base_height;
00051 x_min_ = x_min;
00052 x_max_ = x_max;
00053 y_min_ = y_min;
00054 y_max_ = y_max;
00055 z_min_ = z_min;
00056 z_max_ = z_max;
00057
00058
00059 block_ = new MetaBlock("Virtual1",
00060 pose_zero_,
00061 sprimitive::CYLINDER,
00062 block_size_x_,
00063 block_size_y_,
00064 0.0);
00065
00066
00067 double height = -floor_to_base_height_ + z_min_;
00068 double width = y_max_*2.0;
00069 double depth = 0.35;
00070 geometry_msgs::Pose pose;
00071 setPose(&pose,
00072 x_min_ + depth/2.0,
00073 0.0,
00074 floor_to_base_height_ + height/2.0);
00075
00076 table_ = new MetaBlock("table", pose, sprimitive::BOX, depth, width, height);
00077 }
00078
00079 geometry_msgs::PoseArray Evaluation::generatePosesGrid()
00080 {
00081 std::vector<MetaBlock> blocks_test;
00082 geometry_msgs::PoseArray poses;
00083 poses.header.frame_id = base_frame_;
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 if (verbose_)
00094 ROS_INFO_STREAM(" Generating goals in the target space");
00095
00096 MetaBlock block(*block_);
00097
00098 double y_step = test_step_*1.5;
00099 double y_min(y_min_), y_max(y_max_);
00100
00101 int count = 0;
00102 for (double y=y_min; y<=y_max; y+=y_step)
00103 for (double z=z_min_; z<=z_max_; z+=test_step_)
00104 for (double x=x_min_; x<=x_max_; x+=test_step_)
00105 {
00106 block.pose_.position.x = x;
00107 block.pose_.position.y = y;
00108 block.pose_.position.z = z;
00109 blocks_test.push_back(block);
00110
00111 poses.poses.push_back(block.pose_);
00112 std::cout << x << " " << y << " " << z << std::endl;
00113 ++count;
00114 }
00115
00116 y_min = -y_max_;
00117 y_max = -y_min_;
00118 for (double y=y_min; y<=y_max; y+=y_step)
00119 for (double z=z_min_; z<=z_max_; z+=test_step_)
00120 for (double x=x_min_; x<=x_max_; x+=test_step_)
00121 {
00122 block.pose_.position.x = x;
00123 block.pose_.position.y = y;
00124 block.pose_.position.z = z;
00125 blocks_test.push_back(block);
00126
00127 poses.poses.push_back(block.pose_);
00128 std::cout << x << " " << y << " " << z << std::endl;
00129 ++count;
00130 }
00131
00132 if (verbose_)
00133 ROS_INFO_STREAM("Total number of generated poses=" << count);
00134 return poses;
00135 }
00136
00137 geometry_msgs::PoseArray Evaluation::generatePosesRnd(const int poses_nbr)
00138 {
00139 std::vector<MetaBlock> blocks_test;
00140 geometry_msgs::PoseArray poses;
00141 poses.header.frame_id = "base_link";
00142
00143 int count = 0;
00144 while (count < poses_nbr){
00145 geometry_msgs::Pose pose(pose_zero_);
00146 pose.position.x = 0.35f + float(rand() % 150)/1000.0f;
00147 pose.position.y = float(rand() % 90)/100.0f - 0.45;
00148 pose.position.z = -0.23f + (float(rand() % 230)/1000.0f);
00149 blocks_test.push_back(MetaBlock("BlockTest", pose, sprimitive::CYLINDER, block_size_x_, block_size_y_, 0.0));
00150 poses.poses.push_back(blocks_test.back().pose_);
00151 ++count;
00152 }
00153 return poses;
00154 }
00155
00156 void Evaluation::testReach(ros::NodeHandle &nh,
00157 ros::Publisher *pub_obj_pose,
00158 ros::Publisher *pub_obj_poses,
00159 ros::Publisher *pub_obj_moveit,
00160 moveit_visual_tools::MoveItVisualToolsPtr visual_tools,
00161 Action *action_left,
00162 Action *action_right,
00163 std::vector<MetaBlock> *blocks_surfaces,
00164 const bool pickVsReach,
00165 const bool test_poses_rnd)
00166 {
00167 geometry_msgs::PoseArray poses_test;
00168 if (test_poses_rnd)
00169 poses_test = generatePosesRnd(200);
00170 else
00171 poses_test = generatePosesGrid();
00172
00173
00174 pub_obj_poses->publish(poses_test);
00175 sleep(0.05);
00176
00177 ros::Publisher pub_obj_poses_left =
00178 nh.advertise<geometry_msgs::PoseArray>("/poses_reachable_left", 100);
00179 ros::Publisher pub_obj_poses_right =
00180 nh.advertise<geometry_msgs::PoseArray>("/poses_reachable_right", 100);
00181
00182 int targets_nbr = 0;
00183 int attempts_nbr = 1;
00184 double planning_time = 30.0;
00185 geometry_msgs::PoseArray msg_poses_validated;
00186 msg_poses_validated.header.frame_id = action_right->getBaseLink();
00187 targets_nbr += testReachWithGenSingleHand(action_left,
00188 blocks_surfaces,
00189 pub_obj_pose,
00190 &pub_obj_poses_left,
00191 pub_obj_moveit,
00192 visual_tools,
00193 pickVsReach,
00194 attempts_nbr, planning_time, msg_poses_validated);
00195
00196 targets_nbr += testReachWithGenSingleHand(action_right,
00197 blocks_surfaces,
00198 pub_obj_pose,
00199 &pub_obj_poses_right,
00200 pub_obj_moveit,
00201 visual_tools,
00202 pickVsReach,
00203 attempts_nbr, planning_time, msg_poses_validated);
00204
00205 if (verbose_)
00206 {
00207 ROS_INFO_STREAM("Exploration of reachable space \n"
00208 << "Successfull/total grasps = " << msg_poses_validated.poses.size() << "/" << targets_nbr << "\n"
00209 << "Test params: \n"
00210 << "Max attempts number = " << attempts_nbr << "\n planning time = " << planning_time << "\n"
00211 << "The tested space: step = " << test_step_ << " the zone: \n"
00212 << "x: [ " << x_min_ << " " << x_max_ << " ]\n"
00213 << "y: [ " << y_min_ << " " << y_max_ << " ]\n"
00214 << "z: [ " << z_min_ << " " << z_max_ << " ]");
00215
00216 for (int i =0; i < msg_poses_validated.poses.size(); ++i)
00217 std::cout << msg_poses_validated.poses[i].position.x << " " << msg_poses_validated.poses[i].position.y << " " << msg_poses_validated.poses[i].position.z << std::endl;
00218 }
00219 }
00220
00221 int Evaluation::testReachWithGenSingleHand(Action *action,
00222 std::vector<MetaBlock> *blocks_surfaces,
00223 ros::Publisher *pub_obj_pose,
00224 ros::Publisher *pub_obj_poses,
00225 ros::Publisher *pub_obj_moveit,
00226 moveit_visual_tools::MoveItVisualToolsPtr visual_tools,
00227 const bool pickVsReach,
00228 const int attempts_nbr,
00229 const double planning_time,
00230 geometry_msgs::PoseArray &msg_poses_validated)
00231 {
00232 moveit::planning_interface::PlanningSceneInterface current_scene;
00233
00234
00235 double y_step = test_step_*1.5;
00236 double y_min(y_min_), y_max(y_max_);
00237 if (action->plan_group_.find("right") != std::string::npos)
00238 {
00239 y_min = -y_max_;
00240 y_max = -y_min_;
00241 }
00242
00243 MetaBlock block(*block_);
00244
00245 int count_total = 0;
00246 for (double z=z_min_; z<=z_max_; z+=test_step_)
00247 {
00248
00249 table_->size_z_ = -floor_to_base_height_ + (z-block_size_y_/2.0);
00250 table_->pose_.position.z = floor_to_base_height_ + table_->size_z_/2.0;
00251
00252 for (double y=y_min; y<=y_max; y+=y_step)
00253 for (double x=x_min_; x<=x_max_; x+=test_step_)
00254 {
00255 ++count_total;
00256
00257 table_->pose_.position.x = x - block_size_x_/2.0 + table_->size_x_/2.0,
00258 table_->updatePose(table_->pose_);
00259 std::vector<std::string> objects;
00260 objects.push_back(table_->name_);
00261 current_scene.removeCollisionObjects(objects);
00262 sleep(1.5);
00263 pub_obj_moveit->publish(table_->collObj_);
00264
00265
00266 geometry_msgs::PoseStamped msg_obj_pose;
00267 msg_obj_pose.header.frame_id = action->getBaseLink();
00268 msg_obj_pose.pose.position.x = x;
00269 msg_obj_pose.pose.position.y = y;
00270 msg_obj_pose.pose.position.z = z;
00271 pub_obj_pose->publish(msg_obj_pose);
00272
00273
00274 block.updatePose(msg_obj_pose.pose);
00275 pub_obj_moveit->publish(block.collObj_);
00276
00277 bool success(false);
00278 if (pickVsReach)
00279 {
00280 success = action->pickAction(&block,
00281 table_->name_,
00282 attempts_nbr,
00283 planning_time);
00284 }
00285 else
00286 {
00287 success = action->reachGrasp(&block,
00288 table_->name_,
00289 attempts_nbr,
00290 planning_time);
00291 }
00292 if (success)
00293 {
00294
00295 action->detachObject(block.name_);
00296
00297 msg_poses_validated.poses.push_back(block.pose_);
00298 pub_obj_poses->publish(msg_poses_validated);
00299 stat_poses_success_.push_back(block.pose_);
00300 }
00301
00302 action->poseHand(1);
00303 sleep(1.5);
00304
00305
00306 block.removeBlock(¤t_scene);
00307 }
00308 }
00309
00310
00311 action->poseHand(1);
00312 sleep(1.5);
00313 return count_total;
00314 }
00315
00316 void Evaluation::printStat()
00317 {
00318 ROS_INFO_STREAM("Successfully grasped objects at the following locations: ");
00319 for (std::vector <geometry_msgs::Pose>::iterator it = stat_poses_success_.begin(); it != stat_poses_success_.end(); ++it)
00320 {
00321 ROS_INFO_STREAM(" [" << it-> position.x << " " << it->position.y << " " << it->position.z << "] ["
00322 << it->orientation.x << " " << it->orientation.y << " " << it->orientation.z << " " << it->orientation.w << "]");
00323 }
00324 }
00325
00326 bool Evaluation::inWorkSpace(geometry_msgs::Pose pose,
00327 const bool x,
00328 const bool y,
00329 const bool z)
00330 {
00331 bool res(false);
00332 if (x && y && z)
00333 {
00334 if ((pose.position.x < x_max_) && (pose.position.x > x_min_)
00335 && (pose.position.y < y_max_) && (pose.position.y > y_min_)
00336 && (pose.position.z < z_max_) && (pose.position.z > z_min_))
00337 res = true;
00338 }
00339 if (!x && !y && z)
00340 {
00341 if ((pose.position.z < z_max_) && (pose.position.z > z_min_))
00342 res = true;
00343 }
00344
00345 return res;
00346 }
00347
00348 }