Robot

class urdfgenpy.Robot(name)[source]

Bases: object

Root container that holds links, joints, and global materials.

Build the robot by calling

:meth:’add_link’ :meth:’add_joint’ :meth:’add_material’,

then export with

:meth:’save’ :meth:’to_urdf’, :meth:’to_xacro’.

Parameters:

name (str) – Robot name embedded in the <robot> tag.

Register a :class:’Link’ and return ‘self’ for chaining.

Parameters:

link (Link) – The link to add.

Return type:

Robot

Returns:

This – class:’Robot’ instance.

Raises:

ValueError – If a link with the same name already exists.

add_joint(joint)[source]

Register a :class:’Joint’ and return ‘self’ for chaining.

Both the parent and child links must already be registered before calling this method.

Parameters:

joint (Joint) – The joint to add.

Return type:

Robot

Returns:

This – class:’Robot’ instance.

Raises:

ValueError – If a joint with the same name already exists, or if the parent or child link has not been registered.

add_material(material)[source]

Register a global :class:’Material’ and return ‘self’ for chaining.

Parameters:

material (Material) – The material to add.

Return type:

Robot

Returns:

This – class:’Robot’ instance.

All registered links in insertion order.

property joints: list[Joint]

All registered joints in insertion order.

property materials: list[Material]

All registered global materials in insertion order.

Return the :class:’Link’ registered under name.

Parameters:

name (str) – Link name.

Return type:

Link

Returns:

The matching – class:’Link’.

Raises:

KeyError – If no link with that name exists.

get_joint(name)[source]

Return the :class:’Joint’ registered under name.

Parameters:

name (str) – Joint name.

Return type:

Joint

Returns:

The matching – class:’Joint’.

Raises:

KeyError – If no joint with that name exists.

to_urdf(output_path=None)[source]

Serialize the robot to a URDF XML string.

Parameters:

output_path (Optional[str]) – If provided, also write the XML to this file path.

Return type:

str

Returns:

The complete URDF XML string.

to_xacro(output_path=None)[source]

Serialize the robot to a Xacro XML string.

The output includes standard inertia macros and an ‘INERTIA_MULTIPLY’ property, making the file easy to parameterise further.

Parameters:

output_path (Optional[str]) – If provided, also write the XML to this file path.

Return type:

str

Returns:

The complete Xacro XML string.

save(output_path)[source]

Write the robot to output_path, inferring format from the extension.

Uses :meth:’to_xacro’ for ‘.xacro’ files and :meth:’to_urdf’ for everything else.

Parameters:

output_path (str) – Destination file path (e.g. ‘robot.urdf’ or ‘robot.xacro’).

Return type:

None

tree_string()[source]

Return the kinematic chain as a plain-text ASCII tree.

Return type:

str

Returns:

A multi-line string with the root link at the top and each child indented below its parent joint.

save_tree(output_path)[source]

Write the plain-text kinematic tree to a file.

Parameters:

output_path (str) – Destination file path.

Return type:

None

print_tree()[source]

Print the kinematic chain as a coloured ASCII tree from root to leaves.

Joint types are colour-coded: fixed (gray), revolute (cyan), continuous (blue), prismatic (magenta), floating/planar (red).

Return type:

None