@@ -114,40 +114,17 @@ TEST_F(DiffDriveControllerTest, testNoMove)
114114
115115 // check we have a positive definite covariance matrix
116116 // isCovariance = isSymmetric + isPositiveDefinite
117- const Eigen::IOFormat HeavyFmt (
118- Eigen::FullPrecision, 0 , " , " , " ;\n " , " [" , " ]" , " [" , " ]" );
119-
120- typedef Eigen::SelfAdjointEigenSolver<PoseCovariance> PoseEigenSolver;
121- typedef Eigen::SelfAdjointEigenSolver<TwistCovariance> TwistEigenSolver;
122-
123- PoseEigenSolver pose_eigensolver (pose_covariance);
124- TwistEigenSolver twist_eigensolver (twist_covariance);
125-
126- EXPECT_TRUE (isSymmetric (pose_covariance))
127- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt);
128- EXPECT_TRUE (isPositiveDefinite (pose_covariance, no_tag ()))
129- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt) << " \n "
130- << " Eigenvalues = " << pose_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
131- EXPECT_LT (conditionNumber (pose_covariance),
132- POSE_COVARIANCE_MAX_CONDITION_NUMBER)
133- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt) << " \n "
134- << " Eigenvalues = " << pose_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
135-
136- EXPECT_TRUE (isSymmetric (twist_covariance))
137- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt);
138- EXPECT_TRUE (isPositiveDefinite (twist_covariance, no_tag ()))
139- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt) << " \n "
140- << " Eigenvalues = " << twist_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
141- EXPECT_LT (conditionNumber (pose_covariance),
142- TWIST_COVARIANCE_MAX_CONDITION_NUMBER)
143- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt) << " \n "
144- << " Eigenvalues = " << twist_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
117+ testCovariance (pose_covariance, POSE_COVARIANCE_MAX_CONDITION_NUMBER);
118+ testCovariance (twist_covariance, TWIST_COVARIANCE_MAX_CONDITION_NUMBER);
145119
146120 // when the robot doesn't move the twist covariance should be exactly the
147121 // minimum twist covariance, which is defined as a diagonal covariance matrix
148122 // like this:
149123 // Odometry::DEFAULT_MINIMUM_TWIST_COVARIANCE * TwistCovariance::Identity()
150124 // where Odometry::DEFAULT_MINIMUM_TWIST_COVARIANCE == 1e-9
125+ const Eigen::IOFormat HeavyFmt (
126+ Eigen::FullPrecision, 0 , " , " , " ;\n " , " [" , " ]" , " [" , " ]" );
127+
151128 TwistCovariance minimum_twist_covariance = 1e-9 * TwistCovariance::Identity ();
152129 EXPECT_TRUE (((twist_covariance - minimum_twist_covariance).array () == 0 ).all ())
153130 << " Twist covariance =\n " << twist_covariance.format (HeavyFmt) << " \n "
@@ -306,34 +283,8 @@ TEST_F(DiffDriveControllerTest, testForward)
306283
307284 // check we have a positive definite covariance matrix
308285 // isCovariance = isSymmetric + isPositiveDefinite
309- const Eigen::IOFormat HeavyFmt (
310- Eigen::FullPrecision, 0 , " , " , " ;\n " , " [" , " ]" , " [" , " ]" );
311-
312- typedef Eigen::SelfAdjointEigenSolver<PoseCovariance> PoseEigenSolver;
313- typedef Eigen::SelfAdjointEigenSolver<TwistCovariance> TwistEigenSolver;
314-
315- PoseEigenSolver pose_eigensolver (pose_covariance);
316- TwistEigenSolver twist_eigensolver (twist_covariance);
317-
318- EXPECT_TRUE (isSymmetric (pose_covariance))
319- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt);
320- EXPECT_TRUE (isPositiveDefinite (pose_covariance, no_tag ()))
321- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt) << " \n "
322- << " Eigenvalues = " << pose_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
323- EXPECT_LT (conditionNumber (pose_covariance),
324- POSE_COVARIANCE_MAX_CONDITION_NUMBER)
325- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt) << " \n "
326- << " Eigenvalues = " << pose_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
327-
328- EXPECT_TRUE (isSymmetric (twist_covariance))
329- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt);
330- EXPECT_TRUE (isPositiveDefinite (twist_covariance, no_tag ()))
331- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt) << " \n "
332- << " Eigenvalues = " << twist_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
333- EXPECT_LT (conditionNumber (pose_covariance),
334- TWIST_COVARIANCE_MAX_CONDITION_NUMBER)
335- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt) << " \n "
336- << " Eigenvalues = " << twist_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
286+ testCovariance (pose_covariance, POSE_COVARIANCE_MAX_CONDITION_NUMBER);
287+ testCovariance (twist_covariance, TWIST_COVARIANCE_MAX_CONDITION_NUMBER);
337288
338289 // Take the last two odometry messages:
339290 std::vector<nav_msgs::Odometry> odoms = getLastOdoms ();
@@ -406,6 +357,9 @@ TEST_F(DiffDriveControllerTest, testForward)
406357 EXPECT_NEAR (yaw_0, yaw, std::numeric_limits<double >::epsilon ());
407358
408359 // Check new pose covariance is equal to the expected one:
360+ const Eigen::IOFormat HeavyFmt (
361+ Eigen::FullPrecision, 0 , " , " , " ;\n " , " [" , " ]" , " [" , " ]" );
362+
409363 EXPECT_TRUE (((pose_covariance_0_expected - pose_covariance_0).array ().abs () < 1e-5 ).all ())
410364 << " Pose covariance actual =\n " << pose_covariance_0.format (HeavyFmt)
411365 << " \n Pose covariance expected =\n " << pose_covariance_0_expected.format (HeavyFmt);
@@ -493,37 +447,8 @@ TEST_F(DiffDriveControllerTest, testTurn)
493447
494448 // check we have a positive definite covariance matrix
495449 // isCovariance = isSymmetric + isPositiveDefinite
496- const Eigen::IOFormat HeavyFmt (
497- Eigen::FullPrecision, 0 , " , " , " ;\n " , " [" , " ]" , " [" , " ]" );
498-
499- typedef Eigen::SelfAdjointEigenSolver<PoseCovariance> PoseEigenSolver;
500- typedef Eigen::SelfAdjointEigenSolver<TwistCovariance> TwistEigenSolver;
501-
502- PoseEigenSolver pose_eigensolver (pose_covariance);
503- TwistEigenSolver twist_eigensolver (twist_covariance);
504-
505- EXPECT_TRUE (pose_eigensolver.info () == Eigen::Success);
506- EXPECT_TRUE (twist_eigensolver.info () == Eigen::Success);
507-
508- EXPECT_TRUE (isSymmetric (pose_covariance))
509- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt);
510- EXPECT_TRUE (isPositiveDefinite (pose_covariance, no_tag ()))
511- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt) << " \n "
512- << " Eigenvalues = " << pose_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
513- EXPECT_LT (conditionNumber (pose_covariance),
514- POSE_COVARIANCE_MAX_CONDITION_NUMBER)
515- << " Pose covariance =\n " << pose_covariance.format (HeavyFmt) << " \n "
516- << " Eigenvalues = " << pose_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
517-
518- EXPECT_TRUE (isSymmetric (twist_covariance))
519- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt);
520- EXPECT_TRUE (isPositiveDefinite (twist_covariance, no_tag ()))
521- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt) << " \n "
522- << " Eigenvalues = " << twist_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
523- EXPECT_LT (conditionNumber (pose_covariance),
524- TWIST_COVARIANCE_MAX_CONDITION_NUMBER)
525- << " Twist covariance =\n " << twist_covariance.format (HeavyFmt) << " \n "
526- << " Eigenvalues = " << twist_eigensolver.eigenvalues ().transpose ().format (HeavyFmt);
450+ testCovariance (pose_covariance, POSE_COVARIANCE_MAX_CONDITION_NUMBER);
451+ testCovariance (twist_covariance, TWIST_COVARIANCE_MAX_CONDITION_NUMBER);
527452
528453 // Take the last two odometry messages:
529454 std::vector<nav_msgs::Odometry> odoms = getLastOdoms ();
@@ -596,6 +521,9 @@ TEST_F(DiffDriveControllerTest, testTurn)
596521 EXPECT_NEAR (yaw_0, yaw, ORIENTATION_TOLERANCE);
597522
598523 // Check new pose covariance is equal to the expected one:
524+ const Eigen::IOFormat HeavyFmt (
525+ Eigen::FullPrecision, 0 , " , " , " ;\n " , " [" , " ]" , " [" , " ]" );
526+
599527 EXPECT_TRUE (((pose_covariance_0_expected - pose_covariance_0).array ().abs () < 1e-5 ).all ())
600528 << " Pose covariance actual =\n " << pose_covariance_0.format (HeavyFmt)
601529 << " \n Pose covariance expected =\n " << pose_covariance_0_expected.format (HeavyFmt);
0 commit comments