> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rua.hud.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Direct Control

> Reference for Direct Control standard v0.2: the move tool, spaces, replies, vetoes, and settings.

**Direct Control** is the standard that serves a robot's action space to an agent as one move tool. The idea is in [Direct Control](https://docs.rua.hud.ai/interfaces/direct-control.md), and the setup is in the [guide](https://docs.rua.hud.ai/guides/direct-control.md).

## Tools

`move` takes `keyframes`, a list, and an optional `note`. Each keyframe has `t` and names body parts. A **part** has one space, fixed for the run by the robot's spec, and the schema lists each part with its dimensions and ranges.

| Space | A part's value | Dimensions |
| - | - | - |
| `ee_abs` | Hand pose at `t` | `x`, `y`, `z`, `roll`, `pitch`, `yaw` |
| `ee_delta` | Hand pose change from the pose at the call start | `x`, `y`, `z`, `roll`, `pitch`, `yaw` |
| `joint_abs` | Joint values at `t`, in degrees (metres for a prismatic joint) | Any names the robot gives: `j1`, `j2`, and so on for an arm, `FFJ1` for a finger, `lift` for a torso |
| `grip` | Closure at `t`, a bare number from 0 (open) to 1 (closed) | none |
| `base_vel` | Base velocity at `t`, ramping linearly between keyframes and held after the last until a later call changes it | `vx`, `vy`, `vz`, `wz`, as the robot lists them |
| `base_abs` | Base pose at `t` in the odom frame | `x`, `y`, `yaw` |

```json theme={"dark"}
{"keyframes": [{"t": 2.0, "arm": {"z": 0.15}, "gripper": 1.0}], "note": "the cube is below the hand"}
```

| Other tool | Effect |
| - | - |
| `done` | Ends the agent's moves: a later `move` is refused. It takes `reason` and is served only when notes are on. |
| `hindsight` | Served only when `hindsight` is on. It asks what was hard and what did not work. |

A part or dimension a keyframe leaves out holds, and so does one set to null. A position part or dimension the whole call leaves out keeps its last command, not the measured value, so a closed hand stays closed and an arm that sags under load does not drift down call by call. An `ee_delta` offset left out stays at zero. A `base_vel` part or dimension the call leaves out keeps its last commanded velocity. All parts share one clock, so everything named at one `t` arrives together. There is no `wait` tool.

| Quantity | Convention |
| - | - |
| Frame | Robot base: x forward, y left, z up. A mobile base's pose is in the odom frame, fixed where the episode began. |
| Position | Metres |
| Angles | Degrees. Roll, pitch, and yaw about the fixed base axes X, Y, then Z. The hand turns along the shortest arc between keyframe orientations. |
| `grip` | 0 open to 1 closed |

`t` is seconds from the start of the call, above 0 and increasing. Position parts follow one smooth curve through every keyframe that rests only at the last. A position or grip dimension starts from its last command, or from its measured value before its first: a hand pressing on something or closed on an object measures short of its command, and restarting from the measurement would first move the command back to it, letting go. A `base_vel` part ramps linearly instead, from its last command, and holds its last keyframe's velocity after the call ends: the call returns with the base still moving at it, and the velocity stays commanded until a later call changes it. To stop, command 0 in a keyframe; the base then slows at its acceleration limit. Before the first command, a measured velocity within 5% of its range of zero counts as zero.

## Replies and vetoes

