The Cell Model and Its 3D Viewer: Robot, Target, Camera and Lenses in One Frame
Before the robot of the case study moved, the cell existed as a model: the arm’s kinematics, the target on its stand, the camera on the flange with both lenses, all in one frame, and a viewer that shows them. The path planner, the collision check and the robot programs are computed on it, and motions are approved by looking at them in the viewer first.
What is in the model
Section titled “What is in the model”| Part | Source | Note |
|---|---|---|
| Arm kinematics | The datasheet’s dimensions as a DH table; then the maker’s CAD file | Two offsets not labelled in the datasheet were read off its drawing and confirmed by the stated reach. The CAD later matched every value: the model fits the CAD to 0.004 mm |
| Joint directions | Watched on the real arm | Not in any document: see Robot programs |
| Arm body, for collisions | The maker’s CAD, simplified to 25 boxes and cylinders that enclose it | For three days this body was only drawn in the viewer and not used by the collision check. That is the crash on Camera path |
| Target | A Kalibr AprilGrid: 6 x 6 tags of 88 mm with gaps of 0.3 of a tag on an 800 mm plate | Six by six is the only count that fits the plate |
| Stand, floor, what the robot stands on | Boxes from drawings and a tape measure | |
| Camera | A box for the body, a larger box for cable and plug, two lenses 60 mm apart | The cable box is a guess until measured, so it is generous |
| Lenses | First the datasheet’s field of view, later the calibrated model | The planner improves when the real lens replaces the guess |
Kinematics from a CAD file is worth knowing about: the joint axes are the axes of the cylindrical faces that neighbouring parts share, and the flange is a flat face. No drawing needs to be trusted.
What the viewer is for
Section titled “What the viewer is for”- Approving motion. A slider steps through a path; the smallest distance between camera and robot is shown for each pose.
- Seeing what each lens sees. A panel per lens draws the target through the lens model. In our experience, this panel earned its place on the first day: the target looked small in it, which was measured (a median of 12 % of the image circle) and fixed in the planner before any hardware ran.
- Lights. The viewer drew where a lamp’s reflection would fall on the target. The first lamp positions put a highlight on the target in many poses. The lights were then placed so that, in the words of the person at the cell, there was almost no glare.
Rehearsing on rendered images
Section titled “Rehearsing on rendered images”The model can render what the camera would see at each pose, through a known lens, with noise. The whole chain, from images to calibration, was run on those pictures before the real camera existed in the cell.
In our experience, this found things that would have cost days on hardware:
- two crashes in the calibration tool on wide-angle views (see The solve);
- how a Kalibr AprilGrid is really drawn: a border two bits wide, the code turned by 180 degrees, and a black square in every gap. A detector must be told the border is two bits wide. The tags are the standard tag36h11 family with the same numbers;
- that the planned path, on a perfect lens and target, gave the lens back to 0.02 px. Nothing better can be expected from the real one.
Measuring the real cell back into the model
Section titled “Measuring the real cell back into the model”The model said the target was 850 mm in front of the robot. The first real stills, solved for the target’s position in the robot’s frame, put it at 964 mm. Later the stand was moved to stiffen the base, and one run measured the target 92 mm to the side of where the model had it; after a correction by hand, later runs agreed with the model to 12 to 17 mm sideways and 2 mm in distance.
In our experience, the arm’s uncalibrated kinematics placed the camera to about 1.6 mm at the target, which is ample for planning. The rule is that any change to the stand, the target or the camera mount is followed by one run that measures the target again before anything else.
The prompt
Section titled “The prompt”- Inputs: the arm’s DH table, limits and speeds; what it stands on; the target; the camera and how it is mounted; the lens.
- How to check: the flange position at zero against the datasheet’s drawing; inverse then forward kinematics on random poses; a pose you build with the camera touching the forearm must show near zero distance; open the viewer and move each joint.
Build a model of a robot calibration cell and a 3D viewer for it. A camera is bolted to the robot'sflange; the robot shows it a fixed calibration board from many directions. Everything later(planning the poses, checking them for collisions, writing the robot program) is computed on thismodel, and I will approve robot motions by looking at them in the viewer before they run on the realarm. So the model must be exact where it can be, and honest where it is a guess.
Work in this directory. Python 3 with numpy for the model and pyyaml to read files (no ROS, nosimulator packages), and one self-contained HTML file for the viewer, with the scene data and, ifyou can download it, three.js embedded in the file so it opens by double-click with no network.
Inputs: `inputs.yaml` (the robot's DH table, joint limits and speeds, what the robot stands on, theboard, the camera and how it is mounted, the lens) and `robot_body.json` (the arm's real outer shapeas a few boxes and cylinders per link, simplified from the maker's CAD so that every part of thereal arm is inside them).
Build:1. `cell/robot.py`: forward kinematics from the DH table (a frame per link), and inverse kinematics for a flange pose that returns every solution inside the joint limits (this arm has a spherical-wrist offset layout; if a closed form is not available use a numeric solve from several seeds and remove duplicates).2. `cell/cell.py`: the cell in one world frame: robot base, floor, the stand under the robot, the board with its tag corners in 3D, and the camera rig on the flange with both lenses.3. `cell/camera.py`: project a 3D point into each lens with the lens model in the inputs; say whether a board corner is visible (inside the image, inside the lens's angle limit, seen from the front of the board); and say whether a tag is decodable (all four corners visible, the angle between the board's normal and the line of sight under the limit in the inputs' `detection` table, linear between its rows, and its shortest side at least `min_tag_px`).4. `cell/collision.py`: distances, in millimetres, between (a) the camera body and, separately, a box for its cable and plug, and (b) every link of the robot, the board, the stand and the floor, for one pose and along a move between two poses (the robot moves in a straight line in joint space: sample about every degree of joint travel). For the robot use the shapes in `robot_body.json`, moved with their links. Do NOT use capsules along the kinematic skeleton: the motor housings at the shoulder and elbow of a real arm stick out far beyond it, and when we tested a skeleton model against poses that had really collided it rated them no closer than poses that had run a hundred times. The camera against the robot's own links is the check that matters most: a view of the board from far away folds the wrist back toward the arm, and a tool that clears every obstacle in the room can still hit the robot that carries it. Leave out of the headline number the link the camera is bolted to and the wrist link next to it (their distance to the camera cannot change), and list them separately. Report as well the smallest distance from the arm's own links (forearm, wrist, elbow) to the board, the stand and the floor: an arm that reaches around the target can touch it with its elbow.5. `viewer.html` built by `python3 -m cell.build_viewer [waypoints.json]`: the robot drawn from the shapes in `robot_body.json`, the board with its tags, the stand, the camera and its cable box with each lens's field of view, orbit controls, a slider per joint, and, when a waypoint file is given (a JSON list of poses, each a list of 6 joint angles in degrees in the model's convention), a slider that steps through the poses and shows for each one what each lens sees of the board (a small panel per lens with the projected tag corners), the smallest camera-to-robot and cable-box-to-robot distances at the pose and along the move to the next pose, with the closest pair of parts named, in red under [20] mm and amber under [50] mm.6. `tests/`: checks that run with plain `python3 tests/<file>.py` and print their numbers (pytest may not be installed).
Checks you must run and report, with numbers:- forward kinematics at all-zero joints and at the home pose: print the flange position; state the reach it implies and compare it with the datasheet reach in the inputs;- inverse then forward kinematics on 200 random reachable poses: worst position error under 0.01 mm;- the collision function returns a distance near zero for a pose you construct with the camera touching the upper arm or shoulder, and its value at home; print for each robot link the smallest distance to the camera over 2,000 random poses inside the joint limits, so I can see which links the camera can reach;- the viewer file opens without JavaScript errors (load it headless if a browser is available; say so if you could not).
Things I do not know yet, which you must not guess silently: whether the real robot's jointdirections match the DH convention (keep one sign and one offset per joint in a config file, default+1 and 0, clearly marked unverified), and the exact size of the cable and its support (keep it anamed box with a generous default).
Report back: the files written, the numbers from the checks, anything in the inputs that lookedinconsistent, and three poses with a small camera-to-robot distance that I should approach slowly onthe real arm with a ruler, to check the model against the machine before trusting it.How this prompt was tested
Section titled “How this prompt was tested”Two fresh AI sessions, each with the inputs of our cell and none of our code. What they built was then compared with the model that has run the real robot.
First session, an earlier wording. That wording let the assistant model the arm as capsules along its kinematic skeleton, from one rough radius.
| Check | Result |
|---|---|
| Forward kinematics against ours, 500 random poses | equal to 7 x 10^-13 mm |
| Inverse kinematics | closed form, every solution inside the limits, round trip to 10^-12 mm |
| Target corners against ours | within 5 mm (ours carries the measured 0.7 degree lean) |
| Viewer | loads with no errors |
| Collision model against the path that really crashed | fails: it rated the poses that hit the robot at 41 to 70 mm, in the same range as poses that had run a hundred times (48 mm at their closest). Correlation with the CAD-based distances: 0.3 |
Perfect kinematics and a collision model that would have let our crash through. A real arm’s motor housings stick out far beyond its skeleton, and that is exactly where a folded-back wrist lands. The prompt was changed to require the arm’s real shape, simplified from the maker’s CAD, and to say why.
Second session, the wording above, with the arm’s shape as 25 boxes and cylinders.
| Check | Result |
|---|---|
| Forward kinematics against ours | equal to 6 x 10^-13 mm |
| Camera-to-robot distance against ours, on the 138 poses of the path that crashed | correlation 1.0000, largest difference 1.7 mm |
| The poses that hit, or came within 40 mm, by CAD | all 7 rated closer than anything on the proven path, so the rule “no closer than a path that has run” rejects every one |
| The move on which the real crash happened | 0.0 mm |
| Time per pose | 2 ms |
| Viewer | robot drawn from the real shapes, target, stand, both lenses’ views, distances at the pose and along the move with the closest pair named, and a banner that the joint directions are not yet verified on the real arm |
It also chose three poses to approach slowly with a ruler on the real arm, as the prompt asks, to check the model against the machine before trusting it.
Sources
Section titled “Sources”- Kalibr wiki: calibration targets — ETH Zurich ASL; the AprilGrid and its parameters.
- AprilTag: A robust and flexible visual fiducial system — Olson, ICRA 2011.
- A Kinematic Notation for Lower-Pair Mechanisms Based on Matrices — Denavit and Hartenberg, Journal of Applied Mechanics 1955.