mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-20 05:52:03 +00:00
951 lines
68 KiB
HTML
951 lines
68 KiB
HTML
![]() |
<!doctype html>
|
||
|
<html class="no-js" lang="en" data-content_root="../../../">
|
||
|
<head><meta charset="utf-8"/>
|
||
|
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
||
|
<meta name="color-scheme" content="light dark">
|
||
|
<meta name="description" content="A standard API for reinforcement learning and a diverse set of reference environments (formerly Gym)">
|
||
|
<meta property="og:title" content="Gymnasium Documentation" />
|
||
|
<meta property="og:type" content="website" />
|
||
|
<meta property="og:description" content="A standard API for reinforcement learning and a diverse set of reference environments (formerly Gym)" />
|
||
|
<meta property="og:url" content="https://gymnasium.farama.org/tutorials/gymnasium_basics/load_quadruped_model.html" /><meta property="og:image" content="https://gymnasium.farama.org/_static/img/gymnasium-github.png" /><meta name="twitter:card" content="summary_large_image"><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
<link rel="index" title="Index" href="../../../genindex/" /><link rel="search" title="Search" href="../../../search/" /><link rel="next" title="Handling Time Limits" href="../handling_time_limits/" /><link rel="prev" title="Gymnasium Basics Documentation Links" href="../" />
|
||
|
<link rel="canonical" href="https://gymnasium.farama.org/tutorials/gymnasium_basics/load_quadruped_model.html" />
|
||
|
|
||
|
<link rel="shortcut icon" href="../../../_static/favicon.png"/><!-- Generated with Sphinx 7.4.7 and Furo 2023.08.19.dev1 -->
|
||
|
<title>Load custom quadruped robot environments - Gymnasium Documentation</title>
|
||
|
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css?v=8f2a1f02" />
|
||
|
<link rel="stylesheet" type="text/css" href="../../../_static/styles/furo.css?v=3e7f4c72" />
|
||
|
<link rel="stylesheet" type="text/css" href="../../../_static/sg_gallery.css?v=61a4c737" />
|
||
|
<link rel="stylesheet" type="text/css" href="../../../_static/sg_gallery-binder.css?v=f4aeca0c" />
|
||
|
<link rel="stylesheet" type="text/css" href="../../../_static/sg_gallery-dataframe.css?v=2082cf3c" />
|
||
|
<link rel="stylesheet" type="text/css" href="../../../_static/sg_gallery-rendered-html.css?v=1277b6f3" />
|
||
|
<link rel="stylesheet" type="text/css" href="../../../_static/styles/furo-extensions.css?v=82c8b628" />
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<style>
|
||
|
body {
|
||
|
--color-code-background: #f8f8f8;
|
||
|
--color-code-foreground: black;
|
||
|
|
||
|
}
|
||
|
@media not print {
|
||
|
body[data-theme="dark"] {
|
||
|
--color-code-background: #202020;
|
||
|
--color-code-foreground: #d0d0d0;
|
||
|
|
||
|
}
|
||
|
@media (prefers-color-scheme: dark) {
|
||
|
body:not([data-theme="light"]) {
|
||
|
--color-code-background: #202020;
|
||
|
--color-code-foreground: #d0d0d0;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</style></head>
|
||
|
<body>
|
||
|
<header class="farama-header" aria-label="Farama header">
|
||
|
<div class="farama-header__container">
|
||
|
<div class="farama-header__left--mobile">
|
||
|
<label class="nav-overlay-icon" for="__navigation">
|
||
|
<div class="visually-hidden">Toggle site navigation sidebar</div>
|
||
|
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||
|
<defs></defs>
|
||
|
<line x1="0.5" y1="4" x2="23.5" y2="4"></line>
|
||
|
<line x1="0.232" y1="12" x2="23.5" y2="12"></line>
|
||
|
<line x1="0.232" y1="20" x2="23.5" y2="20"></line>
|
||
|
</svg>
|
||
|
</label>
|
||
|
</div>
|
||
|
<div class="farama-header__left farama-header__center--mobile">
|
||
|
<a href="../../../">
|
||
|
<img class="farama-header__logo only-light" src="../../../_static/img/gymnasium_black.svg" alt="Light Logo"/>
|
||
|
<img class="farama-header__logo only-dark" src="../../../_static/img/gymnasium_white.svg" alt="Dark Logo"/>
|
||
|
<span class="farama-header__title">Gymnasium Documentation</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
<div class="farama-header__right">
|
||
|
<div class="farama-header-menu">
|
||
|
<button class="farama-header-menu__btn" aria-label="Open Farama Menu" aria-expanded="false" aria-haspopup="true" aria-controls="farama-menu">
|
||
|
<img class="farama-black-logo-invert" src="../../../_static/img/farama-logo-header.svg">
|
||
|
<svg viewBox="0 0 24 24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||
|
<polyline style="stroke-linecap: round; stroke-linejoin: round; fill: none; stroke-width: 2px;" points="1 7 12 18 23 7"></polyline>
|
||
|
</svg>
|
||
|
</button>
|
||
|
<div class="farama-header-menu-container farama-hidden" aria-hidden="true" id="farama-menu">
|
||
|
<div class="farama-header-menu__header">
|
||
|
<a href="https://farama.org">
|
||
|
<img class="farama-header-menu__logo farama-white-logo-invert" src="../../../_static/img/farama_solid_white.svg" alt="Farama Foundation logo">
|
||
|
<span>Farama Foundation</span>
|
||
|
</a>
|
||
|
<div class="farama-header-menu-header__right">
|
||
|
<button id="farama-close-menu">
|
||
|
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor"
|
||
|
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon-close">
|
||
|
<line x1="3" y1="21" x2="21" y2="3"></line>
|
||
|
<line x1="3" y1="3" x2="21" y2="21"></line>
|
||
|
</svg>
|
||
|
</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="farama-header-menu__body">
|
||
|
<!-- Response from farama.org/api/projects.json -->
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</header>
|
||
|
|
||
|
|
||
|
<script>
|
||
|
document.body.dataset.theme = localStorage.getItem("theme") || "auto";
|
||
|
</script>
|
||
|
|
||
|
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
|
||
|
<symbol id="svg-toc" viewBox="0 0 24 24">
|
||
|
<title>Contents</title>
|
||
|
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
|
||
|
<path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
|
||
|
</svg>
|
||
|
</symbol>
|
||
|
<symbol id="svg-menu" viewBox="0 0 24 24">
|
||
|
<title>Menu</title>
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||
|
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
|
||
|
<line x1="3" y1="12" x2="21" y2="12"></line>
|
||
|
<line x1="3" y1="6" x2="21" y2="6"></line>
|
||
|
<line x1="3" y1="18" x2="21" y2="18"></line>
|
||
|
</svg>
|
||
|
</symbol>
|
||
|
<symbol id="svg-arrow-right" viewBox="0 0 24 24">
|
||
|
<title>Expand</title>
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||
|
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
|
||
|
<polyline points="9 18 15 12 9 6"></polyline>
|
||
|
</svg>
|
||
|
</symbol>
|
||
|
<symbol id="svg-sun" viewBox="0 0 24 24">
|
||
|
<title>Light mode</title>
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||
|
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
|
||
|
<circle cx="12" cy="12" r="5"></circle>
|
||
|
<line x1="12" y1="1" x2="12" y2="3"></line>
|
||
|
<line x1="12" y1="21" x2="12" y2="23"></line>
|
||
|
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
|
||
|
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
|
||
|
<line x1="1" y1="12" x2="3" y2="12"></line>
|
||
|
<line x1="21" y1="12" x2="23" y2="12"></line>
|
||
|
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
|
||
|
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
|
||
|
</svg>
|
||
|
</symbol>
|
||
|
<symbol id="svg-moon" viewBox="0 0 24 24">
|
||
|
<title>Dark mode</title>
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||
|
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
|
||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||
|
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
|
||
|
</svg>
|
||
|
</symbol>
|
||
|
<symbol id="svg-sun-half" viewBox="0 0 24 24">
|
||
|
<title>Auto light/dark mode</title>
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||
|
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
|
||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||
|
<circle cx="12" cy="12" r="9" />
|
||
|
<path d="M13 12h5" />
|
||
|
<path d="M13 15h4" />
|
||
|
<path d="M13 18h1" />
|
||
|
<path d="M13 9h4" />
|
||
|
<path d="M13 6h1" />
|
||
|
</svg>
|
||
|
</symbol>
|
||
|
</svg>
|
||
|
|
||
|
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
|
||
|
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
|
||
|
<label class="overlay sidebar-overlay" for="__navigation">
|
||
|
<div class="visually-hidden">Hide navigation sidebar</div>
|
||
|
</label>
|
||
|
<label class="overlay toc-overlay" for="__toc">
|
||
|
<div class="visually-hidden">Hide table of contents sidebar</div>
|
||
|
</label>
|
||
|
|
||
|
<div class="page">
|
||
|
<!--<header class="mobile-header">
|
||
|
<div class="header-left">
|
||
|
<label class="nav-overlay-icon" for="__navigation">
|
||
|
<div class="visually-hidden">Toggle site navigation sidebar</div>
|
||
|
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
|
||
|
</label>
|
||
|
</div>
|
||
|
<div class="header-center">
|
||
|
<a href="../../../"><div class="brand">Gymnasium Documentation</div></a>
|
||
|
</div>
|
||
|
<div class="header-right">
|
||
|
<div class="theme-toggle-container theme-toggle-header">
|
||
|
<button class="theme-toggle">
|
||
|
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
|
||
|
<svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
|
||
|
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
|
||
|
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
|
||
|
</button>
|
||
|
</div>
|
||
|
<label class="toc-overlay-icon toc-header-icon" for="__toc">
|
||
|
<div class="visually-hidden">Toggle table of contents sidebar</div>
|
||
|
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
|
||
|
</label>
|
||
|
</div>
|
||
|
</header>-->
|
||
|
<aside class="sidebar-drawer">
|
||
|
<div class="sidebar-container">
|
||
|
|
||
|
<div class="sidebar-sticky"><a class="farama-sidebar__title" href="../../../">
|
||
|
<img class="farama-header__logo only-light" src="../../../_static/img/gymnasium_black.svg" alt="Light Logo"/>
|
||
|
<img class="farama-header__logo only-dark" src="../../../_static/img/gymnasium_white.svg" alt="Dark Logo"/>
|
||
|
<span class="farama-header__title">Gymnasium Documentation</span>
|
||
|
</a><form class="sidebar-search-container" method="get" action="../../../search/" role="search">
|
||
|
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
|
||
|
<input type="hidden" name="check_keywords" value="yes">
|
||
|
<input type="hidden" name="area" value="default">
|
||
|
</form>
|
||
|
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
|
||
|
<p class="caption" role="heading"><span class="caption-text">Introduction</span></p>
|
||
|
<ul>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../introduction/basic_usage/">Basic Usage</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../introduction/train_agent/">Training an Agent</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../introduction/create_custom_env/">Create a Custom Environment</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../introduction/record_agent/">Recording Agents</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../introduction/speed_up_env/">Speeding Up Training</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../introduction/gym_compatibility/">Compatibility with Gym</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../introduction/migration_guide/">Migration Guide - v0.21 to v1.0.0</a></li>
|
||
|
</ul>
|
||
|
<p class="caption" role="heading"><span class="caption-text">API</span></p>
|
||
|
<ul>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../api/env/">Env</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../api/registry/">Make and register</a></li>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../../api/spaces/">Spaces</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Spaces</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/spaces/fundamental/">Fundamental Spaces</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/spaces/composite/">Composite Spaces</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/spaces/utils/">Spaces Utils</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../../api/wrappers/">Wrappers</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of Wrappers</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/table/">List of Wrappers</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/misc_wrappers/">Misc Wrappers</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/action_wrappers/">Action Wrappers</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/observation_wrappers/">Observation Wrappers</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/reward_wrappers/">Reward Wrappers</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../../api/vector/">Vectorize</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of Vectorize</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/vector/wrappers/">Wrappers</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/vector/async_vector_env/">AsyncVectorEnv</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/vector/sync_vector_env/">SyncVectorEnv</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/vector/utils/">Utility functions</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../api/utils/">Utility functions</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../api/functional/">Functional Env</a></li>
|
||
|
</ul>
|
||
|
<p class="caption" role="heading"><span class="caption-text">Environments</span></p>
|
||
|
<ul>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/classic_control/">Classic Control</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle navigation of Classic Control</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/classic_control/acrobot/">Acrobot</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/classic_control/cart_pole/">Cart Pole</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/classic_control/mountain_car_continuous/">Mountain Car Continuous</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/classic_control/mountain_car/">Mountain Car</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/classic_control/pendulum/">Pendulum</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/box2d/">Box2D</a><input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle navigation of Box2D</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/box2d/bipedal_walker/">Bipedal Walker</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/box2d/car_racing/">Car Racing</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/box2d/lunar_lander/">Lunar Lander</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/toy_text/">Toy Text</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle navigation of Toy Text</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/toy_text/blackjack/">Blackjack</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/toy_text/taxi/">Taxi</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/toy_text/cliff_walking/">Cliff Walking</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/toy_text/frozen_lake/">Frozen Lake</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/mujoco/">MuJoCo</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle navigation of MuJoCo</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/ant/">Ant</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/half_cheetah/">Half Cheetah</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/hopper/">Hopper</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/humanoid/">Humanoid</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/humanoid_standup/">Humanoid Standup</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/inverted_double_pendulum/">Inverted Double Pendulum</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/inverted_pendulum/">Inverted Pendulum</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/pusher/">Pusher</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/reacher/">Reacher</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/swimmer/">Swimmer</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/mujoco/walker2d/">Walker2D</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../environments/atari/">Atari</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../environments/third_party_environments/">External Environments</a></li>
|
||
|
</ul>
|
||
|
<p class="caption" role="heading"><span class="caption-text">Tutorials</span></p>
|
||
|
<ul class="current">
|
||
|
<li class="toctree-l1 current has-children"><a class="reference internal" href="../">Gymnasium Basics Documentation Links</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle navigation of Gymnasium Basics Documentation Links</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
|
||
|
<li class="toctree-l2 current current-page"><a class="current reference internal" href="#">Load custom quadruped robot environments</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../handling_time_limits/">Handling Time Limits</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../implementing_custom_wrappers/">Implementing Custom Wrappers</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../environment_creation/">Make your own custom environment</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../vector_envs_tutorial/">Training A2C with Vector Envs and Domain Randomization</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1 has-children"><a class="reference internal" href="../../training_agents/">Training Agents links in the Gymnasium Documentation</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle navigation of Training Agents links in the Gymnasium Documentation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../training_agents/reinforce_invpend_gym_v26/">Training using REINFORCE for Mujoco</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../training_agents/blackjack_tutorial/">Solving Blackjack with Q-Learning</a></li>
|
||
|
<li class="toctree-l2"><a class="reference internal" href="../../training_agents/FrozenLake_tuto/">Frozenlake benchmark</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../third-party-tutorials/">Third-Party Tutorials</a></li>
|
||
|
</ul>
|
||
|
<p class="caption" role="heading"><span class="caption-text">Development</span></p>
|
||
|
<ul>
|
||
|
<li class="toctree-l1"><a class="reference external" href="https://github.com/Farama-Foundation/Gymnasium">Github</a></li>
|
||
|
<li class="toctree-l1"><a class="reference external" href="https://arxiv.org/abs/2407.17032">Paper</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../gymnasium_release_notes/">Gymnasium Release Notes</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../gym_release_notes/">Gym Release Notes</a></li>
|
||
|
<li class="toctree-l1"><a class="reference external" href="https://github.com/Farama-Foundation/Gymnasium/blob/main/docs/README.md">Contribute to the Docs</a></li>
|
||
|
</ul>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</aside>
|
||
|
<div class="main-container">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div class="main">
|
||
|
<div class="content">
|
||
|
<div class="article-container">
|
||
|
<a href="#" class="back-to-top muted-link">
|
||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||
|
<path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
|
||
|
</svg>
|
||
|
<span>Back to top</span>
|
||
|
</a>
|
||
|
<div class="content-icon-container">
|
||
|
<div class="edit-this-page">
|
||
|
<a class="muted-link" href="https://github.com/Farama-Foundation/Gymnasium/edit/main/docs/tutorials/gymnasium_basics/load_quadruped_model.py" title="Edit this page">
|
||
|
<svg aria-hidden="true" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||
|
<path d="M4 20h4l10.5 -10.5a1.5 1.5 0 0 0 -4 -4l-10.5 10.5v4" />
|
||
|
<line x1="13.5" y1="6.5" x2="17.5" y2="10.5" />
|
||
|
</svg>
|
||
|
<span class="visually-hidden">Edit this page</span>
|
||
|
</a>
|
||
|
</div><div class="theme-toggle-container theme-toggle-content">
|
||
|
<button class="theme-toggle" title="Toggle color theme">
|
||
|
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
|
||
|
<svg class="theme-icon-when-auto">
|
||
|
<use href="#svg-sun-half"></use>
|
||
|
</svg>
|
||
|
<svg class="theme-icon-when-dark">
|
||
|
<use href="#svg-moon"></use>
|
||
|
</svg>
|
||
|
<svg class="theme-icon-when-light">
|
||
|
<use href="#svg-sun"></use>
|
||
|
</svg>
|
||
|
</button>
|
||
|
</div>
|
||
|
<label class="toc-overlay-icon toc-content-icon" for="__toc">
|
||
|
<div class="visually-hidden">Toggle table of contents sidebar</div>
|
||
|
<i class="icon"><svg>
|
||
|
<use href="#svg-toc"></use>
|
||
|
</svg></i>
|
||
|
</label>
|
||
|
</div>
|
||
|
<article role="main">
|
||
|
|
||
|
<section class="tex2jax_ignore mathjax_ignore" id="load-custom-quadruped-robot-environments">
|
||
|
<h1>Load custom quadruped robot environments<a class="headerlink" href="#load-custom-quadruped-robot-environments" title="Link to this heading">¶</a></h1>
|
||
|
<p>In this tutorial we will see how to use the <code class="docutils literal notranslate"><span class="pre">MuJoCo/Ant-v5</span></code> framework to create a quadruped walking environment, using a model file (ending in <code class="docutils literal notranslate"><span class="pre">.xml</span></code>) without having to create a new class.</p>
|
||
|
<p>Steps:</p>
|
||
|
<ol class="arabic simple" start="0">
|
||
|
<li><p>Get your <strong>MJCF</strong> (or <strong>URDF</strong>) model file of your robot.</p>
|
||
|
<ul class="simple">
|
||
|
<li><p>Create your own model (see the <a class="reference external" href="https://mujoco.readthedocs.io/en/stable/m22odeling.html">Guide</a>) or,</p></li>
|
||
|
<li><p>Find a ready-made model (in this tutorial, we will use a model from the <a class="reference external" href="https://github.com/google-deepmind/mujoco_menagerie"><strong>MuJoCo Menagerie</strong></a> collection).</p></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li><p>Load the model with the <code class="docutils literal notranslate"><span class="pre">xml_file</span></code> argument.</p></li>
|
||
|
<li><p>Tweak the environment parameters to get the desired behavior.</p>
|
||
|
<ol class="arabic simple">
|
||
|
<li><p>Tweak the environment simulation parameters.</p></li>
|
||
|
<li><p>Tweak the environment termination parameters.</p></li>
|
||
|
<li><p>Tweak the environment reward parameters.</p></li>
|
||
|
<li><p>Tweak the environment observation parameters.</p></li>
|
||
|
</ol>
|
||
|
</li>
|
||
|
<li><p>Train an agent to move your robot.</p></li>
|
||
|
</ol>
|
||
|
<p>The reader is expected to be familiar with the <code class="docutils literal notranslate"><span class="pre">Gymnasium</span></code> API & library, the basics of robotics, and the included <code class="docutils literal notranslate"><span class="pre">Gymnasium/MuJoCo</span></code> environments with the robot model they use. Familiarity with the <strong>MJCF</strong> file model format and the <code class="docutils literal notranslate"><span class="pre">MuJoCo</span></code> simulator is not required but is recommended.</p>
|
||
|
<section id="setup">
|
||
|
<h2>Setup<a class="headerlink" href="#setup" title="Link to this heading">¶</a></h2>
|
||
|
<p>We will need <code class="docutils literal notranslate"><span class="pre">gymnasium>=1.0.0</span></code>.</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>pip<span class="w"> </span>install<span class="w"> </span><span class="s2">"gymnasium>=1.0.0"</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</section>
|
||
|
<section id="step-0-1-download-a-robot-model">
|
||
|
<h2>Step 0.1 - Download a Robot Model<a class="headerlink" href="#step-0-1-download-a-robot-model" title="Link to this heading">¶</a></h2>
|
||
|
<p>In this tutorial we will load the <a class="reference external" href="https://github.com/google-deepmind/mujoco_menagerie/blob/main/unitree_go1/README.md">Unitree Go1</a> robot from the excellent <a class="reference external" href="https://github.com/google-deepmind/mujoco_menagerie">MuJoCo Menagerie</a> robot model collection.
|
||
|
<img alt="Unitree Go1 robot in a flat terrain scene" src="https://github.com/google-deepmind/mujoco_menagerie/blob/main/unitree_go1/go1.png?raw=true" /></p>
|
||
|
<p><code class="docutils literal notranslate"><span class="pre">Go1</span></code> is a quadruped robot, controlling it to move is a significant learning problem, much harder than the <code class="docutils literal notranslate"><span class="pre">Gymnasium/MuJoCo/Ant</span></code> environment.</p>
|
||
|
<p>We can download the whole MuJoCo Menagerie collection (which includes <code class="docutils literal notranslate"><span class="pre">Go1</span></code>),</p>
|
||
|
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>git<span class="w"> </span>clone<span class="w"> </span>https://github.com/google-deepmind/mujoco_menagerie.git
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>You can use any other quadruped robot with this tutorial, just adjust the environment parameter values for your robot.</p>
|
||
|
</section>
|
||
|
<section id="step-1-load-the-model">
|
||
|
<h2>Step 1 - Load the model<a class="headerlink" href="#step-1-load-the-model" title="Link to this heading">¶</a></h2>
|
||
|
<p>To load the model, all we have to do is use the <code class="docutils literal notranslate"><span class="pre">xml_file</span></code> argument with the <code class="docutils literal notranslate"><span class="pre">Ant-v5</span></code> framework.</p>
|
||
|
<div class="highlight-py notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">gymnasium</span>
|
||
|
<span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
|
||
|
<span class="n">env</span> <span class="o">=</span> <span class="n">gymnasium</span><span class="o">.</span><span class="n">make</span><span class="p">(</span><span class="s1">'Ant-v5'</span><span class="p">,</span> <span class="n">xml_file</span><span class="o">=</span><span class="s1">'./mujoco_menagerie/unitree_go1/scene.xml'</span><span class="p">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>Although this is enough to load the model, we will need to tweak some environment parameters to get the desired behavior for our environment, for now we will also explicitly set the simulation, termination, reward and observation arguments, which we will tweak in the next step.</p>
|
||
|
<div class="highlight-py notranslate"><div class="highlight"><pre><span></span><span class="n">env</span> <span class="o">=</span> <span class="n">gymnasium</span><span class="o">.</span><span class="n">make</span><span class="p">(</span>
|
||
|
<span class="s1">'Ant-v5'</span><span class="p">,</span>
|
||
|
<span class="n">xml_file</span><span class="o">=</span><span class="s1">'./mujoco_menagerie/unitree_go1/scene.xml'</span><span class="p">,</span>
|
||
|
<span class="n">forward_reward_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">ctrl_cost_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">contact_cost_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">healthy_reward</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">main_body</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">healthy_z_range</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">),</span>
|
||
|
<span class="n">include_cfrc_ext_in_observation</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
|
||
|
<span class="n">exclude_current_positions_from_observation</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
|
||
|
<span class="n">reset_noise_scale</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">frame_skip</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">max_episode_steps</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span>
|
||
|
<span class="p">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</section>
|
||
|
<section id="step-2-tweaking-the-environment-parameters">
|
||
|
<h2>Step 2 - Tweaking the Environment Parameters<a class="headerlink" href="#step-2-tweaking-the-environment-parameters" title="Link to this heading">¶</a></h2>
|
||
|
<p>Tweaking the environment parameters is essential to get the desired behavior for learning.
|
||
|
In the following subsections, the reader is encouraged to consult the <a class="reference external" href="https://gymnasium.farama.org/main/environments/mujoco/ant/#arguments">documentation of the arguments</a> for more detailed information.</p>
|
||
|
</section>
|
||
|
<section id="step-2-1-tweaking-the-environment-simulation-parameters">
|
||
|
<h2>Step 2.1 - Tweaking the Environment Simulation Parameters<a class="headerlink" href="#step-2-1-tweaking-the-environment-simulation-parameters" title="Link to this heading">¶</a></h2>
|
||
|
<p>The arguments of interest are <code class="docutils literal notranslate"><span class="pre">frame_skip</span></code>, <code class="docutils literal notranslate"><span class="pre">reset_noise_scale</span></code> and <code class="docutils literal notranslate"><span class="pre">max_episode_steps</span></code>.</p>
|
||
|
<p>We want to tweak the <code class="docutils literal notranslate"><span class="pre">frame_skip</span></code> parameter to get <code class="docutils literal notranslate"><span class="pre">dt</span></code> to an acceptable value (typical values are <code class="docutils literal notranslate"><span class="pre">dt</span></code> <span class="math notranslate nohighlight">\(\in [0.01, 0.1]\)</span> seconds),</p>
|
||
|
<p>Reminder: <span class="math notranslate nohighlight">\(dt = frame\_skip \times model.opt.timestep\)</span>, where <code class="docutils literal notranslate"><span class="pre">model.opt.timestep</span></code> is the integrator time step selected in the MJCF model file.</p>
|
||
|
<p>The <code class="docutils literal notranslate"><span class="pre">Go1</span></code> model we are using has an integrator timestep of <code class="docutils literal notranslate"><span class="pre">0.002</span></code>, so by selecting <code class="docutils literal notranslate"><span class="pre">frame_skip=25</span></code> we can set the value of <code class="docutils literal notranslate"><span class="pre">dt</span></code> to <code class="docutils literal notranslate"><span class="pre">0.05s</span></code>.</p>
|
||
|
<p>To avoid overfitting the policy, <code class="docutils literal notranslate"><span class="pre">reset_noise_scale</span></code> should be set to a value appropriate to the size of the robot, we want the value to be as large as possible without the initial distribution of states being invalid (<code class="docutils literal notranslate"><span class="pre">Terminal</span></code> regardless of control actions), for <code class="docutils literal notranslate"><span class="pre">Go1</span></code> we choose a value of <code class="docutils literal notranslate"><span class="pre">0.1</span></code>.</p>
|
||
|
<p>And <code class="docutils literal notranslate"><span class="pre">max_episode_steps</span></code> determines the number of steps per episode before <code class="docutils literal notranslate"><span class="pre">truncation</span></code>, here we set it to 1000 to be consistent with the based <code class="docutils literal notranslate"><span class="pre">Gymnasium/MuJoCo</span></code> environments, but if you need something higher you can set it so.</p>
|
||
|
<div class="highlight-py notranslate"><div class="highlight"><pre><span></span><span class="n">env</span> <span class="o">=</span> <span class="n">gymnasium</span><span class="o">.</span><span class="n">make</span><span class="p">(</span>
|
||
|
<span class="s1">'Ant-v5'</span><span class="p">,</span>
|
||
|
<span class="n">xml_file</span><span class="o">=</span><span class="s1">'./mujoco_menagerie/unitree_go1/scene.xml'</span><span class="p">,</span>
|
||
|
<span class="n">forward_reward_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">ctrl_cost_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">contact_cost_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">healthy_reward</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">main_body</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">healthy_z_range</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">),</span>
|
||
|
<span class="n">include_cfrc_ext_in_observation</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
|
||
|
<span class="n">exclude_current_positions_from_observation</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
|
||
|
<span class="n">reset_noise_scale</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="c1"># set to avoid policy overfitting</span>
|
||
|
<span class="n">frame_skip</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span> <span class="c1"># set dt=0.05</span>
|
||
|
<span class="n">max_episode_steps</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="c1"># kept at 1000</span>
|
||
|
<span class="p">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</section>
|
||
|
<section id="step-2-2-tweaking-the-environment-termination-parameters">
|
||
|
<h2>Step 2.2 - Tweaking the Environment Termination Parameters<a class="headerlink" href="#step-2-2-tweaking-the-environment-termination-parameters" title="Link to this heading">¶</a></h2>
|
||
|
<p>Termination is important for robot environments to avoid sampling “useless” time steps.</p>
|
||
|
<p>The arguments of interest are <code class="docutils literal notranslate"><span class="pre">terminate_when_unhealthy</span></code> and <code class="docutils literal notranslate"><span class="pre">healthy_z_range</span></code>.</p>
|
||
|
<p>We want to set <code class="docutils literal notranslate"><span class="pre">healthy_z_range</span></code> to terminate the environment when the robot falls over, or jumps really high, here we have to choose a value that is logical for the height of the robot, for <code class="docutils literal notranslate"><span class="pre">Go1</span></code> we choose <code class="docutils literal notranslate"><span class="pre">(0.195,</span> <span class="pre">0.75)</span></code>.
|
||
|
Note: <code class="docutils literal notranslate"><span class="pre">healthy_z_range</span></code> checks the absolute value of the height of the robot, so if your scene contains different levels of elevation it should be set to <code class="docutils literal notranslate"><span class="pre">(-np.inf,</span> <span class="pre">np.inf)</span></code></p>
|
||
|
<p>We could also set <code class="docutils literal notranslate"><span class="pre">terminate_when_unhealthy=False</span></code> to disable termination altogether, which is not desirable in the case of <code class="docutils literal notranslate"><span class="pre">Go1</span></code>.</p>
|
||
|
<div class="highlight-py notranslate"><div class="highlight"><pre><span></span><span class="n">env</span> <span class="o">=</span> <span class="n">gymnasium</span><span class="o">.</span><span class="n">make</span><span class="p">(</span>
|
||
|
<span class="s1">'Ant-v5'</span><span class="p">,</span>
|
||
|
<span class="n">xml_file</span><span class="o">=</span><span class="s1">'./mujoco_menagerie/unitree_go1/scene.xml'</span><span class="p">,</span>
|
||
|
<span class="n">forward_reward_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">ctrl_cost_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">contact_cost_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">healthy_reward</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
|
||
|
<span class="n">main_body</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">healthy_z_range</span><span class="o">=</span><span class="p">(</span><span class="mf">0.195</span><span class="p">,</span> <span class="mf">0.75</span><span class="p">),</span> <span class="c1"># set to avoid sampling steps where the robot has fallen or jumped too high</span>
|
||
|
<span class="n">include_cfrc_ext_in_observation</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
|
||
|
<span class="n">exclude_current_positions_from_observation</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
|
||
|
<span class="n">reset_noise_scale</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span>
|
||
|
<span class="n">frame_skip</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span>
|
||
|
<span class="n">max_episode_steps</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span>
|
||
|
<span class="p">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>Note: If you need a different termination condition, you can write your own <code class="docutils literal notranslate"><span class="pre">TerminationWrapper</span></code> (see the <a class="reference external" href="https://gymnasium.farama.org/main/api/wrappers/">documentation</a>).</p>
|
||
|
</section>
|
||
|
<section id="step-2-3-tweaking-the-environment-reward-parameters">
|
||
|
<h2>Step 2.3 - Tweaking the Environment Reward Parameters<a class="headerlink" href="#step-2-3-tweaking-the-environment-reward-parameters" title="Link to this heading">¶</a></h2>
|
||
|
<p>The arguments of interest are <code class="docutils literal notranslate"><span class="pre">forward_reward_weight</span></code>, <code class="docutils literal notranslate"><span class="pre">ctrl_cost_weight</span></code>, <code class="docutils literal notranslate"><span class="pre">contact_cost_weight</span></code>, <code class="docutils literal notranslate"><span class="pre">healthy_reward</span></code>, and <code class="docutils literal notranslate"><span class="pre">main_body</span></code>.</p>
|
||
|
<p>For the arguments <code class="docutils literal notranslate"><span class="pre">forward_reward_weight</span></code>, <code class="docutils literal notranslate"><span class="pre">ctrl_cost_weight</span></code>, <code class="docutils literal notranslate"><span class="pre">contact_cost_weight</span></code> and <code class="docutils literal notranslate"><span class="pre">healthy_reward</span></code> we have to pick values that make sense for our robot, you can use the default <code class="docutils literal notranslate"><span class="pre">MuJoCo/Ant</span></code> parameters for references and tweak them if a change is needed for your environment. In the case of <code class="docutils literal notranslate"><span class="pre">Go1</span></code> we only change the <code class="docutils literal notranslate"><span class="pre">ctrl_cost_weight</span></code> since it has a higher actuator force range.</p>
|
||
|
<p>For the argument <code class="docutils literal notranslate"><span class="pre">main_body</span></code> we have to choose which body part is the main body (usually called something like “torso” or “trunk” in the model file) for the calculation of the <code class="docutils literal notranslate"><span class="pre">forward_reward</span></code>, in the case of <code class="docutils literal notranslate"><span class="pre">Go1</span></code> it is the <code class="docutils literal notranslate"><span class="pre">"trunk"</span></code> (Note: in most cases including this one, it can be left at the default value).</p>
|
||
|
<div class="highlight-py notranslate"><div class="highlight"><pre><span></span><span class="n">env</span> <span class="o">=</span> <span class="n">gymnasium</span><span class="o">.</span><span class="n">make</span><span class="p">(</span>
|
||
|
<span class="s1">'Ant-v5'</span><span class="p">,</span>
|
||
|
<span class="n">xml_file</span><span class="o">=</span><span class="s1">'./mujoco_menagerie/unitree_go1/scene.xml'</span><span class="p">,</span>
|
||
|
<span class="n">forward_reward_weight</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># kept the same as the 'Ant' environment</span>
|
||
|
<span class="n">ctrl_cost_weight</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span> <span class="c1"># changed because of the stronger motors of `Go1`</span>
|
||
|
<span class="n">contact_cost_weight</span><span class="o">=</span><span class="mf">5e-4</span><span class="p">,</span> <span class="c1"># kept the same as the 'Ant' environment</span>
|
||
|
<span class="n">healthy_reward</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># kept the same as the 'Ant' environment</span>
|
||
|
<span class="n">main_body</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># represents the "trunk" of the `Go1` robot</span>
|
||
|
<span class="n">healthy_z_range</span><span class="o">=</span><span class="p">(</span><span class="mf">0.195</span><span class="p">,</span> <span class="mf">0.75</span><span class="p">),</span>
|
||
|
<span class="n">include_cfrc_ext_in_observation</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
|
||
|
<span class="n">exclude_current_positions_from_observation</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
|
||
|
<span class="n">reset_noise_scale</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span>
|
||
|
<span class="n">frame_skip</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span>
|
||
|
<span class="n">max_episode_steps</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span>
|
||
|
<span class="p">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>Note: If you need a different reward function, you can write your own <code class="docutils literal notranslate"><span class="pre">RewardWrapper</span></code> (see the <a class="reference external" href="https://gymnasium.farama.org/main/api/wrappers/reward_wrappers/">documentation</a>).</p>
|
||
|
</section>
|
||
|
<section id="step-2-4-tweaking-the-environment-observation-parameters">
|
||
|
<h2>Step 2.4 - Tweaking the Environment Observation Parameters<a class="headerlink" href="#step-2-4-tweaking-the-environment-observation-parameters" title="Link to this heading">¶</a></h2>
|
||
|
<p>The arguments of interest are <code class="docutils literal notranslate"><span class="pre">include_cfrc_ext_in_observation</span></code> and <code class="docutils literal notranslate"><span class="pre">exclude_current_positions_from_observation</span></code>.</p>
|
||
|
<p>Here for <code class="docutils literal notranslate"><span class="pre">Go1</span></code> we have no particular reason to change them.</p>
|
||
|
<div class="highlight-py notranslate"><div class="highlight"><pre><span></span><span class="n">env</span> <span class="o">=</span> <span class="n">gymnasium</span><span class="o">.</span><span class="n">make</span><span class="p">(</span>
|
||
|
<span class="s1">'Ant-v5'</span><span class="p">,</span>
|
||
|
<span class="n">xml_file</span><span class="o">=</span><span class="s1">'./mujoco_menagerie/unitree_go1/scene.xml'</span><span class="p">,</span>
|
||
|
<span class="n">forward_reward_weight</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">ctrl_cost_weight</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span>
|
||
|
<span class="n">contact_cost_weight</span><span class="o">=</span><span class="mf">5e-4</span><span class="p">,</span>
|
||
|
<span class="n">healthy_reward</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">main_body</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">healthy_z_range</span><span class="o">=</span><span class="p">(</span><span class="mf">0.195</span><span class="p">,</span> <span class="mf">0.75</span><span class="p">),</span>
|
||
|
<span class="n">include_cfrc_ext_in_observation</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="c1"># kept the game as the 'Ant' environment</span>
|
||
|
<span class="n">exclude_current_positions_from_observation</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="c1"># kept the game as the 'Ant' environment</span>
|
||
|
<span class="n">reset_noise_scale</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span>
|
||
|
<span class="n">frame_skip</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span>
|
||
|
<span class="n">max_episode_steps</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span>
|
||
|
<span class="p">)</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p>Note: If you need additional observation elements (such as additional sensors), you can write your own <code class="docutils literal notranslate"><span class="pre">ObservationWrapper</span></code> (see the <a class="reference external" href="https://gymnasium.farama.org/main/api/wrappers/observation_wrappers/">documentation</a>).</p>
|
||
|
</section>
|
||
|
<section id="step-3-train-your-agent">
|
||
|
<h2>Step 3 - Train your Agent<a class="headerlink" href="#step-3-train-your-agent" title="Link to this heading">¶</a></h2>
|
||
|
<p>Finally, we are done, we can use a RL algorithm to train an agent to walk/run the <code class="docutils literal notranslate"><span class="pre">Go1</span></code> robot.
|
||
|
Note: If you have followed this guide with your own robot model, you may discover during training that some environment parameters were not as desired, feel free to go back to step 2 and change anything as needed.</p>
|
||
|
<div class="highlight-py notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">gymnasium</span>
|
||
|
|
||
|
<span class="n">env</span> <span class="o">=</span> <span class="n">gymnasium</span><span class="o">.</span><span class="n">make</span><span class="p">(</span>
|
||
|
<span class="s1">'Ant-v5'</span><span class="p">,</span>
|
||
|
<span class="n">xml_file</span><span class="o">=</span><span class="s1">'./mujoco_menagerie/unitree_go1/scene.xml'</span><span class="p">,</span>
|
||
|
<span class="n">forward_reward_weight</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">ctrl_cost_weight</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span>
|
||
|
<span class="n">contact_cost_weight</span><span class="o">=</span><span class="mf">5e-4</span><span class="p">,</span>
|
||
|
<span class="n">healthy_reward</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">main_body</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
|
<span class="n">healthy_z_range</span><span class="o">=</span><span class="p">(</span><span class="mf">0.195</span><span class="p">,</span> <span class="mf">0.75</span><span class="p">),</span>
|
||
|
<span class="n">include_cfrc_ext_in_observation</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
|
||
|
<span class="n">exclude_current_positions_from_observation</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
|
||
|
<span class="n">reset_noise_scale</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span>
|
||
|
<span class="n">frame_skip</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span>
|
||
|
<span class="n">max_episode_steps</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span>
|
||
|
<span class="p">)</span>
|
||
|
<span class="o">...</span> <span class="c1"># run your RL algorithm</span>
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
<p><img alt="image" src="https://github.com/Kallinteris-Andreas/Gymnasium-kalli/assets/30759571/bf1797a3-264d-47de-b14c-e3c16072f695" /></p>
|
||
|
<iframe id="odysee-iframe" style="width:100%; aspect-ratio:16 / 9;" src="https://odysee.com/$/embed/@Kallinteris-Andreas:7/video0-step-0-to-step-1000:1?r=6fn5jA9uZQUZXGKVpwtqjz1eyJcS3hj3" allowfullscreen></iframe>
|
||
|
<!--
|
||
|
Which can run up to `4.7 m/s` according to the manufacturer
|
||
|
-->
|
||
|
</section>
|
||
|
<section id="epilogue">
|
||
|
<h2>Epilogue<a class="headerlink" href="#epilogue" title="Link to this heading">¶</a></h2>
|
||
|
<p>You can follow this guide to create most quadruped environments.
|
||
|
To create humanoid/bipedal robots, you can also follow this guide using the <code class="docutils literal notranslate"><span class="pre">Gymnasium/MuJoCo/Humnaoid-v5</span></code> framework.</p>
|
||
|
<p>Author: <a class="reference external" href="https://github.com/Kallinteris-Andreas">@kallinteris-andreas</a></p>
|
||
|
</section>
|
||
|
</section>
|
||
|
|
||
|
</article>
|
||
|
</div>
|
||
|
<footer>
|
||
|
|
||
|
<div class="related-pages">
|
||
|
<a class="next-page" href="../handling_time_limits/">
|
||
|
<div class="page-info">
|
||
|
<div class="context">
|
||
|
<span>Next</span>
|
||
|
</div>
|
||
|
<div class="title">Handling Time Limits</div>
|
||
|
</div>
|
||
|
<svg class="furo-related-icon">
|
||
|
<use href="#svg-arrow-right"></use>
|
||
|
</svg>
|
||
|
</a>
|
||
|
<a class="prev-page" href="../">
|
||
|
<svg class="furo-related-icon">
|
||
|
<use href="#svg-arrow-right"></use>
|
||
|
</svg>
|
||
|
<div class="page-info">
|
||
|
<div class="context">
|
||
|
<span>Previous</span>
|
||
|
</div>
|
||
|
|
||
|
<div class="title">Gymnasium Basics Documentation Links</div>
|
||
|
|
||
|
</div>
|
||
|
</a>
|
||
|
</div>
|
||
|
<div class="bottom-of-page">
|
||
|
<div class="left-details">
|
||
|
<div class="copyright">
|
||
|
Copyright © 2025 Farama Foundation
|
||
|
</div>
|
||
|
<!--
|
||
|
Made with <a href="https://www.sphinx-doc.org/">Sphinx</a> and <a class="muted-link" href="https://pradyunsg.me">@pradyunsg</a>'s
|
||
|
|
||
|
<a href="https://github.com/pradyunsg/furo">Furo</a>
|
||
|
-->
|
||
|
</div>
|
||
|
<div class="right-details">
|
||
|
<div class="icons">
|
||
|
<a class="muted-link" href="https://github.com/Farama-Foundation/Gymnasium/"
|
||
|
aria-label="On GitHub">
|
||
|
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
|
||
|
<path fill-rule="evenodd"
|
||
|
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">
|
||
|
</path>
|
||
|
</svg>
|
||
|
</a>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</footer>
|
||
|
</div>
|
||
|
<aside class="toc-drawer">
|
||
|
|
||
|
|
||
|
<div class="toc-sticky toc-scroll">
|
||
|
<div class="toc-title-container">
|
||
|
<span class="toc-title">
|
||
|
On this page
|
||
|
</span>
|
||
|
</div>
|
||
|
<div class="toc-tree-container">
|
||
|
<div class="toc-tree">
|
||
|
<ul>
|
||
|
<li><a class="reference internal" href="#">Load custom quadruped robot environments</a><ul>
|
||
|
<li><a class="reference internal" href="#setup">Setup</a></li>
|
||
|
<li><a class="reference internal" href="#step-0-1-download-a-robot-model">Step 0.1 - Download a Robot Model</a></li>
|
||
|
<li><a class="reference internal" href="#step-1-load-the-model">Step 1 - Load the model</a></li>
|
||
|
<li><a class="reference internal" href="#step-2-tweaking-the-environment-parameters">Step 2 - Tweaking the Environment Parameters</a></li>
|
||
|
<li><a class="reference internal" href="#step-2-1-tweaking-the-environment-simulation-parameters">Step 2.1 - Tweaking the Environment Simulation Parameters</a></li>
|
||
|
<li><a class="reference internal" href="#step-2-2-tweaking-the-environment-termination-parameters">Step 2.2 - Tweaking the Environment Termination Parameters</a></li>
|
||
|
<li><a class="reference internal" href="#step-2-3-tweaking-the-environment-reward-parameters">Step 2.3 - Tweaking the Environment Reward Parameters</a></li>
|
||
|
<li><a class="reference internal" href="#step-2-4-tweaking-the-environment-observation-parameters">Step 2.4 - Tweaking the Environment Observation Parameters</a></li>
|
||
|
<li><a class="reference internal" href="#step-3-train-your-agent">Step 3 - Train your Agent</a></li>
|
||
|
<li><a class="reference internal" href="#epilogue">Epilogue</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
</ul>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</aside>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<script>
|
||
|
const toggleMenu = () => {
|
||
|
const menuBtn = document.querySelector(".farama-header-menu__btn");
|
||
|
const menuContainer = document.querySelector(".farama-header-menu-container");
|
||
|
if (document.querySelector(".farama-header-menu").classList.contains("active")) {
|
||
|
menuBtn.setAttribute("aria-expanded", "false");
|
||
|
menuContainer.setAttribute("aria-hidden", "true");
|
||
|
} else {
|
||
|
menuBtn.setAttribute("aria-expanded", "true");
|
||
|
menuContainer.setAttribute("aria-hidden", "false");
|
||
|
}
|
||
|
document.querySelector(".farama-header-menu").classList.toggle("active");
|
||
|
}
|
||
|
|
||
|
document.querySelector(".farama-header-menu__btn").addEventListener("click", toggleMenu);
|
||
|
document.getElementById("farama-close-menu").addEventListener("click", toggleMenu);
|
||
|
</script>
|
||
|
|
||
|
|
||
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-6H9C8TWXZ8"></script>
|
||
|
<script>
|
||
|
const enableGtag = () => {
|
||
|
window.dataLayer = window.dataLayer || [];
|
||
|
function gtag(){dataLayer.push(arguments);}
|
||
|
gtag('js', new Date());
|
||
|
gtag('config', 'G-6H9C8TWXZ8');
|
||
|
}
|
||
|
(() => {
|
||
|
if (!localStorage.getItem("acceptedCookieAlert")) {
|
||
|
const boxElem = document.createElement("div");
|
||
|
boxElem.classList.add("cookie-alert");
|
||
|
const containerElem = document.createElement("div");
|
||
|
containerElem.classList.add("cookie-alert__container");
|
||
|
const textElem = document.createElement("p");
|
||
|
textElem.innerHTML = `This page uses <a href="https://analytics.google.com/">
|
||
|
Google Analytics</a> to collect statistics.`;
|
||
|
containerElem.appendChild(textElem);
|
||
|
|
||
|
const declineBtn = Object.assign(document.createElement("button"),
|
||
|
{
|
||
|
innerText: "Deny",
|
||
|
className: "farama-btn cookie-alert__button",
|
||
|
id: "cookie-alert__decline",
|
||
|
}
|
||
|
);
|
||
|
declineBtn.addEventListener("click", () => {
|
||
|
localStorage.setItem("acceptedCookieAlert", false);
|
||
|
boxElem.remove();
|
||
|
});
|
||
|
|
||
|
const acceptBtn = Object.assign(document.createElement("button"),
|
||
|
{
|
||
|
innerText: "Allow",
|
||
|
className: "farama-btn cookie-alert__button",
|
||
|
id: "cookie-alert__accept",
|
||
|
}
|
||
|
);
|
||
|
acceptBtn.addEventListener("click", () => {
|
||
|
localStorage.setItem("acceptedCookieAlert", true);
|
||
|
boxElem.remove();
|
||
|
enableGtag();
|
||
|
});
|
||
|
|
||
|
containerElem.appendChild(declineBtn);
|
||
|
containerElem.appendChild(acceptBtn);
|
||
|
boxElem.appendChild(containerElem);
|
||
|
document.body.appendChild(boxElem);
|
||
|
} else if (localStorage.getItem("acceptedCookieAlert") === "true") {
|
||
|
enableGtag();
|
||
|
}
|
||
|
})()
|
||
|
</script>
|
||
|
|
||
|
<script src="../../../_static/documentation_options.js?v=25d39d6f"></script>
|
||
|
<script src="../../../_static/doctools.js?v=9a2dae69"></script>
|
||
|
<script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
|
<script src="../../../_static/scripts/furo.js?v=7660844c"></script>
|
||
|
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
|
||
|
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||
|
|
||
|
<script>
|
||
|
|
||
|
const createProjectsList = (projects, displayImages) => {
|
||
|
const ulElem = Object.assign(document.createElement('ul'),
|
||
|
{
|
||
|
className:'farama-header-menu-list',
|
||
|
}
|
||
|
)
|
||
|
for (let project of projects) {
|
||
|
const liElem = document.createElement("li");
|
||
|
const aElem = Object.assign(document.createElement("a"),
|
||
|
{
|
||
|
href: project.link
|
||
|
}
|
||
|
);
|
||
|
liElem.appendChild(aElem);
|
||
|
if (displayImages) {
|
||
|
const imgElem = Object.assign(document.createElement("img"),
|
||
|
{
|
||
|
src: project.image ? imagesBasepath + project.image : imagesBasepath + "/farama_black.svg",
|
||
|
alt: `${project.name} logo`,
|
||
|
className: "farama-black-logo-invert"
|
||
|
}
|
||
|
);
|
||
|
aElem.appendChild(imgElem);
|
||
|
}
|
||
|
aElem.appendChild(document.createTextNode(project.name));
|
||
|
ulElem.appendChild(liElem);
|
||
|
}
|
||
|
return ulElem;
|
||
|
}
|
||
|
|
||
|
// Create menu with Farama projects by using the API at farama.org/api/projects.json
|
||
|
const createCORSRequest = (method, url) => {
|
||
|
let xhr = new XMLHttpRequest();
|
||
|
xhr.responseType = 'json';
|
||
|
|
||
|
if ("withCredentials" in xhr) {
|
||
|
xhr.open(method, url, true);
|
||
|
} else if (typeof XDomainRequest != "undefined") {
|
||
|
// IE8 & IE9
|
||
|
xhr = new XDomainRequest();
|
||
|
xhr.open(method, url);
|
||
|
} else {
|
||
|
// CORS not supported.
|
||
|
xhr = null;
|
||
|
}
|
||
|
return xhr;
|
||
|
};
|
||
|
|
||
|
const url = 'https://farama.org/api/projects.json';
|
||
|
const imagesBasepath = "https://farama.org/assets/images"
|
||
|
const method = 'GET';
|
||
|
let xhr = createCORSRequest(method, url);
|
||
|
|
||
|
xhr.onload = () => {
|
||
|
const jsonResponse = xhr.response;
|
||
|
const sections = {
|
||
|
"Core Projects": [],
|
||
|
"Mature Projects": {
|
||
|
"Documentation": [],
|
||
|
"Repositories": [],
|
||
|
},
|
||
|
"Incubating Projects": {
|
||
|
"Documentation": [],
|
||
|
"Repositories": [],
|
||
|
},
|
||
|
"Foundation": [
|
||
|
{
|
||
|
name: "About",
|
||
|
link: "https://farama.org/about"
|
||
|
},
|
||
|
{
|
||
|
name: "Standards",
|
||
|
link: "https://farama.org/project_standards",
|
||
|
},
|
||
|
{
|
||
|
name: "Donate",
|
||
|
link: "https://farama.org/donations"
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
|
||
|
// Categorize projects
|
||
|
Object.keys(jsonResponse).forEach(key => {
|
||
|
projectJson = jsonResponse[key];
|
||
|
if (projectJson.website !== null) {
|
||
|
projectJson.link = projectJson.website;
|
||
|
} else {
|
||
|
projectJson.link = projectJson.github;
|
||
|
}
|
||
|
if (projectJson.type === "core") {
|
||
|
sections["Core Projects"].push(projectJson)
|
||
|
} else if (projectJson.type == "mature") {
|
||
|
if (projectJson.website !== null) {
|
||
|
sections["Mature Projects"]["Documentation"].push(projectJson)
|
||
|
} else {
|
||
|
sections["Mature Projects"]["Repositories"].push(projectJson)
|
||
|
}
|
||
|
} else {
|
||
|
if (projectJson.website !== null) {
|
||
|
sections["Incubating Projects"]["Documentation"].push(projectJson)
|
||
|
} else {
|
||
|
sections["Incubating Projects"]["Repositories"].push(projectJson)
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|
||
|
const menuContainer = document.querySelector(".farama-header-menu__body");
|
||
|
|
||
|
Object.keys(sections).forEach((key, i) => {
|
||
|
const sectionElem = Object.assign(
|
||
|
document.createElement('div'), {
|
||
|
className:'farama-header-menu__section',
|
||
|
}
|
||
|
)
|
||
|
sectionElem.appendChild(Object.assign(document.createElement('span'),
|
||
|
{
|
||
|
className:'farama-header-menu__section-title' ,
|
||
|
innerText: key
|
||
|
}
|
||
|
))
|
||
|
// is not a list
|
||
|
if (sections[key].constructor !== Array) {
|
||
|
const subSections = sections[key];
|
||
|
const subSectionContainerElem = Object.assign(
|
||
|
document.createElement('div'), {
|
||
|
className:'farama-header-menu__subsections-container',
|
||
|
style: 'display: flex'
|
||
|
}
|
||
|
)
|
||
|
Object.keys(subSections).forEach((subKey, i) => {
|
||
|
const subSectionElem = Object.assign(
|
||
|
document.createElement('div'), {
|
||
|
className:'farama-header-menu__subsection',
|
||
|
}
|
||
|
)
|
||
|
subSectionElem.appendChild(Object.assign(document.createElement('span'),
|
||
|
{
|
||
|
className:'farama-header-menu__subsection-title' ,
|
||
|
innerText: subKey
|
||
|
}
|
||
|
))
|
||
|
const ulElem = createProjectsList(subSections[subKey], key !== 'Foundation');
|
||
|
subSectionElem.appendChild(ulElem);
|
||
|
subSectionContainerElem.appendChild(subSectionElem);
|
||
|
})
|
||
|
sectionElem.appendChild(subSectionContainerElem);
|
||
|
} else {
|
||
|
const projects = sections[key];
|
||
|
const ulElem = createProjectsList(projects, true);
|
||
|
sectionElem.appendChild(ulElem);
|
||
|
}
|
||
|
menuContainer.appendChild(sectionElem)
|
||
|
});
|
||
|
}
|
||
|
|
||
|
xhr.onerror = function() {
|
||
|
console.error("Unable to load projects");
|
||
|
};
|
||
|
|
||
|
xhr.send();
|
||
|
</script>
|
||
|
|
||
|
|
||
|
<script>
|
||
|
const versioningConfig = {
|
||
|
githubUser: 'Farama-Foundation',
|
||
|
githubRepo: 'Gymnasium',
|
||
|
};
|
||
|
fetch('/main/_static/versioning/versioning_menu.html').then(response => {
|
||
|
if (response.status === 200) {
|
||
|
response.text().then(text => {
|
||
|
const container = document.createElement("div");
|
||
|
container.innerHTML = text;
|
||
|
document.querySelector("body").appendChild(container);
|
||
|
// innerHtml doenst evaluate scripts, we need to add them dynamically
|
||
|
Array.from(container.querySelectorAll("script")).forEach(oldScript => {
|
||
|
const newScript = document.createElement("script");
|
||
|
Array.from(oldScript.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
|
||
|
newScript.appendChild(document.createTextNode(oldScript.innerHTML));
|
||
|
oldScript.parentNode.replaceChild(newScript, oldScript);
|
||
|
});
|
||
|
});
|
||
|
} else {
|
||
|
console.warn("Unable to load versioning menu", response);
|
||
|
}
|
||
|
});
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|