Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/source/api/lab/isaaclab.actuators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,14 @@ Newton Actuator Access
.. autofunction:: isaaclab.actuators.newton.read_group_parameter

.. autofunction:: isaaclab.actuators.newton.write_group_parameter

.. autoclass:: isaaclab.actuators.newton.NativeActuatorHooks
:members:

.. autoclass:: isaaclab.actuators.newton.NativeActuatorContext
:members:
:exclude-members: __init__

.. autoclass:: isaaclab.actuators.newton.NativeActuatorBinding
:members:
:exclude-members: __init__
17 changes: 17 additions & 0 deletions docs/source/api/lab/isaaclab.sim.schemas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ isaaclab.sim.schemas
define_deformable_curve_properties
modify_deformable_body_properties

Native Actuator Registration
----------------------------

.. autofunction:: register_native_actuator

.. autoclass:: ActuatorField
:members:
:exclude-members: __init__

.. autoclass:: ActuatorLayout
:members:
:exclude-members: __init__

.. autoclass:: NativeActuatorAuthoringContext
:members:
:exclude-members: __init__

Schema Fragments
----------------

Expand Down
82 changes: 81 additions & 1 deletion docs/source/concepts/actuators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ produces no torque. A warning names the replaced joints. The

With the default ``use_newton_actuators=True``, every explicit actuator config must be
supported. An unsupported config raises an error before native authoring. Disable
``use_newton_actuators`` to use the Isaac Lab execution path, or select a supported config.
``use_newton_actuators`` to use the Isaac Lab execution path, select a supported config, or
register a custom implementation as described below.

.. note::

Expand All @@ -836,6 +837,85 @@ produces no torque. A warning names the replaced joints. The
starting buffer so its history advances across graph replays.


.. _actuators-native-custom:

Custom native actuators
^^^^^^^^^^^^^^^^^^^^^^^

Use :func:`~isaaclab.sim.schemas.register_native_actuator` to declare how a custom Lab config
maps to a Newton implementation. Register before spawning assets, on every backend that uses
the config. Newton itself is unchanged: register the drive or component with its existing
``newton.actuators.register_actuator_component`` API and arrange any USD schema plugin discovery
before USD initializes its schema registry.

For example, given project-owned ``MyActuator``, ``MyActuatorCfg`` and ``MyNewtonDrive`` classes:

.. code-block:: python

from newton.actuators import ComponentKind, register_actuator_component

from isaaclab.actuators.newton import NativeActuatorHooks
from isaaclab.sim.schemas import ActuatorField, ActuatorLayout, register_native_actuator

class MyHooks(NativeActuatorHooks):
def prepare(self, context):
# A custom drive may need an environment stride before it allocates state.
for binding in context.bindings:
drive = binding.actuator.drive
drive.env_dof_stride = len(binding.actuator.indices) // context.articulation.num_instances

register_actuator_component("MyDriveAPI", MyNewtonDrive, ComponentKind.DRIVE)
register_native_actuator(
MyActuatorCfg,
ActuatorLayout(
MyActuator,
"MyDriveAPI",
(
ActuatorField("stiffness", "MyDriveAPI", "newton:kp"),
ActuatorField("current_limit", "MyDriveAPI", "newton:currentLimit", required=True),
),
),
hooks_type=MyHooks,
)

``MyActuatorCfg.class_type`` must resolve to exactly ``MyActuator``. Config subclasses inherit the
closest registration; changing ``class_type`` requires a matching registration. Native execution
runs ``MyNewtonDrive``, not ``MyActuator.compute()``. Duplicate config registrations raise an error.
Registration does not make a drive's solver-specific features portable to other backends.

A layout declares the drive and component schemas that its config models. Matching asset prims
using registered schemas are retained, and fields left unset keep their asset values. Components
outside the selected layout are removed according to the usual override rules. Use a field's
``source`` callback for non-scalar values, and ``default`` or ``required`` for components the
config adds to a prim.

