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::MoveItVisualToolsPtr 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::MoveItVisualTools(grasp_data_.base_link_));
00098 visual_tools_->setLifetime(120.0);
00099 visual_tools_->loadMarkerPub();
00100
00101
00102
00103 simple_grasps_.reset( new moveit_simple_grasps::SimpleGrasps(visual_tools_) );
00104
00105 geometry_msgs::Pose pose;
00106 visual_tools_->generateEmptyPose(pose);
00107
00108
00109
00110
00111 for (std::size_t i = 0; i < 4; ++i)
00112 {
00113
00114 grasp_data_.setRobotStatePreGrasp( visual_tools_->getSharedRobotState() );
00115 visual_tools_->loadEEMarker(grasp_data_.ee_group_);
00116 const robot_model::JointModelGroup* ee_jmg = visual_tools_->getRobotModel()->getJointModelGroup(grasp_data_.ee_group_);
00117 visual_tools_->publishEEMarkers(pose, ee_jmg, rviz_visual_tools::ORANGE, "test_eef");
00118 ros::Duration(1.0).sleep();
00119
00120
00121 grasp_data_.setRobotStateGrasp( visual_tools_->getSharedRobotState() );
00122 visual_tools_->loadEEMarker(grasp_data_.ee_group_);
00123 visual_tools_->publishEEMarkers(pose, ee_jmg, rviz_visual_tools::GREEN, "test_eef");
00124 ros::Duration(1.0).sleep();
00125 }
00126
00127
00128
00129 geometry_msgs::Pose object_pose;
00130 std::vector<moveit_msgs::Grasp> possible_grasps;
00131
00132
00133 int i = 0;
00134 while(ros::ok())
00135 {
00136 ROS_INFO_STREAM_NAMED("test","Adding random object " << i+1 << " of " << num_tests);
00137
00138
00139 if (num_tests == 1)
00140 generateTestObject(object_pose);
00141 else
00142 generateRandomObject(object_pose);
00143
00144
00145 visual_tools_->publishBlock(object_pose, rviz_visual_tools::BLUE, BLOCK_SIZE);
00146
00147 possible_grasps.clear();
00148
00149
00150 simple_grasps_->generateBlockGrasps( object_pose, grasp_data_, possible_grasps);
00151
00152
00153 const robot_model::JointModelGroup* ee_jmg = visual_tools_->getRobotModel()->getJointModelGroup(grasp_data_.ee_group_);
00154 visual_tools_->publishAnimatedGrasps(possible_grasps, ee_jmg);
00155
00156
00157
00158 ++i;
00159 if( i >= num_tests )
00160 break;
00161 }
00162 }
00163
00164 void generateTestObject(geometry_msgs::Pose& object_pose)
00165 {
00166
00167 geometry_msgs::Pose start_object_pose;
00168
00169 start_object_pose.position.x = 0.4;
00170 start_object_pose.position.y = -0.2;
00171 start_object_pose.position.z = 0.0;
00172
00173
00174 double angle = M_PI / 1.5;
00175 Eigen::Quaterniond quat(Eigen::AngleAxis<double>(double(angle), Eigen::Vector3d::UnitZ()));
00176 start_object_pose.orientation.x = quat.x();
00177 start_object_pose.orientation.y = quat.y();
00178 start_object_pose.orientation.z = quat.z();
00179 start_object_pose.orientation.w = quat.w();
00180
00181
00182 object_pose = start_object_pose;
00183
00184
00185 }
00186
00187 void generateRandomObject(geometry_msgs::Pose& object_pose)
00188 {
00189
00190 object_pose.position.x = fRand(0.1,0.9);
00191 object_pose.position.y = fRand(-0.28,0.28);
00192 object_pose.position.z = 0.02;
00193
00194
00195 double angle = M_PI * fRand(0.1,1);
00196 Eigen::Quaterniond quat(Eigen::AngleAxis<double>(double(angle), Eigen::Vector3d::UnitZ()));
00197 object_pose.orientation.x = quat.x();
00198 object_pose.orientation.y = quat.y();
00199 object_pose.orientation.z = quat.z();
00200 object_pose.orientation.w = quat.w();
00201 }
00202
00203 double fRand(double fMin, double fMax)
00204 {
00205 double f = (double)rand() / RAND_MAX;
00206 return fMin + f * (fMax - fMin);
00207 }
00208
00209 };
00210
00211 }
00212
00213
00214 int main(int argc, char *argv[])
00215 {
00216 int num_tests = 10;
00217 ros::init(argc, argv, "grasp_generator_test");
00218
00219 ROS_INFO_STREAM_NAMED("main","Simple Grasps Test");
00220
00221 ros::AsyncSpinner spinner(2);
00222 spinner.start();
00223
00224
00225 srand(ros::Time::now().toSec());
00226
00227
00228 ros::Time start_time;
00229 start_time = ros::Time::now();
00230
00231
00232 baxter_pick_place::GraspGeneratorTest tester(num_tests);
00233
00234
00235 double duration = (ros::Time::now() - start_time).toNSec() * 1e-6;
00236 ROS_INFO_STREAM_NAMED("","Total time: " << duration);
00237
00238
00239 ros::Duration(1.0).sleep();
00240
00241 return 0;
00242 }