SRDF β Semantic Robot Descriptionο
The SRDF (Semantic Robot Description Format) layer provides data structures, a parser, and a generator for MoveIt-compatible semantic information such as planning groups, named poses, and collision filters.
Data Modelsο
- class linkforge.core.SemanticRobotDescription(robot_name='', virtual_joints=<factory>, groups=<factory>, group_states=<factory>, end_effectors=<factory>, passive_joints=<factory>, disabled_collisions=<factory>, enabled_collisions=<factory>, no_default_collision_links=<factory>, link_sphere_approximations=<factory>, joint_properties=<factory>)[source]ο
Bases:
objectContainer for all semantic information (SRDF).
This class serves as the central repository for MoveIt-compatible metadata, including planning groups, collision filters, and named poses, that complement the kinematic robot model.
- Parameters:
robot_name (
str)virtual_joints (
Sequence[VirtualJoint])groups (
Sequence[PlanningGroup])group_states (
Sequence[GroupState])end_effectors (
Sequence[EndEffector])passive_joints (
Sequence[PassiveJoint])disabled_collisions (
Sequence[CollisionPair])enabled_collisions (
Sequence[CollisionPair])link_sphere_approximations (
Sequence[LinkSphereApproximation])joint_properties (
Sequence[JointProperty])
- virtual_joints: Sequence[VirtualJoint]ο
- groups: Sequence[PlanningGroup]ο
- group_states: Sequence[GroupState]ο
- end_effectors: Sequence[EndEffector]ο
- passive_joints: Sequence[PassiveJoint]ο
- disabled_collisions: Sequence[CollisionPair]ο
- enabled_collisions: Sequence[CollisionPair]ο
- link_sphere_approximations: Sequence[LinkSphereApproximation]ο
- joint_properties: Sequence[JointProperty]ο
- with_prefix(prefix)[source]ο
Create a new description with prefixed name and all sub-elements.
- Parameters:
prefix (
str) β The namespace prefix to apply.- Return type:
- Returns:
A new SemanticRobotDescription instance with all elements prefixed.
- merge_with(other)[source]ο
Merge another semantic description into this one, deduplicating elements.
- Parameters:
other (
SemanticRobotDescription) β The other semantic description to merge into this one.- Return type:
- Returns:
A new SemanticRobotDescription instance containing the combined elements.
- normalized()[source]ο
Return a new description with all components sorted.
This ensures that structural equality checks are order-independent.
- Return type:
- __init__(robot_name='', virtual_joints=<factory>, groups=<factory>, group_states=<factory>, end_effectors=<factory>, passive_joints=<factory>, disabled_collisions=<factory>, enabled_collisions=<factory>, no_default_collision_links=<factory>, link_sphere_approximations=<factory>, joint_properties=<factory>)ο
- Parameters:
robot_name (
str)virtual_joints (
Sequence[VirtualJoint])groups (
Sequence[PlanningGroup])group_states (
Sequence[GroupState])end_effectors (
Sequence[EndEffector])passive_joints (
Sequence[PassiveJoint])disabled_collisions (
Sequence[CollisionPair])enabled_collisions (
Sequence[CollisionPair])link_sphere_approximations (
Sequence[LinkSphereApproximation])joint_properties (
Sequence[JointProperty])
- class linkforge.core.PlanningGroup(name, links=<factory>, joints=<factory>, chains=<factory>, subgroups=<factory>)[source]ο
Bases:
objectA named collection of links, joints, or chains used for motion planning.
- Parameters:
- class linkforge.core.Chain(base_link, tip_link)[source]ο
Bases:
objectA kinematic chain defined by a base link and a tip link.
- class linkforge.core.GroupState(name, group, joint_values=<factory>)[source]ο
Bases:
objectA named set of joint values for a planning group (a pose).
- class linkforge.core.EndEffector(name, group, parent_link, parent_group=None)[source]ο
Bases:
objectDefines a planning group as an end effector.
- class linkforge.core.PassiveJoint(name)[source]ο
Bases:
objectA joint that is not actuated but exists in the kinematic chain.
- Parameters:
name (
str)
- class linkforge.core.VirtualJoint(name, type, parent_frame, child_link)[source]ο
Bases:
objectConnects the robot to a fixed frame in the world.
- class linkforge.core.CollisionPair(link1, link2, reason=None)[source]ο
Bases:
objectRepresents a collision rule between two specific links.
- class linkforge.core.LinkSphereApproximation(link, spheres=<factory>)[source]ο
Bases:
objectSphere-based collision geometry for a link.
- Parameters:
link (
str)spheres (
Sequence[SrdfSphere])
- spheres: Sequence[SrdfSphere]ο
- with_prefix(prefix)[source]ο
Create a new approximation with a prefixed link name.
- Parameters:
prefix (
str) β The namespace prefix to apply.- Return type:
- Returns:
A new LinkSphereApproximation instance with a prefixed link name.
- __init__(link, spheres=<factory>)ο
- Parameters:
link (
str)spheres (
Sequence[SrdfSphere])
- class linkforge.core.SrdfSphere(center_x, center_y, center_z, radius)[source]ο
Bases:
objectA collision sphere approximation.
- class linkforge.core.JointProperty(joint_name, property_name, value)[source]ο
Bases:
objectKey-value metadata for a joint.
SRDF Parserο
- class linkforge.core.SRDFParser(max_file_size=104857600, sandbox_root=None, resource_resolver=None)[source]ο
Bases:
RobotXMLParser[SemanticRobotDescription]Semantic Robot Description Format (SRDF) Parser.
This parser converts SRDF XML content into a structured
SemanticRobotDescriptionmodel. It supports MoveIt-specific tags such as planning groups, end effectors, and collision disabling.- Parameters:
max_file_size (
int)resource_resolver (
IResourceResolver|None)
- __init__(max_file_size=104857600, sandbox_root=None, resource_resolver=None)[source]ο
Initialize SRDF parser.
- Parameters:
max_file_size (
int) β Maximum allowed file size in bytes.sandbox_root (
Path|None) β Optional root directory for security sandbox.resource_resolver (
IResourceResolver|None) β Optional resolver for URIs.
- parse_string(content, **_kwargs)[source]ο
Parse SRDF content from a string.
- Parameters:
- Return type:
- Returns:
A SemanticRobotDescription model representing the SRDF.
- Raises:
RobotParserUnexpectedError β If the XML is malformed.
RobotParserXMLRootError β If the root tag is not <robot>.
- parse(filepath, **_kwargs)[source]ο
Load and parse an SRDF file from disk.
- Parameters:
- Return type:
- Returns:
A SemanticRobotDescription model.
- Raises:
RobotParserIOError β If the file is missing or exceeds max_file_size.
RobotParserXMLRootError β If the root tag is not <robot>.
SRDF Generatorο
- class linkforge.core.SRDFGenerator(pretty_print=True, srdf_path=None)[source]ο
Bases:
RobotXMLGeneratorSemantic Robot Description Format (SRDF) generator.
Usage Examplesο
Parse an existing SRDF fileο
from linkforge.core import SRDFParser
from pathlib import Path
srdf = SRDFParser().parse(Path("my_robot.srdf"))
print(f"Planning groups: {len(srdf.groups)}")
for group in srdf.groups:
print(f" {group.name}: {len(group.links)} links, {len(group.joints)} joints")
Build SRDF programmaticallyο
from linkforge.core import (
SemanticRobotDescription,
PlanningGroup,
GroupState,
CollisionPair,
)
srdf = SemanticRobotDescription(
robot_name="my_arm",
groups=[
PlanningGroup(
name="arm",
links=["base_link", "link1", "link2"],
joints=["joint1", "joint2"],
)
],
group_states=[
GroupState(name="home", group="arm", joint_values={"joint1": 0.0, "joint2": 0.0})
],
disabled_collisions=[
CollisionPair(link1="base_link", link2="link1", reason="Adjacent"),
],
)
Generate SRDF XMLο
from linkforge.core import SRDFGenerator
generator = SRDFGenerator()
srdf_string = generator.generate(srdf)
with open("my_robot.srdf", "w") as f:
f.write(srdf_string)
Round-trip (parse β modify β re-generate)ο
from linkforge.core import SRDFParser, SRDFGenerator, CollisionPair
from pathlib import Path
import dataclasses
original = SRDFParser().parse(Path("robot.srdf"))
# Add a new collision exclusion
updated = dataclasses.replace(
original,
disabled_collisions=[
*original.disabled_collisions,
CollisionPair(link1="hand_link", link2="wrist_link", reason="Adjacent"),
],
)
output = SRDFGenerator().generate(updated)
Path("robot_updated.srdf").write_text(output)
Note
SRDF data is also produced automatically by RobotBuilder.export_srdf() when
you use the group() and disable_collisions() helper methods. Direct
use of the parser and generator is mainly needed when working with existing
SRDF files. See the Composer reference for the higher-level API.