|
| 1 | +# Franka Inference Example |
| 2 | + |
| 3 | +This folder contains a hardware-oriented inference example for running a `vlagents` policy server against the Franka duo setup in [franka.py](franka.py) with configuration from [franka.json](franka.json). |
| 4 | + |
| 5 | +## Policy Server |
| 6 | + |
| 7 | +Before starting `franka.py`, make sure a `vlagents` policy server is already running. The example connects to a remote agent with: |
| 8 | + |
| 9 | +- `vlagents_host` |
| 10 | +- `vlagents_port` |
| 11 | +- `vlagents_model` |
| 12 | + |
| 13 | +The policy server setup and supported launch commands are documented in: |
| 14 | + |
| 15 | +- [RobotControlStack/vlagents](https://github.com/RobotControlStack/vlagents) |
| 16 | +- [vlagents/README.md](../../vlagents/README.md) |
| 17 | + |
| 18 | +Typical server startup looks like: |
| 19 | + |
| 20 | +```shell |
| 21 | +python -m vlagents start-server lerobot --port 20000 --host 0.0.0.0 --kwargs '{"policy_name": "act", "checkpoint_path": "<path to pretrained_model>", "n_action_steps": 1}' |
| 22 | +``` |
| 23 | + |
| 24 | +For other policies such as `pi05` or `xvla`, use the matching startup command from the `vlagents` README and make sure the values in `franka.json` point at that server. |
| 25 | + |
| 26 | +## Config File |
| 27 | + |
| 28 | +[franka.json](franka.json) is an example config, not a universal default. You should review and usually change these values before running inference: |
| 29 | + |
| 30 | +- `vlagents_host`: Hostname or IP address where the policy server is running. |
| 31 | +- `vlagents_port`: Port exposed by the policy server. |
| 32 | +- `vlagents_model`: Agent id passed to `vlagents`, for example `lerobot`. |
| 33 | +- `instruction`: Natural-language task instruction sent to the policy on reset. |
| 34 | +- `robot_keys`: Robot ordering used to pack observations and unpack actions. The script assumes one 8-value action block per robot in this order: `7` joint values plus `1` gripper value. |
| 35 | +- `jpeg_encoding`: Whether observations are sent to the policy server using JPEG-compressed images. |
| 36 | +- `on_same_machine`: Set this according to whether the policy server runs on the same machine as the control process. |
| 37 | +- `fps`: Control loop target frequency used by the local rate limiter. |
| 38 | +- `record_path`: Output directory used when recording episodes. |
| 39 | +- `n_action_steps`: If `null`, the script requests one action per control step. If set to an integer greater than `0`, the script buffers that many actions from each policy response chunk. |
| 40 | +- `max_rel_mov_joints`: Maximum allowed relative joint movement per step when running in joint control mode. |
| 41 | +- `max_rel_mov_cart`: Maximum allowed relative Cartesian translation and rotation per step when running in Cartesian modes. |
| 42 | + |
| 43 | +The current `franka.py` example also contains hardware-specific constants for robot IPs, camera serials, gripper serials, and frame mappings. Those live in the script itself, so update [franka.py](franka.py) if your hardware setup differs. |
| 44 | + |
| 45 | +## Runtime Keys |
| 46 | + |
| 47 | +When [franka.py](franka.py) is running, it waits for keyboard input on stdin. The active commands are: |
| 48 | + |
| 49 | +- `e`: Start an episode without recording. |
| 50 | +- `r`: Start an episode and begin recording to `record_path`. |
| 51 | +- `s`: Mark the current episode as successful and reset the environment. |
| 52 | +- `q`: Stop the current episode and reset the environment. |
| 53 | +- `o`: Reload `franka.json`, reconnect the `vlagents` client, reset the environment, and clear any buffered actions. |
| 54 | +- `x`: Exit the program. |
| 55 | + |
| 56 | +## Observation And Action Mapping |
| 57 | + |
| 58 | +The script translates RCS observations to the `vlagents` `Obs` format as follows: |
| 59 | + |
| 60 | +- Every camera frame in `obs["frames"]` is converted to RGB and resized to `224x224`. |
| 61 | +- State is built by iterating through `robot_keys` in order and concatenating each robot's `joints` and `gripper` values. |
| 62 | + |
| 63 | +Action decoding is also order-dependent: |
| 64 | + |
| 65 | +- For each robot in `robot_keys`, the script reads `8` values from the policy action vector. |
| 66 | +- Values `0:7` become the robot joint command. |
| 67 | +- Value `7:8` becomes the robot gripper command. |
| 68 | + |
| 69 | +That means `robot_keys` must match the policy's expected robot ordering exactly. |
| 70 | + |
| 71 | +## Running |
| 72 | + |
| 73 | +After the policy server is up and `franka.json` is configured, run: |
| 74 | + |
| 75 | +```shell |
| 76 | +python examples/inference/franka.py |
| 77 | +``` |
| 78 | + |
| 79 | +If the policy server is unreachable, the script will keep retrying connection until it becomes available or you exit. |
0 commit comments