Commit Graph

118 Commits

Author SHA1 Message Date
Saran Tunyasuvunakool 58fd72f53d Dynamically allocate contact and efc_ arrays on a new memory arena.
- Add private function `mj_arenaAlloc`. This is used internally to allocate memory from the arena.

- Add private function `mj_nefc` to count constraints. This function returns a tight upper bound on `d->nefc`. The number of counted constraints can be slightly bigger than exact `d->nefc` in the case of constraints with empty Jacobian, as when placing a frictional tendon between two world sites.

- Add new `memory` attribute to the `size` XML element for specification of arena memory size. This attribute is mutually exclusive with `nstack` and `njmax` specifications, which are now deprecated (but left around for the time being for legacy compatibility).

- Move `d->stack` to the end of the new arena space. The stack now grows in reverse from the end.

PiperOrigin-RevId: 479341539
Change-Id: Ie019c202e0908577ffc6f833a37920858116f667
2022-10-06 10:03:05 -07:00
Saran Tunyasuvunakool 5ef8cb6bbc Disable contact in the temporary mjData created during mjCModel::TryCompile.
PiperOrigin-RevId: 478793238
Change-Id: I28ed324b70931eb416ca57574570bf02c977f337
2022-10-04 08:21:11 -07:00
Alessio Quaglino bc1490b7a8 Add realtime parameter to visual global.
PiperOrigin-RevId: 478775714
Change-Id: Ic2d178a5c57d298d005215219ce8470392c4651b
2022-10-04 07:09:15 -07:00
Kevin Zakka 7e89d8dab0 In simulate UI, clear shortcut string for flags with no shortcuts.
PiperOrigin-RevId: 478467279
Change-Id: Icc4317d9e35b41871143572275d03adf7e13d956
2022-10-03 04:31:17 -07:00
Kevin Zakka cce35e1816 Add assetdir compiler option.
PiperOrigin-RevId: 478117894
Change-Id: I4a93108e00558034aa02d22047da80adfa4232b2
2022-09-30 17:59:25 -07:00
Nimrod Gileadi 8a8305d3ca Avoid unnecessary copies after of mju_mulQuat.
Since fdbbc8bbe0, mju_mulQuat allows in-place computations.
There were a few places where the result was unnecessarily assigned to a temporary variable.

PiperOrigin-RevId: 477746005
Change-Id: I7351ef4796e7d70a4a54b930037bfaadee781f12
2022-09-29 09:33:50 -07:00
Kevin Zakka 48f2ed99a5 Enforce strict positivity of extent and znear attributes at parse time.
PiperOrigin-RevId: 477597498
Change-Id: Ic927655cd5ba2fd8fdb1a1a5f7e54ff5040c3370
2022-09-28 17:53:05 -07:00
Yuval Tassa a6b338db64 mju_boxQP only reads from the lower triangle of the input Hessian.
- Before this change, an asymmetric Hessian would lead to solver failure. After this change the Hessian is symmetric by definition (upper triangle is ignored).
- API documentation was updated to reflect this contract.

PiperOrigin-RevId: 477135411
Change-Id: I60d011d36853afebac26c359771c217baf101360
2022-09-27 04:32:40 -07:00
Kyle Bayes 36b47e56d0 Use squared distance for sphere comparison in collision filtering.
PiperOrigin-RevId: 476165394
Change-Id: Id53493fc7cf4c10a22f5f885baeec0ed4b1d8574
2022-09-22 12:18:23 -07:00
Yuval Tassa 5dc26cf4a0 Fix bugs in actuator parsing.
- Adhesion actuator defaults were not parsed, now fixed.
- Both damper and adhesion actuators were requiring `ctrlrange` at parse time, which prevented this attribute from being inherited from defaults, now fixed.
- Added tests for all 3 cases.

PiperOrigin-RevId: 475145255
Change-Id: I8dd6196e20734136d990f522893ebd4d156cd7a8
2022-09-18 11:10:02 -07:00
Saran Tunyasuvunakool 1e2a9a53bc Implement plugin mechanism for actuators and sensors.
PiperOrigin-RevId: 474874088
Change-Id: I65a8ffdf845f4fa0f8266c165883a747ab5812d8
2022-09-16 12:21:29 -07:00
Nimrod Gileadi f556d4d94f Avoid out-of-bounds access when checking file extensions.
Include the '.' in the file extension check.

