Skip to content

Commit 4c1b964

Browse files
authored
Merge pull request #538 from dimensionalOS/ros_transform_test
Validating transforms with ros examples Former-commit-id: 4dfc722 [formerly e192231] Former-commit-id: 1a6a287
1 parent cbe7cb1 commit 4c1b964

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

dimos/msgs/geometry_msgs/Transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __repr__(self) -> str:
5353
return f"Transform(translation={self.translation!r}, rotation={self.rotation!r})"
5454

5555
def __str__(self) -> str:
56-
return f"Transform:\n Translation: {self.translation}\n Rotation: {self.rotation}"
56+
return f"Transform:\n {self.frame_id} -> {self.child_frame_id} Translation: {self.translation}\n Rotation: {self.rotation}"
5757

5858
def __eq__(self, other) -> bool:
5959
"""Check if two transforms are equal."""

dimos/msgs/geometry_msgs/test_Transform.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import math
1516
import time
1617

1718
import numpy as np
@@ -331,6 +332,38 @@ def test_transform_from_pose():
331332
assert transform.child_frame_id == "base_link" # passed as first argument
332333

333334

335+
# validating results from example @
336+
# https://foxglove.dev/blog/understanding-ros-transforms
337+
def test_transform_from_ros():
338+
"""Test converting PoseStamped to Transform"""
339+
test_time = time.time()
340+
pose_stamped = PoseStamped(
341+
ts=test_time,
342+
frame_id="base_link",
343+
position=Vector3(1, -1, 0),
344+
orientation=Quaternion.from_euler(Vector3(0, 0, math.pi / 6)),
345+
)
346+
transform_base_link_to_arm = Transform.from_pose("arm_base_link", pose_stamped)
347+
348+
transform_arm_to_end = Transform.from_pose(
349+
"end",
350+
PoseStamped(
351+
ts=test_time,
352+
frame_id="arm_base_link",
353+
position=Vector3(1, 1, 0),
354+
orientation=Quaternion.from_euler(Vector3(0, 0, math.pi / 6)),
355+
),
356+
)
357+
358+
print(transform_base_link_to_arm)
359+
print(transform_arm_to_end)
360+
361+
end_effector_global_pose = transform_base_link_to_arm + transform_arm_to_end
362+
363+
assert end_effector_global_pose.translation.x == pytest.approx(1.366, abs=1e-3)
364+
assert end_effector_global_pose.translation.y == pytest.approx(0.366, abs=1e-3)
365+
366+
334367
def test_transform_from_pose_stamped():
335368
"""Test converting PoseStamped to Transform"""
336369
# Create a PoseStamped with position, orientation, timestamp and frame

dimos/protocol/tf/test_tf.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,45 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import math
1718
import time
1819

20+
import pytest
21+
1922
from dimos.core import TF
2023
from dimos.msgs.geometry_msgs import PoseStamped, Quaternion, Transform, Vector3
2124
from dimos.protocol.tf import MultiTBuffer, TBuffer
2225

2326

27+
# from https://foxglove.dev/blog/understanding-ros-transforms
28+
def test_tf_ros_example():
29+
tf = TF()
30+
31+
base_link_to_arm = Transform(
32+
translation=Vector3(1.0, -1.0, 0.0),
33+
rotation=Quaternion.from_euler(Vector3(0, 0, math.pi / 6)),
34+
frame_id="base_link",
35+
child_frame_id="arm",
36+
ts=time.time(),
37+
)
38+
39+
arm_to_end = Transform(
40+
translation=Vector3(1.0, 1.0, 0.0),
41+
rotation=Quaternion(0.0, 0.0, 0.0, 1.0), # Identity rotation
42+
frame_id="arm",
43+
child_frame_id="end_effector",
44+
ts=time.time(),
45+
)
46+
47+
tf.publish(base_link_to_arm, arm_to_end)
48+
time.sleep(0.2)
49+
50+
end_effector_global_pose = tf.get("base_link", "end_effector")
51+
52+
assert end_effector_global_pose.translation.x == pytest.approx(1.366, abs=1e-3)
53+
assert end_effector_global_pose.translation.y == pytest.approx(0.366, abs=1e-3)
54+
55+
2456
def test_tf_main():
2557
"""Test TF broadcasting and querying between two TF instances.
2658
If you run foxglove-bridge this will show up in the UI"""

0 commit comments

Comments
 (0)