DEV Community

Second article on my journey with the robot, now on building a physical API. CAN bus telemetry with a Rust daemon, dashboards and alerts, and a live 3D copy of the arm mirroring the real one.

CAN Bus Telemetry with a Rust Daemon

The core of the physical API is a Rust daemon that listens on the CAN bus. This daemon handles all low-level communication with the robot arm, parsing raw CAN frames into structured telemetry data.

The daemon exposes this data through a Unix socket, allowing other services to consume it without needing direct CAN bus access. Key responsibilities include:

  • Reading CAN frames from the bus at 1 kHz
  • Parsing joint positions, velocities, and currents
  • Handling error frames and bus-off conditions
  • Publishing telemetry via the Unix socket interface

Dashboards and Alerts

A Python-based dashboard consumes the telemetry stream and provides real-time visualization. Built with FastAPI and WebSockets, it offers:

  • Live joint position plots
  • Velocity and current monitoring
  • System health indicators
  • Configurable alert thresholds

Alerts are triggered when any joint exceeds predefined limits. The alert system supports multiple notification channels, including:

  • Console logging
  • WebSocket push to connected clients
  • HTTP callbacks for external integrations

Live 3D Arm Mirror

The most visually compelling component is a live 3D copy of the robot arm that mirrors the real one in real time. This uses Three.js for rendering and receives joint positions via WebSocket.

The 3D model matches the physical arm's kinematics exactly. Each joint updates at 60 fps, creating a smooth, accurate digital twin. The mirror runs in a browser and requires no special hardware-just the telemetry stream from the Rust daemon.

Architecture Overview

The complete system stack:

  1. Physical layer: CAN bus on the robot arm
  2. Daemon layer: Rust daemon reading CAN frames
  3. Transport layer: Unix socket for inter-process communication
  4. API layer: FastAPI server with WebSocket endpoints
  5. Presentation layer: Dashboard and 3D mirror in the browser

This separation keeps each component focused and testable. The Rust daemon handles real-time constraints, while the Python services provide flexibility for visualization and alerting.

Comments

No comments yet. Start the discussion.