A reply opens with a JSON block, then a caption and an image per camera for each frame in the history: by default one frame, now, captioned `camera front, now:`. With `observe` on, each keyframe with `observe: true` adds a snapshot of every camera at its `t`, captioned `camera front at t=2.00 s of this call:` and sorted by time with the history frames; see [Settings](#settings).

```json theme={"dark"}
{"status": "completed", "elapsed_s": 2.0, "steps": 30, "parts": {"arm": {"frame": "base", "pose": {"x": 0.3005, "y": 0.0, "z": 0.1501, "roll": -180.0, "pitch": -0.3, "yaw": 0.0}, "joints": {"j1": 0.0, "j2": 106.1, "j3": 99.6, "j4": -83.2, "j5": -0.0, "j6": 0.0}, "gap": {"pos_mm": 0.5, "rot_deg": 0.3}}, "gripper": {"grip": 0.94, "gap": 0.06}}}
```

`status` is `completed`, `cut_short`, `refused`, `vetoed` or `ended`. `reason` is set on a refusal or veto, and `settle` when `settle` is on. Each part reports its measured state, and the gap to its target when the call named it. A robot with several arms reports every part in the same reply, under the names the spec gives:

```json theme={"dark"}
{"status": "completed", "elapsed_s": 3.0, "steps": 30, "parts": {"left_arm": {"frame": "base", "pose": {"x": 0.4, "y": 0.2, "z": 0.3}, "gap": {"pos_mm": 0.0}}, "left_hand": {"grip": 1.0, "gap": 0.0}, "right_arm": {"frame": "base", "pose": {"x": 0.5, "y": -0.3, "z": 0.2}, "gap": {"pos_mm": 0.0}}, "right_hand": {"grip": 0.5, "gap": 0.0}}}
```

Readouts of something no part commands, such as a legged robot's trunk, go under `state`. A move ends when its last setpoint plays, and the next one starts from the last command (see the start rule above), so a part that stopped short shows its gap in the reply.

| Case | Result |
| - | - |
| Bad call: an unknown part or dimension, a value outside the schema's range, a missing `t`, a `t` that is not above the previous one, more than `max_keyframes` keyframes, `observe` on more than 5 keyframes | Refused with a JSON reply and the camera frames, not a tool error. Nothing plays and the robot holds. A schema error names its path, such as `keyframes/1/arm/x`. Every other reason names the part and keyframe, such as `keyframe 2: t=1 must be above the previous keyframe's 2.` Paths count keyframes from 0 and these reasons count from 1. |
| A call after `done` | Refused: no more moves are accepted. |
| Joint limit, self-collision, one arm hitting another, unreachable pose, or speed or acceleration limit broken anywhere on the curve | Vetoed before it plays, with the reason. The embodiment decides which of these it can check. A speed or acceleration veto names the part, keyframe and limit (`position`, `rotation`, `linear` for a base's velocities, or a dimension) and gives the minimum feasible time, rounded up to the hundredth of a second. |
| A contract arm's controller limit | Vetoed when a row would leave the controller's declared limits, for example a step above the per-step limit of a delta controller. The reason names the part, keyframe, dimension and step. There is no minimum time. |
| A contract arm that reads past a limit | Played, with the rows clipped. See [clipping](#clipping). |
| Move reaches the seconds limit | Cut short at `max_call_s`, and the reply says so. Keyframes after the limit are not refused: the call plays up to the limit, and the next call starts from the last setpoint played. |
| The episode ends | The call that ends it plays up to that tick and says the episode ended, for example when the task succeeds mid-move. Any later call plays nothing, and its reply says the episode has ended. |

The speed check runs on the whole curve, not on the average speed between keyframes. A move from rest to rest peaks at 1.5 times its average speed, so a move can be vetoed when distance divided by time looks within the limit. With several parts, the first part to fail vetoes the call for all of them, and the reason names that part.

### Clipping

A contract arm checks its controller rows against the limits its contract declares. An absolute column that already reads past a limit, such as a joint that drifted slightly beyond it, does not make every call fail: the check allows the column as far out as it is, so a call can move it back inside. The rows sent to the controller are then clipped into the declared limits, which the controller enforces anyway, so no row is ever outside them. A column that reads inside its limits is never clipped, because a row outside them is vetoed instead. A `ContractEmbodiment` clips only the columns a call can set.

## Robot specs

A `RobotSpec` lists each part's dimensions with a range and limits. A position dimension needs `max_speed`, and its `max_accel` is optional. A `base_vel` dimension needs `max_accel`, and its range caps the speed.

A part's hand position (`x`, `y`, `z`) or base velocity (`vx`, `vy`, `vz`, named `linear`) is one group, and its `roll`, `pitch`, `yaw` are another. A group's members share one `max_speed` and one `max_accel`, and the limit caps the norm: the hand's speed in m/s, and its turn rate along the shortest arc. Joints and grip are limited one by one.

Each limit is the fastest speed the sim's controller can actually follow. If nobody has measured that, use the robot's rated joint speed. Never use a cautious comfort value: a slow limit makes the agent slow, and a benchmark then measures the limit, not the agent.

Hand joints take Shadow Hand names: a finger, `TH`, `FF`, `MF`, `RF` or `LF`, then `J` and a number counted from the tip, so `FFJ1` is the index fingertip joint. A hand with fewer joints uses the numbers of the joints it has. `rua.direct.finger_joint("FF", 1)` returns `FFJ1`.

A spec has a robot class from `rua.direct.CLASSES`: `single_arm`, `bimanual`, `dexterous_arm`, `complex_upper_body`, `simple_mobile_base`, `articulated_mobile_base`, `drone`, `mobile_manipulator` and `humanoid`. A class outside the list raises a `ValueError`. The class and the `reference` string, which says how the robot is commanded (`ee_abs`, or `base_vel + ee_abs`), are labels: neither changes what a call can do, and the agent is not shown either. The [interface page](https://docs.rua.hud.ai/interfaces/direct-control.md#every-robot-one-tool) shows a call for each class.

## Embodiments

An **embodiment** is the one object that knows a robot. `DirectControl(embodiment)` serves the `move` tool for it, and a new robot is a new class with these four methods.

| Method | What it does |
| - | - |
| `spec()` | Returns the `RobotSpec`: the parts and the space each is commanded in. |
| `measure(state)` | Returns each part's value in its own dimensions, from an observation's state. |
| `report(state)` | Returns extra readouts per part, such as a hand pose for an arm commanded in joints. |
| `realize(curve, measured)` | Returns the controller rows for the whole robot, or the first `Veto`. The curve has every part's setpoints, so a check can span parts. |

Values are in metres, radians and a grip from 0 open to 1 closed. rua ships two embodiments:

| Embodiment | Robot | What it checks |
| - | - | - |
| `rua.embodiments.contract.ContractEmbodiment` | One arm known only by its contract. | The contract's action bounds and the speed limits you give it. It has no model of the arm, so it cannot veto an unreachable pose or a self-collision. |
| `rua.embodiments.composite.Composite` | Several embodiments served as one robot, such as two arms. | What each member checks, on its own, and with an opt-in `clash=` one member against another. |

### Composite

`Composite` gives a robot with several limbs one spec and one clock. Each member keeps its own embodiment and fills its own columns of the controller's action. The members' parts are renamed `<member>_<part>`, and a single arm's `gripper` becomes `hand`. Two contract arms named `left` and `right` give `left_arm`, `left_hand`, `right_arm` and `right_hand`, listed in the order the members are given.

| Parameter | Type | Description |
| - | - | - |
| `members` | `Mapping[str, Embodiment]` | Each member's embodiment by part prefix, at least two. |
| `columns` | `Mapping[str, Sequence[int]]` | The robot's action columns each member's rows fill. Together they cover every column once. |
| `robot_class` | `str` | The class the spec shows. Default `bimanual`. |
| `clash` | `ClashCheck \| None` | Checks the members against each other on the planned path, after each member's own checks pass, such as `HandClearance`. Default `None`, no check between members. |

The spec's `reference` joins the members' references, so an arm in joints beside an arm in hand pose reads `joint_abs + ee_abs`. A veto from one member leads with the robot's part name, such as `left_arm, keyframe 1: x would need a step of 0.0228 at step 2, outside the controller's limits of -0.02 to 0.02.`, and keeps its minimum time.

#### Arm against arm

The check is off by default everywhere: arms that touch play, and the sim decides what happens, so no legal action is refused. An env opts in by passing a check. It fails open: if the check raises, a warning is logged and the call plays unchecked.

A `clash` check sees every member's planned path at every tick, including between keyframes, and vetoes the whole call at the first tick on which two members would collide. The veto names both arms, the keyframe, what would touch and the time, and has no minimum time, since going slower does not help:

```json theme={"dark"}
{"status": "vetoed", "reason": "left_arm and right_arm, keyframe 1: collision, left link_4 would hit right link_4 at t=1.87 s."}
```

| Check | Needs | What it sees |
| - | - | - |
| `rua.embodiments.collision.HandClearance(min_distance_m)` | Members whose `arm` part is in `ee_abs` or `ee_delta`. | The distance between every two hand points. Elbows and forearms are not seen. |

> [!WARNING]
>
> A robot whose members are known only by their contracts has no model of their links, so `HandClearance` is the most it can check, and it is off unless `hand_clearance` is set. A `clash` check is any callable that takes each member's planned path and returns a `Clash` or `None`, so an env with a model of its robot can bring its own. Say in the task prompt that the arms can collide.

`contract_arms` builds a `Composite` of one `ContractEmbodiment` per arm from a contract whose action columns are named `<prefix>.<column>`, such as `left.x` or `right.grip`:

```python theme={"dark"}
from rua.embodiments.composite import contract_arms

robot = contract_arms(CONTRACT, gripper=(0.0, 1.0), max_speed={"position": 0.5, "grip": 2.0})
```

| Parameter | Type | Description |
| - | - | - |
| `contract` | `Mapping` | The robot contract. Every action column is named `<prefix>.<column>`. |
| `arms` | `Mapping[str, str] \| None` | Each arm's contract prefix by part prefix, in the order the parts are listed, such as `{"left": "B", "right": "A"}`. Default: the contract's prefixes, in column order. |
| `state` | `Callable \| None` | Maps the observation's state to the whole robot's pose in the action's layout. Each arm reads its own columns of it. Default: the one state vector as wide as the action. |
| `base_from_native` | `NDArray \| None` | One 4 by 4 transform to the base frame that every arm shares. |
| `gripper` | `tuple[float, float] \| Mapping \| None` | Required. The controller's `(open, closed)` values of the grip column, for every arm or per part prefix, or `None` when no arm has one. |
| `max_speed` | `Mapping` | Required. Speed limits, for every arm or per part prefix: `position` (m/s), `rotation` and `joint` (rad/s), and `grip` (per second) when an arm has a grip column. |
| `space` | `SpaceKind \| Mapping \| None` | The arms' space, for every arm or per part prefix. See `ContractEmbodiment`. |
| `robot_class` | `str` | Default `bimanual`. |
| `hand_clearance` | `float \| None` | The least distance in metres every two hands keep on the planned path, as a `HandClearance` check. Default `None`, no check between the arms. |

A column without a prefix, or an arm without a column, raises a `ValueError` that names it. Arms may differ in space, for example one in joints and one in hand pose: build each `ContractEmbodiment` and pass them to `Composite` with their `columns`.

### ContractEmbodiment

`ContractEmbodiment` reads the contract's action to decide what the agent can move, and converts between the interface's frame and units and the controller's. The action's bounds are its `limits`, or its `stats` when it has none.

| Action kind (`state_type`) | Arm space | Controller rows |
| - | - | - |
| `EE_ABS_POSE`, `EE_ABS_POS` | `ee_abs`, or `ee_delta` with `space=` | Absolute hand targets |
| `EE_DEL_POSE`, `EE_DEL_POS` | `ee_abs`, or `ee_delta` with `space=` | Each step of the curve as the difference from the step before. A rotation is the world-frame change. |
| `JOINT_ABS_POS` | `joint_abs`, joints named `j1` to `jN` | Absolute joint targets |

Any other kind raises a `ValueError` that lists the supported ones. The arm is the part `arm`, and a grip column adds the part `gripper`.

| Parameter | Type | Description |
| - | - | - |
| `contract` | `Mapping` | The robot contract, as the bridge publishes it. |
| `state` | `Callable \| None` | Maps the observation's state to the robot's pose in the action's own layout. Default: the one state vector as wide as the action. A delta contract needs it when none is. |
| `base_from_native` | `NDArray \| None` | A 4 by 4 transform from the controller's world frame to the ROS base frame. Default: the same frame. |
| `gripper` | `tuple[float, float] \| None` | The controller's `(open, closed)` values of the grip column. Required when the action has one. |
| `max_speed` | `Mapping[str, float]` | Required. Speed limits by quantity: `position` (m/s), `rotation` and `joint` (rad/s), and `grip` (per second) when the action has a grip column. A quantity the action needs must be present. |
| `space` | `SpaceKind \| None` | The arm's space, from the table above. |
| `dims` | `list[str] \| None` | The dimensions a call may name, by interface or contract name. The columns it leaves out hold. Needed when the action has a column with no standard name. |

A contract arm serves one end effector, and a contract with two raises a `ValueError`. A contract that states only changes gives no workspace, so absolute calls to it stay within 1 m of the base origin.

## Grading

`DirectControl.recording` holds the episode's played ticks, each with its state and the env's `privileged`
state, and the `done_reason` and `hindsight` the agent gave. An env template grades it outside the sim:

```python theme={"dark"}
from rua.direct import Task, grade
from rua.direct.recording import last_above_first

LIFT = Task("Lift the cube 5 cm.", last_above_first("privileged/cube_pos", index=2, rise=0.05))

yield grade(LIFT, control.recording)
```

A `Task(instruction, measure)` measures a recording: `measure` returns a `Measure(feature, index, value, bar,
unit)`, or `None` when there is nothing to measure. `last_above_first(feature, index, rise)` measures how far
`privileged[feature][index]` ends above where it began. `grade` returns `score` (1.0 or 0.0), `success`, which is
exactly `value >= bar`, the `measure`, and the agent's `done_reason` and `hindsight`. Those two are the agent's
claims, kept beside the measure so a review can check one against the other.

## Settings

The interface settings are the tunable factors of the interface itself, not of a task or an eval. `rua.direct.SETTINGS` holds each setting's one default. `DirectControl(embodiment)` and `create_direct_agent(...)` each resolve every setting the same way, so the tool and the prompt agree: the value in their `settings=` argument, else the `RUA_DC_<NAME>` variable, else the default. `read_settings(overrides, environ)` does that resolving and returns the dict. A setting it does not know, or a value that does not parse, raises a `ValueError` that names it, and so does a `RUA_DC_` variable that is not a setting. A run on Modal, Docker or a deployed env sets the variables where the env runs, and where the agent runs.

```python theme={"dark"}
DirectControl(embodiment, settings={"settle": True})
create_direct_agent(model, spec=spec, cameras=3, max_turns=40, settings={"settle": True})
```

| Setting | Default |
| - | - |
| `path_density` | `keyframes`. `per_tick` takes one pose per control tick instead. |
| `frame_history` | `(0,)`: each camera now only. `RUA_DC_FRAME_HISTORY=-14,-7,0` also shows each camera 14 and 7 control steps ago, oldest first, so a reply shows the motion of the move. Offsets increase and end at 0. `frame_unit` is `steps`, or `seconds`. |
| `observe` | Off, and `observe` is not in the schema, the description or the prompt. `RUA_DC_OBSERVE=1` lets a keyframe take `observe: true` (or false or null). The reply then shows every camera at each observed keyframe's `t`, at the nearest tick, captioned with that time. A snapshot at the call's last tick is the now frame and reads `camera front at t=3.00 s of this call, now:`, and one the history frames already show appears once. Keyframes with only `t` and `observe` hold and watch. At most 5 keyframes of a call may observe; more is refused and nothing plays. Snapshots are JPEG (quality 85); the now and history frames stay PNG. When the reply's images would pass 3 MiB of base64, every snapshot is scaled down together to 75%, 50%, 35% or 25%, whichever is the largest that fits, and its caption says `scaled to 320x240`. When even 25% does not fit, no snapshot is sent and the reply's `status` is `observe_failed` with a `reason`, while the move itself has played. The 3 MiB is rua's own choice, not a transport limit: the reply is one JSON body, so the MCP client's 1 MiB cap on a streamed event does not apply. The agent counts 5 snapshots per reply, so the image horizon keeps `image_turns` replies at the most images each carries, up to the 100-image cap of `image_turns`. A 3-camera env with the default `frame_history` and `image_turns=10` would need 180, so the newest 100 stay. |
| `max_call_s` | 10 s |
| `max_keyframes` | 10 |
| `notes` | On. `move` takes a `note`, and the `done` tool is served. |
| `hindsight` | Off. When on, a `hindsight` tool is served that asks what was hard and what did not work. |
| `describe_cameras` | On. The `move` description says, once, which cameras are fixed in the world and where they sit and look relative to the base, and which move with a body part, from each camera's [`camera`](https://docs.rua.hud.ai/reference/contract#camera-placement) contract field. |
| `settle` | Off. When on, holds the final target until within 1 mm and about 0.4 degrees (0.023 degrees for a joint), rests short for 1.5 s, or 3 s pass. |

An episode has no limit of rua's own. If a benchmark's standard implementation has a time limit, the environment states it in the task prompt, since rua cannot know it. `max_turns` caps the model's turns, and the agent is not told it.

## `create_direct_agent`

```python theme={"dark"}
from rua.direct import create_direct_agent, overview, supports_image_turns

create_direct_agent(
    model: str, *, spec: RobotSpec, cameras: int, max_turns: int, image_turns: int | None = 10, settings: Mapping[str, Any] | None = None, **kwargs
) -> GatewayAgent
```

Builds a HUD gateway agent, which needs `HUD_API_KEY`, with Direct Control's system prompt. `spec` comes from `embodiment.spec()`. The prompt covers the `move` tool, the parts and their ranges, the frames and what a reply shows. It names no budget, no turn count and no time limit, and `max_turns` caps the model's turns without telling it.

| Parameter | Description |
| - | - |
| `cameras` | The number of cameras a reply shows. With `frame_history`, it sets how many images a turn carries. |
| `settings` | The [settings](#settings) the env's `DirectControl` gets. Default: none, so each is read from its variable. |
| `max_turns` | The model's turn cap. |
| `image_turns` | The images of the most recent turns that stay in the model's context. Older images are replaced by a text stub. Default 10. The limit is capped at 100 images, the most Anthropic accepts in one request, so a longer horizon keeps the newest 100. `None` keeps every image. Must be at least 1. |
| `kwargs` | Go to `hud.agents.create_agent`. |

`image_turns` works with Claude agents only today. Any other agent type raises a `ValueError` unless `image_turns` is `None`. `supports_image_turns(model)` says which case a model is, and `overview(read_settings(), spec)` returns the prompt alone.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.