An optional ``author(context)`` callback runs after regular USD authoring for each group, before
cloning and model import. Its :class:`~isaaclab.sim.schemas.NativeActuatorAuthoringContext`
contains the config, group name, stage, articulation path, and joint/actuator prim dictionaries
keyed by joint name. Use it for additional joint attributes or other USD data outside the actuator prim.

Register a :class:`~isaaclab.actuators.newton.NativeActuatorHooks` subclass for Lab-specific runtime work.
Each group in each articulation gets a separate no-argument instance, with callbacks in this order:

* ``prepare(context)``: parsed actuators exist, before component-state allocation.
* ``finalize(context)``: group properties and adapter buffers are bound; sample startup parameters here.
* ``solver_init(context)``: component states and solver resources are ready, before graph capture.
* ``reset(context, env_ids, env_mask)``: after normal component-state reset; a mask takes precedence.

On Newton, state allocation waits until all articulations prepare, at solver initialization.
``finalize`` must not assume those states exist yet. On PhysX and OVPhysX, ``solver_init`` runs
immediately after finalization. The :class:`~isaaclab.actuators.newton.NativeActuatorContext`
provides the public articulation, collection, backend name, public joint indices, owned actuator
bindings and native control object. Its ``adapter`` becomes available at finalization; ``model``
and ``solver`` are Newton-only resources, with ``solver`` available at solver initialization.

Newton can merge groups or articulations into one actuator. A binding's ``slots`` are positions
in that actuator's arrays across all environments that belong to this group. Restrict writes to
those slots; shared settings need explicit agreement and idempotent initialization. Prefer Newton
component state/reset APIs for ordinary drive state. Hooks are recreated on model rebuild and
must not register callbacks that outlive the backend. There are no new per-step Python callbacks.


.. _actuators-bam:

