Skip to content

Change Parent

SUMMARY

change_parent re-parents a frame under a different frame, preserving its pose in the world by recomputing its transform to the new parent.

The Skill

python
tree.change_parent("camera", "base_link")

Example

A frame re-parented in a TransformTree, visualized in Rerun

The camera frame re-parented under a different frame, with its pose in the world unchanged.

The Code

python
"""
Example of TransformTree.change_parent.
"""

from loguru import logger

from telekinesis.tf import tftree


def main():
    """
    Move a frame under a different parent, keeping its pose in the world.
    """
    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")

    logger.info(f"Parent before: {tree.get_parent('camera').get_name()}")

    tree.change_parent("camera", "world")
    logger.info(f"Parent after: {tree.get_parent('camera').get_name()}")
    logger.info(f"camera pose in world (unchanged): {tree.lookup_transform('world', 'camera')}")

    tree.visualize_rerun(axis_len=0.5)

if __name__ == "__main__":
    main()

Parameter Configuration

ParameterTypeDefaultDescription
node_namestrrequiredThe name of the frame to move.
new_parent_namestrrequiredThe name of the frame to re-parent it under.

Raises

ExceptionCondition
TypeErrornode_name is not a string.
TypeErrornew_parent_name is not a string.
ValueErrorEither node_name or new_parent_name does not exist in the tree.