[KongchangAI]
· 1 min read· 822 words

Parametric Robot Bodies: Change Three Lines of Code to Turn a Duck into a Flamingo (Open Source)

Parametric Robot Bodies: Change Three Lines of Code to Turn a Duck into a Flamingo (Open Source)

Change three parameter values in Python CAD code to morph a robot duck into a flamingo, then retrain its MuJoCo control policy.

The Open Duck Mini v2 open-source project explores a "body as code" paradigm for robot design: all 3D-printed parts are rewritten as programs using CadQuery, a Python parametric CAD library, with geometric constraints like servo mounting positions and screw holes enforced by code logic. By changing just three parameter values, a completely new morphology can be generated without breaking any assembly relationships — the author extended the duck robot into a longer-legged, longer-necked flamingo. After the structural change, the project also retrains a motion control policy for the new body in MuJoCo, completing a full loop of parametric modeling → simulation adaptation → policy training. Licensed under Apache-2.0, the repository also includes code-based versions of the SO-101 and LeRobot humanoid platforms.

Writing a Robot's Body as Code

In traditional robot design, 3D-printed parts are typically fixed STL model files — if you want to change a dimension, you have to rebuild the model from scratch. This open-source project takes a different approach: rewriting all of the Open Duck Mini v2's printed parts as programs using CadQuery, a Python-based parametric modeling library.

This means the robot's "body" is no longer a static model, but a piece of code that can be modified and reused. By changing just three values in a single file, you can generate a complete set of structural components in a new size. The author used this method to turn a "duck" into a "flamingo."

CadQuery is an open-source parametric CAD library built on Python and the OpenCASCADE geometry kernel. It lets developers describe 3D geometry in code rather than manually dragging elements around in a GUI. It works like a "text-based SolidWorks" — you describe sketches, extrusions, boolean operations, and more through chained function calls, then export STL or STEP files for printing. Similar to OpenSCAD, but CadQuery can leverage the full Python ecosystem (numpy, variable logic, loops, etc.), allowing parameter dependencies to be arbitrarily complex. For robot structural parts — which typically have many repeated mounting holes and symmetric features — code-based modeling dramatically reduces the maintenance cost of "change one thing, break everything else."

Why Three Values Are Enough

The key here lies in the constraint logic of parametric design. The author emphasizes that the flamingo's leg and neck parts are not copy-pasted from the duck — they run the same duck program, just with different parameter values passed in.

In other words, the relative positions of servo pockets and screw holes are locked by program logic — they always align with the mounting positions required by the STS3215 servo. The only thing that changes is the length of the parts. This is the core advantage of parametric CAD over manual modeling: geometric constraints are enforced by code, so changing one variable doesn't break the overall assembly relationship.

Building on this mechanism, the author added wings and a small bird head to the original duck structure, elongated the legs and neck, and the flamingo took shape — without needing to redesign any assembly interfaces.

New Body, New Policy

Building a new body isn't enough on its own. A robot's motion control policy is trained for a specific body morphology — if the legs get longer and the center of gravity shifts, the original gait policy no longer applies.

Another key focus of this project is retraining the control policy for the new body, using MuJoCo as the simulation environment. This completes the full loop of the "body as code" philosophy — once the structure is parameterized, the simulation and reinforcement learning pipeline can adapt to new morphologies more smoothly, without having to rebuild the simulation model from scratch every time the shape changes.

MuJoCo (Multi-Joint dynamics with Contact) is a high-performance physics simulation engine maintained by DeepMind, designed specifically for robotics and motion control research. It is known for fast, accurate contact dynamics and is one of the most widely used simulation platforms for training gait policies in reinforcement learning. In a sim-to-real workflow, researchers first run millions of simulation steps in MuJoCo with a virtual robot, letting the reinforcement learning algorithm converge on a control policy, then deploy that policy to real hardware. Because structural parameters generated by CadQuery (such as leg length and linkage ratios) can be written directly into MuJoCo's MJCF model description files, the pipeline of "swap body → update simulation model → retrain policy" becomes significantly more automated, avoiding the errors and effort involved in manually editing simulation models.

What Else Is in the Open-Source Repository

The project is open-sourced under the Apache-2.0 license (repository: github.com/yotown/gym). In addition to the duck and flamingo, the repository also provides SO-101 and the LeRobot humanoid in code form.

This means users get not just a few fixed models, but a set of robot platforms that can be parametrically customized. For developers and researchers looking to experiment with custom morphologies and iterate on hardware designs at low cost, this "body as code" paradigm lowers the barrier to entry.

Why This Approach Matters

Encoding mechanical structures as executable programs, paired with control policies retrained in simulation, points toward a more agile approach to robot prototyping. Designers can adjust hardware form factors the same way they tweak software parameters — and assembly constraints and control adaptation no longer need to be rebuilt from scratch every time the shape changes.

Of course, based on a Reddit community post, this looks more like an interesting proof of concept than a mature product. Its core value lies in the methodology it demonstrates: parametric modeling + simulation-trained policies + open-source licensing — together, these three elements provide a highly accessible starting point for DIY robotics and educational research.

#parametric robot design#CadQuery#Open Duck Mini#MuJoCo#open-source robotics#robot body as code#reinforcement learning gait policy#SO-101#LeRobot humanoid
Share:

Related articles