Kinematic Solver Selection for AI Coding Models: A Worm Gear Case Study
This article walks through adding a lightweight, pure-kinematics constraint solver to a self-built physics simulation engine, using worm gear end-effector pose calculation as the test case. It covers how to turn a vague request into an acceptance-ready specification, a reusable prompt skeleton, a multi-round "goal, constraints, interface, self-check" iteration pattern, and five dimensions for evaluating AI coding tools beyond first-token latency. Readers will also find practical recommendations for low-risk adoption, including contract-plus-acceptance-plus-self-check prompting and keeping analytical validation tests before merging.}
1. Background: Dynamics Solves It, but It Is Too Heavy
Our in-house physics simulation engine relies on an impulse-based soft-constraint dynamics solver in most scenarios. The advantage of this approach is generality: collision, friction, and joint limits can all be handled within a single constraint system. The cost is that every solve must build constraint Jacobians, run iterative convergence, and deal with mass and inertia tensors.
For purely kinematic linkages—worm and worm wheel drives, planetary gear sets, parallel four-bar mechanisms—what we usually care about is simply “given the input angle, what is the end-effector pose?” Dynamic quantities do not participate in the calculation at all. Using a dynamics solver for this is like starting a heavy machine just to compute a trigonometric function.
So the requirement was abstracted as follows: add a lightweight, pure-kinematics constraint solving module to the existing engine, serving mechanism modeling, test case setup, and toolchain validation. It is a non-core requirement with low priority, but it has clear boundaries and strong verifiability, which makes it an ideal touchstone for AI coding capability.
2. Requirement Breakdown: Turning a Wish into an Acceptance-Ready Spec
A vague request like “help me implement worm mechanism end-effector pose solving” goes off track easily because it hides a large number of implicit constraints. In practice, we fill in the following dimensions first, then hand it to the model:
- Input/output contract: inputs are the worm rotation angle, module, lead count, gear teeth, assembly offset, and initial mounting phase; output is the pose of the end frame relative to the base (rotation as a quaternion or rotation matrix, position as a 3D vector).
- Mechanism conventions: transmission ratio i = gear teeth / lead count, the worm wheel angle is coupled in the reverse direction to the worm angle; handedness (left-hand/right-hand) and coordinate frame orientation must be stated explicitly.
- Numerical strategy: angle normalization range, representation choices that avoid gimbal lock, and protection against division by zero and degenerate conditions.
- Engineering constraints: align with the engine’s existing math library, no third-party dependencies, unit-testable, idempotent interface with no side effects.
A reusable prompt skeleton looks like this (illustrative):
Role: Senior mechanism and engine developerTask: Implement pure-kinematics worm drive end-effector pose solvingInputs: phi_worm, module, lead_count, gear_teeth, offset, phase0, handednessOutput: {position: Vec3, rotation: Quat}Constraints:1) Use only the in-project math library; do not introduce external dependencies2) Handle handedness and phase0 explicitly3) Normalize angles to [-pi, pi); division by zero is forbidden4) Provide 3 analytically verifiable unit testsAcceptance: when phi_worm=2π*gear_teeth/lead_count, the end effector returns to its initial pose
The key lesson is to write acceptance criteria into the prompt rather than comparing them manually after the fact. Executable acceptance standards significantly shrink the space in which a model can “feel good about itself but fail to run.”
3. Multi-Round Iteration: Converging from Design Draft to Integrable Code
In the first round we gave only the goal, with no constraints, to observe the model’s default assumptions. Most models suggested “directly reuse the dynamics solving path,” which shows they tend to pick the most common option in the training distribution rather than the best option for the current engineering context. Starting from the second round we injected constraints and acceptance criteria; in the third round we asked for interface definitions and unit tests; in the fourth round we had the model self-check degenerate conditions. This progressive “goal, constraints, interface, self-check” structure is more stable than a single long prompt.
What really leveled the speed differences between model tiers during iteration was the learning cost of project context: the model has to repeatedly search the directory structure, math library usage, and existing naming style, and this overhead is unrelated to the model’s own inference speed. So in engineering practice, solidifying key context into in-repository spec documents and interface examples pays off more than switching to a faster model.
4. Capability Evaluation Dimensions: Do Not Look Only at First-Token Latency
When evaluating AI coding tools, cover at least five dimensions:
- Constraint adherence rate: the proportion of implicit constraints proactively filled in.
- Runnability rate: the proportion generated in one pass that compiles and passes unit tests.
- Iteration stability: whether multiple rounds of changes introduce regressions.
- Context efficiency: the number of searches and calls needed to complete the same task.
- Balance between reasoning length and output: too short misses constraints, too long diverges.
Point 5 deserves more detail. A shorter reasoning process quickly produces a runnable skeleton and suits exploratory tasks; but when the spec is incomplete, it easily treats “the most common solution” as “the best solution.” A practical compromise is a two-stage approach: first have the model produce the interface and skeleton with a small amount of reasoning, then drive it with an explicit checklist to fill in boundary conditions. This keeps the speed while suppressing runaway output.
5. Implementation Recommendations
- Hand non-core but clearly bounded requirements to AI coding for the highest return and lowest risk.
- Replace natural-language wishes with the three-piece set of “contract + acceptance + self-check.”
- Write mechanism conventions and coordinate frame specs into repository docs to reduce repeated context overhead.
- Keep analytical-solution comparison tests before merging code; kinematics modules are especially suited to closed-form validation.
- If coordination with the dynamics module is needed later, adapt at the same interface layer rather than stuffing kinematics logic into the constraint solver.
Overall, lightweight kinematic solving is an ideal low-risk test bed: it shows the real level of AI coding in constraint adherence and engineering integration, and it produces a set of prompting and acceptance methods that can transfer to core modules.
