Skip to content

Commit 14b378d

Browse files
committed
Add direct transform test.
Signed-off-by: Florian Vahl <git@flova.de>
1 parent e871279 commit 14b378d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tf2_sensor_msgs/test/test_tf2_sensor_msgs.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from sensor_msgs_py.point_cloud2 import create_cloud_xyz32, read_points
3636
from std_msgs.msg import Header
3737
from tf2_ros import TransformStamped
38-
from tf2_sensor_msgs.tf2_sensor_msgs import do_transform_cloud
38+
from tf2_sensor_msgs.tf2_sensor_msgs import do_transform_cloud, transform_points
3939

4040

4141
class PointCloudConversions(unittest.TestCase):
@@ -112,6 +112,23 @@ def test_rotation_and_translation_transform(self):
112112
new_points = np.array(list(read_points(point_cloud_transformed)))
113113
self.assertTrue(np.allclose(expected_coordinates, new_points))
114114

115+
def test_direct_transform(self):
116+
# Create atransform combining a 100m z translation with
117+
# a 180° rotation around the x-axis
118+
transform = TransformStamped()
119+
transform.transform.translation.z = 100.0
120+
transform.transform.rotation.x = 1.0
121+
transform.transform.rotation.w = 6.123234e-17
122+
123+
# Transform points
124+
points = transform_points(self.points, transform)
125+
126+
# Expected output
127+
expected_coordinates = np.array([[1, -2, 100], [10, -20, 70]], dtype=np.float32)
128+
129+
# Compare to ground truth
130+
self.assertTrue(np.allclose(expected_coordinates, points))
131+
115132

116133
if __name__ == '__main__':
117134
unittest.main()

0 commit comments

Comments
 (0)