Skip to content

Lookup Transform

SUMMARY

lookup_transform returns the transform from a source frame to a target frame, anywhere in the tree, as a 4x4 matrix or a pose in the requested rot_type.

UNITS

The returned position component is in meters, whether returned as a (4, 4) matrix (rot_type="mat") or a pose list. Rotation is in degrees ("deg"), radians ("rad"), or unitless ("quat").

The Skill

python
camera_pose_world = tree.lookup_transform("camera", "world", rot_type="deg")

Example

The transform between two frames in a TransformTree, visualized in Rerun

A robot and camera frame, with the transform between them looked up directly.

The Code

python
"""
Example of TransformTree.lookup_transform.
"""

from loguru import logger

from telekinesis.tf import tftree


def main():
    """
    Get the transform between any two frames in the tree.
    """
    tree = tftree.TransformTree("world")
    tree.add("world", "robot", [1, 0, 0, 0, 0, 0], rot_type="deg")
    tree.add("robot", "camera", [0, 0, 0.5, 0, 0, 0], rot_type="deg")

    world_T_camera = tree.lookup_transform("world", "camera")
    logger.info(f"world_T_camera:\n{world_T_camera}")

    camera_pose_world = tree.lookup_transform("camera", "world", rot_type="deg")
    logger.info(f"camera_pose_world (deg): {camera_pose_world}")

    tree.visualize_rerun(axis_len=0.5)

if __name__ == "__main__":
    main()

Parameter Configuration

ParameterTypeDefaultDescription
source_namestrrequiredThe name of the frame the returned transform is expressed relative to.
target_namestrrequiredThe name of the frame to look up.
rot_typestr"mat"One of "deg", "rad", "quat", "mat".

Returns

TypeDescription
np.ndarray | listThe transform from source_name to target_name, as a (4, 4) matrix (rot_type="mat") or a pose list.

Raises

ExceptionCondition
TypeErrorsource_name is not a string.
TypeErrortarget_name is not a string.
ValueErrorrot_type is not one of "deg", "rad", "quat", "mat".
ValueErrorEither source_name or target_name does not exist in the tree.