Skip to content
Open
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
7 changes: 7 additions & 0 deletions aic_interfaces/aic_control_interfaces/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ channels = [
"robostack-kilted",
"conda-forge",
]

[package.build-dependencies]
empy = "==3.3.4"

[package.host-dependencies]
empy = "==3.3.4"

3 changes: 3 additions & 0 deletions aic_interfaces/aic_model_interfaces/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ channels = [
]

[package.host-dependencies]
empy = "==3.3.4"
ros-kilted-aic-control-interfaces = { path = "../aic_control_interfaces" }

[package.build-dependencies]
empy = "==3.3.4"
ros-kilted-aic-control-interfaces = { path = "../aic_control_interfaces" }

7 changes: 7 additions & 0 deletions aic_interfaces/aic_task_interfaces/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ channels = [
"robostack-kilted",
"conda-forge",
]

[package.build-dependencies]
empy = "==3.3.4"

[package.host-dependencies]
empy = "==3.3.4"

19 changes: 19 additions & 0 deletions aic_logging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.8)
project(aic_logging)

find_package(ament_cmake REQUIRED)

install(
PROGRAMS record.py
DESTINATION lib/${PROJECT_NAME}
)

install(
FILES
recording_config.yaml
zenoh_router_config.json5
zenoh_session_config.json5
DESTINATION share/${PROJECT_NAME}
)

ament_package()
191 changes: 191 additions & 0 deletions aic_logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# 📦 AIC Logging (`aic_logging`)

This package provides a **decoupled, external recording workflow** for logging ROS 2 topics, services, and actions from the AIC solution context to MCAP bag files over a 10GbE network connection.

---

## 🏗️ Architecture & 10GbE Network Bandwidth Math

Rather than recording bag files directly inside Kubernetes pod services (which introduces storage I/O bottlenecks and pod lifecycle constraints), recording is offloaded to a **dedicated external recording machine** connected to the Industrial PC (IPC) network over a high-speed **10GbE link**.

### Bandwidth Calculation for 3x 5MP Cameras:
- **Single 5MP Uncompressed RGB8 Frame**: ~2448 × 2048 × 3 bytes = **~15 MB per frame** (120 Megabits).
- **3 Cameras** (`wrist_camera_1`, `wrist_camera_2`, `workcell_camera_1`): **45 MB per synchronized frame set**.
- **10GbE Real-world Network Limit**: ~950–1,000 MB/s (~7.6–8.0 Gbps) safe operational ceiling.

| Frequency / Camera | Total Image Data Rate | 10GbE Network Status |
| :--- | :--- | :--- |
| **30.0 Hz** | $3 \times 15\text{ MB} \times 30 = \mathbf{1,350\text{ MB/s}}\ (10.8\text{ Gbps})$ | ❌ **Exceeds 10GbE link** (Drops frames) |
| **20.0 Hz** | $3 \times 15\text{ MB} \times 20 = \mathbf{900\text{ MB/s}}\ (7.2\text{ Gbps})$ | ✅ **Selected Operational Rate** (~72% of 10GbE) |
| **15.0 Hz** | $3 \times 15\text{ MB} \times 15 = \mathbf{675\text{ MB/s}}\ (5.4\text{ Gbps})$ | ✅ **Conservative Safe Rate** |

Over a 10GbE link, streaming 3x 5MP uncompressed cameras at **20.0 Hz** consumes **900 MB/s (7.2 Gbps)**, comfortably operating within the 10GbE network bandwidth budget.

---

## ⚙️ Configuration Files

### 1. Zenoh Router Configuration (`zenoh_router_config.json5`)
Configures 20.0 Hz rate limiting rules for wrist and workcell camera RGB streams and camera info topics:

```json5
{
mode: "router",
connect: {
endpoints: [
"tcp/ip.address.of.ipc:17447"
]
},
listen: {
endpoints: [
"tcp/0.0.0.0:7447"
]
},
downsampling: [
{ key_expr: "**/wrist_camera_1/rgb/**", freq: 20.0 },
{ key_expr: "**/wrist_camera_1/camera_info/**", freq: 20.0 },
{ key_expr: "**/wrist_camera_2/rgb/**", freq: 20.0 },
{ key_expr: "**/wrist_camera_2/camera_info/**", freq: 20.0 },
{ key_expr: "**/workcell_camera_1/rgb/**", freq: 20.0 },
{ key_expr: "**/workcell_camera_1/camera_info/**", freq: 20.0 }
]
}
```

> [!IMPORTANT]
> Make sure to update the `connect.endpoints` value in `zenoh_router_config.json5` with the actual IP address or hostname of your Industrial PC (IPC), for example: `"tcp/192.168.1.100:17447"` (replacing `"tcp/ip.address.of.ipc:17447"`).

---

### 2. Bagging Configuration (`recording_config.yaml`)
Configures MCAP storage options and the exact list of topics and actions to record:

