Commit Graph

131 Commits

Author SHA1 Message Date
Nimrod Gileadi 040deb161f Run cmake-format on test/xml/CMakeLists.xml
PiperOrigin-RevId: 458226371
Change-Id: I34f43a890dee7511597b48b303d5674ab9435d64
2022-06-30 07:59:39 -07:00
Nimrod Gileadi d567263959 Fix null pointer dereference in mj_loadModel.
mj_makeModel returns NULL if any of the array sizes are negative. Callers of the function need to handle that case.

PiperOrigin-RevId: 457948558
Change-Id: I9a5c8c0d3293ed0a92c5791f00d3ed34c848e024
2022-06-29 05:09:54 -07:00
Nimrod Gileadi 41bcf2d621 Python bindings: Add __repr__ implementations to grouped views.
PiperOrigin-RevId: 457704673
Change-Id: Idf0d2132ce0872e6ae3eef319b4c3119ab769cd0
2022-06-28 05:23:16 -07:00
Nimrod Gileadi e14cf7ddf1 Python bindings: Give a detailed error message when passing non-existent name.
List all valid names in the error message.

Fix an off-by-one error when accessing elements by numeric index (rather than name).

PiperOrigin-RevId: 457702283
Change-Id: I6e4f1518b4ecd9ca91ac9b0bf6b0963fc0a9bd18
2022-06-28 05:06:28 -07:00
Nimrod Gileadi a077db1b91 Implement __repr__ and __eq__ on MjrRect in Python bindings.
PiperOrigin-RevId: 457457401
Change-Id: I0d395ff301fbcf775b4766ac81c830a625b3be63
2022-06-27 05:55:38 -07:00
Nimrod Gileadi 263c92e301 Update lodepng to latest version.
This speeds up PNG loading significantly.

PiperOrigin-RevId: 457431911
Change-Id: I28da22a1fdbfc912d187a40cd731d9c04b83e07c
2022-06-27 03:06:55 -07:00
Kevin Zakka afc8395376 Make installation instructions more explicit in the README.
PiperOrigin-RevId: 456976659
Change-Id: I9bac31771eb62e069107b30122478437b67c2ebf
2022-06-24 03:48:26 -07:00
Yuval Tassa 228264c92b Add efficient finite-difference Jacobians of mj_step.
- Add `qH` and `qHDiagInv` to `mjData` to save factorized modified inertia.
- Add `mj_EulerSkip`, `mj_implicitSkip`, to `engine_forward.c`.
- Using the above functions, implement `mj_stepSkip` in `engine_derivative.c`.
- Add `mjd_stepFD` and `mjd_transitionFD` to `engine_derivative.c` to compute `mj_step` Jacobians.
  - Exploit "Skip" functionality for speed.
  - Correctly handle quaternion derivatives.
  - Handle warmstarts and control limits.

PiperOrigin-RevId: 456584811
Change-Id: Iee8541f11e7b66feb8f431cb102d9bbe65461f79
2022-06-22 12:48:48 -07:00
Yuval Tassa 2ea01bf2f6 Add Related Software section to README.md.
BEGIN PUBLIC

Add Related Software section to README.md.

Fixes #312.

END_PUBLIC

PiperOrigin-RevId: 456528399
Change-Id: Icf97a31a5ea16e93edf9856f70dec650c7b70791
2022-06-22 09:06:43 -07:00
Yuval Tassa 03c2011463 Enable activation clamping when using implicit integrator.
- Introduced private function `mj_advance()` as single point of state & time advancement.

PiperOrigin-RevId: 456525969
Change-Id: Iae17217e305c7baf07cb5ecd1e1b84b936421097
2022-06-22 08:55:48 -07:00
Nimrod Gileadi 2a26bf1ba5 Disable MSAN poisoning when printing using engine_print.
When using MSAN, mjData->buffer is marked as poisoned, despite being initialized with zeroes.
This is useful for catching computations that accidentally use uninitialized values.

However, when using engine_print, it's OK to assume the buffer is initialized to zeros.