PiperOrigin-RevId: 474866478
Change-Id: I809ae975e4c8b00f17278735975a7d07e0748643
2022-09-16 11:49:33 -07:00
Alessio Quaglino 0e05e7ce52 Do not raise an error for flipped triangles if their area contribution is negligible.
PiperOrigin-RevId: 474552367
Change-Id: I9727a74e50a9bab9b04bb0de0b64e11587ed36f1
2022-09-15 07:07:00 -07:00
Nimrod Gileadi c8517e63a4 Mark mjCError and mjXError as [[nodiscard]].
This lets the compiler catch the mistake of creating an exception without throwing it.

PiperOrigin-RevId: 474536776
Change-Id: I5bd18258ce6ddd266adb1c852b1ba9e3063cd0b2
2022-09-15 05:28:57 -07:00
Yuval Tassa f4e7fa97af Add mju_mulVecMatVec, mutiplies a square matrix M by a vector x on both sides. Returns x^T * M * x.
PiperOrigin-RevId: 474292806
Change-Id: I3432469dbe1f02ccf5a13241c7aa12d824cbe034
2022-09-14 08:05:28 -07:00
Yuval Tassa 8957976674 Add mju_boxQP solving box-constrained quadratic programs.
PiperOrigin-RevId: 474256629
Change-Id: I87d70fe6899608122fe0688b017420a3e81afae2
2022-09-14 04:31:34 -07:00
Saran Tunyasuvunakool 94b6ae2b69 Bump version number to 2.2.2.
PiperOrigin-RevId: 472513958
Change-Id: I42f321c6681fdd42c5f80368f612534aa885af74
2022-09-06 11:32:55 -07:00
Alessio Quaglino 3647584caa Fixed typo ntexdata -> ntextdata.
PiperOrigin-RevId: 472461694
Change-Id: Ia97ffd6aeb1ae2df9ab5e11aabba6e361a98152b
2022-09-06 08:18:05 -07:00
Nimrod Gileadi a693a2d981 Don't infer limited attributes automatically by default.
This is an amendment to 4bfc2c0311.

Add an autolimits compiler option. When true, *limited will be inferred from the presence of the *range attributes.
When false, models where limited is not specified, and range is will fail to compile.

PiperOrigin-RevId: 472438650
Change-Id: I489098e879ee695030f44e0d8cd969787e75fb90
2022-09-06 06:11:53 -07:00
Yuval Tassa 0784a46f62 Add safety check to mjui_event.
PiperOrigin-RevId: 471809554
Change-Id: I563cac24781a9da6f7aa8313c9ea0b15c7b30903
2022-09-02 08:38:26 -07:00
Yuval Tassa e3a82247c2 Add sensor matrices to mjd_transitionFD.
- Also add missing `mj_jacSubtreeCom` to Python bindings.

PiperOrigin-RevId: 471610181
Change-Id: I31410d194527ce6a7bdbd01e176f3a41efa52d84
2022-09-01 13:00:36 -07:00
Yuval Tassa 46da1285af Cartesian end-effector control using site transmission.
- Added `refsite` attribute to actuators with `site` transmission.
- Such actuators now have a well defined length and can be used for e.g., Cartesian end-effector control.
- Added example models and documentation describing the new feature.

PiperOrigin-RevId: 471561218
Change-Id: I538f09af9600d5c53992c4a9fed325648aab4fa3
2022-09-01 10:06:52 -07:00
Yuval Tassa fdbbc8bbe0 Allow in-place computation for mju_mulQuat and mju_mulQuatAxis
PiperOrigin-RevId: 471222168
Change-Id: If43210636cf20000b343ad1efd02836465380ebe
2022-08-31 04:09:08 -07:00
Yuval Tassa eb65273fa1 Add test for rotational Jacobian formula used in weld constraints
PiperOrigin-RevId: 470947389
Change-Id: I39b9495e3e6d6cf8994e603d6eb69e3e5322e734
2022-08-30 03:42:55 -07:00
Nimrod Gileadi 6b6fff69ba Make URDF parser stricter about required attributes.
Following the spec at http://wiki.ros.org/urdf/XML