```yaml
storage:
identifier: "mcap" # Storage plugin: "mcap" or "sqlite3"
output_dir: "/tmp/aic_bags" # Base output directory
preset_profile: "zstd_fast" # Storage preset: "none", "fastwrite", "zstd_fast", "zstd_small"
max_cache_size: 104857600 # 100 MB buffer cache (increase to 500MB-1GB for high throughput)

topics:
record_all: false
include:
- "/wrist_camera_1/rgb"
- "/wrist_camera_1/camera_info"
- "/wrist_camera_2/rgb"
- "/wrist_camera_2/camera_info"
- "/workcell_camera_1/rgb"
- "/workcell_camera_1/camera_info"
- "/ati/wrench"
- "/joint_states"
- "/robot_description"
- "/gripper_state"
- "/controller/cartesian_commands"
- "/controller/joint_commands"
- "/task_state"
- "/rosout"
exclude: []

services:
record_all: false
include: []
exclude: []

actions:
record_all: false
include:
- "/insert_cable"
exclude: []

advanced:
node_name: "aic_external_recorder"
```

---

## 🚀 Option 1: Recording with Local Zenoh Router

### 1. Setup Environment on Recording Machine
```bash
cd src/aic
pixi install
```

### 2. Start the Local Zenoh Router (20.0 Hz Rate Limit)
```bash
ZENOH_ROUTER_CONFIG_URI=aic_logging/zenoh_router_config.json5 pixi run ros2 run rmw_zenoh_cpp rmw_zenohd
```

This can be verified by downsampling further and checking that the rate reported by `ros2 topic hz` goes down.

### 3. Start Recording Session
```bash
# Preview the ros2 bag record command
pixi run python3 aic_logging/record.py --dry-run

# Start recording
pixi run python3 aic_logging/record.py --config aic_logging/recording_config.yaml --name "cable_insertion_run"
```

---

## 🚀 Option 2: Recording without Zenoh Router (Direct to IPC)

This sets the Zenoh session to
* be a client directly to the IPC's Zenoh router
* have no rate limiting
* enable shared memory with increased memory buffer
* use large TCP socket buffer

### 1. Setup Environment on Recording Machine
```bash
cd src/aic
pixi install
```

### 2. Start Recording Session
```bash
# Preview the ros2 bag record command
ZENOH_SESSION_CONFIG_URI=aic_logging/zenoh_session_config.json5 pixi run python3 aic_logging/record.py --dry-run

# Start recording
ZENOH_SESSION_CONFIG_URI=aic_logging/zenoh_session_config.json5 pixi run python3 aic_logging/record.py --config aic_logging/recording_config.yaml --name "cable_insertion_run"
```

---

## 🔍 Inspecting and Playing Back Bags

### Inspect Bag Metadata
```bash
pixi run ros2 bag info /tmp/aic_bags/<BAG_FOLDER_NAME>
```

### Play Back Recorded Bag
```bash
pixi run ros2 bag play /tmp/aic_bags/<BAG_FOLDER_NAME>
```

---

## 💡 High-Throughput & Bandwidth Optimization Recommendations

When logging multiple uncompressed 5MP camera streams (~900 MB/s continuous):

1. **Eliminate CPU Compression Bottleneck (`preset_profile`)**:
- `zstd_fast` compresses frames on CPU in real-time. At ~900 MB/s, Zstd compression requires multiple CPU cores and can saturate CPU threads, causing writer queue overflow.
- For ultra-high write speeds to an NVMe SSD, switch `preset_profile` to `"fastwrite"` or `"none"` in `recording_config.yaml`.
2. **Increase Recorder Cache (`max_cache_size`)**:
- Increase `max_cache_size` to `524288000` (500 MB) or `1048576000` (1 GB) to smooth out NVMe write flush spikes.
3. **TCP Socket Buffer & Kernel Tuning**:
- Increase OS TCP receive buffers on both host and recording machine:
```bash
sudo sysctl -w net.core.rmem_max=67108864
sudo sysctl -w net.core.wmem_max=67108864
sudo sysctl -w net.ipv4.tcp_rmem="4096 87380 67108864"
sudo sysctl -w net.ipv4.tcp_wmem="4096 65536 67108864"
```
4. **Enable 9000 MTU Jumbo Frames**:
- Standard 1500 MTU generates ~600,000 packets/sec for 900 MB/s. Configuring MTU 9000 on the 10GbE NICs drops interrupt rate by 6x and reduces CPU overhead.
5. **Shared Memory Pool Size (`/dev/shm`)**:
- The default SHM pool in Zenoh is 48 MiB. When handling 3x 15 MB frames (45 MB), the pool quickly exhausts. We increased `pool_size` in `zenoh_session_config.json5` to 256 MiB (`268435456`). Ensure `/dev/shm` has sufficient capacity (`df -h /dev/shm`).
21 changes: 21 additions & 0 deletions aic_logging/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>aic_logging</name>
<version>0.1.0</version>
<description>External ROS 2 logging and Zenoh router configuration for AIC</description>
<maintainer email="aaronchong@google.com">aaronchong</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<exec_depend>ros2bag</exec_depend>
<exec_depend>rosbag2_cpp</exec_depend>
<exec_depend>rosbag2_storage_mcap</exec_depend>
<exec_depend>rosbag2_transport</exec_depend>
<exec_depend>rmw_zenoh_cpp</exec_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
8 changes: 8 additions & 0 deletions aic_logging/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package.build.backend]
name = "pixi-build-ros"
version = "==0.3.3.20260113.c8b6a54"
channels = [
"https://prefix.dev/pixi-build-backends",
"robostack-kilted",
"conda-forge",
]
Loading
Loading