Reproducible Hardware-in-the-Loop (HIL) CI System for Robotics
This design outlines a fully reproducible HIL CI system for robotics development, emphasizing determinism, scalability, and automation. It assumes a ROS 2 (Humble/Iron) ecosystem with embedded hardware (e.g., NVIDIA Jetson or Raspberry Pi for robot controllers) interfaced with simulated physics (Gazebo) and real actuators/sensors via USB/Ethernet. The system uses containerization and orchestration for portability across CI providers (e.g., GitHub Actions, GitLab CI, or self-hosted Kubernetes).
Key principles for reproducibility:
- Determinism: Fixed Docker images, seeded RNGs, immutable infrastructure.
- Isolation: Per-job namespaces, resource limits.
- Idempotency: Clean teardown, snapshot-based rollbacks.
- Hardware Fidelity: QEMU-emulated hardware for CI + optional real hardware pools.
High-Level Architecture
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Git Repo │───▶│ CI Orchestrator │───▶│ HIL Runners │
│ (PR/Merge) │ │ (Kubernetes/ │ │ (VMs/Containers│
└─────────────────┘ │ GitHub Actions)│ │ + HW Pools) │
└──────────────────┘ └──────────────────┘
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ Telemetry │◀──▶│ Execution │
│ Storage │ │ (Gazebo + HW) │
│ (S3/ClickHouse)│ └──────────────────┘
└──────────────────┘ │
▼
┌──────────────────┐
│ Failure Triage │
│ (ML/Log Parser)│
└──────────────────┘
- Triggers: PRs, merges, nightly builds, or cron.
- Scale: 10-100 parallel jobs; hardware-limited.
1. Virtualization Strategy
Achieve HIL reproducibility by layering simulation (software-in-the-loop fallback) over virtualized hardware, with opt-in real hardware.
Core Stack
2. Telemetry Capture
Capture full-fidelity data for debugging/replay. Zero-overhead in happy path.
3. Failure Triage
Automated, ML-assisted classification to reduce MTTR from hours to minutes.
-
Pipeline (Post-job hook):
- Collection: Aggregate telemetry to shared volume/S3.
- Parsing: Custom script (
pytest + pandas):
import mcap.reader; import pandas as pd
def triage(bag_path):
df = pd.read_feather(extract_topics(bag_path, ['/odom', '/errors']))
anomalies = detect_outliers(df['position_error']) # e.g., Isolation Forest
return classify(anomaly_type='drift' if np.mean > 0.1 else 'crash')
- Classification (ML): Train scikit-learn model on historical failures (e.g., timeout, segfault, nav-fail).
- Features: Log entropy, topic latency, CPU spikes.
- 95% accuracy target; fallback to human via Slack notifications.
- Root Cause: Replay in
ros2 bag play + delta debugging (minimize failing input seed).
- Reporting: GitHub Issue auto-create w/ triage label, replay link (Foxglove Studio), flamegraph.
-
Tools: ELK Stack (Elasticsearch for search), Grafana for dashboards, Sentry for crashes.
-
Metrics: Triage accuracy >90%, auto-resolve 40% of flakes.
4. Scheduling
Resource-aware, fair-share queuing for hardware contention.
-
Orchestrator: Kubernetes (KubeCI) or GitHub Actions self-hosted runners.
- Queueing: Argo Workflows for DAGs (e.g., SIL → QEMU → Real).
- Priorities:
| Priority | Triggers | Queue | Timeout |
|---|
| High | Release PRs | 1min | 10min |
| Medium | PRs | 5min | 30min |
| Low | Nightly | 1hr | 2hr |
-
Resource Allocation:
-
Flake Handling: 3 retries w/ exponential backoff + chaos injection (e.g., chaos-mesh for net drops).
Deployment & Cost
- Bootstrap: Terraform for K8s cluster (EKS/GKE, ~$500/mo for 10 nodes).
- Open-Source: All configs in
infra/ repo; Nix flakes for images.
- Validation: Self-test pipeline runs HIL on merge.
- Extensions: Multi-robot swarms (scale Gazebo worlds), air-gapped for classified robotics.
This system has been prototyped in ROS projects (e.g., Nav2 CI); expect 10x faster iteration. Ping for YAML templates or refinements!