Elements

class urdfgenpy.Origin(xyz=(0.0, 0.0, 0.0), rpy=(0.0, 0.0, 0.0))[source]

Bases: object

Pose of a link or joint relative to its parent frame.

Parameters:
xyz: tuple[float, float, float] = (0.0, 0.0, 0.0)
rpy: tuple[float, float, float] = (0.0, 0.0, 0.0)
to_xml(indent='')[source]

Return the ‘<origin>’ XML attribute string.

Parameters:

indent (str) – Leading whitespace prepended to the element.

Return type:

str

Returns:

A single-line ‘<origin xyz=”…” rpy=”…”/>’ XML string.

classmethod above(geometry, xy=(0.0, 0.0), rpy=(0.0, 0.0, 0.0))[source]

Return an origin that lifts geometry so its bottom sits at z=0.

Computes the Z offset as half the height for a :class:’~urdfgenpy.Box’, half the length for a :class:’~urdfgenpy.Cylinder’, or the radius for a :class:’~urdfgenpy.Sphere’.

Parameters:
  • geometry (Box | Cylinder | Sphere) – A :class:’Box’, :class:’Cylinder’, or :class:’Sphere’ instance.

  • xy (tuple[float, float]) – Optional (x, y) translation in metres (default ‘(0, 0)’).

  • rpy (tuple[float, float, float]) – Optional (roll, pitch, yaw) rotation in radians (default ‘(0, 0, 0)’).

Return type:

Origin

Returns:

An – class:’Origin’ with Z set so the geometry rests on the XY plane.

Raises:

ValueError – If geometry is not a supported primitive type.

classmethod wheel(xy=(0.0, 0.0), z=0.0)[source]

Return an origin with −pi/2 roll so a URDF cylinder becomes a wheel.

URDF cylinders default to the Z axis; applying −pi/2 roll reorients the symmetry axis to Y so the wheel disc lies in the XZ plane and rolls in the X direction.

Parameters:
  • xy (tuple[float, float]) – (x, y) position of the wheel centre in metres (default ‘(0, 0)’).

  • z (float) – Height of the wheel centre in metres (default ‘0’).

Return type:

Origin

Returns:

An – class:’Origin’ with ‘rpy = (-pi/2, 0, 0)’.

class urdfgenpy.Material(name, rgba=None, texture=None)[source]

Bases: object

Visual material - colour or texture.

Parameters:
  • name (str) – Unique material name referenced by :class:’Visual’.

  • rgba (Optional[tuple[float, float, float, float]]) – (r, g, b, a) colour, each in ‘’[0, 1]’’.

  • texture (Optional[str]) – Path to a texture file (mutually exclusive with rgba).

name: str
rgba: tuple[float, float, float, float] | None = None
texture: str | None = None
to_xml(indent='')[source]

Return the ‘<material>’ XML block string.

Parameters:

indent (str) – Leading whitespace prepended to each line.

Return type:

str

Returns:

A multi-line ‘<material>…</material>’ XML string.

class urdfgenpy.Visual(geometry, origin=<factory>, material=None, name=None)[source]

Bases: object

Rendered appearance of a link.

Parameters:
geometry: Box | Cylinder | Sphere
origin: Origin
material: Material | None = None
name: str | None = None
to_xml(indent='')[source]

Return the ‘<visual>’ XML block string.

Parameters:

indent (str) – Leading whitespace prepended to each line.

Return type:

str

Returns:

A multi-line ‘<visual>…</visual>’ XML string.

class urdfgenpy.Collision(geometry, origin=<factory>, name=None)[source]

Bases: object

Collision shape of a link used by physics engines.

Parameters:
geometry: Box | Cylinder | Sphere
origin: Origin
name: str | None = None
to_xml(indent='')[source]

Return the ‘<collision>’ XML block string.

Parameters:

indent (str) – Leading whitespace prepended to each line.

Return type:

str

Returns:

A multi-line ‘<collision>…</collision>’ XML string.

class urdfgenpy.Inertial(mass, matrix, origin=<factory>)[source]

Bases: object

Mass and inertia of a link.

Prefer the factory class methods over direct construction:

  • :meth:’from_geometry’ - auto-dispatch from any supported geometry

  • :meth:’from_box’, :meth:’from_cylinder’, :meth:’from_sphere’

Parameters:
  • mass (float) – Mass in kg.

  • matrix (InertiaMatrix) – 3x3 symmetric inertia tensor (upper triangle).

  • origin (Origin) – Pose of the centre of mass relative to the link frame.

mass: float
matrix: InertiaMatrix
origin: Origin
classmethod from_box(mass, length, w, h, origin=None, inertia_multiply=1.0)[source]

Create an :class:’Inertial’ for a solid box.

Parameters:
  • mass (float) – Mass in kg.

  • length (float) – Dimension along X (metres).

  • w (float) – Dimension along Y (metres).

  • h (float) – Dimension along Z (metres).

  • origin (Optional[Origin]) – Pose of the centre of mass; defaults to the link frame origin.

  • inertia_multiply (float) – Scalar multiplier on all inertia components (default 1.0).

Return type:

Inertial

Returns:

An – class:’Inertial’ with analytically computed box inertia.

classmethod from_sphere(mass, radius, origin=None, inertia_multiply=1.0)[source]

Create an :class:’Inertial’ for a solid sphere.

Parameters:
  • mass (float) – Mass in kg.

  • radius (float) – Sphere radius in metres.

  • origin (Optional[Origin]) – Pose of the centre of mass; defaults to the link frame origin.

  • inertia_multiply (float) – Scalar multiplier on all inertia components (default 1.0).

Return type:

Inertial

Returns:

An – class:’Inertial’ with analytically computed sphere inertia.

classmethod from_cylinder(mass, radius, length, origin=None, inertia_multiply=1.0)[source]

Create an :class:’Inertial’ for a solid cylinder.

Parameters:
  • mass (float) – Mass in kg.

  • radius (float) – Cylinder radius in metres.

  • length (float) – Cylinder length (height) in metres.

  • origin (Optional[Origin]) – Pose of the centre of mass; defaults to the link frame origin.

  • inertia_multiply (float) – Scalar multiplier on all inertia components (default 1.0).

Return type:

Inertial

Returns:

An – class:’Inertial’ with analytically computed cylinder inertia.

classmethod from_geometry(mass, geometry, origin=None, inertia_multiply=1.0)[source]

Create an :class:’Inertial’ by dispatching on the geometry type.

Delegates to :meth:’from_box’, :meth:’from_sphere’, or :meth:’from_cylinder’ based on the runtime type of geometry.

Parameters:
  • mass (float) – Mass in kg.

  • geometry (Box | Cylinder | Sphere) – A :class:’Box’, :class:’Cylinder’, or :class:’Sphere’ instance.

  • origin (Optional[Origin]) – Pose of the centre of mass; defaults to the link frame origin.

  • inertia_multiply (float) – Scalar multiplier on all inertia components (default 1.0).

Return type:

Inertial

Returns:

An – class:’Inertial’ with analytically computed inertia.

Raises:

ValueError – If geometry is not a supported primitive type.

to_xml(indent='')[source]

Return the ‘<inertial>’ XML block string.

Parameters:

indent (str) – Leading whitespace prepended to each line.

Return type:

str

Returns:

A multi-line ‘<inertial>…</inertial>’ XML string.