Add A Kinematics Backend¶
Kinematics backends implement KinematicsBackend and are registered in kinematics_backends. The retargeting engine uses this protocol instead of depending on a simulator directly.
Required operations:
forward_kinematicsandlink_positionsfor named body/link positionsbody_jacobiansfor translational and rotational Jacobianspoint_jacobiansfor point positions and translational Jacobians used by the optimizerqpos_to_qvelandintegrate_qvelfor simulator-safe qpos/qvel conversionjoint_limitsfor actuator bounds used directly by the optimizergeom_distancesfor explicit geometry pairs used by collision-aware constraints
Register a backend factory with a typed key:
from retarget import KinematicsKind
from retarget.kinematics import kinematics_backends
from retarget.pipeline.compiled import CompiledRobotSpec
class LabKinematics(KinematicsKind):
BACKEND = "lab_backend"
@kinematics_backends.register(LabKinematics.BACKEND)
def make_backend(robot: CompiledRobotSpec) -> MyKinematicsBackend:
return MyKinematicsBackend(robot)
The built-in SimpleKinematicsBackend is deterministic and dependency-light for tests. MuJoCoKinematicsBackend keeps MuJoCo-specific FK, Jacobians, position integration, joint range extraction, and geom-distance calls behind the same protocol.
Backend joint limits are the optimizer source of truth. MuJoCo extracts limited hinge and slide ranges by exact joint name or by qpos order after the configured root layout; explicit RobotSpec.joint_limits then override those ranges for experiments that need tighter or corrected bounds.