PiperOrigin-RevId: 456085776
Change-Id: I9d85e37fa82958eb54ac413140543a6581aa46ad
2022-06-20 08:57:54 -07:00
Yuval Tassa 08b2db2f62 Allow in-place mju_rotVecMat and mju_rotVecMatT (res=vec)
PiperOrigin-RevId: 456021131
Change-Id: Id38ff5fabd15706d3087bc95d341b4f7a673449f
2022-06-20 01:57:45 -07:00
Nimrod Gileadi b1faec1dc2 Use _Generic instead of string comparisons for code that depends on field type.
This will allow us to add fields that can't be cast to int or double, without breaking print.

PiperOrigin-RevId: 456005913
Change-Id: I1fccfd11466f4745f69172af0ae61be07642927c
2022-06-20 00:03:17 -07:00
Saran Tunyasuvunakool 37fe45d41e Change macOS bundle structure.
This allows us to sign and notarize the bundle with mujoco.tbd in place, which is required for AppleClang to be able to build against the embedded framework.

PiperOrigin-RevId: 455952502
Change-Id: I366f1c17e7a6c06d956467ced6f16f3c37aebf6a
2022-06-19 14:13:23 -07:00
Saran Tunyasuvunakool 0e5ce18cff Manually parse inf and nan.
The C++ standard library `std::istringstream` is not guaranteed to parse "inf" and "nan" as valid floating point numbers. In our testing, libc++ does this, but libstdc++ and MSVCRT do not.

PiperOrigin-RevId: 455435431
Change-Id: I99c00303b08c2e4e62acfa3ca52a21a3008f4545
2022-06-16 11:57:52 -07:00
Alessio Quaglino 69a506e6ba Use C++ strcpy_arr in xml_native_reader_test.
PiperOrigin-RevId: 455375707
Change-Id: Ia3dbb11886ab29c4ad3192e4f78b4b60b94baad0
2022-06-16 07:15:14 -07:00
Alessio Quaglino 307cf692e5 Add <damper> actuator shortcut and related mjGAIN_AFFINE.
**Rationale**

A general `mjGAIN_AFFINE` actuator adds the term `force = (c + kp * length + kv * velocity) * ctrl`. The damper shortcut restricts it to `kv * velocity * ctrl` and sets the `ctrllimited` attribute to true.

**API**

```xml
<actuator>
  <damper ctrlrange="0 1" kv="1"/>
</actuator>
```

* Required attributes: `ctrlrange` (>=0)
* Optional attributes: `kv` (>=0)

PiperOrigin-RevId: 455366866
Change-Id: I88773abbeccabb6442f215c9fc05e205df63f692
2022-06-16 06:21:17 -07:00
Alessio Quaglino e0b6ba4a13 Raise warning if there are NaNs in the XML.
For Windows, throw an error if NaNs are present.

PiperOrigin-RevId: 455340787
Change-Id: Ibd95e2335ab15b706ee3328816983e5b57b2315e
2022-06-16 03:09:24 -07:00
Yuval Tassa 8958e13878 Improve best-practice description of included models in GitHub issues.
PiperOrigin-RevId: 455060429
Change-Id: I6a4544e99436749590a8d46ada09777ce2e90330
2022-06-15 01:06:15 -07:00
Kevin Zakka 2de8aa9e92 Fix redundant actuators in modeling doc.
PiperOrigin-RevId: 454942117
Change-Id: Id5ffa3339cb0188863570071dc56f6ead794e5a4
2022-06-14 13:29:42 -07:00
Kevin Zakka 6048a55daf Add intvelocity actuator shortcut.
PiperOrigin-RevId: 454899823
Change-Id: I9b5494baacfab5a7d03bd680d0ded06a7790e75e
2022-06-14 10:36:58 -07:00
Kevin Zakka 0e1918782a Handle invalid joint type in URDF conversion. Fixes #317.
PiperOrigin-RevId: 454798685
Change-Id: Ic29a3756e78f8714ed8acc70b10e115c3df46561
2022-06-14 01:42:52 -07:00
DeepMind 8dda269c8a Avoid msan reports on globals destructors
Somehow tests load these libs twice, and construct/destruct globals twice.
Can be preproduced even without sanitizers with logging from GlobalModel::~GlobalModel.

themodel does not need to be visible. If it's static each instance will have own a copy.
_mjMap does not need to use string and avoid lifecycle issues at all.

