Repository navigation
Commit 94483e1
Add discrete elastic rod bending elasticity to 1D flexes.
1D flexes had no elasticity besides edge springs, so cables needed the cable plugin, whose chain of ball joints gives a dense mass matrix along the cable. With this change, a positive `young` on a 1D flex adds bending forces on the existing translational vertex dofs.
The model is a twist-free isotropic discrete elastic rod (Bergou et al. 2008). Every vertex with exactly two edges stores `k |κb|^2`, where κb is the discrete curvature binormal and `k = EI / (l0 + l1)` with I the second moment of area of the cross-section. The reference configuration (qpos0) must be straight: the compiler rejects any hinge bent by more than 1e-4 rad. Without material frames, an isotropic rod with a curved reference would only resist the curvature magnitude, so a planar arc could coil into a helix at no cost, and the force would not vanish through straight. Curved initial poses (coiled, draped) are set through qpos or keyframes and start with stored bending energy. Rods with a curved rest shape, such as coil springs, still need the cable plugin; curved rest shapes without material frames are left for a follow-up. Twist is assumed to relax instantly, which is exact unless both rod ends have constrained orientations. Damping acts on the rate of |κb| only, so rigid rotations are not damped.
Forces go through the generic flex scatter, so pinned and articulated attachments work, and 1D bending is compatible with edge equality constraints, and with mocap attachments when its damping is zero (mocap vertices have no velocity). Interpolated and rigid 1D flexes get no rod bending. Under the discrete integrator the bending is integrated implicitly with a PSD Gauss-Newton Hessian that is exact at rest; it is state dependent, so it rides the per-step stiffness path, not the constant 2D bending factor. Other integrators integrate it explicitly. The matrix-free operator applies J'(W(Jv)) per hinge; only the CSR assembly forms the 9x9 hinge stiffness.
The cross-section is selected by new `elasticity` attributes `section="circle|box"` and `sectionsize` (box half-sizes, stored as `mjsFlex.section`, of the new enum type `mjtFlexSection`, and `mjsFlex.sectionsize`). A circle uses the flex radius. A box uses the weak-axis `I = min(w h^3, h w^3) / 12`, because the bending model is isotropic. Both half-sizes are kept so that a later anisotropic model with material frames can use them without an API change. Decoupling the section from the radius also lets the collision/visual radius stay small, since flexcomp requires the spacing to be larger than the radius. The schema-generated files, references.h, the introspection enums and structs, and the wasm bindings are regenerated; APItypes.rst documents mjtFlexSection.
The connecting rod of `model/flex/mechanisms/slidercrank.xml` and the arm of `dipper.xml` are now rods (21 vertices each) instead of 12-cell trilinear 3D flexes, with the same mass and (weak-axis) cross-section and a flex radius of half the section height, so they look as thick; two point equalities per attachment replace the four-node clamps. The trilinear cells shear-locked, so `young` is raised 1.8x and 2.25x to keep the original deflections, and the Rayleigh damping coefficients are divided by the same factors to keep the physical damping. `cantilever.xml` keeps the 3D comparison and gets a fourth beam: a 1D rod with the same box cross-section and material as the soft 3D beam. Its edge equalities set their own solref/solimp, since the scene's `equality` default does not apply to flex edges. It settles at a tip deflection of 0.0746 m, versus 0.0752 m from Euler-Bernoulli and 0.069 m for the 3D quadratic beams.
Tests cover compiled data (circle and box), zero force at rest, force vs energy gradient, damping, the Hessian against finite differences, CSR assembly vs operator, a cantilever that matches Euler-Bernoulli tip deflection within 0.5% for both sections, XML save/reload of the section attributes, interpolated 1D flexes (no rod bending), the mocap/damping rule, the curved-reference compile error, a straight reference posed curved through qpos (the bending force straightens it), rigid 1D flexes (no rod bending, no straightness check), and loading and simulating the three mechanism models.
MJWarp implements 1D rod bending with the same model: passive forces and damping (`passive.py`), the hinge stiffness assembled into the effective-metric CSR and its matrix-free operator for non-simple attachments and the velocity shift (`derivative.py`, `passive.flex_rod_mul`), a per-hinge map built in `put_model` (new Model fields `nflexrodhinge`, `flex_rodhinge_map`, `has_flex_stiff_dim23`, with the MJX warp shims regenerated), and the C rule that rods do not require the discrete integrator (`forward.check_discrete`). `flex_test.py` compares forces, damping, disable flags, `efm_K_val`, `efm_c`, the `qacc_smooth` residual and 10-step trajectories (including slider-crank- and dipper-like rods and an articulated attachment) with MuJoCo C, for one and two worlds.
Under IPC, an elastic 1D flex is now a covered non-2D flex, so the sparse 2D metric factor falls back to blocks, like a 3D solid. `IpcTest.SparseFactorCoverage` keeps its inelastic cable case and adds an elastic rod case for this.
PiperOrigin-RevId: 1003076441
Change-Id: I689ad4cdcd8ad952e693027aeb0af2263183dba91 parent aab9efd commit 94483e1
47 files changed
Lines changed: 2040 additions & 93 deletions
File tree
- doc
- APIreference
- includes
- include/mujoco
- mjx/mujoco/mjx
- third_party/mujoco_warp/_src
- warp
- model/flex/mechanisms
- python/mujoco/introspect
- src
- engine
- experimental/studio/ux
- user
- xml
- generated
- test
- engine
- user
- unity/Runtime/Bindings
- wasm
- codegen/generated
- tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
973 | 973 | | |
974 | 974 | | |
975 | 975 | | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
976 | 985 | | |
977 | 986 | | |
978 | 987 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4202 | 4202 | | |
4203 | 4203 | | |
4204 | 4204 | | |
| 4205 | + | |
| 4206 | + | |
4205 | 4207 | | |
4206 | 4208 | | |
4207 | | - | |
| 4209 | + | |
4208 | 4210 | | |
4209 | 4211 | | |
4210 | 4212 | | |
| |||
4743 | 4745 | | |
4744 | 4746 | | |
4745 | 4747 | | |
| 4748 | + | |
| 4749 | + | |
| 4750 | + | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
| 4754 | + | |
| 4755 | + | |
| 4756 | + | |
| 4757 | + | |
| 4758 | + | |
| 4759 | + | |
| 4760 | + | |
| 4761 | + | |
| 4762 | + | |
| 4763 | + | |
4746 | 4764 | | |
4747 | 4765 | | |
4748 | 4766 | | |
| |||
4781 | 4799 | | |
4782 | 4800 | | |
4783 | 4801 | | |
4784 | | - | |
| 4802 | + | |
| 4803 | + | |
| 4804 | + | |
| 4805 | + | |
| 4806 | + | |
| 4807 | + | |
| 4808 | + | |
| 4809 | + | |
| 4810 | + | |
| 4811 | + | |
| 4812 | + | |
| 4813 | + | |
| 4814 | + | |
| 4815 | + | |
| 4816 | + | |
| 4817 | + | |
4785 | 4818 | | |
4786 | 4819 | | |
4787 | 4820 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1580 | 1580 | | |
1581 | 1581 | | |
1582 | 1582 | | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
1583 | 1589 | | |
1584 | 1590 | | |
1585 | 1591 | | |
| |||
1802 | 1808 | | |
1803 | 1809 | | |
1804 | 1810 | | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
1805 | 1817 | | |
1806 | 1818 | | |
1807 | 1819 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
| 577 | + | |
| 578 | + | |
577 | 579 | | |
578 | 580 | | |
579 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
| |||
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
95 | 110 | | |
96 | 111 | | |
97 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1712 | 1712 | | |
1713 | 1713 | | |
1714 | 1714 | | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
1715 | 1719 | | |
1716 | 1720 | | |
1717 | 1721 | | |
| |||
2113 | 2117 | | |
2114 | 2118 | | |
2115 | 2119 | | |
| 2120 | + | |
| 2121 | + | |
2116 | 2122 | | |
2117 | 2123 | | |
2118 | 2124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
92 | 98 | | |
93 | 99 | | |
94 | 100 | | |
| |||
534 | 540 | | |
535 | 541 | | |
536 | 542 | | |
| 543 | + | |
| 544 | + | |
537 | 545 | | |
538 | 546 | | |
539 | 547 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
318 | 320 | | |
319 | 321 | | |
320 | 322 | | |
| |||
0 commit comments