Commit Graph

41 Commits

Author SHA1 Message Date
Alessio Quaglino 644dfc7fb5 Fix assigning bytes to texture data.
PiperOrigin-RevId: 706747323
Change-Id: I6b0ee67d4f35db3a149ba8d9979546d3c712bb8b
2024-12-16 10:05:23 -08:00
Baruch Tabanpour f3b3024291 Add pyink and isort config. Reformat.
PiperOrigin-RevId: 704533915
Change-Id: I37e9fd51261bd166b725c7460fc65d02fed2b391
2024-12-09 21:10:50 -08:00
Alessio Quaglino 41968f1527 Support body.find_all("joint") in bindings.
PiperOrigin-RevId: 703071822
Change-Id: I6457ca0561c794447cc06aab29dcd0aac82c49a0
2024-12-05 04:54:42 -08:00
Alessio Quaglino a729acb4fa Add spec find_sensor, find_actuator functions.
PiperOrigin-RevId: 703054696
Change-Id: Ie384f1a31de3ecd9b22b7f4be43234d452e7bb88
2024-12-05 03:42:26 -08:00
Alessio Quaglino 503e5e1815 Change site.attach to accept a spec instead of a body.
Add site.attach_body for attaching a body to a site.

PiperOrigin-RevId: 703047770
Change-Id: Ibc1f916f8741872135220461cda7cebc4b418913
2024-12-05 03:10:17 -08:00
Alessio Quaglino a3b9f986c0 Add spec.find_site().
PiperOrigin-RevId: 702733068
Change-Id: I4cc7fd2b9b59185a4458fdac8537f8287af1f295
2024-12-04 08:20:57 -08:00
Alessio Quaglino d1b02556ef Allow keyword arguments in attach.
PiperOrigin-RevId: 702718597
Change-Id: I1f1a5e9c88c8e102d5cbe5984511e7923ec7be3e
2024-12-04 07:32:31 -08:00
Alessio Quaglino c6ba8f27fd Add bind() method to MjModel and MjData.
This method allows users to bind a spec to a model or data object, making it less verbose to access its arrays.

PiperOrigin-RevId: 699952211
Change-Id: I6b71a88d5a6968bc0f902bd49db7c568b46a4dfb
2024-11-25 05:53:58 -08:00
Alessio Quaglino f909d63cdf Enable to attach a spec to a frame.
PiperOrigin-RevId: 699703988
Change-Id: Idbddcbce1e68286248458eb0bd24d5080451a58a
2024-11-24 07:35:14 -08:00
Alessio Quaglino 3a12db9ad2 Remove id attribute from mjSpec objects in Python bindings.
Using ids is error prone in scenarios of repeated attachment and detachment. Python users are encouraged to use names for unique identification of model elements.

PiperOrigin-RevId: 699227286
Change-Id: Ifd83e6d85d36ff72ea43caf8b82eab9e4d552440
2024-11-22 11:05:14 -08:00
Alessio Quaglino e835f139c8 Add sibling traversal for tree elements.
PiperOrigin-RevId: 691057957
Change-Id: I3f30cf175b5ad0842f3fbbf7fdb42ba7a2212682
2024-10-29 09:55:08 -07:00
Copybara-Service 2c86136dd6 Merge pull request #2160 from traversaro:patch-40
PiperOrigin-RevId: 690660035
Change-Id: Id4dc7eb53b7c6cda050d1e6b385eec16d66d077e
2024-10-28 10:17:13 -07:00
Silvio Traversaro 455116466b Fix running tests out of a installed mujoco python package 2024-10-25 13:24:21 +02:00
Alessio Quaglino bebec52869 Add find_all with string input.
PiperOrigin-RevId: 689487165
Change-Id: I48511aec1610b2112f9456e8f410d077c57c7a95
2024-10-24 13:01:49 -07:00
Alessio Quaglino 159f23e6b4 Remember compiler options during attach.
Note:
- Move compiler options into `mjsCompiler` struct.
- The compiler options from the attached model are not written by mj_SaveXML.
PiperOrigin-RevId: 689391440
Change-Id: I1d63c146a32f87c737b7a55b64a54b0ffe3aecc9
2024-10-24 08:31:15 -07:00
Alessio Quaglino bfa78614c8 Require prefix for the attach tag.
For `mjs_attachFrame` and `mjs_attachBody`, require either a prefix or suffix.