PiperOrigin-RevId: 454678814
Change-Id: I8fca5e1f06cbc2b413beabcece1219445482c0ed
2022-06-13 12:59:09 -07:00
Kevin Zakka ec7133b0d3 More efficient implementation of mju_rotVecQuat.
```
Before:
BM_RotVecQuat_mean           10.1           10.1    833409628  99.055M items/s

After:
BM_RotVecQuat_mean            6.41           6.41  1200000000  156.095M items/s
```
PiperOrigin-RevId: 454601673
Change-Id: Ibb3ce8a6c838a88bdcebd7aaa979b649639edf0b
2022-06-13 07:16:55 -07:00
Copybara-Service 959ed08246 Merge pull request #320 from djbutler:main
PiperOrigin-RevId: 454562743
Change-Id: Ia0d3067f7a37f30b1d2ae3b7a5755b7cbad3a114
2022-06-13 03:13:42 -07:00
Kevin Zakka f8b9e3e00f Add CMake entry for engine_util_spatial_benchmark_test.
PiperOrigin-RevId: 454424726
Change-Id: If79e9452c18220ddf0107157d78a2f08ce099a04
2022-06-12 01:01:46 -07:00
Nimrod Gileadi 5ac797965c Use batch mode in step_benchmark_test.
d8880e9a12 introduced measuring performance of a fixed batch of 50 steps, with a fixed starting state.
The Google Benchmark library has a more direct API for doing this, which ends up with nicer looking reported numbers.

PiperOrigin-RevId: 454133316
Change-Id: I368b985dc871084b9ed8c41a87016408719b53ad
2022-06-10 04:22:18 -07:00
Copybara-Service d90d50629b Merge pull request #329 from liuliu:liu/fix-memory-issues
PiperOrigin-RevId: 454115420
Change-Id: I741f5f24b67ab79f19051e4e6d67c0a155f639e1
2022-06-10 02:28:18 -07:00
Yuval Tassa d8880e9a12 Modify step_benchmark_test.cc to benchmark a fixed, 50-step sequence.
- Also remove multithreaded benchmark results.

PiperOrigin-RevId: 454102292
Change-Id: I5bd5fb1642adc547e695d2d3553bcaf0cf5c7bed
2022-06-10 00:52:43 -07:00
Alessio Quaglino 6ead14614f Adds rendering of ball and free joints actuators using an inflated joint geometry.
PiperOrigin-RevId: 453939612
Change-Id: I621f91d242b2974e6ae6acf239cdcb10efcb2629
2022-06-09 09:10:03 -07:00
Alessio Quaglino e050f36b5a Write sensor reftype and refname (if present) to XML file.
PiperOrigin-RevId: 453926332
Change-Id: I61f4aa2dc6186149b22af71eb8bb0fb2ffd84209
2022-06-09 08:03:47 -07:00
Copybara-Service 3bf377a10d Merge pull request #311 from lucas-inacio:main
PiperOrigin-RevId: 453879533
Change-Id: Ic535ad0a2bc919e98af0561fd9bad1708e9019f6
2022-06-09 03:16:40 -07:00
Alessio Quaglino d61a575a8c Replace fabs with std::abs.
Using fabs with int arguments broke the clang build on GitHub Actions, with a `-Wabsolute-value` error.

PiperOrigin-RevId: 453872474
Change-Id: I5c1278e9e628b0ea3d6f26c7ee7d6925c6276850
2022-06-09 02:31:18 -07:00
Alessio Quaglino c7c765b6eb Refactor mjXUtil::WriteAttr using templates.
PiperOrigin-RevId: 453848941
Change-Id: I1f87f0c20f0c89caab89ea4891aee7583a92534e
2022-06-08 23:33:49 -07:00
Alessio Quaglino 066367fcc8 Add visualisation flag for activations.
- Added illustrative model: `test/engine/testdata/activation.xml`

PiperOrigin-RevId: 453628961
Change-Id: I061ec3d17e57c6baffa0fe446a0be3564c44519d
2022-06-08 02:19:03 -07:00
Alessio Quaglino 736e0b391b Added visualization of site actuators.
PiperOrigin-RevId: 453609866
Change-Id: Icde220687f0c0e9e7fbbe0e3e56d995f823ffe07
2022-06-07 23:59:06 -07:00
Kevin Zakka 78c7e6e21f Add an example benchmark for methods in engine_util_spatial.
PiperOrigin-RevId: 453609626
Change-Id: I4986196ea3573bc22669c146ab6a311566035b73
2022-06-07 23:56:43 -07:00
Liu Liu f748018b28 Fix two asan detected memory bugs
I am running through simulate.swift (my port of simulate.cc) with
address sanitizer to discover related bugs.

