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 <string>
00041 #include <vector>
00042
00043 #include <ros/ros.h>
00044 #include <gtest/gtest.h>
00045
00046
00047 #include <rviz_visual_tools/rviz_visual_tools.h>
00048
00049 class RVTTest
00050 {
00051 public:
00052
00053
00054
00055
00056 rviz_visual_tools::RvizVisualToolsPtr visual_tools_;
00057
00058 bool initialize()
00059 {
00060 visual_tools_.reset(new rviz_visual_tools::RvizVisualTools("base", "/rviz_visual_tools"));
00061
00062
00063 ROS_INFO_STREAM_NAMED("test", "Waiting 4 seconds to start test...");
00064 return true;
00065 }
00066
00067 bool testAffine3d(const std::string& id, const Eigen::Affine3d& expect, const Eigen::Affine3d& actual)
00068 {
00069 static const double EPSILON = 0.000001;
00070 EXPECT_GT(EPSILON, fabs(expect.translation().x() - actual.translation().x()))
00071 << id << " Translation x - expect: " << expect.translation().x() << " actual: " << actual.translation().x();
00072 EXPECT_GT(EPSILON, fabs(expect.translation().y() - actual.translation().y()))
00073 << id << " Translation y - expect: " << expect.translation().y() << " actual: " << actual.translation().y();
00074 EXPECT_GT(EPSILON, fabs(expect.translation().z() - actual.translation().z()))
00075 << id << " Translation z - expect: " << expect.translation().z() << " actual: " << actual.translation().z();
00076
00077 Eigen::Quaterniond q1(expect.rotation());
00078 Eigen::Quaterniond q2(actual.rotation());
00079 EXPECT_GT(EPSILON, fabs(q1.x() - q2.x())) << id << " Quaternion x - expect: " << q1.x() << " actual: " << q2.x();
00080 EXPECT_GT(EPSILON, fabs(q1.y() - q2.y())) << id << " Quaternion y - expect: " << q1.y() << " actual: " << q2.y();
00081 EXPECT_GT(EPSILON, fabs(q1.z() - q2.z())) << id << " Quaternion z - expect: " << q1.z() << " actual: " << q2.z();
00082 EXPECT_GT(EPSILON, fabs(q1.w() - q2.w())) << id << " Quaternion w - expect: " << q1.w() << " actual: " << q2.w();
00083
00084 return true;
00085 }
00086
00087 bool testVector(const std::string& id, const std::vector<double>& expect, const std::vector<double>& actual)
00088 {
00089 EXPECT_EQ(expect.size(), actual.size()) << id << " Unequal vector sizes";
00090
00091 static const double EPSILON = 0.000001;
00092 for (std::size_t i = 0; i < expect.size(); ++i)
00093 {
00094 EXPECT_GT(EPSILON, fabs(expect[i] - actual[i])) << "Section " << id << ", Element " << i
00095 << ", Expect: " << expect[i] << ", Actual: " << actual[i];
00096 }
00097
00098 return true;
00099 }
00100 };
00101
00102
00103 RVTTest base;
00104
00105
00106 TEST(RVTTest, initialize) { ASSERT_TRUE(base.initialize()); }
00107
00108
00109 TEST(RVTTest, test_rpy_conversions)
00110 {
00111
00112 Eigen::Affine3d expected_affine = Eigen::Affine3d::Identity();
00113 std::vector<double> xyzrpy;
00114 base.visual_tools_->convertToXYZRPY(expected_affine, xyzrpy);
00115 std::vector<double> expected_vector;
00116 expected_vector.push_back(0);
00117 expected_vector.push_back(0);
00118 expected_vector.push_back(0);
00119 expected_vector.push_back(0);
00120 expected_vector.push_back(0);
00121 expected_vector.push_back(0);
00122 EXPECT_TRUE(base.testVector("Identity: ", expected_vector, xyzrpy));
00123
00124
00125 Eigen::Affine3d expected_affine2 = base.visual_tools_->convertFromXYZRPY(xyzrpy);
00126 EXPECT_TRUE(base.testAffine3d("Identity convert back", expected_affine, expected_affine2));
00127
00128
00129 expected_affine.translation().x() = 1;
00130 expected_affine.translation().y() = 2;
00131 expected_affine.translation().z() = 3;
00132 base.visual_tools_->convertToXYZRPY(expected_affine, xyzrpy);
00133 expected_vector[0] = 1;
00134 expected_vector[1] = 2;
00135 expected_vector[2] = 3;
00136 EXPECT_TRUE(base.testVector("123: ", expected_vector, xyzrpy));
00137
00138
00139 expected_affine2 = base.visual_tools_->convertFromXYZRPY(xyzrpy);
00140 EXPECT_TRUE(base.testAffine3d("123 convert back", expected_affine, expected_affine2));
00141
00142
00143 expected_vector[3] = 1;
00144 expected_vector[4] = 1.5;
00145 expected_vector[5] = 2;
00146
00147 expected_affine2 = base.visual_tools_->convertFromXYZRPY(expected_vector);
00148 base.visual_tools_->convertToXYZRPY(expected_affine2, xyzrpy);
00149 EXPECT_TRUE(base.testVector("Rotation", expected_vector, xyzrpy));
00150 }
00151
00152
00153 int main(int argc, char** argv)
00154 {
00155 testing::InitGoogleTest(&argc, argv);
00156 ros::init(argc, argv, "rviz_visual_tools_tests");
00157 return RUN_ALL_TESTS();
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167