Skip to content

Commit 8b650a6

Browse files
committed
Add WithCovarianceStamped test
1 parent 1495b2f commit 8b650a6

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tf2_geometry_msgs/test/test_tf2_geometry_msgs.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,52 @@ TEST(TfGeometry, Conversions)
108108
EXPECT_NEAR(tf_from_msg.getOrigin().getZ(), tf_stamped_msg.transform.translation.z, EPS);
109109
EXPECT_EQ(tf_from_msg.frame_id_, tf_stamped_msg.header.frame_id);
110110
}
111+
{
112+
geometry_msgs::msg::PoseWithCovarianceStamped v1;
113+
v1.pose.pose.position.x = 1;
114+
v1.pose.pose.position.y = 2;
115+
v1.pose.pose.position.z = 3;
116+
v1.pose.pose.orientation.w = 0;
117+
v1.pose.pose.orientation.x = 1;
118+
v1.pose.pose.orientation.y = 0;
119+
v1.pose.pose.orientation.z = 0;
120+
v1.header.stamp = tf2_ros::toMsg(tf2::timeFromSec(2));
121+
v1.header.frame_id = "A";
122+
v1.pose.covariance = {
123+
1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
124+
1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
125+
1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
126+
1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
127+
1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
128+
1.0, 2.0, 3.0, 4.0, 5.0, 6.0,
129+
};
130+
const std::array<std::array<double, 6>, 6> cov{
131+
std::array<double, 6>{1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
132+
std::array<double, 6> {1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
133+
std::array<double, 6> {1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
134+
std::array<double, 6> {1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
135+
std::array<double, 6> {1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
136+
std::array<double, 6> {1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
137+
};
138+
139+
EXPECT_EQ(tf2::getCovarianceMatrix(v1), cov);
140+
141+
tf2::WithCovarianceStamped<tf2::Transform> tf_from_msg;
142+
tf2::convert(v1, tf_from_msg);
143+
EXPECT_EQ(tf_from_msg.getOrigin(), tf2::Vector3(1.0, 2.0, 3.0));
144+
EXPECT_EQ(tf_from_msg.getRotation(), tf2::Quaternion(1.0, 0.0, 0.0, 0.0));
145+
EXPECT_EQ(tf_from_msg.cov_mat_, cov);
146+
EXPECT_EQ(tf_from_msg.frame_id_, "A");
147+
EXPECT_EQ(tf_from_msg.stamp_, tf2::timeFromSec(2));
148+
149+
tf_from_msg.setRotation({0.0, 0.0, 0.0, 1.0});
150+
v1.pose.pose.orientation.w = 1;
151+
v1.pose.pose.orientation.x = 0;
152+
153+
geometry_msgs::msg::PoseWithCovarianceStamped v2;
154+
tf2::convert(tf_from_msg, v2);
155+
EXPECT_EQ(v1, v2);
156+
}
111157
}
112158

113159
TEST(TfGeometry, Frame)

0 commit comments

Comments
 (0)