PiperOrigin-RevId: 470192022
Change-Id: I4699b6f87fff5706b3ba5f33bb8242bb2ad33478
2022-08-26 02:08:39 -07:00
Alessio Quaglino d26501c0f3 Add two new attributes to weld constraints:
- `anchor` determines the point of wrench application, in the frame of body2.
- `tfratio` scales applied torques relative to applied forces.
- Add visualisation of both anchor points to both weld and connect constraints.
- Add a test model showing how the new weld parameters behave.

PiperOrigin-RevId: 470021901
Change-Id: I3faba0e5dcab2e29ee81096f5ff71ff66d99758c
2022-08-25 10:22:15 -07:00
Kevin Zakka e2c3f04097 Improve error message for invalid keyframe values.
PiperOrigin-RevId: 470007035
Change-Id: I482aea255954b0ec811b7400226419836d8449e3
2022-08-25 09:23:21 -07:00
Kevin Zakka a90803d643 "exactmeshinertia" is now only saved if its value is different than default.
PiperOrigin-RevId: 469848032
Change-Id: I9abdeccbf764f5e4267753c0e2bfdd42b3bec723
2022-08-24 16:08:55 -07:00
Nimrod Gileadi 00fcd10b20 Don't use user input as a format string in mjCError.
PiperOrigin-RevId: 469686222
Change-Id: Icb05df04f11387847aa8d66dcf1b63da9c470b9f
2022-08-24 03:54:34 -07:00
Yuval Tassa 090fe2db3f Add a disable flag for sensors.
PiperOrigin-RevId: 469473066
Change-Id: I296ed790c6261c4fb15b349540edcb77e53e0567
2022-08-23 09:02:56 -07:00
Alessio Quaglino 83ce236479 Process meshes for computing the correct scaling even when they have flipped faces.
PiperOrigin-RevId: 469414367
Change-Id: Ia5c75b4f2c9fd592c81a1ec659720f9820c0dfbb
2022-08-23 03:29:40 -07:00
Alessio Quaglino abc0a39b7a Add two new attributes to weld constraints:
- `anchor` determines the point of wrench application, in the frame of body2.
- `tfratio` scales applied torques relative to applied forces.
- Add visualisation of both anchor points to both weld and connect constraints.
- Add a test model showing how the new weld parameters behave.

PiperOrigin-RevId: 469228149
Change-Id: I836b0791f10fb624607a12ef3c687da991c21789
2022-08-22 10:46:46 -07:00
Yuval Tassa 558aaf2923 Tighter bound for triggering invalid condim in mj_collideGeoms.
PiperOrigin-RevId: 469210244
Change-Id: I349de59aac7ba1bc80df322f667fa9afc87d4b1f
2022-08-22 09:50:42 -07:00
Alessio Quaglino 8ca5887c20 Add two new attributes to weld constraints:
- `anchor` determines the point of wrench application, in the frame of body2.
- `tfratio` scales applied torques relative to applied forces.
- Add visualisation of both anchor points to both weld and connect constraints.
- Add a test model showing how the new weld parameters behave.

PiperOrigin-RevId: 469190483
Change-Id: I20f6da85b09cd2c4c0b5d29eb8003eabb524e55e
2022-08-22 08:19:22 -07:00
Kevin Zakka 0b2f19bbe7 Fix "actrange" parsing for "intvelocity" actuators.
PiperOrigin-RevId: 468759706
Change-Id: I1d9eeb723d28cccb64a6112b103345fcf451700f
2022-08-19 12:22:55 -07:00
Kevin Zakka ee6fed1230 Add minor enhancements to compile binary.
* If output file exists, ask user whether to overwrite
* Fix erroneous check for whether XML file was successfully saved

PiperOrigin-RevId: 468743682
Change-Id: I06058c498328d333792e4b40d65c3a99ca1842e4
2022-08-19 11:15:19 -07:00
Yuval Tassa ae0ac86ec3 Add catenary visualisation to string-like tendons.
https://youtu.be/I2q7D0Vda-A

PiperOrigin-RevId: 468687422
Change-Id: I84f34e149cf098346a77a51f265113d8fa4f2525
2022-08-19 06:25:07 -07:00
Saran Tunyasuvunakool 7bd686cd87 Change signature of TryCompile so that *m isn't strewn across the function.
PiperOrigin-RevId: 468685571
Change-Id: I61e5b0cff29a0b1fc1a88bc088dc73f48b95c800
2022-08-19 06:12:07 -07:00
Yuval Tassa 833dc74074 Add support for excluded contacts in adhesion actuators.
- Update example model.
- Update video.

