armctl
# armctl: Claude-controlled capstan joints
MCP server that lets Claude (in Claude Code) drive the Group 26K66 capstan joints through ODrive S1 controllers over USB.
It is written for the single-drum test stand now and the 3-joint v8 arm (J1/J2/J3 + parallelogram elbow limit) later.
Author: Zin Lin Htet. MIT license.
```
You ──chat──> Claude Code ──tool call──> armctl-mcp (this repo, on your laptop) ──USB──> ODrive S1 ──> motor
```
## Files
| File | What it is |
|---|---|
| `arm.toml` | **Your settings**: joints, ODrive serials, limits, speeds, gains. Edit this, not the code. |
| `src/armctl/server.py` | MCP tools Claude can call |
| `src/armctl/joint.py` | Degrees ↔ motor turns, limits, move-and-wait, jam detection |
| `src/armctl/drive.py` | `ODriveDrive` (real hardware) and `SimDrive` (fake motor) |
| `src/armctl/config.py` | Reads `arm.toml` |
| `src/armctl/check.py` | `armctl-check`: finds the ODrive and prints its serial (no motion) |
| `tests/` | Simulator tests: full MCP session plus jam and stop handling |
| `logs/moves.csv` | Created automatically: every move with its error and peak current (use it for reports) |
## Tools Claude gets
| Tool | Action |
|---|---|
| `joints` | Lists the configured joints and their limits (no hardware access) |
| `status(joint)` | Reads on/off state, angle, current, Vbus and errors; nothing moves |
| `zero_here(joint)` | Sets the reference while the motor is off and the joint is held on its stop |
| `enable(joint)` / `disable(joint)` | Motor on (holds its position) / motor off |
| `move(joint, deg)` | Moves to an absolute angle and waits; returns the result, error and peak current |
| `jog(joint, delta_deg)` | Relative move, at most 30° per call |
| `park(joint)` | Moves to `home_deg`, then turns the motor off |
| `stop()` | Turns every motor off immediately and aborts any move in progress |
| `clear_errors(joint)` | Clears the ODrive error flags |
| `history(last)` | Recent moves plus mean and maximum error |
Built-in safety:
- No motion until the joint has been zeroed and enabled.
- Moves outside the limits are refused.
- The J3−J2 elbow coupling limit is enforced.
- A jam (|Iq| above 3.5 A for 0.3 s) turns the motor off.
- Every move has a timeout.
- The reference is cleared if the USB link drops.
## Setup (Windows, VS Code terminal)
Requires Python 3.11 or newer (`py --version`).
```powershell
cd $HOME\Documents\capstan-arm-mcp
py -3.12 -m venv .venv
.\.venv\Scripts\pip install -e .
```
**1. Test with no hardware:**
```powershell
.\.venv\Scripts\python tests\test_safety.py
.\.venv\Scripts\python tests\test_sim.py
```
Both should end with `ALL PASSED`.
**2. Register with Claude Code.** Add a simulator copy first so you can practise:
```powershell
claude mcp add armctl-sim -- "$PWD\.venv\Scripts\armctl-mcp.exe" --config "$PWD\arm.toml" --sim
claude mcp add armctl -- "$PWD\.venv\Scripts\armctl-mcp.exe" --config "$PWD\arm.toml"
claude mcp list
```
In Claude Code, `/mcp` shows both servers. Keep only one of them enabled at a time.
**3. Check the ODrive.** With 24 V on, USB plugged in and the Web GUI closed:
```powershell
.\.venv\Scripts\armctl-check
```
It prints the serial, firmware, Vbus and errors. If no ODrive is found, install the WinUSB driver for it with Zadig, then try again.
With more than one board, plug them in one at a time and copy each serial into `arm.toml`.
## First run on the stand
Say to Claude Code:
1. "Status of the stand."
2. Motor off; hold the drum on the bottom stop. "It's on the bottom stop, zero it."
3. "Enable and move to 20°."
4. "Jog +1° five times, then show history."
5. "Park."
Rules:
- Someone keeps a hand on the 24 V switch whenever the motor can move.
- Zero again after every ODrive power-up.
- Only one program can use the ODrive's USB at a time, so close the Web GUI and `odrivetool` first.
## Moving to the v8 arm
In `arm.toml`, uncomment `J1`/`J2`/`J3` and the `[[couplings]]` block, fill in the serials, and measure the real `stop_deg` / limits.
The stand block can then be removed. No code changes are needed.
## Tuning notes
- `direction`: if "move to 20°" drives the drum **down**, motor off now, flip the sign and re-zero.
- `speed_dps`, `accel_dps2`: set in drum degrees. With 8:1 gearing, 45°/s is 1 motor turn/s.
- Gains and the current limit are written to the ODrive on every connect. They are never saved to its flash.
TDQS
Scored across 12 tools
Most tools have clearly distinct purposes, and descriptions explicitly separate motion commands (move=absolute, jog=relative, home=auto-referencing, park=go home then disable). Minor overlap remains between zero_here and home (both establish the angle reference) and between park and a move-to-home_deg, which an agent could conflate without reading carefully.
There is a coherent readable pattern: noun-style names for read-only queries (joints, status, history) and imperative verbs for actions (enable, disable, stop, move, jog, park, home). The only deviations are the two snake_case verb_noun names (zero_here, clear_errors) breaking an otherwise uniform single-token scheme.
Twelve tools is well within the sweet spot and each one maps to a distinct operation an agent actually needs (query, reference, energize, move, safety stop, error recovery, telemetry). No tool feels like filler.
The surface covers the full safe-motion lifecycle: inspect config/state, establish reference, enable, move, stop, park, clear faults, and review accuracy history. Gaps are minor — joints is read-only (no way to add or reconfigure a joint), and there is no way to adjust current limits or other motion parameters from the tool set.