Skip to content

Add Tree

SUMMARY

add_tree grafts the root of another TransformTree onto an existing frame, given the transform between the source frame and the subtree's root.

Unlike add and update, add_tree requires transform to already be a 4x4 np.ndarray — it does not accept a 6/7-element pose list, even with rot_type set.

UNITS

transform's translation is in meters.

The Skill

python
from telekinesis.tf import tftree, tfutils

subtree = tftree.TransformTree("gripper")
camera_T_gripper = tfutils.pose_to_transformation_matrix([0, 0, 0.1, 0, 0, 0], rot_type="deg")
tree.add_tree("camera", subtree, camera_T_gripper)

Example

A subtree grafted onto an existing frame in a TransformTree, visualized in Rerun

A mount subtree, with a robot frame of its own, grafted onto the table frame.

The Code

python
"""
Example of TransformTree.add_tree.
"""

from loguru import logger

from telekinesis.tf import tftree, tfutils


def main():
    """
    Graft another TransformTree in as a subtree.
    """
    tree = tftree.TransformTree("world")
    tree.add("world", "table", [1, 0, 0, 0, 0, 0], rot_type="deg")

    subtree = tftree.TransformTree("mount")
    subtree.add("mount", "robot", [0, 0, 0, 90, 0, 0], rot_type="deg")

    # add_tree requires transform as a 4x4 matrix, unlike add()/update() it does not accept a pose list

    table_T_mount = tfutils.pose_to_transformation_matrix([0.1, 0.1, 0.2, 0, 0, 0], rot_type="deg")
    tree.add_tree("table", subtree, table_T_mount)

    logger.info(f"Frames after add_tree: {list(tree.get_all_frames(reference_node_name='world').keys())}")

    tree.visualize_rerun(axis_len=0.5)

if __name__ == "__main__":
    main()

Parameter Configuration

ParameterTypeDefaultDescription
source_namestrrequiredThe name of the existing frame to graft the subtree onto.
subtreeTransformTreerequiredThe tree whose root becomes a child of source_name.
transformnp.ndarrayrequiredThe (4, 4) transform from source_name to the subtree's root. Must already be a matrix, a pose list is not accepted regardless of rot_type.
rot_typestr"mat"One of "deg", "rad", "quat", "mat".

Raises

ExceptionCondition
ValueErrorsource_name is not a string.
ValueErrorsubtree is not a TransformTree.
ValueErrortransform is not a (4, 4) np.ndarray.
ValueErrorrot_type is not one of "deg", "rad", "quat", "mat".
ValueErrorNo frame named source_name exists in the tree.