# real-stanford/arx5-sdk architecture

> Architecture diagram of the GitHub repository real-stanford/arx5-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/real-stanford/arx5-sdk
- Repository: https://github.com/real-stanford/arx5-sdk

## Overview

#### Purpose and Entry Points
ARX5 SDK is a ROS-free C++ control library with Python bindings for ARX5/X5/L5/X7 robot arms. It drives arm motors over CAN/EtherCAT-CAN, offering background joint control and Cartesian end-effector control. Primary user entry points are Python examples under `python/examples/`, C++ examples under `examples/`, and the pybind module `python/arx5_pybind.cpp`.

#### Controller Core
The controller layer owns robot lifecycle, state/target management, safety limits, and the high-rate control loop. `ControllerBase` provides shared behavior; joint and Cartesian controllers specialize command interpretation.
- `include/app/controller_base.h`
- `src/app/controller_base.cpp`
- `include/app/joint_controller.h`
- `src/app/cartesian_controller.cpp`

Control inputs are converted into bounded joint-level targets; configured joint position, velocity, and torque limits are the internal safety boundary, but callers must apply additional application-level checks, particularly near singularities or with noisy inputs.

#### Kinematics and Cartesian Control
Cartesian control maps desired end-effector motion/poses to joint commands through the solver and a selected robot URDF. This separates application-space command generation from actuator-space execution.
- `include/app/cartesian_controller.h`
- `include/app/solver.h`
- `models/X5.urdf`
- `models/L5.urdf`

Multiple arm/model variants are represented by distinct URDFs, including X5, L5, and left/right X7 variants.

#### Hardware Transport Boundary
The hardware layer abstracts motor communication through CAN frames and SocketCAN. Linux network/CAN interfaces are the operational boundary: USB-CAN adapters expose `can*` devices, while EtherCAT-CAN requires raw/network capabilities on the process.
- `include/hardware/arx_can.h`
- `include/libcan/SocketCAN.h`
- `include/libcan/CANFrame.h`

The library depends on physical ARX motor hardware and Linux SocketCAN/Ethernet networking; it is not a simulator or web service.

#### Python SDK and Interprocess Options
Pybind exposes the C++ controllers/configuration to Python, with type declarations for IDE/static-analysis consumers. Python applications can directly control one or multiple arms; examples cover joint control, waypoint scheduling, teleoperation, calibration, torque control, and bimanual use.
- `python/arx5_pybind.cpp`
- `python/arx5_interface.pyi`
- `python/examples/test_joint_control.py`

Optional ZeroMQ client/server modules provide a process/network control boundary. Shared-memory queues, ring buffers, and ndarrays support local high-throughput peripheral/control pipelines.
- `python/communication/zmq_client.py`
- `python/communication/zmq_server.py`
- `python/shared_memory/shared_memory_ring_buffer.py`

#### Operator Input and Replay Flows
Keyboard and SpaceMouse inputs feed Cartesian commands; teach/replay records or reuses robot trajectories. SpaceMouse support depends on the host spacenav service/library.
- `python/examples/keyboard_teleop.py`
- `python/examples/spacemouse_teleop.py`
- `python/examples/teach_replay.py`

#### Build, Binary Distribution, and Runtimes
CMake builds the native library, examples, and Python extension. Conda environments support source builds across Python 3.8–3.12; wheel packaging distributes prebuilt x86_64 and aarch64 binaries for pip installation, including bundled architecture-specific libraries.
- `CMakeLists.txt`
- `python/CMakeLists.txt`
- `wheels/setup.py`
- `wheels/Dockerfile.x86_64`

