forked from lupinjia/genesis_lr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9179c2
Showing
32 changed files
with
4,640 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# These are some examples of commonly ignored file patterns. | ||
# You should customize this list as applicable to your project. | ||
# Learn more about .gitignore: | ||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore | ||
|
||
# Node artifact files | ||
node_modules/ | ||
dist/ | ||
|
||
# Compiled Java class files | ||
*.class | ||
|
||
# Compiled Python bytecode | ||
*.py[cod] | ||
|
||
# Log files | ||
*.log | ||
|
||
# Package files | ||
*.jar | ||
|
||
# Maven | ||
target/ | ||
dist/ | ||
|
||
# JetBrains IDE | ||
.idea/ | ||
|
||
# Unit test reports | ||
TEST*.xml | ||
|
||
# Generated by MacOS | ||
.DS_Store | ||
|
||
# Generated by Windows | ||
Thumbs.db | ||
|
||
# Applications | ||
*.app | ||
*.exe | ||
*.war | ||
|
||
# Large media files | ||
*.mp4 | ||
*.tiff | ||
*.avi | ||
*.flv | ||
*.mov | ||
*.wmv | ||
|
||
# VS Code | ||
.vscode | ||
# logs | ||
logs | ||
runs | ||
|
||
# other | ||
*.egg-info | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
BSD 3-Clause License | ||
Copyright (c) 2024 Yasen Jia([email protected], https://github.com/lupinjia) | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Legged Robotics in Genesis | ||
|
||
A [legged_gym](https://github.com/leggedrobotics/legged_gym) based framework for training legged robots in [genesis](https://github.com/Genesis-Embodied-AI/Genesis/tree/main) | ||
|
||
|
||
## Usage | ||
|
||
1. Create a new python virtual env with python>=3.9 | ||
2. Install [PyTorch](https://pytorch.org/) | ||
3. Install Genesis following the instructions in the [Genesis repo](https://github.com/Genesis-Embodied-AI/Genesis) | ||
4. Install rsl_rl and tensorboard | ||
```bash | ||
# Install rsl_rl. | ||
git clone https://github.com/leggedrobotics/rsl_rl | ||
cd rsl_rl && git checkout v1.0.2 && pip install -e . | ||
|
||
# Install tensorboard. | ||
pip install tensorboard | ||
``` | ||
5. Install genesis_lr | ||
```bash | ||
git clone https://github.com/lupinjia/genesis_lr | ||
cd genesis_lr | ||
pip install -e . | ||
``` | ||
|
||
## Features | ||
|
||
- **Totally based on [legged_gym](https://github.com/leggedrobotics/legged_gym)** | ||
|
||
It's easy to use for those who are familiar with legged_gym and rsl_rl | ||
|
||
- **Faster and Smaller** | ||
|
||
For a go2 walking on the plane task with 4096 envs, the training speed is approximately **1.3x** compared to [Isaac Gym](https://developer.nvidia.com/isaac-gym). | ||
|
||
- Training speed in genesis: | ||
 | ||
|
||
- Training speed in isaac gym: | ||
 | ||
|
||
While the graphics memory usage is roughly **1/2** compared to IsaacGym. | ||
|
||
- Graphics memory usage in genesis: | ||
 | ||
|
||
- Graphics memory usage in isaac gym: | ||
 | ||
|
||
With this smaller memory usage, it's possible to run more parallel environments, which can further improve the training speed. | ||
|
||
## Acknowledgements | ||
|
||
- [Genesis](https://github.com/Genesis-Embodied-AI/Genesis/tree/main) | ||
- [Genesis-backflip](https://github.com/ziyanx02/Genesis-backflip) | ||
- [legged_gym](https://github.com/leggedrobotics/legged_gym) | ||
- [rsl_rl](https://github.com/leggedrobotics/rsl_rl) | ||
|
||
## TODO | ||
|
||
- [] Add Heightfield support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
|
||
LEGGED_GYM_ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
LEGGED_GYM_ENVS_DIR = os.path.join(LEGGED_GYM_ROOT_DIR, 'legged_gym', 'envs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# Copyright (c) 2021 ETH Zurich, Nikita Rudin | ||
|
||
from legged_gym import LEGGED_GYM_ROOT_DIR, LEGGED_GYM_ENVS_DIR | ||
from .base.legged_robot import LeggedRobot | ||
from legged_gym.envs.go2.go2_config import GO2RoughCfg, GO2RoughCfgPPO | ||
import os | ||
|
||
from legged_gym.utils.task_registry import task_registry | ||
|
||
task_registry.register( "go2", LeggedRobot, GO2RoughCfg(), GO2RoughCfgPPO()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# Copyright (c) 2021 ETH Zurich, Nikita Rudin | ||
|
||
import inspect | ||
|
||
class BaseConfig: | ||
def __init__(self) -> None: | ||
""" Initializes all member classes recursively. Ignores all namse starting with '__' (buit-in methods).""" | ||
self.init_member_classes(self) | ||
|
||
@staticmethod | ||
def init_member_classes(obj): | ||
# iterate over all attributes names | ||
for key in dir(obj): | ||
# disregard builtin attributes | ||
# if key.startswith("__"): | ||
if key=="__class__": | ||
continue | ||
# get the corresponding attribute object | ||
var = getattr(obj, key) | ||
# check if it the attribute is a class | ||
if inspect.isclass(var): | ||
# instantate the class | ||
i_var = var() | ||
# set the attribute to the instance instead of the type | ||
setattr(obj, key, i_var) | ||
# recursively init members of the attribute | ||
BaseConfig.init_member_classes(i_var) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# Copyright (c) 2021 ETH Zurich, Nikita Rudin | ||
|
||
import sys | ||
import numpy as np | ||
import torch | ||
import time | ||
import genesis as gs | ||
|
||
# Base class for RL tasks | ||
class BaseTask(): | ||
|
||
def __init__(self, cfg, sim_device, headless): | ||
|
||
self.render_fps = 50 | ||
self.last_frame_time = 0 | ||
|
||
if not torch.cuda.is_available(): | ||
self.device = torch.device('cpu') | ||
else: | ||
assert sim_device in ["cpu", "cuda"] | ||
self.device = torch.device(sim_device) | ||
self.headless = headless | ||
|
||
self.num_envs = 1 if cfg.env.num_envs == 0 else cfg.env.num_envs | ||
self.num_build_envs = self.num_envs | ||
self.num_obs = cfg.env.num_observations | ||
self.num_privileged_obs = cfg.env.num_privileged_obs | ||
self.num_actions = cfg.env.num_actions | ||
|
||
# allocate buffers | ||
self.obs_buf = torch.zeros(self.num_envs, self.num_obs, device=self.device, dtype=gs.tc_float) | ||
self.rew_buf = torch.zeros(self.num_envs, device=self.device, dtype=gs.tc_float) | ||
self.reset_buf = torch.ones(self.num_envs, device=self.device, dtype=gs.tc_int) | ||
self.episode_length_buf = torch.zeros(self.num_envs, device=self.device, dtype=gs.tc_int) | ||
self.time_out_buf = torch.zeros(self.num_envs, device=self.device, dtype=gs.tc_int) | ||
if self.num_privileged_obs is not None: | ||
self.privileged_obs_buf = torch.zeros(self.num_envs, self.num_privileged_obs, device=self.device, dtype=gs.tc_float) | ||
else: | ||
self.privileged_obs_buf = None | ||
|
||
self.extras = {} | ||
|
||
self.create_sim() | ||
|
||
def get_observations(self): | ||
return self.obs_buf | ||
|
||
def get_privileged_observations(self): | ||
return self.privileged_obs_buf | ||
|
||
def reset_idx(self, env_ids): | ||
"""Reset selected robots""" | ||
raise NotImplementedError | ||
|
||
def reset(self): | ||
""" Reset all robots""" | ||
self.reset_idx(torch.arange(self.num_envs, device=self.device)) | ||
obs, privileged_obs, _, _, _ = self.step(torch.zeros(self.num_envs, self.num_actions, device=self.device, requires_grad=False)) | ||
return obs, privileged_obs | ||
|
||
def step(self, actions): | ||
raise NotImplementedError |
Oops, something went wrong.