embodichain.lab.sim.motion.planners#
Motion planning stack.
BasePlanner trajectory planners (TOPPRA, neural, cuRobo) produce joint
trajectories from waypoints. Motion generation composes these backends in
embodichain.lab.sim.motion.motion_generator.
Classes
BasePlannerCfg(robot_uid: 'str' = <factory>, planner_type: 'str' = <factory>) |
|
Base class for trajectory planners. |
|
ToppraPlannerCfg(robot_uid: 'str' = <factory>, planner_type: 'str' = <factory>, max_workers: 'int | None' = <factory>, mp_context: 'str | None' = <factory>) |
|
Time-optimal joint-space planner backed by TOPPRA. |
|
Enumeration for different trajectory sampling methods. |
|
Enumeration for different robot parts to move. |
|
Enumeration for different types of movements. |
|
Data class representing the result of a motion plan (env-batched). |
|
Data class representing the state for a motion plan (env-batched). |
Base Planner#
- class embodichain.lab.sim.motion.planners.BasePlannerCfg[source]#
BasePlannerCfg(robot_uid: ‘str’ = <factory>, planner_type: ‘str’ = <factory>)
Attributes:
UID of the robot to control.
-
robot_uid:
str# UID of the robot to control. Must correspond to a robot added to the simulation with this UID.
-
robot_uid:
- class embodichain.lab.sim.motion.planners.BasePlanner[source]#
Bases:
ABCBase class for trajectory planners.
This class provides common functionality that can be shared across different planner implementations.
- Parameters:
cfg (
BasePlannerCfg) – Configuration object for the planner.
Methods:
__init__(cfg)Return backend-default planning options.
is_satisfied_constraint(vels, accs, constraints)Check if the trajectory satisfies velocity and acceleration constraints.
plan(target_states[, options])Execute trajectory planning.
supports_move_type(move_type)Return whether the planner accepts a movement target type directly.
validate_joint_trajectory(trajectory, *, ...)Validate exact joint samples without replacing their path.
with_collision_world(options, *, obstacle_poses)Attach dynamic obstacle poses to backend planning options.
with_motion_context(options, *, start_qpos, ...)Attach MotionGenerator runtime context to backend options.
Attributes:
Return the planner's collision-world contract, if it has one.
Whether callers must retain this planner's returned sample points exactly.
Movement target types accepted directly by this planner.
Whether per-plan dynamic obstacle poses can update the collision world.
Whether exact joint samples can be checked against bounds/collisions.
- property collision_world_info: CollisionWorldInfo | None#
Return the planner’s collision-world contract, if it has one.
- is_satisfied_constraint(vels, accs, constraints)[source]#
Check if the trajectory satisfies velocity and acceleration constraints.
This method checks whether the given velocities and accelerations satisfy the constraints defined in constraints. It allows for some tolerance to account for numerical errors in dense waypoint scenarios.
- Parameters:
vels (
Tensor) – Velocity tensor (…, DOF) where the last dimension is DOFaccs (
Tensor) – Acceleration tensor (…, DOF) where the last dimension is DOFconstraints (
dict) – Dictionary containing ‘velocity’ and ‘acceleration’ limits
- Returns:
True if all constraints are satisfied, False otherwise
- Return type:
bool
Note
Allows 10% tolerance for velocity constraints
Allows 25% tolerance for acceleration constraints
Prints exceed information if constraints are violated
Assumes symmetric constraints (velocities and accelerations can be positive or negative)
Supports batch dimension computation, e.g. (B, N, DOF) or (N, DOF)
- abstract plan(target_states, options=PlanOptions())[source]#
Execute trajectory planning.
This method must be implemented by subclasses to provide the specific planning algorithm.
- Parameters:
target_states (
list[PlanState]) – list ofPlanStatewaypoints. Tensor fields carry a leading batch dimB(e.g.qposis(B, DOF)).- Returns:
- An env-batched object containing:
success: torch.Tensor
(B,)bool, per-env successpositions: torch.Tensor
(B, N, DOF), joint positionsvelocities: torch.Tensor
(B, N, DOF)orNone, joint velocities. Populated by planners that compute dynamics; may beNonefor planners that do not.accelerations: torch.Tensor
(B, N, DOF)orNone, joint accelerations. Populated by planners that compute dynamics; may beNonefor planners that do not.dt: torch.Tensor
(B, N), per-point time deltasduration: derived torch.Tensor
(B,), total trajectory duration per env
Returning
positionswithoutdtraises atPlanResultconstruction.durationis always derived fromdt.sum(dim=1).
- Return type:
-
preserve_plan_samples:
bool= False# Whether callers must retain this planner’s returned sample points exactly.
When
True,MotionGeneratorreturns the planner’s trajectory without resampling, preserving collision-checked samples. WhenFalse(the default), the generator may normalize the trajectory to a requested waypoint count.
-
supported_move_types:
frozenset[MoveType] = frozenset({})# Movement target types accepted directly by this planner.
MotionGeneratoruses this declaration to validate targets and determine whether Cartesian targets must first be converted into joint waypoints for a joint-only backend.
-
supports_collision_world_updates:
bool= False# Whether per-plan dynamic obstacle poses can update the collision world.
-
supports_joint_trajectory_validation:
bool= False# Whether exact joint samples can be checked against bounds/collisions.
- supports_move_type(move_type)[source]#
Return whether the planner accepts a movement target type directly.
- validate_joint_trajectory(trajectory, *, control_part, obstacle_poses=None)[source]#
Validate exact joint samples without replacing their path.
Backends that implement this contract must evaluate every supplied sample against joint bounds, self-collision, and their configured world collision model. They return a boolean mask with shape
(B, T).- Parameters:
trajectory (
Tensor) – Simulator-order joint samples with shape(B, T, D).control_part (
str) – Robot control part whose ordered joints formD.obstacle_poses (
Mapping[str,Tensor] |None) – Optional current dynamic-obstacle world poses.
- Return type:
Tensor- Returns:
Per-environment, per-sample validity mask.
- Raises:
NotImplementedError – Always for the base planner.
- with_collision_world(options, *, obstacle_poses)[source]#
Attach dynamic obstacle poses to backend planning options.
The base planner does not consume a collision world. Backends whose
collision_world_infoenables updates override this method.- Parameters:
options (
PlanOptions) – Backend-specific options to enrich.obstacle_poses (
Mapping[str,Tensor]) – Batched world poses keyed by stable obstacle ID.
- Return type:
PlanOptions- Returns:
Planning options unchanged for a backend without world updates.
- with_motion_context(options, *, start_qpos, control_part)[source]#
Attach MotionGenerator runtime context to backend options.
The base planner has no context fields and therefore returns
optionsunchanged. Backends with contextual options override this method.- Parameters:
options (
PlanOptions) – The backend’s planning options, already constructed (either by the caller or viadefault_plan_options()).start_qpos (
Tensor|None) – Optional starting joint configuration(B, DOF).control_part (
str|None) – Optional control-part name.
- Return type:
PlanOptions- Returns:
The (possibly mutated) planning options carrying the context.
Toppra Planner#
- class embodichain.lab.sim.motion.planners.ToppraPlannerCfg[source]#
ToppraPlannerCfg(robot_uid: ‘str’ = <factory>, planner_type: ‘str’ = <factory>, max_workers: ‘int | None’ = <factory>, mp_context: ‘str | None’ = <factory>)
Attributes:
Worker process count for the batched fan-out.
Multiprocessing start method for the batched fan-out.
UID of the robot to control.
-
max_workers:
int|None# Worker process count for the batched fan-out. None => min(cpu_count()//2, B).
-
mp_context:
str|None# Multiprocessing start method for the batched fan-out.
None(default) auto-selects based on the simulation device:'fork'on CPU and'spawn'on GPU.'fork'is faster — workers inherit the parent’s already-loaded modules, so pool startup is near-instant — and is safe here because the TOPPRA worker (_toppra_solve_one_env()) is pure numpy/scipy and never touches the parent’s Vulkan/Warp/CUDA context or render threads;_worker_initclears the inherited atexit registry and installsprctl(PR_SET_PDEATHSIG)so workers are reaped when the parent dies (incl. theos._exitpath).'spawn'is the safer choice when the parent has initialized CUDA physics (sim_device='cuda') — fork-after-CUDA-init is the officially unsupported case — or if fork deadlocks are observed, at the cost of re-importing modules per worker.
-
robot_uid:
str# UID of the robot to control. Must correspond to a robot added to the simulation with this UID.
-
max_workers:
- class embodichain.lab.sim.motion.planners.ToppraPlanner[source]#
Bases:
BasePlannerTime-optimal joint-space planner backed by TOPPRA.
Methods:
__init__(cfg)Initialize the TOPPRA trajectory planner.
close()Release TOPPRA worker processes owned by this planner.
Return backend-default planning options.
is_satisfied_constraint(vels, accs, constraints)Check if the trajectory satisfies velocity and acceleration constraints.
plan(target_states[, options])Execute trajectory planning.
supports_move_type(move_type)Return whether the planner accepts a movement target type directly.
validate_joint_trajectory(trajectory, *, ...)Validate exact joint samples without replacing their path.
with_collision_world(options, *, obstacle_poses)Attach dynamic obstacle poses to backend planning options.
with_motion_context(options, *, start_qpos, ...)Attach MotionGenerator runtime context to backend options.
Attributes:
Return the planner's collision-world contract, if it has one.
Whether callers must retain this planner's returned sample points exactly.
Movement target types accepted directly by this planner.
Whether per-plan dynamic obstacle poses can update the collision world.
Whether exact joint samples can be checked against bounds/collisions.
- __init__(cfg)[source]#
Initialize the TOPPRA trajectory planner.
References
TOPPRA: Time-Optimal Path Parameterization for Robotic Systems (hungpham2511/toppra)
- Parameters:
cfg (
ToppraPlannerCfg) – Configuration object containing ToppraPlanner settings
- property collision_world_info: CollisionWorldInfo | None#
Return the planner’s collision-world contract, if it has one.
- default_plan_options()[source]#
Return backend-default planning options.
- Return type:
ToppraPlanOptions
- is_satisfied_constraint(vels, accs, constraints)#
Check if the trajectory satisfies velocity and acceleration constraints.
This method checks whether the given velocities and accelerations satisfy the constraints defined in constraints. It allows for some tolerance to account for numerical errors in dense waypoint scenarios.
- Parameters:
vels (
Tensor) – Velocity tensor (…, DOF) where the last dimension is DOFaccs (
Tensor) – Acceleration tensor (…, DOF) where the last dimension is DOFconstraints (
dict) – Dictionary containing ‘velocity’ and ‘acceleration’ limits
- Returns:
True if all constraints are satisfied, False otherwise
- Return type:
bool
Note
Allows 10% tolerance for velocity constraints
Allows 25% tolerance for acceleration constraints
Prints exceed information if constraints are violated
Assumes symmetric constraints (velocities and accelerations can be positive or negative)
Supports batch dimension computation, e.g. (B, N, DOF) or (N, DOF)
- plan(target_states, options=ToppraPlanOptions(constraints={'velocity': 0.2, 'acceleration': 0.5}, sample_method=<TrajectorySampleMethod.QUANTITY: 'quantity'>, sample_interval=0.01))[source]#
Execute trajectory planning.
- Parameters:
- Return type:
- Returns:
PlanResult containing the planned trajectory details. All tensor fields are env-batched with leading dim
B:success(B,),positions/velocities/accelerations(B, N, DOF),dt(B, N),duration(B,).
-
preserve_plan_samples:
bool= False# Whether callers must retain this planner’s returned sample points exactly.
When
True,MotionGeneratorreturns the planner’s trajectory without resampling, preserving collision-checked samples. WhenFalse(the default), the generator may normalize the trajectory to a requested waypoint count.
-
supported_move_types:
frozenset[MoveType] = frozenset({MoveType.JOINT_MOVE})# Movement target types accepted directly by this planner.
MotionGeneratoruses this declaration to validate targets and determine whether Cartesian targets must first be converted into joint waypoints for a joint-only backend.
-
supports_collision_world_updates:
bool= False# Whether per-plan dynamic obstacle poses can update the collision world.
-
supports_joint_trajectory_validation:
bool= False# Whether exact joint samples can be checked against bounds/collisions.
- supports_move_type(move_type)#
Return whether the planner accepts a movement target type directly.
- validate_joint_trajectory(trajectory, *, control_part, obstacle_poses=None)#
Validate exact joint samples without replacing their path.
Backends that implement this contract must evaluate every supplied sample against joint bounds, self-collision, and their configured world collision model. They return a boolean mask with shape
(B, T).- Parameters:
trajectory (
Tensor) – Simulator-order joint samples with shape(B, T, D).control_part (
str) – Robot control part whose ordered joints formD.obstacle_poses (
Mapping[str,Tensor] |None) – Optional current dynamic-obstacle world poses.
- Return type:
Tensor- Returns:
Per-environment, per-sample validity mask.
- Raises:
NotImplementedError – Always for the base planner.
- with_collision_world(options, *, obstacle_poses)#
Attach dynamic obstacle poses to backend planning options.
The base planner does not consume a collision world. Backends whose
collision_world_infoenables updates override this method.- Parameters:
options (
PlanOptions) – Backend-specific options to enrich.obstacle_poses (
Mapping[str,Tensor]) – Batched world poses keyed by stable obstacle ID.
- Return type:
PlanOptions- Returns:
Planning options unchanged for a backend without world updates.
- with_motion_context(options, *, start_qpos, control_part)#
Attach MotionGenerator runtime context to backend options.
The base planner has no context fields and therefore returns
optionsunchanged. Backends with contextual options override this method.- Parameters:
options (
PlanOptions) – The backend’s planning options, already constructed (either by the caller or viadefault_plan_options()).start_qpos (
Tensor|None) – Optional starting joint configuration(B, DOF).control_part (
str|None) – Optional control-part name.
- Return type:
PlanOptions- Returns:
The (possibly mutated) planning options carrying the context.
Utilities#
- class embodichain.lab.sim.motion.planners.TrajectorySampleMethod[source]#
Bases:
EnumEnumeration for different trajectory sampling methods.
This enum defines various methods for sampling trajectories, providing meaningful names for different sampling strategies.
Attributes:
Sample based on distance intervals.
Sample based on a specified number of points.
Sample based on time intervals.
Methods:
from_str(value)- DISTANCE = 'distance'#
Sample based on distance intervals.
- QUANTITY = 'quantity'#
Sample based on a specified number of points.
- TIME = 'time'#
Sample based on time intervals.
- class embodichain.lab.sim.motion.planners.MovePart[source]#
Bases:
EnumEnumeration for different robot parts to move.
Defines robot part selection for motion planning.
- LEFT#
left arm or end-effector.
- Type:
int
- RIGHT#
right arm or end-effector.
- Type:
int
- BOTH#
both arms or end-effectors.
- Type:
int
- TORSO#
torso for humanoid robot.
- Type:
int
- ALL#
all joints of the robot (joint control only).
- Type:
int
Attributes:
- ALL = 4#
- BOTH = 2#
- LEFT = 0#
- RIGHT = 1#
- TORSO = 3#
- class embodichain.lab.sim.motion.planners.MoveType[source]#
Bases:
EnumEnumeration for different types of movements.
Defines movement types for robot planning.
- TOOL#
Tool open or close.
- Type:
int
- EEF_MOVE#
Move end-effector to target pose (IK + trajectory).
- Type:
int
- JOINT_MOVE#
Move joints to target angles (trajectory planning).
- Type:
int
- SYNC#
Synchronized left/right arm movement (dual-arm robots).
- Type:
int
- PAUSE#
Pause for specified duration (see PlanState.pause_seconds).
- Type:
int
Attributes:
- EEF_MOVE = 1#
- JOINT_MOVE = 2#
- PAUSE = 4#
- SYNC = 3#
- TOOL = 0#
- class embodichain.lab.sim.motion.planners.PlanResult[source]#
Bases:
objectData class representing the result of a motion plan (env-batched).
A result that contains joint positions must also contain per-sample
dt. Per-environmentdurationis derived from those intervals. Failed plans may omit all trajectory fields by leavingpositionsasNone.Methods:
__init__([success, xpos_list, positions, ...])Return True only when every env succeeded.
Attributes:
Joint accelerations, shape
(B, N, DOF).Per-env time deltas, shape
(B, N).Return per-environment duration derived from
dt.Joint positions, shape
(B, N, DOF).Per-env success, shape
(B,)bool tensor (or scalar bool).Joint velocities, shape
(B, N, DOF).End-effector poses, shape
(B, N, 4, 4).- __init__(success=False, xpos_list=None, positions=None, velocities=None, accelerations=None, dt=None)#
-
accelerations:
Tensor|None= None# Joint accelerations, shape
(B, N, DOF).
-
dt:
Tensor|None= None# Per-env time deltas, shape
(B, N).
-
positions:
Tensor|None= None# Joint positions, shape
(B, N, DOF).
-
success:
bool|Tensor= False# Per-env success, shape
(B,)bool tensor (or scalar bool).
-
velocities:
Tensor|None= None# Joint velocities, shape
(B, N, DOF).
-
xpos_list:
Tensor|None= None# End-effector poses, shape
(B, N, 4, 4).
- class embodichain.lab.sim.motion.planners.PlanState[source]#
Bases:
objectData class representing the state for a motion plan (env-batched).
Tensor fields carry a leading batch dim
B:qpos:(B, DOF),xpos:(B, 4, 4). Enum/scalar fields are shared acrossB(vectorized envs share the same task skeleton).Methods:
__init__([move_type, move_part, xpos, qpos, ...])from_qpos(qpos, *[, move_type, move_part])Create a PlanState from batched joint positions
(B, DOF).from_xpos(xpos, *[, move_type, move_part])Create a PlanState from batched end-effector poses
(B, 4, 4).single(*[, qpos, xpos, move_type, move_part])B=1 convenience constructor: unsqueezes a single-env qpos/xpos.
Attributes:
For
MoveType.TOOL, indicates whether to open (True) or close (False) the tool.Trueif the target pose is in world coordinates,Falseif relative to the current pose.Robot part that should move.
Type of movement used by the plan.
Duration of a pause when
move_typeisMoveType.PAUSE.Target joint accelerations for
MoveType.JOINT_MOVEwith shape(B, DOF).Target joint angles for
MoveType.JOINT_MOVEwith shape(B, DOF).Target joint velocities for
MoveType.JOINT_MOVEwith shape(B, DOF).Target TCP pose (Bx4x4) for
MoveType.EEF_MOVE.- __init__(move_type=MoveType.JOINT_MOVE, move_part=MovePart.LEFT, xpos=None, qpos=None, qvel=None, qacc=None, is_open=True, is_world_coordinate=True, pause_seconds=0.0)#
- classmethod from_qpos(qpos, *, move_type=MoveType.JOINT_MOVE, move_part=MovePart.LEFT, **kwargs)[source]#
Create a PlanState from batched joint positions
(B, DOF).- Return type:
- classmethod from_xpos(xpos, *, move_type=MoveType.EEF_MOVE, move_part=MovePart.LEFT, **kwargs)[source]#
Create a PlanState from batched end-effector poses
(B, 4, 4).- Return type:
-
is_open:
bool= True# For
MoveType.TOOL, indicates whether to open (True) or close (False) the tool.
-
is_world_coordinate:
bool= True# Trueif the target pose is in world coordinates,Falseif relative to the current pose.
-
pause_seconds:
float= 0.0# Duration of a pause when
move_typeisMoveType.PAUSE.
-
qacc:
Tensor|None= None# Target joint accelerations for
MoveType.JOINT_MOVEwith shape(B, DOF).
-
qpos:
Tensor|None= None# Target joint angles for
MoveType.JOINT_MOVEwith shape(B, DOF).
-
qvel:
Tensor|None= None# Target joint velocities for
MoveType.JOINT_MOVEwith shape(B, DOF).
- classmethod single(*, qpos=None, xpos=None, move_type=MoveType.JOINT_MOVE, move_part=MovePart.LEFT, **kwargs)[source]#
B=1 convenience constructor: unsqueezes a single-env qpos/xpos.
Already-batched tensors (2D qpos / 3D xpos) pass through unchanged (idempotent).
- Return type:
-
xpos:
Tensor|None= None# Target TCP pose (Bx4x4) for
MoveType.EEF_MOVE.