Besides ones in my port, there are two in MuJoCo:

1. in maketext, the logic to find . is not protected against j is less
   than 0 (due to the decreasing logic above), creating out of bound
   access.

2. in mj_printFormattedData, qfrc_applied should use length nv not nq,
   otherwise out of bound access could be triggered.

Test Plan:

Run through the simulate.cc with asan. Before this fix, when presenting
profiler view, it will trigger bug #1. When print data, it will trigger
bug #2. Both are using model/humanoid/22_humanoids.xml.
2022-06-07 18:25:26 -04:00
Yuval Tassa f428c1bf56 Improve example XML snippet in "URDF Extensions" section.
`discardvisual="false"` is often required when importing URDF models.

[Relevant issue](https://github.com/deepmind/mujoco/issues/326).

PiperOrigin-RevId: 453429187
Change-Id: I6dccc5656114224d11010c87e6a127321cce93c1
2022-06-07 07:12:26 -07:00
Yuval Tassa c062531fc7 Fix formatting bug in overview.rst
PiperOrigin-RevId: 453257852
Change-Id: I9312f6a30e0b73199148435da8f6dd8ed1249e10
2022-06-06 12:28:29 -07:00
Kevin Zakka 53d3220fcc Fix quaternion typos.
PiperOrigin-RevId: 453203844
Change-Id: I7d788c21bb00b7746f941fb2cf755f0b046e35f2
2022-06-06 08:24:21 -07:00
Alessio Quaglino 16baac9353 Throw an error if multiple orientation specifiers are used in the same element.
- Applies to [orientation specifiers](https://mujoco.readthedocs.io/en/latest/modeling.html#frame-orientations) in `body`, `inertial`, `geom`, `site`, `camera`.
- Before this change the check was done only for multiple *alternative* specifiers, but not for `quat` and an alternative specifier.
- Moved the check from the compiler to the parser.
- Added tests.

PiperOrigin-RevId: 453201981
Change-Id: I20907361f211dae904e734cd083e9df0efe4f654
2022-06-06 08:13:06 -07:00
Yuval Tassa 652bab3eec Improve documentation of <freejoint> element.
PiperOrigin-RevId: 453192974
Change-Id: I14b02c8c37f6208a67b35efc17887668f6555aef
2022-06-06 07:15:41 -07:00
Yuval Tassa 8e38a8a020 Add "Asking Questions" section to README.md
PiperOrigin-RevId: 453178202
Change-Id: I0cb3a52983930fb3665cc40e26d5d19b44ac99f1
2022-06-06 05:23:55 -07:00
Yuval Tassa 880304abba Update the asset/mesh section of the XML reference to mention OBJ files.
Also clean up some formatting.

PiperOrigin-RevId: 453173729
Change-Id: I069b9433542dda0e3effe71d162cb51a46ce2f4e
2022-06-06 05:02:41 -07:00
Dan Butler c0282237f1 Update documentation for 'boundmass' attribute of 'compiler' xml element to include usage 2022-06-02 19:35:06 -07:00
Lucas Inácio Viegas edd7fd8695 Merge branch 'deepmind:main' into main 2022-05-31 12:52:25 -03:00
Lucas Inácio Viegas 2c54ec67cb Using CMAKE_CURRENT_SOURCE_DIR to properly refer to mujoco's include directory 2022-05-31 12:36:14 -03:00
Kevin Zakka d7ae7f5433 Improve error message when loading textures that are not PNGs.
PiperOrigin-RevId: 452052514
Change-Id: Ic2f0e8717e43d1a17b2d07ac0e07efe96c5ae1bd
2022-05-31 08:27:05 -07:00
Alessio Quaglino 8902c2089a Add dyntype to IncompleteActlimited test.
The test is meant to illustrate a failure of an incomplete actrange when the rest of the line is correct.

PiperOrigin-RevId: 451895379
Change-Id: I9782fae7055c9bed87ccbc0fda18495aacb2ae8a
2022-05-30 10:37:10 -07:00