It is tempting for users to not use a prefix (see #2162), but this causes issues. For example, it creates a duplicate "main" default class in the parent as a child of the already existing "main" default.

PiperOrigin-RevId: 688535755
Change-Id: I653181ca35943f1e4eb89c70fca8b5289818324e
2024-10-22 07:08:33 -07:00
Alessio Quaglino 766cd20273 Add mjs_bodyToFrame() to convert a body to a frame.
Also add test for attaching the world body.

PiperOrigin-RevId: 685603933
Change-Id: I3cfe7d226d6f032b5a587e44d0f4f18207977188
2024-10-14 00:39:20 -07:00
Alessio Quaglino cdb167f275 Add mjs_attachToSite for attaching a body to a site.
PiperOrigin-RevId: 684432183
Change-Id: I7100bebfb6521f9dbfbb07f31490b2b9298bf18c
2024-10-10 07:12:49 -07:00
Alessio Quaglino 1f9dca8bc4 Do not expose plugin_slot.
PiperOrigin-RevId: 683215401
Change-Id: Ic64f7221ed83ca3b0c8cca16eb680ea67c67b564
2024-10-07 09:38:01 -07:00
Alessio Quaglino 66faba9aa5 Avoid changing semantics of mjsPlugin.name across XML sections.
The `extension` section used to discard the plugin name and write the instance name in `plugin.name`, while all of the other sections wrote the instance name in `plugin.instance_name` and optionally the plugin name in `plugin.name` (via the function `OnePlugin`). Now all plugin names are in `plugin.plugin_name` and the instance is written in `plugin.name`, so that it is possible to lookup a plugin via its unique instance name.

PiperOrigin-RevId: 683183804
Change-Id: I179ef5d221143b720db24d745b09e327bf1449ef
2024-10-07 07:57:03 -07:00
Alessio Quaglino 6e66cafe76 Capture mjs_attach error message in the Python bindings.
PiperOrigin-RevId: 682409212
Change-Id: I391ee48626e7dcd985f65a231370ef5ec16124d7
2024-10-04 12:19:42 -07:00
Alessio Quaglino e973dc74dd Yield ownership of char[], vector<string>, and vector<byte> to mjSpec in Python bindings.
PiperOrigin-RevId: 681522091
Change-Id: Icb3788d9ef6e914a307531e39ad8171c24f590af
2024-10-02 11:14:48 -07:00
Alessio Quaglino 89aea5e217 Add body.find_all() to Python bindings.
This enables to generate a list of all body children of a given type.

Also, add recursive option to mjs_firstChild and mjs_nextChild. Fixes #2112.

PiperOrigin-RevId: 681039348
Change-Id: Iebbb26fd5ec314150206edfdddd88633baa0bec6
2024-10-01 08:57:25 -07:00
Alessio Quaglino 8a825e6050 Add auto-generated tree element lists to Python bindings.
PiperOrigin-RevId: 680973047
Change-Id: I948151260cba330c6b7218cecf13aae2c7ae92c7
2024-10-01 05:23:03 -07:00
Alessio Quaglino 6a415da267 Make from_file() and from_string() classmethod functions.
This prevents the user from modifying an mjSpec and then calling the functions to load it from string/file.

PiperOrigin-RevId: 679311284
Change-Id: I4f1ae3cc8f15bece245f624303470d538deec410
2024-09-26 15:16:10 -07:00
Alessio Quaglino 5bca7876c4 Update spec.from_string() and spec.from_file() to match the respective mjModel functions.
PiperOrigin-RevId: 678230403
Change-Id: I7f3d8c5fd44d30b5695eee1f8513cc27f4158d94
2024-09-24 06:57:20 -07:00
Alessio Quaglino b5bcc91a03 Add bindings generation for mjOption, mjVisual, and mjStatistic.
Fixes #2076.

PiperOrigin-RevId: 677789263
Change-Id: Ie1bda40af62c5ac9bbba541668a50adfc59d3f7c
2024-09-23 07:43:09 -07:00
Alessio Quaglino 0ba11b9623 Add plugins list to mjSpec Python API.
Fixes #2061.

PiperOrigin-RevId: 677762985
Change-Id: I8e407373e7b505d9b0f1c023e97c5ea92169bbf6
2024-09-23 06:13:42 -07:00
Taylor Howell 6c7e1095c5 Add mjsPlugin and mjsOrientation related keyword argument support for mjSpec Python bindings.
PiperOrigin-RevId: 676412967
Change-Id: I8cc1bfcc443327fde33246981400b375f8d4ff3d
2024-09-19 07:55:31 -07:00
Taylor Howell bfda9f4ace Add optional kwarg inputs to mjSpec Python bindings for mjSpec add constructors.
PiperOrigin-RevId: 675929024
Change-Id: Idd8c584276d8f585b79585230f5167f79760eaef
2024-09-18 04:02:10 -07:00
Taylor Howell b0c7101f1c Add optional kwarg inputs to mjSpec Python bindings for mjsBody add constructors.
PiperOrigin-RevId: 675141078
Change-Id: I8d735ae7d0a018ce7cd1aca56c899d1455586015
2024-09-16 07:32:55 -07:00
Alessio Quaglino 505d01a1c1 Add error handling to mj_recompile.
This CL adds error handling to the mj_recompile function. If the recompile fails, the function will return -1 and set the error message in the spec. The Python wrapper for mj_recompile will catch the error and raise a ValueError exception.

PiperOrigin-RevId: 666784579
Change-Id: I225eca1769ea839c782be3c03fc4ff1ea5885a48
2024-08-23 07:18:28 -07:00
Alessio Quaglino e0e134ca63 Add plugin tests for mjSpec.
Fixes #1903.

PiperOrigin-RevId: 663352920
Change-Id: I3a9e17aec5694e49c20b542f4b0a4402f88a2f17
2024-08-15 10:19:53 -07:00
Alessio Quaglino b341bd391d Fix a bug with mjs_delete functions.
PiperOrigin-RevId: 657615906
Change-Id: Ic70eaa9a5c20337db3897cf882a60e9d94f2869b
2024-07-30 09:13:57 -07:00
Alessio Quaglino 70ac76bb4b Add assets to MjSpec.compile()
PiperOrigin-RevId: 653965318
Change-Id: Ib9ec1c70a7241f7ee547b799a08cc58e7d4bace7
2024-07-19 04:34:38 -07:00
Alessio Quaglino 5d51b4cd5f Check that element is a nullptr before casting.
The bug was caused by the fact that the `mjs_as*` functions would return a pointer to a `mjC*` object, even if the input `mjsElement` pointer was null. This would cause a segfault.

PiperOrigin-RevId: 651802736
Change-Id: Ibec00d269a4befadff8a68e0513fd381c7e38a2a
2024-07-12 09:46:16 -07:00
Yuval Tassa 9d0812911c Add a test for type attribute.
PiperOrigin-RevId: 649635359
Change-Id: Ibe5d9fcb5f14371e5f154d645b838a9d012331d5
2024-07-05 06:16:46 -07:00
Yuval Tassa 118b6810b3 Make "id" a property rather than a method of mjsElements in Python bindings.
PiperOrigin-RevId: 649424035
Change-Id: I8226b3040aa2001ae9748399257e36ac263b7c8b
2024-07-04 08:35:37 -07:00
Alessio Quaglino a0945e4b5a Add non-tree element lists to python bindings.
Fixes #1752.

PiperOrigin-RevId: 649405039
Change-Id: Ie0b575a3ec912b773141694397ac2f394bff1227
2024-07-04 07:24:02 -07:00
Yuval Tassa 8f16b72f44 Rename mjSpec.euler to eulerseq to match MJCF.
PiperOrigin-RevId: 649007737
Change-Id: Iedb53c1d8a6e6a082a6ba30a1fb2bb4516839fa1
2024-07-03 03:10:02 -07:00
Alessio Quaglino 9106f40e2b Add mjSpec bindings.
Co-authored-by: Saran Tunyasuvunakool <stunya@google.com>
PiperOrigin-RevId: 648444641
Change-Id: I08ee1d3f4fae1efbc7934ba94702b1c06d8cb92a
2024-07-01 12:05:50 -07:00