LinkForge Composer APIο
The Composer provides a high-level, fluent API for programmatically constructing and assembling robot models. It is designed to be ergonomic, human-readable, and robust.
RobotBuilderο
The main entry point for constructing a robot model.
Tip
Context Managers & Cloning
RobotBuilder supports deep cloning via .clone(), allowing you to use a base builder as a template and fork it into multiple variations.
Additionally, LinkBuilder supports context managers (with builder.link(...)) to automatically set the parent context for nested links, removing the need to manually specify the parent= argument.
- class linkforge.core.RobotBuilder(name=None, robot=None)[source]ο
Bases:
objectA high-level API to compose robots programmatically.
This class serves as the entry point for building robots. It can create new robots from scratch or modify existing ones by adding links or attaching sub-components.
- __init__(name=None, robot=None)[source]ο
Initialize a new robot builder.
- Parameters:
- Raises:
RobotModelError β If neither name nor robot is provided.
- attach(component, at_link, joint_name=None, prefix='', joint_type=JointType.FIXED, xyz=(0, 0, 0), rpy=(0, 0, 0), axis=None, limits=None, disable_collision=False, reason='Adjacent')[source]ο
Merge another robot or assembly into the current one.
- Parameters:
component (
Robot|IComposer) β The Robot or IComposer (e.g. RobotBuilder) to attach.at_link (
str) β The link in the current robot to attach to.joint_name (
str|None) β Optional name for the connecting joint.prefix (
str) β Optional prefix for all links/joints in the component.joint_type (
JointType) β Type of connecting joint.xyz (
tuple[float,float,float]) β Joint origin translation.axis (
tuple[float,float,float] |None) β Optional joint axis (automatically normalized).limits (
tuple[float,float] |None) β Optional (lower, upper) joint limits.disable_collision (
bool) β Whether to disable collision checking at the interface.reason (
str) β Semantic reason for disabling collisions (e.g., βAdjacentβ).
- Return type:
- Returns:
The RobotBuilder instance.
- material(name, color=None)[source]ο
Define a global material that can be reused by multiple links.
- ros2_control(name, hardware_plugin, control_type='system', parameters=None)[source]ο
Add a global ros2_control system configuration.
- Parameters:
- Return type:
- Returns:
The RobotBuilder instance.
- property semantic: SemanticBuilderο
Access the semantic (SRDF/MoveIt) construction API.
Example
>>> builder.semantic.group("arm", links=["link1", "link2"])
- clone()[source]ο
Create a deep copy of the builder and its robot state.
- Return type:
- Returns:
A new independent RobotBuilder instance with cloned state.
- build(validate=True)[source]ο
Finalize the assembly and return the completed Robot model.
- Parameters:
validate (
bool) β If True, performs a kinematic check for disconnected links or cycles.- Return type:
- Returns:
The completed Robot object.
- Raises:
RobotValidationError β If validation is requested and the robot is invalid.
LinkBuilderο
A staged builder for configuring individual links and their parent joints.
- class linkforge.core.LinkBuilder(builder, name, parent=None, joint_name=None)[source]ο
Bases:
objectStaged fluent builder for programmatic link and joint construction.
This builder accumulates link and joint properties in stages. It is usually returned by builder.link() or link_builder.child().
- __init__(builder, name, parent=None, joint_name=None)[source]ο
Initialize a new LinkBuilder. Internal use only.
- __enter__()[source]ο
Enter the context of this link.
Pushes this linkβs name onto the parent stack, making it the default parent for any links created within this block.
- Return type:
- __exit__(exc_type, exc_val, exc_tb)[source]ο
Exit the context of this link.
Pops this linkβs name from the parent stack and automatically commits the link to flush its configured properties if no exception occurred.
- Parameters:
exc_type (
type[BaseException] |None)exc_val (
BaseException|None)exc_tb (
Any)
- Return type:
- visual(geometry, xyz=(0, 0, 0), rpy=(0, 0, 0), material=None, name=None)[source]ο
Add a visual representation to the link.
- Parameters:
geometry (
Box|Cylinder|Sphere|Mesh) β Shape of the visual (e.g., box(), cylinder()).xyz (
tuple[float,float,float]) β Translation relative to the link frame.rpy (
tuple[float,float,float]) β Rotation (roll-pitch-yaw) in radians.material (
str|Material|None) β Material name or Material object.name (
str|None) β Optional name for this visual element.
- Return type:
- Returns:
The LinkBuilder instance for chaining.
- collision(geometry=None, xyz=None, rpy=None, name=None)[source]ο
Add a collision geometry to the link.
If no arguments are provided, it automatically clones the last added visual elementβs geometry and origin.
- Parameters:
geometry (
Box|Cylinder|Sphere|Mesh|None) β Shape of the collision element.xyz (
tuple[float,float,float] |None) β Translation relative to the link frame.rpy (
tuple[float,float,float] |None) β Rotation relative to the link frame.name (
str|None) β Optional name for this collision element.
- Return type:
- Returns:
The LinkBuilder instance.
- mass(value, origin_xyz=None, origin_rpy=None, inertia=None)[source]ο
Define the mass and center of gravity for the link.
If no inertia is provided, LinkForge will automatically calculate the inertia tensor based on the linkβs geometry and mass during commit().
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- inertia(ixx, iyy, izz, ixy=0, ixz=0, iyz=0)[source]ο
Manually specify the inertia tensor components.
- at_origin(xyz=(0, 0, 0), rpy=(0, 0, 0))[source]ο
Set the transform from the parent link to this linkβs frame.
- revolute(axis, limits, name=None, xyz=None, rpy=None, effort=10.0, velocity=1.0)[source]ο
Configure the connection as a REVOLUTE (limited rotation) joint.
- Parameters:
axis (
tuple[float,float,float]) β Rotation axis unit vector.limits (
tuple[float,float]) β (lower, upper) joint limits in radians.xyz (
tuple[float,float,float] |None) β Joint origin translation.rpy (
tuple[float,float,float] |None) β Joint origin rotation.effort (
float) β Maximum joint effort.velocity (
float) β Maximum joint velocity.
- Return type:
- Returns:
The LinkBuilder instance.
- continuous(axis, name=None, xyz=None, rpy=None, effort=10.0, velocity=1.0)[source]ο
Configure the connection as a CONTINUOUS (unlimited rotation) joint.
- Parameters:
axis (
tuple[float,float,float]) β Rotation axis unit vector.xyz (
tuple[float,float,float] |None) β Joint origin translation.rpy (
tuple[float,float,float] |None) β Joint origin rotation.effort (
float) β Maximum joint effort (optional).velocity (
float) β Maximum joint velocity (optional).
- Return type:
- Returns:
The LinkBuilder instance.
- prismatic(axis, limits, name=None, xyz=None, rpy=None, effort=10.0, velocity=1.0)[source]ο
Configure the connection as a PRISMATIC (linear sliding) joint.
- Parameters:
axis (
tuple[float,float,float]) β Translation axis unit vector.limits (
tuple[float,float]) β (lower, upper) joint limits in meters.xyz (
tuple[float,float,float] |None) β Joint origin translation.rpy (
tuple[float,float,float] |None) β Joint origin rotation.effort (
float) β Maximum joint effort.velocity (
float) β Maximum joint velocity.
- Return type:
- Returns:
The LinkBuilder instance.
- floating(name=None, xyz=None, rpy=None)[source]ο
Configure the connection as a FLOATING (6 DOF) joint.
- planar(axis, name=None, xyz=None, rpy=None)[source]ο
Configure the connection as a PLANAR joint.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- dynamics(damping=0.0, friction=0.0)[source]ο
Set the physical dynamics for the joint.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- mimic(joint, multiplier=1.0, offset=0.0)[source]ο
Set this joint to mimic another jointβs movement.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- safety(soft_lower=None, soft_upper=None, k_position=None, k_velocity=0.0)[source]ο
Define a safety controller for the joint.
- calibration(rising=None, falling=None)[source]ο
Set calibration offsets for the joint.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- physics(**kwargs)[source]ο
Set surface and contact physics properties for this link.
Supports both typed LinkPhysics fields and raw engine-specific parameters.
- Common arguments:
self_collide (bool): Enable self-collision. gravity (bool): Enable gravity. mu, mu2 (float): Friction coefficients. kp, kd (float): Contact stiffness and damping.
- Return type:
- Returns:
The LinkBuilder instance.
- Parameters:
kwargs (
Any)
- transmission(reduction=1.0, interface='effort', actuator=None, name=None)[source]ο
Define a transmission (mechanical reduction) for the current joint.
- ros2_control(command_interfaces, state_interfaces, parameters=None, system_name=None)[source]ο
Configure ros2_control interfaces for the current joint.
- Parameters:
command_interfaces (
list[str]) β List of allowed commands (e.g. [βpositionβ]).state_interfaces (
list[str]) β List of exposed states (e.g. [βpositionβ, βvelocityβ]).parameters (
dict[str,Any] |None) β Key-value parameters for the joint control.system_name (
str|None) β Optional name of the specific ros2_control system to attach to.
- Return type:
- Returns:
The LinkBuilder instance.
- camera(name, fov=1.047, width=640, height=480, xyz=(0, 0, 0), rpy=(0, 0, 0))[source]ο
Attach a camera sensor to this link.
- Parameters:
name (
str) β Unique sensor name.fov (
float) β Horizontal field of view in radians.width (
int) β Resolution in pixels.height (
int) β Resolution in pixels.xyz (
tuple[float,float,float]) β Position/Orientation relative to link frame.rpy (
tuple[float,float,float]) β Position/Orientation relative to link frame.
- Return type:
- Returns:
The LinkBuilder instance.
- lidar(name, range_min=0.1, range_max=10.0, samples=640, xyz=(0, 0, 0), rpy=(0, 0, 0))[source]ο
Attach a 1D/2D lidar sensor to this link.
- Parameters:
name (
str) β Unique sensor name.range_min (
float) β Distance limits in meters.range_max (
float) β Distance limits in meters.samples (
int) β Number of rays per scan.xyz (
tuple[float,float,float]) β Position/Orientation relative to link frame.rpy (
tuple[float,float,float]) β Position/Orientation relative to link frame.
- Return type:
- Returns:
The LinkBuilder instance.
- gpu_lidar(name, range_min=0.1, range_max=10.0, samples=640, xyz=(0, 0, 0), rpy=(0, 0, 0))[source]ο
Attach a high-performance GPU-accelerated lidar sensor to this link.
- Parameters:
name (
str) β Unique sensor name.range_min (
float) β Distance limits in meters.range_max (
float) β Distance limits in meters.samples (
int) β Number of rays per scan.xyz (
tuple[float,float,float]) β Position/Orientation relative to link frame.rpy (
tuple[float,float,float]) β Position/Orientation relative to link frame.
- Return type:
- Returns:
The LinkBuilder instance.
- imu(name, update_rate=100.0, xyz=(0, 0, 0), rpy=(0, 0, 0))[source]ο
Attach an IMU (Inertial Measurement Unit) to this link.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- gps(name, update_rate=5.0, xyz=(0, 0, 0), rpy=(0, 0, 0))[source]ο
Attach a GPS sensor to this link.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- force_torque(name, update_rate=100.0, xyz=(0, 0, 0), rpy=(0, 0, 0))[source]ο
Attach a force-torque sensor to this link.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- contact(name, collision, update_rate=50.0)[source]ο
Attach a contact sensor to this link.
- Parameters:
- Return type:
- Returns:
The LinkBuilder instance.
- sensor(sensor)[source]ο
Attach a pre-configured Sensor object to this link.
- Parameters:
sensor (
Sensor) β Pre-configured Sensor model.- Return type:
- Returns:
The LinkBuilder instance.
- child(name, joint_name=None)[source]ο
Finalize this link and start building a new child link attached to it.
- Parameters:
- Return type:
- Returns:
A new LinkBuilder instance for the child link.
- commit()[source]ο
Finalize this link and return to the main RobotBuilder.
- Return type:
- Returns:
The parent RobotBuilder instance.
- root()[source]ο
Finalize this link as the robotβs root link (no joint).
- Raises:
RobotValidationError β If the link already has a parent assigned.
- Return type:
- Returns:
The parent RobotBuilder instance.
SemanticBuilderο
A namespace for SRDF and MoveIt planning groups, named states, and self-collision settings.
- class linkforge.core.composer.semantic_builder.SemanticBuilder(builder)[source]ο
Bases:
objectNamespace for SRDF and MoveIt-specific semantic properties.
Accessed via RobotBuilder.semantic.
- Parameters:
builder (
IComposer)
- group(name, links=None, joints=None, chains=None, subgroups=None, base_link=None, tip_link=None)[source]ο
Define a planning group for MoveIt.
- Parameters:
name (
str) β Unique name for the group.joints (
list[str] |None) β List of joint names to include.chains (
list[Chain] |None) β List of (base, tip) tuples for kinematic chains.subgroups (
list[str] |None) β List of other planning group names to include.base_link (
str|None) β Optional shorthand for chain base.
- Return type:
- Returns:
The parent RobotBuilder instance.
- group_state(name, group, values)[source]ο
Define a named state (e.g. βhomeβ) for a planning group.
- end_effector(name, group, parent_link, parent_group=None)[source]ο
Define an end effector for MoveIt.
- Parameters:
- Return type:
- Returns:
The parent RobotBuilder instance.
- passive_joint(name)[source]ο
Mark a joint as passive (not actuated) for MoveIt.
- Parameters:
name (
str) β Name of the joint to mark as passive.- Return type:
- Returns:
The parent RobotBuilder instance.
- virtual_joint(name, child_link, parent_frame='world', joint_type='fixed')[source]ο
Define a virtual joint connecting the robot to the world frame.
- Parameters:
- Return type:
- Returns:
The parent RobotBuilder instance.
- disable_collisions(link1, link2, reason='Adjacent')[source]ο
Instruct MoveIt to ignore collisions between two specific links.
- Parameters:
- Return type:
- Returns:
The parent RobotBuilder instance.
- enable_collisions(link1, link2, reason=None)[source]ο
Explicitly re-enable collision checking between two specific links.
- Parameters:
- Return type:
- Returns:
The parent RobotBuilder instance.
- disable_default_collisions(link)[source]ο
Disable all default collisions for a specific link.
- Parameters:
link (
str) β Name of the link.- Return type:
- Returns:
The parent RobotBuilder instance.
- joint_property(joint_name, property_name, value)[source]ο
Add a custom property/metadata to a joint.
- Parameters:
- Return type:
- Returns:
The parent RobotBuilder instance.
- approximate_link_collision(link, spheres)[source]ο
Add sphere-based collision approximation for a link.
- Parameters:
link (
str) β Name of the link.spheres (
list[SrdfSphere]) β List of SrdfSphere objects.
- Return type:
- Returns:
The parent RobotBuilder instance.
Interfacesο
- class linkforge.core.composer.interfaces.IComposer(*args, **kwargs)[source]ο
Bases:
ProtocolInterface for a builder that can contain and manage links.
- __init__(*args, **kwargs)ο