Skip to main content
Glama
gcu-gimbal-mcp

gcu-gimbal-mcp

by ros-claw
README.md
# gcu-gimbal-mcp

๐ŸŒ **English** | [ไธญๆ–‡](./README.zh.md)

ROSClaw MCP Server for **Xianfei GCU Series Camera Gimbal** via Serial protocol.

Part of the [ROSClaw](https://github.com/ros-claw) Embodied Intelligence Operating System.

## Overview

This MCP server enables LLM agents to control **Xianfei Technology** GCU series camera gimbals through the Model Context Protocol. The GCU (Gimbal Control Unit) series includes the **Z-2Mini** and **A5** dual-camera gimbal models featuring visible light + thermal imaging cameras.

The server communicates via RS-232/USB serial using the proprietary GCU binary protocol with CRC-16 error checking.

```
LLM Agent  โ”€โ”€MCPโ”€โ”€โ–บ  gcu-gimbal-mcp  โ”€โ”€Serialโ”€โ”€โ–บ  GCU Gimbal (Z-2Mini/A5)
```

### Manufacturer Information

| Item | Details |
|------|---------|
| **Manufacturer** | Xianfei Technology |
| **Location** | Nanjing, China |
| **Product Series** | GCU (Gimbal Control Unit) |
| **Supported Models** | Z-2Mini, A5 Gimbal |
| **Product Type** | Dual-camera payload (Visible + Thermal) |

## SDK Information

| Property | Value |
|----------|-------|
| **SDK Name** | GCU Gimbal SDK |
| **SDK Version** | V2.0.6 |
| **Protocol** | Binary Serial (Proprietary) |
| **Protocol Document** | [GCU Protocol V2.0.6 (Chinese)](./docs/GCU็งๆœ‰้€šไฟกๅ่ฎฎ-XF(A5)V2.0.6.pdf) |
| **Manufacturer** | Xianfei Technology |
| **Product Series** | GCU (Gimbal Control Unit) |
| **Source** | Proprietary |
| **License** | Proprietary |
| **Generated** | 2026-04-07 |

## Hardware Specification

### Product Information

| Specification | Value |
|--------------|-------|
| **Product Name** | GCU Dual-Camera Gimbal |
| **Manufacturer** | Xianfei Technology, Nanjing, China |
| **Supported Models** | Z-2Mini, A5 |
| **Camera Type** | Visible Light + Thermal Imaging |
| **Application** | UAV Payload, Robotics, Surveillance |

### Mechanical Specifications

| Specification | Value |
|--------------|-------|
| **Axes** | 3-axis (Yaw, Pitch, Roll) |
| **Rotation Range** | Yaw: ยฑ170ยฐ, Pitch: -90ยฐ to +30ยฐ, Roll: ยฑ45ยฐ |
| **Max Speed** | ยฑ150ยฐ/s (pitch/yaw) |
| **Stabilization** | 3-axis mechanical stabilization |

### Communication Interface

| Specification | Value |
|--------------|-------|
| **Protocol** | GCU Binary Serial Protocol |
| **Serial Config** | 115200 bps, 8 data bits, 1 stop bit, No parity |
| **Frame Header** | 0xA8 0xE5 (send) / 0x8A 0x5E (receive) |
| **Checksum** | CRC-16 |
| **Command Frequency** | Up to 50Hz |

### Supported Models

| Model | Description | Weight | Application |
|-------|-------------|--------|-------------|
| **Z-2Mini** | Compact dual-camera gimbal | ~300g | Small UAVs, robotics |
| **A5** | Advanced thermal+visible camera system | ~500g | Professional UAVs |

### Camera Specifications

| Feature | Visible Camera | Thermal Camera |
|---------|---------------|----------------|
| Resolution | 1920x1080 | 640x512 |
| Zoom | Optical + Digital | Fixed |
| Night Vision | No | Yes (IR mode) |
| Recording | Yes | Yes |

## Features

- **3-axis control**: Yaw, pitch, roll with degree precision
- **Multiple modes**: Stabilization, follow, FPV, lock
- **Camera control**: Photo capture, video record, zoom, focus
- **Night vision**: IR mode with multiple sensitivity levels
- **Real-time feedback**: Position, temperature, velocity at 50Hz
- **CRC-16 checksum**: Reliable serial communication
- **Auto-reconnect**: Handles serial disconnections gracefully

## Installation

```bash
# Clone
git clone https://github.com/ros-claw/gcu-gimbal-mcp.git
cd gcu-gimbal-mcp

# Install with uv (recommended)
uv venv --python python3.10
source .venv/bin/activate
uv pip install -e .

# Or with pip
pip install -e .
```

### Serial Port Permissions (Linux)

```bash
sudo usermod -a -G dialout $USER
# Log out and back in for group changes to take effect
```

## Quick Start

### Run as MCP Server

```bash
# stdio transport
python src/gimbal_mcp_server.py
```

### Claude Desktop Configuration

```json
{
  "mcpServers": {
    "rosclaw-gimbal": {
      "command": "python",
      "args": ["/path/to/rosclaw-gimbal-mcp/src/gimbal_mcp_server.py"],
      "transportType": "stdio",
      "description": "GCU Gimbal V2.0.6",
      "sdk_version": "V2.0.6",
      "sdk_source": "Proprietary"
    }
  }
}
```

### MCP Inspector (Testing)

```bash
mcp dev src/gimbal_mcp_server.py
```

## Available Tools

| Tool | Description |
|------|-------------|
| `connect_gimbal` | Connect to gimbal on serial port |
| `disconnect_gimbal` | Disconnect from gimbal |
| `set_mode` | Set control mode (stabilize/follow/fpv/lock) |
| `rotate` | Rotate with angular velocity |
| `set_euler_angles` | Go to absolute yaw/pitch/roll |
| `reset_gimbal` | Return to center position |
| `calibrate` | Calibrate gimbal IMU |
| `take_photo` | Trigger camera shutter |
| `toggle_record` | Toggle video recording |
| `zoom` | Control zoom (in/out/stop) |
| `set_zoom_level` | Set specific zoom level |
| `focus` | Trigger autofocus |
| `set_night_vision` | Enable IR/night vision mode |
| `set_osd` | Enable/disable on-screen display |
| `set_illumination` | Set LED illumination brightness |
| `set_ranging` | Enable laser rangefinder |
| `stop_rotation` | Emergency stop rotation |
| `demo_scan` | Perform scan demonstration |

## Available Resources

| Resource | Description |
|----------|-------------|
| `gimbal://status` | Current angles, mode, temperature |
| `gimbal://connection` | Serial connection status |
| `gimbal://sdk_info` | SDK metadata and version |

## Work Modes

| Mode | Code | Description |
|------|------|-------------|
| `angle_lock` | 0x11 | Pointing lock mode |
| `follow` | 0x12 | Pointing follow mode |
| `euler` | 0x14 | Euler angle control mode |
| `fpv` | 0x1C | First-person view mode |
| `top_down` | 0x13 | Top-down shooting mode |

## Angle Limits

| Axis | Range | Safety Level |
|------|-------|--------------|
| Yaw | -170ยฐ to +170ยฐ | ๐ŸŸ  HIGH |
| Pitch | -90ยฐ to +30ยฐ | ๐ŸŸ  HIGH |
| Roll | -45ยฐ to +45ยฐ | ๐ŸŸก MEDIUM |

### Speed Limits

| Axis | Max Speed | Safety Level |
|------|-----------|--------------|
| Pitch | ยฑ150ยฐ/s | ๐Ÿ”ด CRITICAL |
| Yaw | ยฑ150ยฐ/s | ๐Ÿ”ด CRITICAL |
| Roll | ยฑ150ยฐ/s | ๐Ÿ”ด CRITICAL |

## Serial Protocol

The GCU protocol uses binary frames:

```
[0xA8][0xE5][LEN_L][LEN_H][VER][DATA...][CRC16_L][CRC16_H]
```

### Frame Structure

| Field | Size | Description |
|-------|------|-------------|
| Header | 2 bytes | 0xA8 0xE5 (send) / 0x8A 0x5E (receive) |
| Length | 2 bytes | Packet length (little-endian) |
| Version | 1 byte | Protocol version (0x01) |
| Data | Variable | Command + parameters |
| CRC16 | 2 bytes | CRC-16 checksum (big-endian) |

### Command Codes

| Command | Code | Description |
|---------|------|-------------|
| `CMD_CALIBRATION` | 0x01 | IMU calibration |
| `CMD_RESET` | 0x03 | Reset to center |
| `CMD_PHOTO` | 0x20 | Take photo |
| `CMD_RECORD` | 0x21 | Toggle recording |
| `CMD_ZOOM_IN` | 0x22 | Zoom in |
| `CMD_ZOOM_OUT` | 0x23 | Zoom out |
| `CMD_ZOOM_STOP` | 0x24 | Stop zoom |
| `CMD_ZOOM_SET` | 0x25 | Set zoom level |
| `CMD_FOCUS` | 0x26 | Autofocus |
| `CMD_NIGHT_VISION` | 0x2B | IR/night vision |
| `CMD_OSD` | 0x73 | On-screen display |
| `CMD_ILLUMINATION` | 0x80 | LED brightness |
| `CMD_RANGING` | 0x81 | Laser rangefinder |

## Safety Information

**WARNING:** This MCP server controls a motorized gimbal. Improper use can cause:
- Equipment damage
- Motor overheating
- Mechanical wear

### Safety Features

| Feature | Description |
|---------|-------------|
| **Speed Limits** | ยฑ150ยฐ/s enforced in software |
| **Angle Limits** | Mechanical limits enforced |
| **CRC Checksum** | All packets validated |
| **Emergency Stop** | `stop_rotation()` immediate halt |

### Safety Levels

| Level | Color | Description | Example |
|-------|-------|-------------|---------|
| **CRITICAL** | ๐Ÿ”ด | Immediate danger | Speed > 150ยฐ/s |
| **HIGH** | ๐ŸŸ  | Potential damage | Angle near limit |
| **MEDIUM** | ๐ŸŸก | Caution needed | Extended operation |
| **LOW** | ๐ŸŸข | Informational | Status check |

### Emergency Procedures

1. **Immediate Stop**: Use `stop_rotation()` tool
2. **Power Off**: Disconnect power if mechanical issue
3. **Reset**: Use `reset_gimbal()` to return to center

## Error Handling

### Error Codes

| Code | Name | Severity | Description |
|------|------|----------|-------------|
| -1 | CONNECTION_FAILED | ๐ŸŸ  error | Serial port not accessible |
| -2 | TIMEOUT | ๐ŸŸ  error | Command response timeout |
| -3 | INVALID_PARAMETER | ๐ŸŸ  error | Invalid angle or speed |
| -4 | SAFETY_VIOLATION | ๐Ÿ”ด critical | Exceeds speed/angle limits |
| -5 | NOT_INITIALIZED | ๐ŸŸ  error | Not connected |
| -6 | CRC_ERROR | ๐ŸŸ  error | Checksum mismatch |

### Troubleshooting

| Issue | Possible Cause | Solution |
|-------|---------------|----------|
| Connection failed | Port not found | Check COM port in Device Manager |
| Connection failed | Permission denied | Add user to `dialout` group |
| Command no response | Wrong baudrate | Verify 115200 setting |
| Jerky movement | EMI interference | Use shielded cable |
| CRC errors | Cable too long | Max 3m for USB-serial |

## Finding Your Serial Port

```bash
# Linux
ls /dev/ttyUSB* /dev/ttyACM*

# Windows
# Use Device Manager โ†’ Ports (COM & LPT)
# Common: COM3, COM4, COM8

# macOS
ls /dev/tty.usbserial-*
```

## Dependencies

- Python 3.10+
- `mcp[fastmcp]` โ€” MCP framework
- `pyserial` โ€” Serial communication

## Architecture

```
gimbal_mcp_server.py
โ”œโ”€โ”€ SDK_METADATA          โ€” SDK version and protocol info
โ”œโ”€โ”€ GimbalState          โ€” Gimbal state dataclass
โ”œโ”€โ”€ GimbalSerialBridge   โ€” Serial communication bridge
โ”‚   โ”œโ”€โ”€ connect()        โ€” Open serial port
โ”‚   โ”œโ”€โ”€ _calculate_crc16() โ€” CRC-16 implementation
โ”‚   โ”œโ”€โ”€ _build_control_packet() โ€” Build binary frame
โ”‚   โ”œโ”€โ”€ send_packet()    โ€” Thread-safe send
โ”‚   โ””โ”€โ”€ _recv_loop()     โ€” Background 50Hz reader
โ””โ”€โ”€ MCP Tools           โ€” FastMCP tool definitions
```

## References

- **GCU Protocol**: [GCU Protocol V2.0.6 (Chinese)](./docs/GCU็งๆœ‰้€šไฟกๅ่ฎฎ-XF(A5)V2.0.6.pdf)
- **User Manual**: [Z-2Mini User Manual (Chinese)](./docs/Z-2Mini็”จๆˆทๆ‰‹ๅ†Œ-XF(A5)V1.4.pdf)
- **MCP Protocol**: https://modelcontextprotocol.io/
- **PySerial**: https://pyserial.readthedocs.io/

## License

MIT License โ€” See [LICENSE](LICENSE)

**Note**: The GCU protocol is proprietary to Xianfei Technology. This MCP server is an independent implementation based on the published protocol specification.

## Part of ROSClaw

- [rosclaw](https://github.com/ros-claw/rosclaw) โ€” Core framework (see [arXiv paper](https://arxiv.org/pdf/2604.04664))
- [rosclaw-g1-dds-mcp](https://github.com/ros-claw/rosclaw-g1-dds-mcp) โ€” Unitree G1 (DDS)
- [rosclaw-ur-ros2-mcp](https://github.com/ros-claw/rosclaw-ur-ros2-mcp) โ€” UR5 arm (ROS2)
- [rosclaw-gimbal-mcp](https://github.com/ros-claw/rosclaw-gimbal-mcp) โ€” GCU Gimbal (Serial)
- [rosclaw-ur-rtde-mcp](https://github.com/ros-claw/rosclaw-ur-rtde-mcp) โ€” UR5 via RTDE

---

**Generated by ROSClaw SDK-to-MCP Transformer**

*SDK Version: GCU V2.0.6 | Protocol: Binary Serial | CRC-16*