00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "descartes_trajectory/cart_trajectory_pt.h"
00020 #include "descartes_core/utils.h"
00021 #include "descartes_trajectory_test/cartesian_robot.h"
00022 #include <gtest/gtest.h>
00023
00024 using namespace descartes_trajectory;
00025 using namespace descartes_core;
00026 using namespace descartes_trajectory_test;
00027
00028 TEST(CartTrajPt, construction)
00029 {
00030 CartTrajectoryPt def();
00031 }
00032
00033 TEST(CartTrajPt, getPoses)
00034 {
00035 const double POS_TOL = 2.0;
00036 const double POS_INC = 0.2;
00037
00038 const double ORIENT_TOL = 2 * M_PI;
00039 const double ORIENT_INC = M_PI / 4;
00040
00041 const double EPSILON = 0.001;
00042
00043 const int NUM_SAMPLED_POS = pow((POS_TOL / POS_INC) + 1, 3.0);
00044 const int NUM_SAMPLED_ORIENT = pow((ORIENT_TOL / ORIENT_INC) + 1, 3.0);
00045 const int NUM_SAMPLED_BOTH = NUM_SAMPLED_POS * NUM_SAMPLED_ORIENT;
00046
00047 ROS_INFO_STREAM("Expected samples, position: " << NUM_SAMPLED_POS << ", orientation: " << NUM_SAMPLED_ORIENT
00048 << ", both: " << NUM_SAMPLED_BOTH);
00049
00050 ROS_INFO_STREAM("Initializing fuzzy position point");
00051 CartTrajectoryPt fuzzy_pos(
00052 TolerancedFrame(utils::toFrame(0, 0, 0, 0, 0, 0),
00053 ToleranceBase::createSymmetric<PositionTolerance>(0.0, 0.0, 0.0, POS_TOL + EPSILON),
00054 ToleranceBase::createSymmetric<OrientationTolerance>(0.0, 0.0, 0.0, 0.0)),
00055 POS_INC, ORIENT_INC);
00056
00057 ROS_INFO_STREAM("Initializing fuzzy orientation point");
00058 CartTrajectoryPt fuzzy_orient(
00059 TolerancedFrame(utils::toFrame(0, 0, 0, 0, 0, 0),
00060 ToleranceBase::createSymmetric<PositionTolerance>(0.0, 0.0, 0.0, 0.0),
00061 ToleranceBase::createSymmetric<OrientationTolerance>(0.0, 0.0, 0.0, ORIENT_TOL + EPSILON)),
00062 POS_INC, ORIENT_INC);
00063
00064 ROS_INFO_STREAM("Initializing fuzzy position/orientation point");
00065 CartTrajectoryPt fuzzy_both(
00066 TolerancedFrame(utils::toFrame(0, 0, 0, 0, 0, 0),
00067 ToleranceBase::createSymmetric<PositionTolerance>(0.0, 0.0, 0.0, POS_TOL + EPSILON),
00068 ToleranceBase::createSymmetric<OrientationTolerance>(0.0, 0.0, 0.0, ORIENT_TOL + EPSILON)),
00069 POS_INC, ORIENT_INC);
00070
00071 EigenSTL::vector_Affine3d solutions;
00072 std::vector<std::vector<double> > joint_solutions;
00073
00074 ROS_INFO_STREAM("Testing fuzzy pos point");
00075 CartesianRobot robot(POS_TOL + 2 * EPSILON, ORIENT_TOL + 2 * EPSILON);
00076 fuzzy_pos.getCartesianPoses(robot, solutions);
00077 EXPECT_EQ(solutions.size(), NUM_SAMPLED_POS);
00078 fuzzy_pos.getJointPoses(robot, joint_solutions);
00079 EXPECT_EQ(joint_solutions.size(), NUM_SAMPLED_POS);
00080
00081 ROS_INFO_STREAM("Testing fuzzy orient point");
00082 fuzzy_orient.getCartesianPoses(robot, solutions);
00083 EXPECT_EQ(solutions.size(), NUM_SAMPLED_ORIENT);
00084 fuzzy_orient.getJointPoses(robot, joint_solutions);
00085 EXPECT_EQ(joint_solutions.size(), NUM_SAMPLED_ORIENT);
00086
00087 ROS_INFO_STREAM("Testing fuzzy both point");
00088 fuzzy_both.getCartesianPoses(robot, solutions);
00089 EXPECT_EQ(solutions.size(), NUM_SAMPLED_BOTH);
00090 fuzzy_both.getJointPoses(robot, joint_solutions);
00091 EXPECT_EQ(joint_solutions.size(), NUM_SAMPLED_BOTH);
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 }
00110
00111 TEST(CartTrajPt, zeroTolerance)
00112 {
00113 ROS_INFO_STREAM("Initializing zero tolerance cartesian point");
00114 CartTrajectoryPt zero_tol_pos(TolerancedFrame(utils::toFrame(0, 0, 0, 0, 0, 0),
00115 ToleranceBase::zeroTolerance<PositionTolerance>(0.0, 0.0, 0.0),
00116 ToleranceBase::zeroTolerance<OrientationTolerance>(0.0, 0.0, 0.0)),
00117 0, 0);
00118
00119 EigenSTL::vector_Affine3d solutions;
00120 std::vector<std::vector<double> > joint_solutions;
00121
00122 CartesianRobot robot;
00123 zero_tol_pos.getCartesianPoses(robot, solutions);
00124 EXPECT_EQ(solutions.size(), 1);
00125 zero_tol_pos.getJointPoses(robot, joint_solutions);
00126 EXPECT_EQ(joint_solutions.size(), 1);
00127 }
00128
00129 TEST(CartTrajPt, closestJointPose)
00130 {
00131 const double POS_TOL = 0.5f;
00132 const double POS_INC = 0.2;
00133 const double ORIENT_TOL = 1.0;
00134 const double ORIENT_INC = 0.2;
00135 CartesianRobot robot(10, 4);
00136
00137
00138 const double x = 4.0f;
00139 const double y = 5.0f;
00140 const double z = 2.0f;
00141 const double rx = 0.0f;
00142 const double ry = 0.0f;
00143 const double rz = M_PI / 4;
00144 std::vector<double> joint_pose = { x, y, z, rx, ry, rz };
00145 Eigen::Affine3d frame_pose = descartes_core::utils::toFrame(x, y, z, rx, ry, rz);
00146
00147 ROS_INFO_STREAM("Initializing tolerance cartesian point");
00148 CartTrajectoryPt cart_point(
00149 TolerancedFrame(utils::toFrame(x, y, z, rx, ry, rz),
00150 ToleranceBase::createSymmetric<PositionTolerance>(x, y, z, POS_TOL),
00151 ToleranceBase::createSymmetric<OrientationTolerance>(rx, ry, rz, ORIENT_TOL)),
00152 POS_INC, ORIENT_INC);
00153
00154 ROS_INFO_STREAM("Testing getClosestJointPose(...)");
00155 std::vector<double> closest_joint_pose;
00156 EXPECT_TRUE(cart_point.getClosestJointPose(joint_pose, robot, closest_joint_pose));
00157
00158 ROS_INFO_STREAM("Testing equality between seed joint pose and closest joint pose");
00159 EXPECT_EQ(joint_pose, closest_joint_pose);
00160 }