BAM servo model
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Added public native actuator layout registration, USD authoring callbacks and per-group runtime hooks
so external actuator implementations can use Newton execution without modifying Isaac Lab.
Empty file.
20 changes: 11 additions & 9 deletions source/isaaclab/isaaclab/actuators/actuator_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def __init__(

resolved_cfgs = {name: clone(cfg) for name, cfg in actuator_cfgs.items()}
resolved_group_joints = self._resolve_group_joints(resolved_cfgs)
for name, (joint_ids, joint_names) in resolved_group_joints.items():
self._group_joint_names[name] = joint_names
if len(joint_names) == self.num_joints:
self._group_joint_indices[name] = slice(None)
elif isinstance(joint_ids, ProxyArray):
self._group_joint_indices[name] = joint_ids.torch
else:
self._group_joint_indices[name] = torch.tensor(joint_ids, device=self.device, dtype=torch.int32)
self._allocate_buffers()
self._target_command = ActuatorTargetCommand(self)
self._output_command = ActuatorOutputCommand(self)
Expand All @@ -108,6 +116,7 @@ def __init__(
self._groups[actuator_name] = self._resolve_newton_group_actuators(actuator_name)
self._validate_coverage()
self._build_execution_plan()
self._control.finalize_native_actuator_hooks()
if self._debug_value_resolution:
self._print_value_resolution_table()
if not self._control.native_actuator_path_active:
Expand Down Expand Up @@ -320,15 +329,8 @@ def _build_groups(
"""
construction_records: list[tuple[dict[str, torch.Tensor], torch.Tensor | slice, bool, bool]] = []
for actuator_name, actuator_cfg in actuator_cfgs.items():
joint_ids, joint_names = resolved_group_joints[actuator_name]
if len(joint_names) == self.num_joints:
actuator_joint_ids: slice | torch.Tensor = slice(None)
elif isinstance(joint_ids, ProxyArray):
actuator_joint_ids = joint_ids.torch
else:
actuator_joint_ids = torch.tensor(joint_ids, device=self.device, dtype=torch.int32)
self._group_joint_names[actuator_name] = joint_names
self._group_joint_indices[actuator_name] = actuator_joint_ids
_, joint_names = resolved_group_joints[actuator_name]
actuator_joint_ids = self._group_joint_indices[actuator_name]

joint_defaults = self._control.get_default_joint_properties(actuator_joint_ids)
implicit = _is_implicit_actuator_cfg(actuator_cfg)
Expand Down
3 changes: 3 additions & 0 deletions source/isaaclab/isaaclab/actuators/actuator_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ def finalize_native_actuators(self, collection: ActuatorCollection) -> NewtonAct
"""
return None

def finalize_native_actuator_hooks(self) -> None:
"""Run extension startup hooks after collection membership and parameter access are ready."""

def compute_native_actuators(self, collection: ActuatorCollection, dt: float) -> bool:
"""Compute backend-native actuator outputs.

Expand Down
4 changes: 4 additions & 0 deletions source/isaaclab/isaaclab/actuators/newton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@

from .adapter import NewtonActuatorAdapter, read_group_parameter, write_group_parameter
from .kernels import build_implicit_dof_mask
from .hooks import NativeActuatorBinding, NativeActuatorContext, NativeActuatorHooks
from .physx_wrapper import PhysxActuatorWrapper

__all__ = [
"NativeActuatorBinding",
"NativeActuatorContext",
"NativeActuatorHooks",
"NewtonActuatorAdapter",
"PhysxActuatorWrapper",
"build_implicit_dof_mask",
Expand Down
36 changes: 29 additions & 7 deletions source/isaaclab/isaaclab/actuators/newton/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def __init__(
num_joints: int,
dof_offset: int,
device: str,
*,
defer_state_initialization: bool = False,
):
self.actuators = actuators
self.num_joints = num_joints
Expand All @@ -104,13 +106,10 @@ def __init__(
else:
self.joint_indices = torch.tensor(sorted(managed), dtype=torch.int32, device=device)

self._states_a = [act.state() for act in actuators]
self._states_b = [act.state() for act in actuators]
# per-DOF reset masks of the stateful actuators, rewritten by every partial reset so a reset does not allocate
self._reset_dof_masks = [
None if state is None else wp.zeros(act.indices.shape[0], dtype=wp.bool, device=device)
for act, state in zip(actuators, self._states_a)
]
self._states_initialized = False
self._states_a = []
self._states_b = []
self._reset_dof_masks = []

# Pre-clamp computed effort buffer. Each Newton actuator scatter-adds
# its raw drive output to ``sim_control.joint_computed_f`` when
Expand All @@ -126,6 +125,25 @@ def __init__(
self.computed_effort_2d = self._computed_effort.reshape((num_envs, num_joints))
for act in actuators:
act.control_computed_output_attr = "joint_computed_f"
if not defer_state_initialization:
self.initialize_states()

def initialize_states(self) -> None:
"""Allocate component states once, after all registered preparation hooks.

Construction is eager by default. Lab's Newton backend defers this until solver
initialization because its adapter is shared by all articulations. Call before step/reset
when constructing with ``defer_state_initialization=True``.
"""
if self._states_initialized:
return
self._states_a = [act.state() for act in self.actuators]
self._states_b = [act.state() for act in self.actuators]
self._reset_dof_masks = [
None if state is None else wp.zeros(act.indices.shape[0], dtype=wp.bool, device=self._device)
for act, state in zip(self.actuators, self._states_a)
]
self._states_initialized = True

def finalize(self, sim_control: Any) -> None:
"""Bind the pre-clamp computed-effort buffer onto ``sim_control``.
Expand Down Expand Up @@ -156,6 +174,8 @@ def step(self, sim_state: Any, sim_control: Any, dt: float, *, swap_state: bool
of an odd-length graph to copy the output back into the input buffers instead,
keeping their addresses stable across replays.
"""
if not self._states_initialized:
raise RuntimeError("Native actuator states must be initialized before stepping.")
# Zero before scatter-add (actuators accumulate into this buffer).
self._computed_effort.zero_()
for act in self.actuators:
Expand Down Expand Up @@ -197,6 +217,8 @@ def reset(
etc.). We therefore build a per-actuator per-DOF mask from the
env mask before delegating to each state.
"""
if not self._states_initialized:
raise RuntimeError("Native actuator states must be initialized before reset.")
if env_mask is not None:
self._reset_states(env_mask)
return
Expand Down
Loading
Loading