More › robot-prototyping

More

Robot prototyping: a task in words to a tuned arm

Say what a robot arm should do. archec gives you a model of the arm, its gripper, its sensors and the object, with requirements and test cases. You watch it move in 3D, a tuner changes the controller's values until the test cases pass, and archec generates the code for a real board.

What decides is the simulation and the requirements' test cases. A tuner (a search, or an AI model if you allow one) only proposes values.

Be clear about what this is: a scripted path or grasp whose values are tuned. It is not a learned skill. The arm does what its controller says, and MuJoCo simulates the contacts.

Start from a sentence#

archec new my-arm --kind robot --describe "unscrew a bottle cap"

The sentence picks one of the scenes below. Offline, the default, its words do. With an AI allowed (archec config ai local-ai or online), the model picks, through the gateway (AI engineering); an answer that is not a scene falls back to the words. For robot-draw, the sentence also gives the shape (square, triangle, star) and its size: "draw a 9 cm triangle".

The project then runs once: the model checks, the planner's C builds, and with MuJoCo's Python the test plan runs against the arm (new).

The scenes#

Each scene is a template, and the same model is in examples/:

Scene The task The requirements
robot-draw draw an 8 cm square with a pen every inked point within 3 mm of the square, every corner, one stroke, in 20 s
robot-cap unscrew a bottle cap the cap off its thread within 20 s, never squeezed with more than 15 N
robot-cube turn one face of a puzzle cube a quarter turn within 3° once let go, within 15 s, never more than 20 N
archec new my-draw --template robot-draw
cd my-draw
archec gen main.arche --target mujoco -o out
archec sim main.arche --plant out/mujoco/plant_bridge.py --test

The test cases need MuJoCo's Python (pip install mujoco, or MUJOCO_PYTHON=/path/to/python). Without it, archec sim --test runs the controller alone: nothing moves, and the cases fail.

The arm#

The arm is a small SCARA. Two links swing over the table on hinges, a quill slides up and down at their end, and the tool is on the quill. Each joint is a position servo, like a hobby servo: it is sent an angle (or a height) and holds it. The planner works out the angles for a point with inverse kinematics.

robot-draw#

The pen is fixed in the quill. The planner moves to the first corner, puts the pen down, goes round the square at SPEED, then lifts the pen. The tracer reads the pen tip's position (a framepos sensor in MuJoCo). While the tip is below 0.2 mm (on the paper: MuJoCo's contacts are soft), the pen inks. The tracer keeps:

  • worst: how far the worst inked point is from the square;
  • corners: how many corners the pen went through, in order, back to the first;
  • strokes: how many times the pen came down.

The pen height matters most. Pressed too hard, the pen drags on the paper, the servos give way, and the square comes out 2.5 mm small at its corners. Too high, it never touches.

PEN_DOWN What happens TC-DRAW-SHAPE
-0.0925 m the pen drags: 2.5 mm off, a corner missed fails
-0.0903 m (the template) on the paper, 1 to 2 mm off passes
-0.089 m it hovers 0.3 mm over the paper: no ink fails

robot-cap#

The gripper has two fingers on slides, pushed by force (slow lead screws), and a touch pad on one of them. The cap sits on a thread: a hinge and a slide coupled (prop couple), 3 mm a turn, against 0.15 N·m of dry friction. Only the fingers' friction turns it.

GRIP_FORCE, TWIST_TURNS What happens
9 N, 2 turns (the template) the cap rises 4.5 mm and lets go passes
4 N, 1.6 turns the fingers slip: the cap stays on fails
18 N the pad feels more than 15 N fails

The wrist turns two turns in one go. A real wrist turns a limited angle and grips again.

robot-cube#

The same arm turns the top layer of a cube. The cube is simplified: two layers, the bottom one held in a fixture, the top one on a hinge with dry friction. The fingers come down square to its faces. They slip a little, so the wrist turns a bit past the quarter turn (TWIST_ANGLE, 1.6 rad).

Tunable values#

A value a tuner may change is a constant with a range (tuning):

const SPEED = 0.04 unit m/s { range 0.01..0.08 }
const LEAD = 0.05 unit s { range 0..0.3 }
const PEN_DOWN = -0.0903 unit m { range -0.1..-0.085 }

archec fit --pass runs the test cases against the plant and changes these until every case passes. From a pen pressed too hard:

archec fit main.arche --pass --plant out/mujoco/plant_bridge.py
  1 fail score 1.5  SPEED=0.04 LEAD=0.05 PEN_DOWN=-0.0925  (start: the values as written)
      REQ-DRAW-SHAPE failed at 20.00 s: … tracer.corners = 4
  …
  6 pass score 0  SPEED=0.04 LEAD=0.05 PEN_DOWN=-0.08875  (search: PEN_DOWN up by 25% of its range)
✓ try 6 of 6 passes

Each try is kept in .arche/tries/. --write puts the values in the source. Tuning says how the search goes, how an AI may propose values, and the MCP tools.

The reel#

The tries make a reel: the task, each try in 3D with its verdict, the passing one last. A constant whose name has TARGET or SHAPE in it, a list of points in metres, is drawn as a ghost (robot-draw's SHAPE_TARGET); the pen's line and what touches what come from the plant.

archec story export main.arche --tries -o reel.webm

See watching the tries.

Contacts in MuJoCo#

A body part's props say how it touches and how its joint moves (see robotics):

  • prop friction = 1.2: its geom's sliding friction;
  • prop damping, prop armature, prop frictionloss: its joint's;
  • prop couple = {joint: turn, ratio: 0.0005}: this joint follows that one, like a screw thread.

Limits#

  • The paths and grasps are scripted. A tuner finds values for them; it does not learn a new way to do the task.
  • The pen tip's position, the cap's height and the layer's angle are the simulation's truth. On a real bench, a camera or an encoder would measure them.
  • The cube is two layers, not eight pieces on a core. The thread is a coupled hinge and slide, not a helix. The wrist turns without end.