Skip to content

Build a Robot That Feels a Lock

Category Creative & Real-World AI Builds
Status 🟡 Partially completed
Repo nextwork-build-a-robot-that-feels-a-lock
Original NextWork guide nextwork.ai

Learning project

Practice work following a NextWork guide, separate from my production projects.

📚 NextWork learning project. This is a practice project I built while working through NextWork's Build a Robot That Feels a Lock guide. It is part of my Learning portfolio and is fully separate from my production projects.

Category: Learning › Creative & Real-World AI Builds
Status: 🟡 Partial

Overview

A probe on a load cell pushes one pin of a clear practice lock. The point is layered control: the firmware owns the hard limits, local Python logic can veto, and the AI supervisor only requests PUSH, HOLD, or BACKOFF about once every 1.2 s.

Summary

The software side is built and tested against a simulated touch rig. It has ESP32 firmware with hard safety limits (force stop, travel envelope, command timeout, disconnect park), a rig simulator speaking the same protocol, monitor-only mode, and the supervised PUSH/HOLD/BACKOFF loop with a local safety veto and CSV evidence. The secret mission's blind first-contact detection is within 2° over three hidden trials. No hardware was built.

The checks behind this are in docs/verification.txt.

Skills & tools

Embedded C++ (ESP32), Control loops, Safety engineering, Python, Simulation, LLM supervision

What I built

  • firmware/TouchRobot/TouchRobot.ino: XIAO ESP32-C3 firmware with an HX711 load cell, a servo, and a TCP JSON stream. It enforces the force stop (latching fault), the angle envelope, the command timeout back-off, park on disconnect, and monitor-only mode.
  • rig_sim.py: a simulated rig with the same protocol and rules. A spring model of the pin gives the force, which drops once the pin sets, plus HX711 noise and drift.
  • robot_touch.py: monitor-only mode (commands ignored, servo parked) and supervised mode. A supervisor (rule baseline or ollama LLM) proposes an action from a force summary, local_safety can veto it, and the firmware rules still apply. Each run writes force.csv and decisions.csv.
  • first_contact(): the secret mission. It finds first contact from the force signature alone (baseline + 6σ, sustained), and the test checks it against three hidden contact points.
  • test_robot.py: 6 tests (parked monitor mode, contact under the cap, latching force stop, timeout back-off, local veto, blind contact detection).

How to run

python robot_touch.py --sim --mode monitor --seconds 10
python robot_touch.py --sim --seconds 45 --out run1                       # rule supervisor
MODEL=qwen2.5:3b python robot_touch.py --sim --supervisor ollama --out run2   # LLM supervisor (local)
Flash the firmware with the Arduino IDE (board: XIAO ESP32C3; libraries: Adafruit HX711, ESP32Servo) after setting Wi-Fi locally.

Verification

I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.

mkdir -p docs && /workspace/nextwork-portfolio/.venv/bin/python robot_touch.py --sim --mode monitor --seconds 10 --out docs/monitor-run | tee docs/monitor-run.txt && /workspace/nextwork-portfolio/.venv/bin/python robot_touch.py --sim --seconds 45 --out docs/supervised-run | tee docs/supervised-run.txt && /workspace/nextwork-portfolio/.venv/bin/python -m pytest -q -p no:cacheprovider test_robot.py

Notes

The guide's supervisor is the Anthropic Claude API (paid key). robot_touch.py has an ollama supervisor using the same JSON action contract with a local model. The verified runs use the deterministic rule baseline, because a CPU-only local model can't keep up with a 1.2 s decision cadence.

What isn't done, and why

There's no hardware: no ESP32, load cell, servo, or practice lock, so the firmware wasn't compiled or flashed, there was no 100 g calibration, and there's no video evidence run. The verified supervised runs use the rule baseline rather than an LLM (Claude API in the guide, a local model as an option here). To finish, build the rig, calibrate it, and run robot_touch.py against the board's IP with an LLM supervisor.


Original project: https://nextwork.ai/projects/96d96b53-ced0-4139-a432-a6749da2f716 · Part of my NextWork Learning portfolio (hub).

Verification output

From docs/verification.txt:

