9 #include "gtest/gtest.h" 12 #include <sensor_msgs/Imu.h> 13 #include <sensor_msgs/MagneticField.h> 15 #include <tf2_geometry_msgs/tf2_geometry_msgs.h> 19 for (
size_t i = 0; i < 9; ++i)
20 EXPECT_NEAR(c1[i], c2[i], 1e-6) <<
"Wrong value at position " << i;
23 TEST(Covariance, Transform)
25 boost::array<double, 9> in = {1, 0, 0, 0, 2, 0, 0, 0, 3};
26 boost::array<double, 9> expectedOut = {1, 0, 0, 0, 2, 0, 0, 0, 3};
27 boost::array<double, 9> out{};
28 Eigen::Quaterniond q(1, 0, 0, 0);
32 q = Eigen::Quaterniond(Eigen::AngleAxisd(M_PI_2, Eigen::Vector3d(0, 0, 1)));
33 expectedOut = {2, 0, 0, 0, 1, 0, 0, 0, 3};
41 q = Eigen::Quaterniond(Eigen::AngleAxisd(M_PI_2, Eigen::Vector3d(1, 0, 0)));
42 expectedOut = {1, 0, 0, 0, 3, 0, 0, 0, 2};
50 q = Eigen::Quaterniond(Eigen::AngleAxisd(M_PI_2, Eigen::Vector3d(0, 1, 0)));
51 expectedOut = {3, 0, 0, 0, 2, 0, 0, 0, 1};
59 q = Eigen::Quaterniond(Eigen::AngleAxisd(M_PI_2, Eigen::Vector3d(1, 1, 1)));
60 expectedOut = {2.5, -0.5, 3, 1, 0, -1, -1.5, 2, 0.5};
65 expectedOut = {1.5, -1, 1, 2, 2, -1.5, -0.5, 3, -0.5};
73 msg.header.stamp.sec = 1;
74 msg.header.stamp.nsec = 2;
82 msg.header.frame_id =
"test";
89 msg.header.frame_id =
"test2";
90 msg.header.stamp.sec = 1;
91 msg.angular_velocity.x = 1;
92 msg.angular_velocity.y = 2;
93 msg.angular_velocity.z = 3;
94 msg.angular_velocity_covariance = {1, 0, 0, 0, 2, 0, 0, 0, 3};
95 msg.linear_acceleration.x = 1;
96 msg.linear_acceleration.y = 2;
97 msg.linear_acceleration.z = 3;
98 msg.linear_acceleration_covariance = {1, 0, 0, 0, 2, 0, 0, 0, 3};
99 msg.orientation.w = 1;
100 msg.orientation_covariance = {1, 0, 0, 0, 2, 0, 0, 0, 3};
105 tf.header.frame_id =
"test";
106 tf.header.stamp.sec = 1;
107 tf.child_frame_id =
"test2";
108 tf.transform.translation.x = 1e6;
109 tf.transform.translation.y = 2e6;
110 tf.transform.translation.z = -3e6;
111 tf.transform.rotation.w = 1;
118 sensor_msgs::Imu msg;
121 geometry_msgs::TransformStamped
tf;
128 sensor_msgs::Imu out;
133 EXPECT_EQ(
"test", out.header.frame_id);
134 EXPECT_EQ(msg.header.stamp, out.header.stamp);
135 EXPECT_NEAR(-msg.angular_velocity.y, out.angular_velocity.x, 1e-6);
136 EXPECT_NEAR(msg.angular_velocity.x, out.angular_velocity.y, 1e-6);
137 EXPECT_NEAR(msg.angular_velocity.z, out.angular_velocity.z, 1e-6);
138 EXPECT_NEAR(-msg.linear_acceleration.y, out.linear_acceleration.x, 1e-6);
139 EXPECT_NEAR(msg.linear_acceleration.x, out.linear_acceleration.y, 1e-6);
140 EXPECT_NEAR(msg.linear_acceleration.z, out.linear_acceleration.z, 1e-6);
157 sensor_msgs::Imu msg;
160 geometry_msgs::TransformStamped
tf;
164 q.
setRPY(M_PI, 0, M_PI_2);
167 sensor_msgs::Imu out;
172 EXPECT_EQ(
"test", out.header.frame_id);
173 EXPECT_EQ(msg.header.stamp, out.header.stamp);
174 EXPECT_NEAR(msg.angular_velocity.y, out.angular_velocity.x, 1e-6);
175 EXPECT_NEAR(msg.angular_velocity.x, out.angular_velocity.y, 1e-6);
176 EXPECT_NEAR(-msg.angular_velocity.z, out.angular_velocity.z, 1e-6);
177 EXPECT_NEAR(msg.linear_acceleration.y, out.linear_acceleration.x, 1e-6);
178 EXPECT_NEAR(msg.linear_acceleration.x, out.linear_acceleration.y, 1e-6);
179 EXPECT_NEAR(-msg.linear_acceleration.z, out.linear_acceleration.z, 1e-6);
194 sensor_msgs::MagneticField msg;
195 msg.header.stamp.sec = 1;
196 msg.header.stamp.nsec = 2;
203 sensor_msgs::MagneticField msg;
204 msg.header.frame_id =
"test";
211 msg.header.frame_id =
"test2";
212 msg.header.stamp.sec = 1;
213 msg.magnetic_field.x = 1;
214 msg.magnetic_field.y = 2;
215 msg.magnetic_field.z = 3;
216 msg.magnetic_field_covariance = {1, 0, 0, 0, 2, 0, 0, 0, 3};
223 sensor_msgs::MagneticField msg;
226 geometry_msgs::TransformStamped
tf;
233 sensor_msgs::MagneticField out;
236 EXPECT_EQ(
"test", out.header.frame_id);
237 EXPECT_EQ(msg.header.stamp, out.header.stamp);
238 EXPECT_NEAR(-msg.magnetic_field.y, out.magnetic_field.x, 1e-6);
239 EXPECT_NEAR(msg.magnetic_field.x, out.magnetic_field.y, 1e-6);
240 EXPECT_NEAR(msg.magnetic_field.z, out.magnetic_field.z, 1e-6);
249 sensor_msgs::MagneticField msg;
252 geometry_msgs::TransformStamped
tf;
256 q.
setRPY(M_PI, 0, M_PI_2);
259 sensor_msgs::MagneticField out;
262 EXPECT_EQ(
"test", out.header.frame_id);
263 EXPECT_EQ(msg.header.stamp, out.header.stamp);
264 EXPECT_NEAR(msg.magnetic_field.y, out.magnetic_field.x, 1e-6);
265 EXPECT_NEAR(msg.magnetic_field.x, out.magnetic_field.y, 1e-6);
266 EXPECT_NEAR(-msg.magnetic_field.z, out.magnetic_field.z, 1e-6);
271 int main(
int argc,
char **argv)
273 testing::InitGoogleTest(&argc, argv);
274 return RUN_ALL_TESTS();
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
const std::string & getFrameId(const T &t)
void transformCovariance(const boost::array< double, 9 > &in, boost::array< double, 9 > &out, Eigen::Quaternion< double > r)
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
Quaternion inverse() const
const ros::Time & getTimestamp(const T &t)
void convert(const A &a, B &b)
tf2Scalar angleShortestPath(const Quaternion &q) const