File size: 11,900 Bytes
700dd75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | # C++ Deployment Program Flow
This document describes how the main executables run, their arguments, and the logging/configuration options.
## Program Pipeline
High-level flow (matches current code):
- Input interfaces: `keyboard | gamepad | gamepad_manager | zmq | zmq_manager | ros2 | manager`
- Optional planner (when enabled) generates target animations
- Motion reader provides reference motions for non-planner mode
- Policy inference (TensorRT; optional encoder β decoder)
- Output publishing via `--output-type <zmq|ros2|all>`
## Available Commands
```sh
just build # Build main project
just clean # Clean build artifacts
just --list # Show all available commands
```
## Run
### Frequency Test
Load an ONNX model and print input/output info. This is a sanity check for model loading; the reported frequency is not TensorRT inference speed.
```sh
# Basic usage with default settings (1000 iterations, random data)
just run freq_test policy/example/model_step_000000.onnx
# Custom iterations and data mode
just run freq_test policy/example/model_step_000000.onnx 5000 random
```
**Usage:** `just run freq_test <model_file> [iterations] [data_mode]`
- `model_file`: Path to ONNX model file (required)
- `iterations`: Number of inference iterations (default: 1000)
- `data_mode`: Input data type β `zeros|random|ones` (default: random)
### Policy Deployment
Deploy ONNX policy on G1 robot with motion reference control:
```sh
# Example command (real robot)
just run g1_deploy_onnx_ref enP8p1s0 policy/release/model_decoder.onnx reference/example/ \
--obs-config policy/release/observation_config.yaml \
--encoder-file policy/release/model_encoder.onnx \
--planner-file planner/target_vel/V2/planner_sonic.onnx \
--input-type manager \
--enable-motion-recording \
--enable-csv-logs
# MuJoCo simulation (disables CRC validation)
python ../gear_sonic/scripts/run_sim_loop.py
just run g1_deploy_onnx_ref lo policy/release/model_decoder.onnx reference/example/ \
--obs-config policy/release/observation_config.yaml \
--encoder-file policy/release/model_encoder.onnx \
--planner-file planner/target_vel/V2/planner_sonic.onnx \
--input-type manager \
--enable-motion-recording \
--enable-csv-logs \
--disable-crc-check
```
**Usage:** `just run g1_deploy_onnx_ref <network_interface> <model_file> <motion_data_path> [options...]`
**Required Arguments:**
- `network_interface`: Network interface for DDS communication (e.g., `eth0`, `enp5s0`, `enP8p1s0`, `lo`)
- `model_file`: Path to ONNX policy model file
- `motion_data_path`: Path to motion data directory containing reference motions
**Optional Arguments:**
**Model Configuration:**
- `--obs-config <path>`: Path to observation configuration YAML file
- `--encoder-file <path>`: Path to ONNX encoder model file (optional, for token-based policies)
- `--planner-file <path>`: Path to ONNX planner model file (required for ROS2, `gamepad_manager`, and `zmq_manager` planner mode)
- `--planner-precision <16|32>`: Floating point precision for planner (default: 32)
- `--policy-precision <16|32>`: Floating point precision for policy (default: 32)
**Output Mode:**
- `--output-type <type>`: Output interface for publishing control results
- `zmq` β Publish via ZMQ (default)
- `ros2` β Publish via ROS2 (only if built with ROS2 support)
- `all` β Create all available output interfaces simultaneously
**Input Mode:**
- `--input-type <type>`: Input interface type (default: `keyboard`)
- `keyboard` β Direct keyboard input
- `gamepad` β Wireless controller
- `gamepad_manager` β Gamepad + quick switching to ZMQ/ROS2
- `zmq` β Network motion streaming
- `zmq_manager` β Dynamic switching between planner and network motion streaming
- `manager` β Dynamic switching between keyboard, gamepad, ZMQ, and ROS2
- `ros2` β ROS2 topic control (requires planner, only if built with ROS2 support)
**ZMQ Configuration (when using `--input-type zmq`, `zmq_manager`, `demo_gamepad_manager`, or `manager`):**
- `--zmq-host <host>`: ZMQ server host (default: `localhost`)
- `--zmq-port <port>`: ZMQ server port (default: `5556`)
- `--zmq-topic <topic>`: ZMQ topic/prefix (default: `pose`)
- `--zmq-conflate`: Enable ZMQ CONFLATE mode
- `--zmq-verbose`: Enable verbose ZMQ subscriber logging
- `--zmq-out-port`: Port to which control results will be published when using `--output-type zmq` (default: `5557`)
- `--zmq-out-topic`: Topic to which control results will be published when using `--output-type zmq` (default: `g1_debug`)
**Simulation:**
- `--disable-crc-check`: Disable CRC validation (required for MuJoCo simulation)
**Hand & Compliance Control:**
- `--set-compliance <value>`: Set initial VR 3-point compliance (0.01 = rigid, 0.5 = compliant; default: `0.5,0.5,0.0`). Can specify 1 value (applied to both hands) or 3 comma-separated values (`left_wrist,right_wrist,head`). Runtime keyboard controls: `g/h` = left hand Β±0.1, `b/v` = right hand Β±0.1.
- `--max-close-ratio <value>`: Set initial hand max close ratio (0.2β1.0; default: 1.0 = full closure allowed). Runtime keyboard controls: `x/c` = Β±0.1.
**Logging (CLI flags):**
- **Debug / analysis logs (write a single CSV file)**:
- `--target-motion-logfile <path>`: Log the target motion tracked by the controller (visualize with `visualize_motion.py`)
- `--planner-motion-logfile <path>`: Log planner-generated animation sequences
- `--policy-input-logfile <path>`: Log policy input (observation) tensors
- `--record-input-file <path>`: Record operator control inputs to CSV for later playback
- `--playback-input-file <path>`: Play back previously recorded control inputs from CSV
- **State CSV logs (write a timestamped directory)**:
- `--logs-dir <path>`: Base directory for state CSV logs (default: `logs/dd-mm-yy/hh-mm-ss`)
- `--enable-csv-logs`: Enable robot state CSV logging (default: OFF)
- `--enable-motion-recording`: Record the active motion stream(s) to `reference/recorded_motion/...` (default: OFF)
## Logging (Details)
The system provides multiple logging capabilities for debugging, analysis, and replay.
### Motion Logging
**Target Motion (`--target-motion-logfile <path>`):**
- Logs the motion the controller is tracking each control frame (~50 Hz)
- CSV columns: `pos_x, pos_y, pos_z, rot_qw, rot_qx, rot_qy, rot_qz, dof_0, dof_1, ... dof_28`
- Global position (xyz)
- Global rotation quaternion (w, x, y, z)
- 29 joint angles (DoF)
**Planner Motion (`--planner-motion-logfile <path>`):**
- Logs animation sequences generated by the planner (~10 Hz planning updates)
- Each planner update produces a short sequence (e.g., ~100 frames) that is appended to the CSV
- Same CSV format as target motion
- Contains motion blending and replanning results
**Motion Recording (`--enable-motion-recording`):**
- Automatically records the currently active motion stream(s) into timestamped folders under `reference/recorded_motion/YYYYMMDD/`
- **Streamed motion** (ZMQ pose topic): saved as `streamed_HHMMSS/`
- **Planner motion** (planner-generated sequence): saved as `planner_motion_HHMMSS/`
- Each recording folder contains `joint_pos.csv`, `joint_vel.csv`, `body_pos.csv`, `body_quat.csv`, etc.
- Useful for offline inspection / regression comparisons of closed-loop behavior
### Visualization
All motion CSV files (logged data and reference motions) can be visualized using the `visualize_motion.py` script:
```sh
# Visualize logged motion data (single CSV file)
python visualize_motion.py --csv_path target_motion.csv
# Visualize reference motion from motion data directory
python visualize_motion.py --motion_dir reference/example/high_jump_full_turn/
```
The visualizer script can connect to a running `g1_deploy` executable to visualize target/measured robot motions in real time:
```sh
python visualize_motion.py --realtime_debug_url tcp://localhost:5557
```
This displays four G1 robots: target animation (colored), target with zero translation (green), measured sensor data (red), and motor temperature heatmap (white, with per-joint color indicators: green β yellow β orange β red/flashing by temperature).
**Configuration:**
- Default port: 5557 (change with `--zmq-out-port <port>`)
- Default topic: `g1_debug` (change with `--zmq-out-topic <topic>` on executable, `--realtime_debug_topic <topic>` on visualizer)
- For physical robots, replace `localhost` with the robot's IP address
**Playback Controls:**
- **Space**: Pause/resume playback
- **`.`** (period): Step forward one frame
- **`,`** (comma): Step backward one frame
- **`r`**: Reset to frame 0
### Policy Input Logging
**Policy Input (`--policy-input-logfile <path>`):**
- Logs the raw observation tensor fed to the neural network policy
- Output: a single CSV file (one row per control step, all observation values)
- Useful for debugging observation configuration and input drift
### Control Input Recording/Playback
**Recording (`--record-input-file <path>`):**
- Records control inputs (motion index, frame, operator state, planner state, movement commands)
- Logging starts when the control system is activated
- Tip: Wait a few seconds after lowering from gantry before starting control to give yourself setup time during playback
**Playback (`--playback-input-file <path>`):**
- Replays recorded control inputs for reproducible experiments
- Playback starts when the control system is activated
- Useful for testing policy changes with identical inputs
### Robot State CSV Logger
When enabled with `--enable-csv-logs`, the system logs detailed robot state at each control step (50 Hz).
**Output Directory:**
- Default: `logs/dd-mm-yy/hh-mm-ss` (auto-generated timestamp)
- Custom: Use `--logs-dir <path>` to specify directory
**Files Generated (split by signal type):**
- `base_quat.csv` β Base IMU quaternion (4 values: w, x, y, z)
- `base_ang_vel.csv` β Base angular velocity (3 values: x, y, z)
- `torso_quat.csv` β Torso IMU quaternion (4 values)
- `torso_ang_vel.csv` β Torso angular velocity (3 values)
- `q.csv` β Joint positions (29 joints)
- `dq.csv` β Joint velocities (29 joints)
- `action.csv` β Policy actions (29 joints)
**CSV Format:**
- Columns: `index,time_ms,...`
- `time_ms`: Milliseconds since first log (0.0 at start, fractional allowed)
- Synchronized across all files using the same index/timestamp
**Example:**
```sh
just run g1_deploy_onnx_ref enp5s0 policy/model.onnx reference/motions/ \
--obs-config policy/obs_config.yaml \
--enable-csv-logs \
--logs-dir logs/my_experiment
```
## Observation Configuration
The system uses YAML configuration files to define which observations are fed to the policy. This allows flexible policy designs without code changes.
**Basic Structure (`--obs-config <path>`):**
```yaml
observations:
- name: "body_joint_positions"
enabled: true
- name: "base_angular_velocity"
enabled: true
# ... other observations
```
**With Encoder (Token-Based Policies):**
For policies that use encoded tokens, add an `encoder:` section:
```yaml
observations:
- name: "token_state" # Encoder outputs (64-dim tokens)
enabled: true
- name: "base_angular_velocity" # Direct observations
enabled: true
encoder:
dimension: 64 # Token output dimension
use_fp16: false # TensorRT precision (optional)
encoder_observations:
- name: "motion_joint_positions_10frame_step5"
enabled: true
# ... observations fed to encoder
```
Then run with `--encoder-file <path>` to load the encoder model. If omitted, tokens can be set externally via ROS2/ZMQ.
**Complete Observation Reference:**
For the full list of all available observation names, dimensions, and example configurations, see [Observation Configuration](observation_config.md).
**Examples:**
- See `policy/observation_config_example.yaml`
|