test_constraint_samplers.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2011, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: Ioan Sucan */
00036 
00037 #include <planning_scene_monitor/planning_scene_monitor.h>
00038 #include <kinematic_constraints/kinematic_constraint.h>
00039 #include <constraint_samplers/default_constraint_samplers.h>
00040 #include <constraint_samplers/constraint_sampler_manager.h>
00041 #include <constraint_samplers/constraint_sampler_tools.h>
00042 #include <geometric_shapes/shape_operations.h>
00043 #include <moveit_msgs/DisplayTrajectory.h>
00044 #include <planning_models/conversions.h>
00045 #include <visualization_msgs/MarkerArray.h>
00046 
00047 #include <ros/ros.h>
00048 #include <gtest/gtest.h>
00049 
00050 static const std::string ROBOT_DESCRIPTION="robot_description";
00051 
00052 class ConstraintSamplerTestBase : public testing::Test
00053 {
00054 protected:
00055 
00056   virtual void SetUp()
00057   {
00058     psm_.reset(new planning_scene_monitor::PlanningSceneMonitor(ROBOT_DESCRIPTION));
00059     kmodel_ = psm_->getPlanningScene()->getRobotModel();
00060   };
00061 
00062   virtual void TearDown()
00063   {
00064   }
00065 
00066 protected:
00067 
00068   ros::NodeHandle nh_;
00069   planning_scene_monitor::PlanningSceneMonitorPtr psm_;
00070   planning_models::RobotModelConstPtr kmodel_;
00071 };
00072 
00073 
00074 TEST_F(ConstraintSamplerTestBase, JointConstraintsSampler)
00075 {
00076   planning_models::RobotState *ks(kmodel_);
00077   ks.setToDefaultValues();
00078   planning_models::TransformsPtr tf = psm_->getPlanningScene()->getTransforms();
00079 
00080   kinematic_constraints::JointConstraint jc1(kmodel_, tf);
00081   moveit_msgs::JointConstraint jcm1;
00082   jcm1.joint_name = "head_pan_joint";
00083   jcm1.position = 0.42;
00084   jcm1.tolerance_above = 0.01;
00085   jcm1.tolerance_below = 0.05;
00086   jcm1.weight = 1.0;
00087   EXPECT_TRUE(jc1.configure(jcm1));
00088 
00089   kinematic_constraints::JointConstraint jc2(kmodel_, tf);
00090   moveit_msgs::JointConstraint jcm2;
00091   jcm2.joint_name = "l_shoulder_pan_joint";
00092   jcm2.position = 0.9;
00093   jcm2.tolerance_above = 0.1;
00094   jcm2.tolerance_below = 0.05;
00095   jcm2.weight = 1.0;
00096   EXPECT_TRUE(jc2.configure(jcm2));
00097 
00098   kinematic_constraints::JointConstraint jc3(kmodel_, tf);
00099   moveit_msgs::JointConstraint jcm3;
00100   jcm3.joint_name = "r_wrist_roll_joint";
00101   jcm3.position = 0.7;
00102   jcm3.tolerance_above = 0.14;
00103   jcm3.tolerance_below = 0.005;
00104   jcm3.weight = 1.0;
00105   EXPECT_TRUE(jc3.configure(jcm3));
00106 
00107   kinematic_constraints::JointConstraint jc4(kmodel_, tf);
00108   moveit_msgs::JointConstraint jcm4;
00109   jcm4.joint_name = "torso_lift_joint";
00110   jcm4.position = 0.2;
00111   jcm4.tolerance_above = 0.09;
00112   jcm4.tolerance_below = 0.01;
00113   jcm4.weight = 1.0;
00114   EXPECT_TRUE(jc4.configure(jcm4));
00115 
00116   std::vector<kinematic_constraints::JointConstraint> js;
00117   js.push_back(jc1);
00118   js.push_back(jc2);
00119   js.push_back(jc3);
00120   js.push_back(jc4);
00121 
00122   constraint_samplers::JointConstraintSampler jcs(psm_->getPlanningScene(), "arms", js);
00123   EXPECT_EQ(jcs.getConstrainedJointCount(), 2);
00124   EXPECT_EQ(jcs.getUnconstrainedJointCount(), 12);
00125 
00126   for (int t = 0 ; t < 1000 ; ++t)
00127   {
00128     EXPECT_TRUE(jcs.sample(ks.getJointStateGroup("arms"), ks, 1));
00129     EXPECT_TRUE(jc2.decide(ks).satisfied);
00130     EXPECT_TRUE(jc3.decide(ks).satisfied);
00131   }
00132 
00133   // test the automatic construction of constraint sampler
00134   moveit_msgs::Constraints c;
00135 
00136   // no constraints should give no sampler
00137   constraint_samplers::ConstraintSamplerPtr s0 = constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(psm_->getPlanningScene(), "arms", c);
00138   EXPECT_TRUE(s0.get() == NULL);
00139 
00140   // add the constraints
00141   c.joint_constraints.push_back(jcm1);
00142   c.joint_constraints.push_back(jcm2);
00143   c.joint_constraints.push_back(jcm3);
00144   c.joint_constraints.push_back(jcm4);
00145 
00146   constraint_samplers::ConstraintSamplerPtr s = constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(psm_->getPlanningScene(), "arms", c);
00147   EXPECT_TRUE(s.get() != NULL);
00148 
00149   // test the generated sampler
00150   for (int t = 0 ; t < 1000 ; ++t)
00151   {
00152     EXPECT_TRUE(s->sample(ks.getJointStateGroup("arms"), ks, 1));
00153     EXPECT_TRUE(jc2.decide(ks).satisfied);
00154     EXPECT_TRUE(jc3.decide(ks).satisfied);
00155   }
00156 }
00157 
00158 TEST_F(ConstraintSamplerTestBase, OrientationConstraintsSampler)
00159 {
00160   planning_models::RobotState *ks(kmodel_);
00161   ks.setToDefaultValues();
00162   planning_models::TransformsPtr tf = psm_->getPlanningScene()->getTransforms();
00163 
00164   kinematic_constraints::OrientationConstraint oc(kmodel_, tf);
00165   moveit_msgs::OrientationConstraint ocm;
00166 
00167   ocm.link_name = "r_wrist_roll_link";
00168   ocm.header.frame_id = ocm.link_name;
00169   ocm.orientation.x = 0.5;
00170   ocm.orientation.y = 0.5;
00171   ocm.orientation.z = 0.5;
00172   ocm.orientation.w = 0.5;
00173   ocm.absolute_x_axis_tolerance = 0.01;
00174   ocm.absolute_y_axis_tolerance = 0.01;
00175   ocm.absolute_z_axis_tolerance = 0.01;
00176   ocm.weight = 1.0;
00177 
00178   EXPECT_TRUE(oc.configure(ocm));
00179 
00180   bool p1 = oc.decide(ks).satisfied;
00181   EXPECT_FALSE(p1);
00182 
00183   ocm.header.frame_id = kmodel_->getModelFrame();
00184   EXPECT_TRUE(oc.configure(ocm));
00185 
00186   constraint_samplers::IKConstraintSampler iks(psm_->getPlanningScene(), "right_arm", constraint_samplers::IKSamplingPose(oc));
00187   for (int t = 0 ; t < 100 ; ++t)
00188   {
00189     EXPECT_TRUE(iks.sample(ks.getJointStateGroup("right_arm"), ks, 100));
00190     EXPECT_TRUE(oc.decide(ks).satisfied);
00191   }
00192 
00193 }
00194 
00195 TEST_F(ConstraintSamplerTestBase, PoseConstraintsSampler)
00196 {
00197   planning_models::RobotState *ks(kmodel_);
00198   ks.setToDefaultValues();
00199   planning_models::TransformsPtr tf = psm_->getPlanningScene()->getTransforms();
00200 
00201   kinematic_constraints::PositionConstraint pc(kmodel_, tf);
00202   moveit_msgs::PositionConstraint pcm;
00203 
00204   pcm.link_name = "l_wrist_roll_link";
00205   pcm.target_point_offset.x = 0;
00206   pcm.target_point_offset.y = 0;
00207   pcm.target_point_offset.z = 0;
00208   pcm.constraint_region.primitives.resize(1);
00209   pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
00210   pcm.constraint_region.primitives[0].dimensions.x = 0.001;
00211 
00212   pcm.header.frame_id = kmodel_->getModelFrame();
00213 
00214   pcm.constraint_region.primitive_poses.resize(1);
00215   pcm.constraint_region.primitive_poses[0].position.x = 0.55;
00216   pcm.constraint_region.primitive_poses[0].position.y = 0.2;
00217   pcm.constraint_region.primitive_poses[0].position.z = 1.25;
00218   pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
00219   pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
00220   pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
00221   pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
00222   pcm.weight = 1.0;
00223 
00224   EXPECT_TRUE(pc.configure(pcm));
00225 
00226   kinematic_constraints::OrientationConstraint oc(kmodel_, tf);
00227   moveit_msgs::OrientationConstraint ocm;
00228 
00229   ocm.link_name = "l_wrist_roll_link";
00230   ocm.header.frame_id = kmodel_->getModelFrame();
00231   ocm.orientation.x = 0.0;
00232   ocm.orientation.y = 0.0;
00233   ocm.orientation.z = 0.0;
00234   ocm.orientation.w = 1.0;
00235   ocm.absolute_x_axis_tolerance = 0.2;
00236   ocm.absolute_y_axis_tolerance = 0.1;
00237   ocm.absolute_z_axis_tolerance = 0.4;
00238   ocm.weight = 1.0;
00239 
00240   EXPECT_TRUE(oc.configure(ocm));
00241 
00242   constraint_samplers::IKConstraintSampler iks1(psm_->getPlanningScene(), "left_arm", constraint_samplers::IKSamplingPose(pc, oc));
00243   for (int t = 0 ; t < 100 ; ++t)
00244   {
00245     EXPECT_TRUE(iks1.sample(ks.getJointStateGroup("left_arm"), ks, 100));
00246     EXPECT_TRUE(pc.decide(ks).satisfied);
00247     EXPECT_TRUE(oc.decide(ks).satisfied);
00248   }
00249 
00250   constraint_samplers::IKConstraintSampler iks2(psm_->getPlanningScene(), "left_arm", constraint_samplers::IKSamplingPose(pc));
00251   for (int t = 0 ; t < 100 ; ++t)
00252   {
00253     EXPECT_TRUE(iks2.sample(ks.getJointStateGroup("left_arm"), ks, 100));
00254     EXPECT_TRUE(pc.decide(ks).satisfied);
00255   }
00256 
00257   constraint_samplers::IKConstraintSampler iks3(psm_->getPlanningScene(), "left_arm", constraint_samplers::IKSamplingPose(oc));
00258   for (int t = 0 ; t < 100 ; ++t)
00259   {
00260     EXPECT_TRUE(iks3.sample(ks.getJointStateGroup("left_arm"), ks, 100));
00261     EXPECT_TRUE(oc.decide(ks).satisfied);
00262   }
00263 
00264 
00265   // test the automatic construction of constraint sampler
00266   moveit_msgs::Constraints c;
00267   c.position_constraints.push_back(pcm);
00268   c.orientation_constraints.push_back(ocm);
00269 
00270   constraint_samplers::ConstraintSamplerPtr s = constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(psm_->getPlanningScene(), "left_arm", c);
00271   EXPECT_TRUE(s.get() != NULL);
00272   static const int NT = 1000;
00273   int succ = 0;
00274   for (int t = 0 ; t < NT ; ++t)
00275   {
00276     EXPECT_TRUE(s->sample(ks.getJointStateGroup("left_arm"), ks, 100));
00277     EXPECT_TRUE(pc.decide(ks).satisfied);
00278     EXPECT_TRUE(oc.decide(ks).satisfied);
00279     if (s->sample(ks.getJointStateGroup("left_arm"), ks, 1))
00280       succ++;
00281   }
00282   ROS_INFO("Success rate for IK Constraint Sampler with position & orientation constraints for one arm: %lf", (double)succ / (double)NT);
00283 }
00284 
00285 TEST_F(ConstraintSamplerTestBase, GenericConstraintsSampler)
00286 {
00287   moveit_msgs::Constraints c;
00288 
00289   moveit_msgs::PositionConstraint pcm;
00290   pcm.link_name = "l_wrist_roll_link";
00291   pcm.target_point_offset.x = 0;
00292   pcm.target_point_offset.y = 0;
00293   pcm.target_point_offset.z = 0;
00294 
00295   pcm.constraint_region.primitives.resize(1);
00296   pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
00297   pcm.constraint_region.primitives[0].dimensions.x = 0.001;
00298 
00299   pcm.header.frame_id = kmodel_->getModelFrame();
00300 
00301   pcm.constraint_region.primitive_poses.resize(1);
00302   pcm.constraint_region.primitive_poses[0].position.x = 0.55;
00303   pcm.constraint_region.primitive_poses[0].position.y = 0.2;
00304   pcm.constraint_region.primitive_poses[0].position.z = 1.25;
00305   pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
00306   pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
00307   pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
00308   pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
00309   pcm.weight = 1.0;
00310   c.position_constraints.push_back(pcm);
00311 
00312   moveit_msgs::OrientationConstraint ocm;
00313   ocm.link_name = "l_wrist_roll_link";
00314   ocm.header.frame_id = kmodel_->getModelFrame();
00315   ocm.orientation.x = 0.0;
00316   ocm.orientation.y = 0.0;
00317   ocm.orientation.z = 0.0;
00318   ocm.orientation.w = 1.0;
00319   ocm.absolute_x_axis_tolerance = 0.2;
00320   ocm.absolute_y_axis_tolerance = 0.1;
00321   ocm.absolute_z_axis_tolerance = 0.4;
00322   ocm.weight = 1.0;
00323   c.orientation_constraints.push_back(ocm);
00324 
00325   ocm.link_name = "r_wrist_roll_link";
00326   ocm.header.frame_id = kmodel_->getModelFrame();
00327   ocm.orientation.x = 0.0;
00328   ocm.orientation.y = 0.0;
00329   ocm.orientation.z = 0.0;
00330   ocm.orientation.w = 1.0;
00331   ocm.absolute_x_axis_tolerance = 0.01;
00332   ocm.absolute_y_axis_tolerance = 0.01;
00333   ocm.absolute_z_axis_tolerance = 0.01;
00334   ocm.weight = 1.0;
00335   c.orientation_constraints.push_back(ocm);
00336 
00337   planning_models::TransformsPtr tf = psm_->getPlanningScene()->getTransforms();
00338   constraint_samplers::ConstraintSamplerPtr s = constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(psm_->getPlanningScene(), "arms", c);
00339   EXPECT_TRUE(s.get() != NULL);
00340 
00341   kinematic_constraints::KinematicConstraintSet kset(kmodel_, tf);
00342   kset.add(c);
00343 
00344   planning_models::RobotState *ks(kmodel_);
00345   ks.setToDefaultValues();
00346   static const int NT = 1000;
00347   int succ = 0;
00348   for (int t = 0 ; t < 1000 ; ++t)
00349   {
00350     EXPECT_TRUE(s->sample(ks.getJointStateGroup("arms"), ks, 1000));
00351     EXPECT_TRUE(kset.decide(ks).satisfied);
00352     if (s->sample(ks.getJointStateGroup("arms"), ks, 1))
00353       succ++;
00354   }
00355   ROS_INFO("Success rate for IK Constraint Sampler with position & orientation constraints for both arms: %lf", (double)succ / (double)NT);
00356 }
00357 
00358 TEST_F(ConstraintSamplerTestBase, DisplayGenericConstraintsSamples1)
00359 {
00360   moveit_msgs::Constraints c;
00361 
00362   moveit_msgs::OrientationConstraint ocm;
00363   ocm.link_name = "r_wrist_roll_link";
00364   ocm.header.frame_id = kmodel_->getModelFrame();
00365   ocm.orientation.x = 0;
00366   ocm.orientation.y = 0;
00367   ocm.orientation.z = 0;
00368   ocm.orientation.w = 1.0;
00369   ocm.absolute_x_axis_tolerance = 0.01;
00370   ocm.absolute_y_axis_tolerance = 0.01;
00371   ocm.absolute_z_axis_tolerance = M_PI;
00372   ocm.weight = 1.0;
00373   c.orientation_constraints.push_back(ocm);
00374 
00375   ros::NodeHandle nh;
00376   ros::Publisher pub_state = nh.advertise<moveit_msgs::DisplayTrajectory>("display_motion_plan", 20);
00377 
00378   planning_models::TransformsPtr tf = psm_->getPlanningScene()->getTransforms();
00379   constraint_samplers::ConstraintSamplerPtr s = constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(psm_->getPlanningScene(), "right_arm", c);
00380   EXPECT_TRUE(s.get() != NULL);
00381 
00382   kinematic_constraints::KinematicConstraintSet kset(kmodel_, tf);
00383   kset.add(c);
00384 
00385   planning_models::RobotState *ks(kmodel_);
00386   ks.setToDefaultValues();
00387 
00388   ros::WallTime start = ros::WallTime::now();
00389   unsigned int ns = 0;
00390   for (int t = 0 ; t < 500 ; ++t)
00391   {
00392     if ((s->sample(ks.getJointStateGroup("right_arm"), ks, 2)))
00393       ns++;
00394   }
00395   ROS_INFO("%lf samples per second", ns / (ros::WallTime::now() - start).toSec());
00396   ros::Publisher pub_markers = nh.advertise<visualization_msgs::MarkerArray>("/visualization_marker_array", 5);
00397   sleep(1);
00398   visualization_msgs::MarkerArray arr;
00399   constraint_samplers::visualizeDistribution(s, ks, "r_wrist_roll_link", 10, 1000, arr);
00400   pub_markers.publish(arr);
00401   ros::Duration(1.0).sleep();
00402 }
00403 
00404 TEST_F(ConstraintSamplerTestBase, DisplayGenericConstraintsSamples2)
00405 {
00406   moveit_msgs::Constraints c;
00407 
00408   moveit_msgs::PositionConstraint pcm;
00409   pcm.link_name = "l_wrist_roll_link";
00410   pcm.target_point_offset.x = 0;
00411   pcm.target_point_offset.y = 0;
00412   pcm.target_point_offset.z = 0;
00413   pcm.header.frame_id = kmodel_->getModelFrame();
00414 
00415   pcm.constraint_region.primitives.resize(1);
00416   pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::BOX;
00417   pcm.constraint_region.primitives[0].dimensions.x = 0.2;
00418   pcm.constraint_region.primitives[0].dimensions.y = 0.3;
00419   pcm.constraint_region.primitives[0].dimensions.z = 0.4;
00420 
00421   pcm.constraint_region.primitive_poses.resize(1);
00422   pcm.constraint_region.primitive_poses[0].position.x = 0.5;
00423   pcm.constraint_region.primitive_poses[0].position.y = 0.2;
00424   pcm.constraint_region.primitive_poses[0].position.z = 0.6;
00425   pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
00426   pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
00427   pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
00428   pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
00429   pcm.weight = 1.0;
00430   c.position_constraints.push_back(pcm);
00431 
00432   moveit_msgs::PositionConstraint pcm2;
00433   pcm2.link_name = "r_wrist_roll_link";
00434   pcm2.target_point_offset.x = 0.7;
00435   pcm2.target_point_offset.y = 0;
00436   pcm2.target_point_offset.z = 0;
00437   pcm2.header.frame_id = "l_wrist_roll_link";
00438 
00439   pcm2.constraint_region.primitives.resize(1);
00440   pcm2.constraint_region.primitive_poses.resize(1);
00441 
00442   pcm2.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::BOX;
00443   pcm2.constraint_region.primitives[0].dimensions.x = 0.01;
00444   pcm2.constraint_region.primitives[0].dimensions.y = 0.01;
00445   pcm2.constraint_region.primitives[0].dimensions.z = 0.01;
00446 
00447   pcm2.constraint_region.primitive_poses[0].position.x = 0.0;
00448   pcm2.constraint_region.primitive_poses[0].position.y = 0.0;
00449   pcm2.constraint_region.primitive_poses[0].position.z = 0.0;
00450   pcm2.constraint_region.primitive_poses[0].orientation.x = 0.0;
00451   pcm2.constraint_region.primitive_poses[0].orientation.y = 0.0;
00452   pcm2.constraint_region.primitive_poses[0].orientation.z = 0.0;
00453   pcm2.constraint_region.primitive_poses[0].orientation.w = 1.0;
00454   pcm2.weight = 1.0;
00455   c.position_constraints.push_back(pcm2);
00456 
00457 
00458   moveit_msgs::OrientationConstraint ocm;
00459   ocm.link_name = "l_wrist_roll_link";
00460   ocm.header.frame_id = kmodel_->getModelFrame();
00461   ocm.orientation.x = 0.5;
00462   ocm.orientation.y = 0.5;
00463   ocm.orientation.z = 0.5;
00464   ocm.orientation.w = 0.5;
00465   ocm.absolute_x_axis_tolerance = 0.01;
00466   ocm.absolute_y_axis_tolerance = M_PI;
00467   ocm.absolute_z_axis_tolerance = 0.01;
00468   ocm.weight = 1.0;
00469   c.orientation_constraints.push_back(ocm);
00470 
00471   ocm.link_name = "r_wrist_roll_link";
00472   ocm.header.frame_id = "l_wrist_roll_link";
00473   ocm.orientation.x = 0.0;
00474   ocm.orientation.y = 0.0;
00475   ocm.orientation.z = 1.0;
00476   ocm.orientation.w = 0.0;
00477   ocm.absolute_x_axis_tolerance = 0.01;
00478   ocm.absolute_y_axis_tolerance = 0.01;
00479   ocm.absolute_z_axis_tolerance = 0.01;
00480   ocm.weight = 1.0;
00481   c.orientation_constraints.push_back(ocm);
00482 
00483   ros::NodeHandle nh;
00484   ros::Publisher pub_state = nh.advertise<moveit_msgs::DisplayTrajectory>("display_motion_plan", 20);
00485 
00486   planning_models::TransformsPtr tf = psm_->getPlanningScene()->getTransforms();
00487   constraint_samplers::ConstraintSamplerPtr s = constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(psm_->getPlanningScene(), "arms", c);
00488   EXPECT_TRUE(s.get() != NULL);
00489 
00490   kinematic_constraints::KinematicConstraintSet kset(kmodel_, tf);
00491   kset.add(c);
00492 
00493   planning_models::RobotState *ks(kmodel_);
00494   ks.setToDefaultValues();
00495 
00496   ros::WallTime start = ros::WallTime::now();
00497   unsigned int ns = 0;
00498   for (int t = 0 ; t < 500 ; ++t)
00499   {
00500     if ((s->sample(ks.getJointStateGroup("arms"), ks, 2)))
00501       ns++;
00502   }
00503   ROS_INFO("%lf samples per second", ns / (ros::WallTime::now() - start).toSec());
00504 
00505   for (int t = 0 ; t < 100 ; ++t)
00506   {
00507     if ((s->sample(ks.getJointStateGroup("arms"), ks, 3)))
00508     {
00509       bool valid = kset.decide(ks).satisfied;
00510       EXPECT_TRUE(valid);
00511       if (valid)
00512       {
00513         moveit_msgs::DisplayTrajectory d;
00514         d.model_id = kmodel_->getName();
00515         planning_models::robotStateToRobotStateMsg(ks, d.trajectory_start);
00516         pub_state.publish(d);
00517         ros::WallDuration(1.0).sleep();
00518       }
00519     }
00520   }
00521 }
00522 
00523 /*
00524 TEST_F(ConstraintSamplerTestBase, VisibilityConstraint)
00525 {
00526   moveit_msgs::AttachedCollisionObject aco;
00527   aco.link_name = "r_wrist_roll_link";
00528   aco.touch_links.push_back("r_wrist_roll_link");
00529 
00530   moveit_msgs::CollisionObject &co = aco.object;
00531   co.id = "attached";
00532   co.header.stamp = ros::Time::now();
00533   co.header.frame_id = aco.link_name;
00534   co.operation = moveit_msgs::CollisionObject::ADD;
00535   co.shapes.resize(1);
00536   co.shapes[0].type = shape_msgs::Shape::BOX;
00537   co.shapes[0].dimensions.push_back(0.3);
00538   co.shapes[0].dimensions.push_back(0.01);
00539   co.shapes[0].dimensions.push_back(0.3);
00540   co.poses.resize(1);
00541   co.poses[0].position.x = 0.28;
00542   co.poses[0].position.y = 0;
00543   co.poses[0].position.z = 0;
00544   co.poses[0].orientation.w = 1.0;
00545   psm_->getPlanningScene()->processAttachedCollisionObjectMsg(aco);
00546 
00547   ros::NodeHandle nh;
00548   planning_models::TransformsPtr tf = psm_->getPlanningScene()->getTransforms();
00549 
00550   kinematic_constraints::VisibilityConstraint vc(kmodel_, tf);
00551   moveit_msgs::VisibilityConstraint vcm;
00552   vcm.target_radius = 0.1;
00553   vcm.cone_sides = 12;
00554   vcm.max_view_angle = 0.35;
00555   vcm.max_range_angle = 0.35;
00556 
00557   vcm.target_pose.header.frame_id = aco.object.id;
00558   vcm.target.primitive_poses[0].position.x = 0;
00559   vcm.target.primitive_poses[0].position.y = 0.05;
00560   vcm.target.primitive_poses[0].position.z = 0;
00561   vcm.target.primitive_poses[0].orientation.x = sqrt(2.0)/2.0;
00562   vcm.target.primitive_poses[0].orientation.y = 0.0;
00563   vcm.target.primitive_poses[0].orientation.z = 0.0;
00564   vcm.target.primitive_poses[0].orientation.w = sqrt(2.0)/2.0;
00565 
00566   vcm.sensor_pose.header.frame_id = "double_stereo_link";
00567   vcm.sensor.primitive_poses[0].position.x = 0.1;
00568   vcm.sensor.primitive_poses[0].position.y = 0;
00569   vcm.sensor.primitive_poses[0].position.z = 0;
00570   vcm.sensor.primitive_poses[0].orientation.x = 0;
00571   vcm.sensor.primitive_poses[0].orientation.y = 0;
00572   vcm.sensor.primitive_poses[0].orientation.z = 0;
00573   vcm.sensor.primitive_poses[0].orientation.w = 1;
00574   vcm.weight = 1.0;
00575 
00576   planning_models::RobotState& ks = psm_->getPlanningScene()->getCurrentState();
00577 
00578   double distance;
00579   EXPECT_TRUE(vc.configure(vcm));
00580   ros::Publisher pub = nh.advertise<visualization_msgs::MarkerArray>("/visualization_marker_array", 10);
00581   ros::Publisher pub_scene = nh.advertise<moveit_msgs::PlanningScene>("/planning_scene", 20);
00582   ros::WallDuration(0.5).sleep();
00583 
00584   for (int i = 0 ; i < 100 ; ++i)
00585   {
00586       do
00587       {
00588       ks.setToRandomValues();
00589       }
00590       while (!vc.decide(ks, distance));
00591       //      ROS_INFO("Found");
00592       visualization_msgs::MarkerArray markers;
00593       vc.getMarkers(ks, markers);
00594       pub.publish(markers);
00595       moveit_msgs::PlanningScene ps;
00596       psm_->getPlanningScene()->getPlanningSceneMsg(ps);
00597       pub_scene.publish(ps);
00598 
00599       ros::WallDuration(.01).sleep();
00600   }
00601 }
00602 */
00603 
00604 int main(int argc, char **argv)
00605 {
00606   testing::InitGoogleTest(&argc, argv);
00607   ros::init(argc, argv, "test_kinematic_constraints");
00608 
00609   ros::AsyncSpinner spinner(1);
00610   spinner.start();
00611 
00612   bool result = RUN_ALL_TESTS();
00613   sleep(1);
00614   return result;
00615 
00616 }


pr2_test_kinematic_constraints
Author(s): Ioan Sucan
autogenerated on Mon Oct 6 2014 11:12:32