Main entry points: [`python/arx5_pybind.cpp`](https://github.com/real-stanford/arx5-sdk/blob/main/python/arx5_pybind.cpp) (Pybind module), [`include/app/controller_base.h`](https://github.com/real-stanford/arx5-sdk/blob/main/include/app/controller_base.h) (ControllerBase), [`src/app/cartesian_controller.cpp`](https://github.com/real-stanford/arx5-sdk/blob/main/src/app/cartesian_controller.cpp) (Cartesian controller), [`include/libcan/SocketCAN.h`](https://github.com/real-stanford/arx5-sdk/blob/main/include/libcan/SocketCAN.h) (SocketCAN)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_native["Native Control Core"]
  node_cpp_examples["C++ examples<br/>entry points"]
  node_controller_base["ControllerBase<br/>lifecycle and control loop<br/>[controller_base.h]"]
  node_joint_controller["Joint controller<br/>joint command controller<br/>[joint_controller.h]"]
  node_cartesian_controller["Cartesian controller<br/>Cartesian command controller"]
  node_solver["Kinematics solver<br/>joint/Catesian mapping<br/>[solver.h]"]
  node_robot_urdf["Robot URDFs<br/>arm model definitions<br/>[X5.urdf]"]
end

subgraph group_transport["Hardware Transport"]
  node_arx_can["ARX CAN layer<br/>motor transport abstraction<br/>[arx_can.h]"]
  node_socketcan["SocketCAN<br/>Linux CAN transport<br/>[SocketCAN.h]"]
  node_can_frame["CAN frames<br/>wire message<br/>[CANFrame.h]"]
  node_physical_hardware{{"ARX motors &amp; CAN network<br/>physical hardware"}}
end

subgraph group_python["Python SDK &amp; Flows"]
  node_pybind_module["Pybind module<br/>Python native extension<br/>[arx5_pybind.cpp]"]
  node_python_api["Python API declarations<br/>typed SDK interface<br/>[arx5_interface.pyi]"]
  node_python_examples["Python control examples<br/>application entry points"]
  node_teleoperation["Keyboard &amp; SpaceMouse teleop<br/>operator input flow<br/>[keyboard_teleop.py]"]
  node_teach_replay["Teach/replay<br/>trajectory workflow<br/>[teach_replay.py]"]
  node_zmq_boundary["ZeroMQ client/server<br/>optional process boundary<br/>[zmq_client.py]"]
  node_shared_memory["Shared-memory ring buffer<br/>local high-throughput IPC"]
end

subgraph group_build["Build &amp; Distribution"]
  node_cmake_build["CMake build<br/>native build system<br/>[CMakeLists.txt]"]
  node_wheel_packaging["Wheel packaging<br/>binary distribution<br/>[setup.py]"]
end

node_cpp_examples -->|"uses"| node_controller_base
node_joint_controller -->|"specializes"| node_controller_base
node_cartesian_controller -->|"specializes"| node_controller_base
node_cartesian_controller -->|"solves Cartesian targets"| node_solver
node_solver -->|"uses selected model"| node_robot_urdf
node_controller_base -->|"sends bounded joint targets"| node_arx_can
node_arx_can -->|"transports over"| node_socketcan
node_socketcan -->|"encodes"| node_can_frame
node_socketcan -->|"uses can* interface"| node_physical_hardware
node_pybind_module -->|"exposes"| node_controller_base
node_pybind_module -->|"exposes"| node_joint_controller
node_pybind_module -->|"exposes"| node_cartesian_controller
node_python_api -.->|"declares types for"| node_pybind_module
node_python_examples -->|"controls through"| node_pybind_module
node_teleoperation -->|"feeds Cartesian commands"| node_cartesian_controller
node_teach_replay -->|"records and replays through"| node_pybind_module
node_zmq_boundary -.->|"optional remote control"| node_pybind_module
node_shared_memory -.->|"supports local pipelines"| node_zmq_boundary
node_cmake_build -->|"builds"| node_pybind_module
node_cmake_build -->|"builds"| node_cpp_examples
node_wheel_packaging -->|"distributes"| node_pybind_module

click node_controller_base "https://github.com/real-stanford/arx5-sdk/blob/main/include/app/controller_base.h"
click node_joint_controller "https://github.com/real-stanford/arx5-sdk/blob/main/include/app/joint_controller.h"
click node_cartesian_controller "https://github.com/real-stanford/arx5-sdk/blob/main/src/app/cartesian_controller.cpp"
click node_solver "https://github.com/real-stanford/arx5-sdk/blob/main/include/app/solver.h"
click node_robot_urdf "https://github.com/real-stanford/arx5-sdk/blob/main/models/X5.urdf"
click node_arx_can "https://github.com/real-stanford/arx5-sdk/blob/main/include/hardware/arx_can.h"
click node_socketcan "https://github.com/real-stanford/arx5-sdk/blob/main/include/libcan/SocketCAN.h"
click node_can_frame "https://github.com/real-stanford/arx5-sdk/blob/main/include/libcan/CANFrame.h"
click node_pybind_module "https://github.com/real-stanford/arx5-sdk/blob/main/python/arx5_pybind.cpp"
click node_python_api "https://github.com/real-stanford/arx5-sdk/blob/main/python/arx5_interface.pyi"
click node_python_examples "https://github.com/real-stanford/arx5-sdk/blob/main/python/examples/test_joint_control.py"
click node_teleoperation "https://github.com/real-stanford/arx5-sdk/blob/main/python/examples/keyboard_teleop.py"
click node_teach_replay "https://github.com/real-stanford/arx5-sdk/blob/main/python/examples/teach_replay.py"
click node_zmq_boundary "https://github.com/real-stanford/arx5-sdk/blob/main/python/communication/zmq_client.py"
click node_shared_memory "https://github.com/real-stanford/arx5-sdk/blob/main/python/shared_memory/shared_memory_ring_buffer.py"
click node_cmake_build "https://github.com/real-stanford/arx5-sdk/blob/main/CMakeLists.txt"
click node_wheel_packaging "https://github.com/real-stanford/arx5-sdk/blob/main/wheels/setup.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cpp_examples,node_controller_base,node_joint_controller,node_cartesian_controller,node_solver,node_robot_urdf toneBlue
class node_arx_can,node_socketcan,node_can_frame,node_physical_hardware toneAmber
class node_pybind_module,node_python_api,node_python_examples,node_teleoperation,node_teach_replay,node_zmq_boundary,node_shared_memory toneMint
class node_cmake_build,node_wheel_packaging toneRose
```

## Components

### Native Control Core

- **C++ examples**: entry points
- [ControllerBase](https://github.com/real-stanford/arx5-sdk/blob/main/include/app/controller_base.h): lifecycle and control loop · Owns state, targets, and bounded joint safety limits. · `include/app/controller_base.h`
- [Joint controller](https://github.com/real-stanford/arx5-sdk/blob/main/include/app/joint_controller.h): joint command controller · `include/app/joint_controller.h`
- [Cartesian controller](https://github.com/real-stanford/arx5-sdk/blob/main/src/app/cartesian_controller.cpp): Cartesian command controller · `src/app/cartesian_controller.cpp`
- [Kinematics solver](https://github.com/real-stanford/arx5-sdk/blob/main/include/app/solver.h): joint/Catesian mapping · `include/app/solver.h`
- [Robot URDFs](https://github.com/real-stanford/arx5-sdk/blob/main/models/X5.urdf): arm model definitions · Selects X5, L5, or other arm variants for Cartesian control. · `models/X5.urdf`

### Hardware Transport

- [ARX CAN layer](https://github.com/real-stanford/arx5-sdk/blob/main/include/hardware/arx_can.h): motor transport abstraction · `include/hardware/arx_can.h`
- [SocketCAN](https://github.com/real-stanford/arx5-sdk/blob/main/include/libcan/SocketCAN.h): Linux CAN transport · `include/libcan/SocketCAN.h`
- [CAN frames](https://github.com/real-stanford/arx5-sdk/blob/main/include/libcan/CANFrame.h): wire message · `include/libcan/CANFrame.h`
- **ARX motors & CAN network**: physical hardware · USB-CAN or EtherCAT-CAN requires Linux network capabilities.

### Python SDK & Flows

- [Pybind module](https://github.com/real-stanford/arx5-sdk/blob/main/python/arx5_pybind.cpp): Python native extension · `python/arx5_pybind.cpp`
- [Python API declarations](https://github.com/real-stanford/arx5-sdk/blob/main/python/arx5_interface.pyi): typed SDK interface · `python/arx5_interface.pyi`
- [Python control examples](https://github.com/real-stanford/arx5-sdk/blob/main/python/examples/test_joint_control.py): application entry points · Includes direct joint control, waypoints, torque, calibration, and bimanual use. · `python/examples/test_joint_control.py`
- [Keyboard & SpaceMouse teleop](https://github.com/real-stanford/arx5-sdk/blob/main/python/examples/keyboard_teleop.py): operator input flow · Converts operator input into Cartesian commands. · `python/examples/keyboard_teleop.py`
- [Teach/replay](https://github.com/real-stanford/arx5-sdk/blob/main/python/examples/teach_replay.py): trajectory workflow · Records or reuses robot trajectories. · `python/examples/teach_replay.py`
- [ZeroMQ client/server](https://github.com/real-stanford/arx5-sdk/blob/main/python/communication/zmq_client.py): optional process boundary · `python/communication/zmq_client.py`
- [Shared-memory ring buffer](https://github.com/real-stanford/arx5-sdk/blob/main/python/shared_memory/shared_memory_ring_buffer.py): local high-throughput IPC · `python/shared_memory/shared_memory_ring_buffer.py`

### Build & Distribution

- [CMake build](https://github.com/real-stanford/arx5-sdk/blob/main/CMakeLists.txt): native build system · Builds the library, examples, and Python extension. · `CMakeLists.txt`
- [Wheel packaging](https://github.com/real-stanford/arx5-sdk/blob/main/wheels/setup.py): binary distribution · Produces x86_64 and aarch64 pip binaries. · `wheels/setup.py`

## Connections

- C++ examples → ControllerBase: uses
- Joint controller → ControllerBase: specializes
- Cartesian controller → ControllerBase: specializes
- Cartesian controller → Kinematics solver: solves Cartesian targets
- Kinematics solver → Robot URDFs: uses selected model
- ControllerBase → ARX CAN layer: sends bounded joint targets
- ARX CAN layer → SocketCAN: transports over
- SocketCAN → CAN frames: encodes
- SocketCAN → ARX motors & CAN network: uses can* interface
- Pybind module → ControllerBase: exposes
- Pybind module → Joint controller: exposes
- Pybind module → Cartesian controller: exposes
- Python API declarations → Pybind module: declares types for
- Python control examples → Pybind module: controls through
- Keyboard & SpaceMouse teleop → Cartesian controller: feeds Cartesian commands
- Teach/replay → Pybind module: records and replays through
- ZeroMQ client/server → Pybind module: optional remote control
- Shared-memory ring buffer → ZeroMQ client/server: supports local pipelines
- CMake build → Pybind module: builds
- CMake build → C++ examples: builds
- Wheel packaging → Pybind module: distributes