$ mkdir -p docs && /workspace/nextwork-portfolio/.venv/bin/python robot_touch.py --sim --mode monitor --seconds 10 --out docs/monitor-run | tee docs/monitor-run.txt && /workspace/nextwork-portfolio/.venv/bin/python robot_touch.py --sim --seconds 45 --out docs/supervised-run | tee docs/supervised-run.txt && /workspace/nextwork-portfolio/.venv/bin/python -m pytest -q -p no:cacheprovider test_robot.py

monitor: 801 force samples, 0 decisions; max force 4.3 g; final angle 20; fault=False
no contact detected
supervised: 3600 force samples, 37 decisions; max force 102.3 g; final angle 53; fault=False
  t=  1.2s angle=21 force=  -1.5g  PUSH    -> PUSH    below target force
  t=  2.4s angle=22 force=  -0.1g  PUSH    -> PUSH    below target force
  t=  3.6s angle=23 force=   0.3g  PUSH    -> PUSH    below target force
  t=  4.8s angle=24 force=  -0.0g  PUSH    -> PUSH    below target force
  t=  6.0s angle=25 force=   0.2g  PUSH    -> PUSH    below target force
  t=  7.2s angle=26 force=  -0.6g  PUSH    -> PUSH    below target force
  t=  8.4s angle=27 force=  -0.0g  PUSH    -> PUSH    below target force
  t=  9.6s angle=28 force=  -0.2g  PUSH    -> PUSH    below target force
  t= 10.8s angle=29 force=   0.5g  PUSH    -> PUSH    below target force
  t= 12.0s angle=30 force=   0.1g  PUSH    -> PUSH    below target force
  t= 13.2s angle=31 force=  -0.2g  PUSH    -> PUSH    below target force
  t= 14.4s angle=32 force=   0.7g  PUSH    -> PUSH    below target force
  t= 15.6s angle=33 force=  -0.2g  PUSH    -> PUSH    below target force
  t= 16.8s angle=34 force=   0.2g  PUSH    -> PUSH    below target force
  t= 18.0s angle=35 force=   0.5g  PUSH    -> PUSH    below target force
  t= 19.2s angle=36 force=   0.5g  PUSH    -> PUSH    below target force
  t= 20.4s angle=37 force=  -0.1g  PUSH    -> PUSH    below target force
  t= 21.6s angle=38 force=   0.5g  PUSH    -> PUSH    below target force
  t= 22.8s angle=39 force=   0.5g  PUSH    -> PUSH    below target force
  t= 24.0s angle=40 force=   0.8g  PUSH    -> PUSH    below target force
  t= 25.2s angle=41 force=   0.2g  PUSH    -> PUSH    below target force
  t= 26.4s angle=42 force=  -0.6g  PUSH    -> PUSH    below target force
  t= 27.6s angle=43 force=  10.1g  PUSH    -> PUSH    below target force
  t= 28.8s angle=44 force=  18.7g  PUSH    -> PUSH    below target force
  t= 30.0s angle=45 force=  27.5g  PUSH    -> PUSH    below target force
  t= 31.2s angle=46 force=  36.6g  PUSH    -> PUSH    below target force
  t= 32.4s angle=47 force=  45.0g  PUSH    -> PUSH    below target force
  t= 33.6s angle=48 force=  54.9g  PUSH    -> PUSH    below target force
  t= 34.8s angle=49 force=  63.7g  PUSH    -> PUSH    below target force
  t= 36.0s angle=50 force=  73.1g  PUSH    -> PUSH    below target force
  t= 37.2s angle=51 force=  82.5g  PUSH    -> PUSH    below target force
  t= 38.4s angle=52 force=  91.0g  PUSH    -> PUSH    below target force
  t= 39.6s angle=53 force=  99.9g  PUSH    -> PUSH    below target force
  t= 40.8s angle=53 force=  49.3g  HOLD    -> HOLD    force dropped after rising: the pin has set
  t= 42.0s angle=53 force=  49.4g  HOLD    -> HOLD    force dropped after rising: the pin has set
  t= 43.2s angle=53 force=  49.6g  HOLD    -> HOLD    force dropped after rising: the pin has set
  t= 44.4s angle=53 force=  49.4g  HOLD    -> HOLD    force dropped after rising: the pin has set
first contact from force signature: t=26.475s angle=42
......                                                                   [100%]
6 passed in 0.45s

[exit code 0]