Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <ros/ros.h>
00041 #include <geometry_msgs/PoseArray.h>
00042 #include <Eigen/Core>
00043 #include <Eigen/Geometry>
00044
00045
00046 #include <moveit_simple_grasps/simple_grasps.h>
00047
00048
00049 #include <moveit_simple_grasps/custom_environment2.h>
00050
00051 namespace baxter_pick_place
00052 {
00053
00054 static const double BLOCK_SIZE = 0.04;
00055
00056 class GraspGeneratorTest
00057 {
00058 private:
00059
00060 ros::NodeHandle nh_;
00061
00062
00063 moveit_simple_grasps::SimpleGraspsPtr simple_grasps_;
00064
00065
00066 moveit_visual_tools::VisualToolsPtr visual_tools_;
00067
00068
00069 moveit_simple_grasps::GraspData grasp_data_;
00070
00071
00072 std::string arm_;
00073 std::string ee_group_name_;
00074 std::string planning_group_name_;
00075
00076 public:
00077
00078
00079 GraspGeneratorTest(int num_tests)
00080 : nh_("~")
00081 {
00082 nh_.param("arm", arm_, std::string("left"));
00083 nh_.param("ee_group_name", ee_group_name_, std::string(arm_ + "_hand"));
00084 planning_group_name_ = arm_ + "_arm";
00085
00086 ROS_INFO_STREAM_NAMED("test","Arm: " << arm_);
00087 ROS_INFO_STREAM_NAMED("test","End Effector: " << ee_group_name_);
00088 ROS_INFO_STREAM_NAMED("test","Planning Group: " << planning_group_name_);
00089
00090
00091
00092 if (!grasp_data_.loadRobotGraspData(nh_, ee_group_name_))
00093 ros::shutdown();
00094
00095
00096
00097 visual_tools_.reset(new moveit_visual_tools::VisualTools(grasp_data_.base_link_));
00098 visual_tools_->setLifetime(120.0);
00099 visual_tools_->setMuted(false);
00100 visual_tools_->loadEEMarker(grasp_data_.ee_group_, planning_group_name_);
00101
00102
00103
00104 simple_grasps_.reset( new moveit_simple_grasps::SimpleGrasps(visual_tools_) );
00105
00106
00107
00108 geometry_msgs::Pose object_pose;
00109 std::vector<moveit_msgs::Grasp> possible_grasps;
00110
00111
00112 ros::Duration(2.0).sleep();
00113
00114
00115 int i = 0;
00116 while(ros::ok())
00117 {
00118 ROS_INFO_STREAM_NAMED("test","Adding random object " << i+1 << " of " << num_tests);
00119
00120
00121 if (num_tests == 1)
00122 generateTestObject(object_pose);
00123 else
00124 generateRandomObject(object_pose);
00125
00126
00127 visual_tools_->publishBlock(object_pose, moveit_visual_tools::BLUE, BLOCK_SIZE);
00128
00129 possible_grasps.clear();
00130
00131
00132 simple_grasps_->generateBlockGrasps( object_pose, grasp_data_, possible_grasps);
00133
00134
00135 visual_tools_->publishAnimatedGrasps(possible_grasps, grasp_data_.ee_parent_link_);
00136
00137
00138
00139 ++i;
00140 if( i >= num_tests )
00141 break;
00142 }
00143 }
00144
00145 void generateTestObject(geometry_msgs::Pose& object_pose)
00146 {
00147
00148 geometry_msgs::Pose start_object_pose;
00149
00150 start_object_pose.position.x = 0.4;
00151 start_object_pose.position.y = -0.2;
00152 start_object_pose.position.z = 0.0;
00153
00154
00155 double angle = M_PI / 1.5;
00156 Eigen::Quaterniond quat(Eigen::AngleAxis<double>(double(angle), Eigen::Vector3d::UnitZ()));
00157 start_object_pose.orientation.x = quat.x();
00158 start_object_pose.orientation.y = quat.y();
00159 start_object_pose.orientation.z = quat.z();
00160 start_object_pose.orientation.w = quat.w();
00161
00162
00163 object_pose = start_object_pose;
00164
00165
00166 }
00167
00168 void generateRandomObject(geometry_msgs::Pose& object_pose)
00169 {
00170
00171 object_pose.position.x = fRand(0.1,0.9);
00172 object_pose.position.y = fRand(-0.28,0.28);
00173 object_pose.position.z = 0.02;
00174
00175
00176 double angle = M_PI * fRand(0.1,1);
00177 Eigen::Quaterniond quat(Eigen::AngleAxis<double>(double(angle), Eigen::Vector3d::UnitZ()));
00178 object_pose.orientation.x = quat.x();
00179 object_pose.orientation.y = quat.y();
00180 object_pose.orientation.z = quat.z();
00181 object_pose.orientation.w = quat.w();
00182 }
00183
00184 double fRand(double fMin, double fMax)
00185 {
00186 double f = (double)rand() / RAND_MAX;
00187 return fMin + f * (fMax - fMin);
00188 }
00189
00190 };
00191
00192 }
00193
00194
00195 int main(int argc, char *argv[])
00196 {
00197 int num_tests = 10;
00198 ros::init(argc, argv, "grasp_generator_test");
00199
00200 ROS_INFO_STREAM_NAMED("main","Simple Grasps Test");
00201
00202 ros::AsyncSpinner spinner(2);
00203 spinner.start();
00204
00205
00206 srand(ros::Time::now().toSec());
00207
00208
00209 ros::Time start_time;
00210 start_time = ros::Time::now();
00211
00212
00213 baxter_pick_place::GraspGeneratorTest tester(num_tests);
00214
00215
00216 double duration = (ros::Time::now() - start_time).toNSec() * 1e-6;
00217 ROS_INFO_STREAM_NAMED("","Total time: " << duration);
00218
00219
00220 ros::Duration(1.0).sleep();
00221
00222 return 0;
00223 }