Skip to content

Commit

Permalink
Restore rendering using libGL
Browse files Browse the repository at this point in the history
  • Loading branch information
flferretti committed May 21, 2024
1 parent b37defb commit 3e31f33
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions examples/PD_controller.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,50 @@
"source": [
"# @title Set up MuJoCo renderer\n",
"\n",
"from jaxsim.mujoco.visualizer import MujocoVisualizer\n",
"from jaxsim.mujoco import RodModelToMjcf, MujocoModelHelper, MujocoVideoRecorder\n",
"from jaxsim.mujoco.loaders import UrdfToMjcf\n",
"\n",
"try:\n",
" import mujoco\n",
"except Exception as e:\n",
" raise e from RuntimeError(\n",
" \"Something went wrong during installation. Check the shell output above \"\n",
" \"for more information.\\n\"\n",
" \"If using a hosted Colab runtime, make sure you enable GPU acceleration \"\n",
" 'by going to the Runtime menu and selecting \"Choose runtime type\".'\n",
" )\n",
"import os\n",
"import subprocess\n",
"\n",
"\n",
"if IS_COLAB:\n",
" if subprocess.run(\"ffmpeg -version\", shell=True).returncode:\n",
" !command -v ffmpeg >/dev/null || (apt update && apt install -y ffmpeg)\n",
" clear_output()\n",
"\n",
" if subprocess.run(\"nvidia-smi\").returncode:\n",
" raise RuntimeError(\n",
" \"Cannot communicate with GPU. \"\n",
" \"Make sure you are using a GPU Colab runtime. \"\n",
" \"Go to the Runtime menu and select Choose runtime type.\"\n",
" )\n",
"\n",
" # Add an ICD config so that glvnd can pick up the Nvidia EGL driver.\n",
" # This is usually installed as part of an Nvidia driver package, but the Colab\n",
" # kernel doesn't install its driver via APT, and as a result the ICD is missing.\n",
" # (https://github.com/NVIDIA/libglvnd/blob/master/src/EGL/icd_enumeration.md)\n",
" NVIDIA_ICD_CONFIG_PATH = \"/usr/share/glvnd/egl_vendor.d/10_nvidia.json\"\n",
" if not os.path.exists(NVIDIA_ICD_CONFIG_PATH):\n",
" with open(NVIDIA_ICD_CONFIG_PATH, \"w\") as f:\n",
" f.write(\n",
" \"\"\"{\n",
" \"file_format_version\" : \"1.0.0\",\n",
" \"ICD\" : {\n",
" \"library_path\" : \"libEGL_nvidia.so.0\"\n",
" }\n",
" }\n",
" \"\"\"\n",
" )\n",
"\n",
"%env MUJOCO_GL=egl\n",
"\n",
"camera = {\n",
" \"name\":\"cartpole_camera\",\n",
" \"mode\":\"fixed\",\n",
" \"pos\":\"3.954 3.533 2.343\",\n",
" \"xyaxes\":\"-0.594 0.804 -0.000 -0.163 -0.120 0.979\",\n",
" \"fovy\":\"60\",\n",
" \"name\": \"cartpole_camera\",\n",
" \"mode\": \"fixed\",\n",
" \"pos\": \"3.954 3.533 2.343\",\n",
" \"xyaxes\": \"-0.594 0.804 -0.000 -0.163 -0.120 0.979\",\n",
" \"fovy\": \"60\",\n",
"}\n",
"\n",
"mjcf_string, assets = UrdfToMjcf.convert(urdf=model.built_from, cameras=camera)\n",
Expand Down

0 comments on commit 3e31f33

Please sign in to comment.