From f1d4b23e48a3c71e15a0f36c56e6e04c06886d60 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 28 Oct 2024 14:17:51 -0700 Subject: [PATCH] mjSpec tutorial backwards compatibility with the latest MuJoCo release. PiperOrigin-RevId: 690747714 Change-Id: Ib8894a1dc2a68e30a110e773c77fbd2baee87efd --- python/mjspec.ipynb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/python/mjspec.ipynb b/python/mjspec.ipynb index 6f9455fd87..6d54be7250 100644 --- a/python/mjspec.ipynb +++ b/python/mjspec.ipynb @@ -172,7 +172,7 @@ "render(model)\n", "\n", "# Change the mjSpec, re-compile and re-render\n", - "geoms = spec.worldbody.find_all('geom')\n", + "geoms = spec.worldbody.find_all(mj.mjtObj.mjOBJ_GEOM)\n", "geoms[0].name = 'blue_box'\n", "geoms[0].rgba = [0, 0, 1, 1]\n", "geoms[1].name = 'yellow_sphere'\n", @@ -392,7 +392,11 @@ "#@title Six Creatures on a floor.{vertical-output: true}\n", "\n", "arena = mj.MjSpec()\n", - "arena.compiler.degree = False # Use radians.\n", + "\n", + "if hasattr(arena, 'compiler'):\n", + " arena.compiler.degree = False # MuJoCo dev (next release).\n", + "else:\n", + " arena.degree = False # MuJoCo release\n", "\n", "# Make arena with textured floor.\n", "chequered = arena.add_texture(\n", @@ -452,7 +456,7 @@ "video = []\n", "pos_x = []\n", "pos_y = []\n", - "geoms = arena.worldbody.find_all(\"geom\")\n", + "geoms = arena.worldbody.find_all(mj.mjtObj.mjOBJ_GEOM)\n", "torsos = [geom.id for geom in geoms if 'torso' in geom.name]\n", "actuators = [actuator.id for actuator in arena.actuators]\n", "\n", @@ -703,7 +707,11 @@ "\n", "spec = mj.MjSpec.from_file(humanoid_file)\n", "franka = mj.MjSpec.from_file(franka_file)\n", - "spec.compiler.degree = False # This has no effect on the humanoid as it does not contain angles\n", + "\n", + "if hasattr(spec, 'compiler'):\n", + " spec.compiler.degree = False # MuJoCo dev (next release).\n", + "else:\n", + " spec.degree = False # MuJoCo release\n", "\n", "# Replace right arm with frame\n", "arm_right = spec.find_body('upper_arm_right')\n", @@ -805,15 +813,18 @@ } ], "metadata": { + "accelerator": "GPU", "colab": { + "collapsed_sections": [ + "sJFuNetilv4m" + ], + "gpuClass": "premium", "private_outputs": true }, + "gpuClass": "premium", "kernelspec": { "display_name": "Python 3", "name": "python3" - }, - "language_info": { - "name": "python" } }, "nbformat": 4,