PiperOrigin-RevId: 468464196
Change-Id: I603c5a89c2d5a736de127440e6d542beffc12583
2022-08-18 08:28:11 -07:00
Kevin Zakka 4bfc2c0311 Automatically infer *limited field from *range field for joints, tendons and actuators.
PiperOrigin-RevId: 467980594
Change-Id: If635c55a90cf949796b99a41395a6c2c4f7ea094
2022-08-16 11:35:34 -07:00
Yuval Tassa 670b6136f9 Geoms of selected bodies respect transparency setting.
PiperOrigin-RevId: 467505247
Change-Id: I6864118e28d9c98aa1f8002583c2faeb011659ee
2022-08-14 04:34:38 -07:00
Nimrod Gileadi 5dd7bf8613 Verify that body_parentid and similar properties always go up the kinematic chain.
PiperOrigin-RevId: 467063831
Change-Id: I591c6a6f78178e9c2196cc94d7e622eba93d8191
2022-08-11 15:27:10 -07:00
Yuval Tassa c8ff7b3d34 Remove distance constraints.
- `distance` constraints were not very useful and increased the contact buffer within the constraint solver, violating a core design principle. Therefore they have been removed.
- The enum value `mjEQ_DISTANCE` is retained, but errors will be thrown in the parser and engine if these constraints are selected.

PiperOrigin-RevId: 467050101
Change-Id: Ie72a07e4fe338eea5107004a9fc0f5e47eb0c3b7
2022-08-11 14:31:11 -07:00
Copybara-Service 396fdf00c3 Merge pull request #425 from aftersomemath:cull-face-flag
PiperOrigin-RevId: 466904386
Change-Id: Icd5515c2bbb8f8f3417501ea43c8e5ae22b32f91
2022-08-11 02:44:37 -07:00
Nimrod Gileadi 01c297cddd Validate that fields like mjModel.body_jntnum don't contain negative values.
PiperOrigin-RevId: 466733848
Change-Id: I0b1f41fa8841c678307f2185aac4c46a2fd40396
2022-08-10 10:57:36 -07:00
Saran Tunyasuvunakool e3ded23c66 Fix memory leak in mjCModel::Compile.
This is a very subtle leak caused interaction between longjmp and compiler optimisation. Specifically, at the point where the setjmp takes places, these pointers have never been reassigned from its nullptr initialization. Without the volatile keyword, the compiler is free to assume that these pointers remain nullptr when the setjmp returns, and therefore to pass nullptr directly to the mj_deleteModel and mj_deleteData calls in the subsequent catch block, without ever reading the actual pointer values.

PiperOrigin-RevId: 466649447
Change-Id: I51e82ec8b566deb144221e11a99d5124a8267de4
2022-08-10 05:11:53 -07:00
Saran Tunyasuvunakool c2aff3a9f2 Fix memory leak and possibly use-after-free in user_mesh.cc.
The memory handling in the asset loading logic in user_mesh.cc is currently flipped: it frees the asset content buffer when reading from VFS but not from the filesystem. This causes the VFS object to leave these functions in an invalid state, while leaking locally allocated buffers that hold contents read from the filesystem.

PiperOrigin-RevId: 466643390
Change-Id: I162221e019861f23fb61308facd63dbb0422e113
2022-08-10 04:40:11 -07:00
Yuval Tassa d6e46bda50 Add missing braces.
PiperOrigin-RevId: 466576293
Change-Id: Ifea04abeed531befac6ab335bb66b1f1ce0f10a6
2022-08-09 22:53:13 -07:00
Alessio Quaglino 95d5db3f81 Allow malformed meshes for visualization purposes. Throw error only if the mesh is required for inertia computation.
PiperOrigin-RevId: 466421062
Change-Id: I947dbc107e481bd8c328b1a6430ab2e88bc82fd6
2022-08-09 11:41:29 -07:00
Saran Tunyasuvunakool aee73a9023 Fix memory leaks in mj_makeData and mj_makeModel.
Currently, if these functions fail to allocate space for the buffer or stack, it will exit without freeing any of the memory successfully allocated so far.

PiperOrigin-RevId: 466271030
Change-Id: Id01c115ec976482ac5d28c373b5eb47d77f424be
2022-08-09 00:42:17 -07:00