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.
- register_link_builder(builder)[source]
Register an active LinkBuilder with this composer.
- Parameters:
builder (
LinkBuilder)- Return type:
- 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.
- 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.
- 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:
- 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.
- 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.
- register_link_builder(builder)[source]
Register an active LinkBuilder with this composer.
- Parameters:
builder (
LinkBuilder)- Return type:
- __init__(*args, **kwargs)