$search
00001 #include <move_arm_warehouse/move_arm_utils.h> 00002 #include <gtest/gtest.h> 00003 static const std::string VIS_TOPIC_NAME = "planning_scene_visualizer_markers"; 00004 00005 //in 100 hz ticks 00006 static const unsigned int CONTROL_SPEED = 5; 00007 00008 static const double BASE_TRANS_SPEED = .3; 00009 static const double BASE_ROT_SPEED = .15; 00010 00011 static const double HAND_TRANS_SPEED = .05; 00012 static const double HAND_ROT_SPEED = .15; 00013 00014 static const std::string EXECUTE_RIGHT_TRAJECTORY = "/r_arm_controller/follow_joint_trajectory"; 00015 static const std::string EXECUTE_LEFT_TRAJECTORY = "/l_arm_controller/follow_joint_trajectory"; 00016 static const std::string LEFT_IK_NAME = "/pr2_left_arm_kinematics/get_constraint_aware_ik"; 00017 static const std::string RIGHT_IK_NAME = "/pr2_right_arm_kinematics/get_constraint_aware_ik"; 00018 00019 static const std::string NON_COLL_LEFT_IK_NAME = "/pr2_left_arm_kinematics/get_ik"; 00020 static const std::string NON_COLL_RIGHT_IK_NAME = "/pr2_right_arm_kinematics/get_ik"; 00021 00022 static const std::string RIGHT_ARM_GROUP = "right_arm"; 00023 static const std::string LEFT_ARM_GROUP = "left_arm"; 00024 00025 static const std::string RIGHT_ARM_REDUNDANCY = "r_upper_arm_roll_joint"; 00026 static const std::string LEFT_ARM_REDUNDANCY = "l_upper_arm_roll_joint"; 00027 00028 static const std::string LEFT_IK_LINK = "l_wrist_roll_link"; 00029 static const std::string RIGHT_IK_LINK = "r_wrist_roll_link"; 00030 00031 static const std::string PLANNER_SERVICE_NAME = "/ompl_planning/plan_kinematic_path"; 00032 static const std::string LEFT_INTERPOLATE_SERVICE_NAME = "/l_interpolated_ik_motion_plan"; 00033 static const std::string RIGHT_INTERPOLATE_SERVICE_NAME = "/r_interpolated_ik_motion_plan"; 00034 static const std::string TRAJECTORY_FILTER_SERVICE_NAME = "/trajectory_filter/filter_trajectory_with_constraints"; 00035 static const std::string PROXIMITY_SPACE_SERVICE_NAME = "/collision_proximity_server_test/get_distance_aware_plan"; 00036 static const std::string PROXIMITY_SPACE_VALIDITY_NAME = "/collision_proximity_server_test/get_state_validity"; 00037 static const std::string PROXIMITY_SPACE_PLANNER_NAME = "/collision_proximity_planner/plan"; 00038 static const std::string SET_PLANNING_SCENE_DIFF_NAME = "environment_server/set_planning_scene_diff"; 00039 00040 using namespace collision_space; 00041 using namespace kinematics_msgs; 00042 using namespace arm_navigation_msgs; 00043 using namespace head_monitor_msgs; 00044 using namespace move_arm_warehouse; 00045 using namespace planning_environment; 00046 using namespace planning_models; 00047 using namespace std; 00048 using namespace trajectory_msgs; 00049 using namespace planning_scene_utils; 00050 using namespace ros::param; 00051 00052 class PlanningSceneEditorTest : public planning_scene_utils::PlanningSceneEditor 00053 { 00054 public: 00055 00056 PlanningSceneEditorTest(PlanningSceneParameters& params) : PlanningSceneEditor(params) 00057 { 00058 } 00059 00060 virtual void planCallback(arm_navigation_msgs::ArmNavigationErrorCodes& errorCode) 00061 { 00062 } 00063 virtual void filterCallback(arm_navigation_msgs::ArmNavigationErrorCodes& errorCode) 00064 { 00065 } 00066 00067 virtual void attachObjectCallback(const std::string& name) 00068 { 00069 } 00070 00071 }; 00072 00073 PlanningSceneEditorTest* editor = NULL; 00074 planning_scene_utils::PlanningSceneParameters params; 00075 00076 bool killThread = false; 00077 bool inited = false; 00078 00082 TEST(TestSuite, connectTest) 00083 { 00084 editor = new PlanningSceneEditorTest(params); 00085 } 00086 00090 TEST(TestSuite, createPlanningSceneTest) 00091 { 00092 for(int i = 0; i < 10; i++) 00093 { 00094 std::string name = editor->createNewPlanningScene(); 00095 inited = true; 00096 ROS_INFO("Created scene %s", name.c_str()); 00097 } 00098 } 00099 00100 00104 TEST(TestSuite, createSaveTest) 00105 { 00106 std::string name = editor->createNewPlanningScene(); 00107 ROS_INFO("Created scene %s", name.c_str()); 00108 ROS_INFO("Saving..."); 00109 editor->savePlanningScene(editor->planning_scene_map_[name]); 00110 } 00111 00115 TEST(TestSuite, createDeleteMotionPlanTest) 00116 { 00117 ROS_INFO("Creating planning scene ..."); 00118 std::string planningSceneID = editor->createNewPlanningScene(); 00119 ROS_INFO("Created planning scene %s", planningSceneID.c_str()); 00120 00121 for(int i = 0; i < 100; i++) 00122 { 00123 unsigned int id; 00124 std::string rightarm = RIGHT_ARM_GROUP; 00125 std::string rightik = RIGHT_IK_LINK; 00126 00127 ROS_INFO("Creating motion plan request ..."); 00128 editor->createMotionPlanRequest(*(editor->getRobotState()), 00129 *(editor->getRobotState()), 00130 rightarm, rightik, false, 00131 getPlanningSceneIdFromName(planningSceneID), false, id); 00132 ROS_INFO_STREAM("Deleting motion plan request " << id); 00133 std::vector<unsigned int> traj; 00134 editor->deleteMotionPlanRequest(id, traj); 00135 00136 } 00137 } 00138 00142 TEST(TestSuite, planTrajectoryTest) 00143 { 00144 ROS_INFO("Creating planning scene ..."); 00145 std::string planningSceneID = editor->createNewPlanningScene(); 00146 ROS_INFO("Created planning scene %s", planningSceneID.c_str()); 00147 00148 unsigned int id; 00149 std::string rightarm = RIGHT_ARM_GROUP; 00150 std::string rightik = RIGHT_IK_LINK; 00151 00152 ROS_INFO("Creating motion plan request ..."); 00153 editor->createMotionPlanRequest(*(editor->getRobotState()), 00154 *(editor->getRobotState()), 00155 rightarm, rightik,false, 00156 getPlanningSceneIdFromName(planningSceneID), 00157 false, id); 00158 00159 00160 MotionPlanRequestData& data = editor->motion_plan_map_[getMotionPlanRequestNameFromId(id)]; 00161 for(int i = 0; i < 100; i++) 00162 { 00163 ROS_INFO("Randomly Perturbing"); 00164 editor->randomlyPerturb(data, GoalPosition); 00165 unsigned int traj_id; 00166 ROS_INFO("Planning..."); 00167 editor->planToRequest(data, traj_id); 00168 ROS_INFO_STREAM("Got plan " << traj_id); 00169 editor->playTrajectory(editor->motion_plan_map_[getMotionPlanRequestNameFromId(id)], 00170 editor->trajectory_map_[getMotionPlanRequestNameFromId(id)][getTrajectoryNameFromId(traj_id)]); 00171 ROS_INFO("Deleting..."); 00172 editor->deleteTrajectory(data.getId(), traj_id); 00173 } 00174 std::vector<unsigned int> traj; 00175 editor->deleteMotionPlanRequest(id, traj); 00176 00177 } 00178 00182 TEST(TestSuite, filterTrajectoryTest) 00183 { 00184 ROS_INFO("Creating planning scene ..."); 00185 std::string planningSceneID = editor->createNewPlanningScene(); 00186 ROS_INFO("Created planning scene %s", planningSceneID.c_str()); 00187 00188 unsigned int id; 00189 std::string rightarm = RIGHT_ARM_GROUP; 00190 std::string rightik = RIGHT_IK_LINK; 00191 00192 ROS_INFO("Creating motion plan request ..."); 00193 editor->createMotionPlanRequest(*(editor->getRobotState()), 00194 *(editor->getRobotState()), 00195 rightarm, rightik,false, 00196 getPlanningSceneIdFromName(planningSceneID), 00197 false, id); 00198 00199 00200 MotionPlanRequestData& data = editor->motion_plan_map_[getMotionPlanRequestNameFromId(id)]; 00201 for(int i = 0; i < 20; i++) 00202 { 00203 ROS_INFO("Randomly Perturbing"); 00204 editor->randomlyPerturb(data, GoalPosition); 00205 unsigned int traj_id; 00206 ROS_INFO("Planning..."); 00207 editor->planToRequest(data, traj_id); 00208 ROS_INFO_STREAM("Got plan " << traj_id); 00209 editor->playTrajectory(editor->motion_plan_map_[getMotionPlanRequestNameFromId(id)], 00210 editor->trajectory_map_[getMotionPlanRequestNameFromId(id)][getTrajectoryNameFromId(traj_id)]); 00211 unsigned int filter_id; 00212 editor->filterTrajectory(editor->motion_plan_map_[getMotionPlanRequestNameFromId(id)], 00213 editor->trajectory_map_[getMotionPlanRequestNameFromId(id)][getTrajectoryNameFromId(traj_id)], 00214 filter_id); 00215 editor->playTrajectory(editor->motion_plan_map_[getMotionPlanRequestNameFromId(id)], 00216 editor->trajectory_map_[getMotionPlanRequestNameFromId(id)][getTrajectoryNameFromId(filter_id)]); 00217 ROS_INFO("Deleting..."); 00218 editor->deleteTrajectory(data.getId(), traj_id); 00219 editor->deleteTrajectory(data.getId(), filter_id); 00220 } 00221 } 00222 00223 float randFloat(float minValue, float maxValue) 00224 { 00225 return ((float)random() / (float)RAND_MAX) * (maxValue - minValue) + minValue; 00226 } 00227 00228 TEST(TestSuite, randomGeneratorTest) 00229 { 00230 for(int i = 0; i < 100; i++) 00231 { 00232 ASSERT_TRUE(randFloat(-100, 100) >= -100); 00233 ASSERT_TRUE(randFloat(-100, 100) <= 100); 00234 } 00235 ASSERT_FLOAT_EQ(5, randFloat(5, 5)); 00236 } 00237 00241 TEST(TestSuite, collisionObjectTest) 00242 { 00243 geometry_msgs::Pose pose; 00244 PlanningSceneEditor::GeneratedShape shape; 00245 float scaleX; 00246 float scaleY; 00247 float scaleZ; 00248 00249 std::vector<std::string> objs; 00250 for(int i = 0; i < 100; i++) 00251 { 00252 pose.position.x = randFloat(-1.5f, 1.5f); 00253 pose.position.y = randFloat(-1.5f, 1.5f); 00254 pose.position.z = randFloat(-1.5f, 1.5f); 00255 pose.orientation.x = randFloat(0.0f, 1.0f); 00256 pose.orientation.y = randFloat(0.0f, 1.0f); 00257 pose.orientation.z = randFloat(0.0f, 1.0f); 00258 pose.orientation.w = 1.0f; 00259 00260 float rand = randFloat(0.0f, 1.0f); 00261 if(rand < 0.333f) 00262 { 00263 shape = PlanningSceneEditor::Box; 00264 } 00265 else if(rand < 0.666f) 00266 { 00267 shape = PlanningSceneEditor::Cylinder; 00268 } 00269 else 00270 { 00271 shape = PlanningSceneEditor::Sphere; 00272 } 00273 00274 scaleX = randFloat(0.01f, 0.2f); 00275 scaleY = randFloat(0.01f, 0.2f); 00276 scaleZ = randFloat(0.01f, 0.2f); 00277 std_msgs::ColorRGBA color; 00278 color.r = 0.5; 00279 color.g = 0.5; 00280 color.b = 0.5; 00281 color.a = 1.0; 00282 ROS_INFO("Creating object with size %f %f %f and position %f %f %f",scaleX, scaleY, scaleZ, pose.position.x, pose.position.y, pose.position.z); 00283 std::string obj = editor->createCollisionObject("", pose, shape, scaleX, scaleY, scaleZ,color); 00284 objs.push_back(obj); 00285 } 00286 00287 for(size_t i = 0; i < objs.size(); i ++) 00288 { 00289 ROS_INFO("Deleting..."); 00290 editor->deleteCollisionObject(objs[i]); 00291 } 00292 } 00293 00294 00295 void spinThread() 00296 { 00297 while(!inited) 00298 { 00299 usleep(10000); 00300 } 00301 while(!killThread && ros::ok()) 00302 { 00303 ros::spinOnce(); 00304 editor->sendMarkers(); 00305 editor->sendTransformsAndClock(); 00306 usleep(10000); 00307 } 00308 } 00309 00310 int main(int argc, char **argv) 00311 { 00312 testing::InitGoogleTest(&argc, argv); 00313 ros::init(argc, argv, "planning_scene_warehouse_viewer", ros::init_options::NoSigintHandler); 00314 00315 00316 param<string>("set_planning_scene_diff_name", params.set_planning_scene_diff_name_, SET_PLANNING_SCENE_DIFF_NAME); 00317 param<string>("left_ik_name", params.left_ik_name_, LEFT_IK_NAME); 00318 param<string>("left_interpolate_service_name", params.left_interpolate_service_name_, LEFT_INTERPOLATE_SERVICE_NAME); 00319 param<string>("non_coll_left_ik_name", params.non_coll_left_ik_name_, NON_COLL_LEFT_IK_NAME); 00320 param<string>("non_coll_right_ik_name", params.non_coll_right_ik_name_, NON_COLL_RIGHT_IK_NAME); 00321 param<string>("planner_service_name", params.planner_service_name_, PLANNER_SERVICE_NAME); 00322 param<string>("proximity_space_planner_name", params.proximity_space_planner_name_, PROXIMITY_SPACE_PLANNER_NAME); 00323 param<string>("proximity_space_service_name", params.proximity_space_service_name_, PROXIMITY_SPACE_SERVICE_NAME); 00324 param<string>("proximity_space_validity_name", params.proximity_space_validity_name_, PROXIMITY_SPACE_VALIDITY_NAME); 00325 param<string>("right_ik_name", params.right_ik_name_, RIGHT_IK_NAME); 00326 param<string>("right_interpolate_service_name", params.right_interpolate_service_name_, RIGHT_INTERPOLATE_SERVICE_NAME); 00327 param<string>("trajectory_filter_service_name", params.trajectory_filter_service_name_, TRAJECTORY_FILTER_SERVICE_NAME); 00328 param<string>("vis_topic_name", params.vis_topic_name_ , VIS_TOPIC_NAME); 00329 param<string>("right_ik_link", params.right_ik_link_ , RIGHT_IK_LINK); 00330 param<string>("left_ik_link", params.left_ik_link_ , LEFT_IK_LINK); 00331 param<string>("right_arm_group", params.right_arm_group_ , RIGHT_ARM_GROUP); 00332 param<string>("left_arm_group", params.left_arm_group_ , LEFT_ARM_GROUP); 00333 param<string>("right_redundancy", params.right_redundancy_ , RIGHT_ARM_REDUNDANCY); 00334 param<string>("left_redundancy", params.left_redundancy_ , LEFT_ARM_REDUNDANCY); 00335 param<string>("execute_left_trajectory", params.execute_left_trajectory_ , EXECUTE_LEFT_TRAJECTORY); 00336 param<string>("execute_right_trajectory", params.execute_right_trajectory_ , EXECUTE_RIGHT_TRAJECTORY); 00337 00338 00339 boost::thread spin_thread(boost::bind(&spinThread)); 00340 00341 int ret = RUN_ALL_TESTS(); 00342 00343 killThread = true; 00344 00345 spin_thread.join(); 00346 00347 00348 return ret; 00349 }