Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Dm control TCP Initializer

From Leeroopedia
Knowledge Sources
Domains Composer, Manipulation, Initialization
Last Updated 2026-02-15 04:00 GMT

Overview

ToolCenterPointInitializer is a Composer initializer that sets the pose of a robot hand's tool center point (TCP) via inverse kinematics with optional rejection sampling for collision avoidance.

Description

ToolCenterPointInitializer extends composer.Initializer and accepts a hand, arm, position/quaternion variations, and IK/rejection sampling parameters. When called, it determines the target site (either the hand's tool center point or the arm's wrist site if no hand is provided) and performs rejection sampling over target poses.

For each sample, it evaluates position and quaternion variations using variation.evaluate, then calls arm.set_site_to_xpos() to solve inverse kinematics. If successful, it recalculates physics contacts and checks for "relevant collisions" via _has_relevant_collisions(). This method examines contacts to find arm-arm self-collisions, arm-hand collisions, and collisions between the robot and external bodies that do not have a freejoint (fixed scene elements). Collisions with free-floating objects are intentionally allowed since these objects can move out of the way.

If IK fails or collisions are detected, the arm joints are reset to their original configuration and a new target is sampled. After exhausting all attempts, it raises EpisodeInitializationError.

Usage

Use this initializer in manipulation task environments where the robot end-effector needs to start at a randomized but physically valid pose. It is particularly useful when the initial TCP position should avoid self-collisions and collisions with fixed scene geometry.

Code Reference

Source Location

Signature

class ToolCenterPointInitializer(composer.Initializer):
    def __init__(self,
                 hand,
                 arm,
                 position,
                 quaternion=base.DOWN_QUATERNION,
                 ignore_collisions=False,
                 max_ik_attempts=10,
                 max_rejection_samples=10):

    def _has_relevant_collisions(self, physics):

    def __call__(self, physics, random_state):

Import

from dm_control.composer.initializers.tcp_initializer import ToolCenterPointInitializer

I/O Contract

Inputs

Name Type Required Description
hand base.RobotHand or None Yes A RobotHand instance, or None to use arm.wrist_site as TCP
arm base.RobotArm Yes A RobotArm instance providing IK solving
position array or Variation Yes Fixed Cartesian position or a Variation object that generates positions
quaternion array or Variation No Fixed unit quaternion or a Variation (default: base.DOWN_QUATERNION)
ignore_collisions bool No If True, disables rejection sampling for collisions (default: False)
max_ik_attempts int No Maximum IK attempts per rejection sample (default: 10)
max_rejection_samples int No Maximum number of TCP target poses to sample (default: 10)

Outputs

Name Type Description
(side effect) None Sets joint positions on the physics instance to achieve the target TCP pose

Exceptions

Exception Condition
composer.EpisodeInitializationError Raised when a valid collision-free configuration cannot be found within the maximum attempts

Usage Examples

from dm_control.composer.initializers.tcp_initializer import ToolCenterPointInitializer
from dm_control.composer import variation

# Create a TCP initializer with randomized position
tcp_init = ToolCenterPointInitializer(
    hand=my_hand,
    arm=my_arm,
    position=variation.Uniform(low=[0.3, -0.2, 0.1], high=[0.5, 0.2, 0.4]),
    quaternion=variation.Uniform(low=[-1, -1, -1, -1], high=[1, 1, 1, 1]),
    ignore_collisions=False,
    max_ik_attempts=10,
    max_rejection_samples=20,
)

# Use during episode initialization
tcp_init(physics, random_state)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment