# Step language

A Kata plan is a list of steps. You rarely write them by hand: the planner writes them from what you say. This reference is for reading plans, checking what Kata will do, and writing steps directly, as Claude does through the [connector](/docs/claude-connector).

Each step is a JSON object with an `op`. Every plan ends with `{"op":"home"}`.

## Picking and placing

| Step | What it does |
| --- | --- |
| `{"op":"pick","object":"box_r1"}` | Takes one named part |
| `{"op":"pick","select":{"kind":"box","color":"red"}}` | Takes whatever matches when the step runs. Fields: `kind`, `color`, `at` (station), `fragile`, `condition`, `state`, `order` (`front`, `top`, `nearest`, `farthest`) |
| `"approach":"side"` on a pick | Comes in level from the side instead of from the top. Also `front`, `back`, `left`, `right` |
| `{"op":"place","location":"pallet_a"}` | Sets the held part down. Optional `slot` (same slot stacks) and `yaw_deg`. In a bin it drops in |
| `{"op":"palletize","from":"conveyor","to":"pallet_a"}` | Moves matching parts across, layer by layer. Optional `select`, `count`, `layers`, `interlock` |
| `{"op":"machine","station":"cnc","seconds":30}` | Runs one machine cycle on what's loaded |
| `{"op":"turn_part","object":"box_r1","by_deg":90}` | Turns a part in place. The gripper must be empty |
| `{"op":"flip","object":"box_r1","to_side":"on_side"}` | Turns a part over: `upside_down` (default), `on_side` or `upright` |

Use ids for one-off moves of parts you can see; use selectors inside loops and for sources.

## Moving the tool

| Step | What it does |
| --- | --- |
| `{"op":"move","to":"pallet_a"}` | Goes to a station or waypoint. Optional `slot`, `above_mm` |
| `{"op":"move","xyz_mm":[x,y,z]}` | Goes to a point. `"linear":true` for a straight line |
| `{"op":"move","by_mm":[0,50,0]}` | Moves relative, as [right, up, front], keeping orientation. `"frame":"tool"` measures along the tool's own axes |
| `face`, `tilt_deg` + `tilt_toward`, `yaw_deg` | Orientation on any move. A move with only these turns the tool where it stands |
| `speed_mm_s`, `blend_mm` | On one move: its speed, and rounding the corner into the next move (max 100) |
| `{"op":"rotate","by_deg":90}` | Turns the tool and what it holds about the vertical. `"about":"tool"`, `"pitch"` or `"roll"`; `to_deg` for a heading. Positive is anticlockwise seen from above |
| `{"op":"joint","joint":"base","by_deg":-45}` | Turns one joint; `joints_deg` sets all six |
| `{"op":"arc","via_mm":[…],"to_mm":[…]}` | A circular move through one point to another |
| `{"op":"save_waypoint","name":"load"}` | Remembers where the tool is now |
| `{"op":"grip"}`, `{"op":"release"}` | Closes or opens the gripper |

## Paths

`{"op":"trace","station":"table","shape":"zigzag"}` follows a path just above a station: `line`, `rectangle`, `circle`, `zigzag`, `spiral` or `path` (with `points_mm`). Optional `size_mm`, `height_mm`, `speed_mm_s`, `passes`, `signal` (an output held on along the path), `turns`, `tilt_deg` (lean the tool like a glue gun) and `press_n` (press onto the surface for sanding or polishing).

## Contact and force

Using the arm's flange force sensor. Contact is simulated nominally, so watch the first run.

| Step | What it does |
| --- | --- |
| `{"op":"move","by_mm":[0,-100,0],"until_contact_n":15}` | Moves until it touches something over that force |
| `{"op":"push","object":"billet_4","to_slot":4}` | Slides a part along its station with the closed gripper |
| `{"op":"insert","location":"cnc","depth_mm":15,"force_n":20,"spiral_mm":2}` | Presses the held part into a fixture, searching in a spiral if it sticks |
| `{"op":"screw","direction":"in","location":"…","turns":3,"torque_nm":2}` | Screws the held part down; `"direction":"out"` unscrews and ends holding it |

## Working beside people

Collaborative cells only.

| Step | What it does |
| --- | --- |
| `{"op":"hand_over","pull_n":10}` | Holds the part out and lets go when a person pulls it |
| `{"op":"freedrive","seconds":30}` | Lets the operator guide the arm by hand. Always the last step |

## Signals, messages and timing

| Step | What it does |
| --- | --- |
| `{"op":"set_output","signal":"lamp","value":true}` | Sets an output |
| `{"op":"pulse_output","signal":"stamp","seconds":0.5}` | Pulses an output |
| `{"op":"wait_input","signal":"door_closed","value":true,"timeout_s":30}` | Waits for an input |
| `{"op":"message","text":"…","popup":true}` | Tells the operator; a popup waits for them |
| `{"op":"counter","name":"made","add":1}` | Counts |
| `{"op":"set_speed","mm_s":250}`, `{"op":"wait","seconds":2}` | Speed from here on; a pause |
| `{"op":"swap","station":"pallet_a"}` | Waits while a full pallet or bin is exchanged. Optional `signal` that says it's done |

## Loops and conditions

```json
{"op":"repeat","times":5,"body":[…]}
{"op":"repeat","until":{"type":"full","station":"pallet_a"},"body":[…]}
{"op":"repeat","forever":true,"body":[…]}
{"op":"if","condition":{…},"then":[…],"else":[…]}
```

A loop body must leave the gripper as it found it.

Conditions: `input` (read on the controller), `count` of parts matching a selector, `full` and `empty` for a station, `counter`, `held` (is the held part like this), `contact` (after a touch move). Any condition takes `"not":true`.

## Production loops

"Run production" is one endless loop that swaps any full destination, picks from the source by selector, and places. It's a true production loop only if the cell comes back to the same state each time round. To route parts, pick once, then use one `if` with a `held` condition per case. On a real arm, route only by what the cell's inputs report.

## Rules the planner follows

- Use only ids that are in the cell.
- Respect what each station accepts, its layers and what's already there. A part with another on top can't be picked.
- Never pick a part heavier than the payload.
- Never place anything on a fragile part; move fragile parts last.
- Damaged parts go in a bin if the cell has one.
- "Stack N high" means N per slot. "The red boxes" means all of them.
