Skip to content

Commit

Permalink
Merge branch 'master' into four_ages_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
henriTUD committed May 24, 2024
2 parents edb2744 + 5fd903c commit c2677fd
Show file tree
Hide file tree
Showing 97 changed files with 1,027 additions and 53 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ cd loco-mujoco
pip install -e .
```

> [!NOTE]
> We fixed the version of MuJoCo to 2.3.7 during installation since we found that there are slight
> differences in the simulation, which made testing very difficult. However, in practice, you can
> use any newer version of MuJoCo! Just install it after installing LocoMuJoCo.
### Download the Datasets
After installing LocoMuJoCo, new commands for downloading the datasets will be setup for you.
You have the choice of downloading all datasets available or only the ones you need.
Expand Down
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@

import os
import sys

sys.path.insert(0, os.path.abspath(".."))


project = 'LocoMuJoCo'
copyright = '2024, Firas Al-Hafez'
author = 'Firas Al-Hafez'
release = 'v0.2.2'
release = 'v0.3.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc', "m2r2"]
extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc', "m2r2", 'sphinx.ext.napoleon']

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
add_module_names = False
autodoc_member_order = 'groupwise'
source_suffix = [".rst", ".md"]

napoleon_google_docstring = True

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
Expand Down
13 changes: 13 additions & 0 deletions docs/source/humanoids/unitreeg1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Unitree G1
=======================================================

.. image:: https://github.com/robfiras/loco-mujoco/assets/69359729/be7c3b29-03db-49c2-8e27-527562218f74
:width: 49%
.. image:: https://github.com/robfiras/loco-mujoco/assets/69359729/23cf5988-7326-453e-af24-0f0adc255c9c
:width: 49%

.. automodule:: loco_mujoco.environments.humanoids.unitreeG1
:members:
:undoc-members:
:private-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/loco_mujoco.environments.humanoids.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Here you find an overview of the API of all Humanoid environments.
./humanoids/talos.rst
./humanoids/atlas.rst
./humanoids/unitreeh1.rst
./humanoids/unitreeg1.rst
./humanoids/torque_humanoid.rst
./humanoids/muscle_humanoid.rst
./humanoids/base_humanoids.rst
4 changes: 4 additions & 0 deletions docs/source/loco_mujoco.installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ or you do an editable installation by cloning this repository and then running:
cd loco-mujoco
pip install -e .
.. note::
We fixed the version of MuJoCo to 2.3.7 during installation since we found that there are slight
differences in the simulation, which made testing very difficult. However, in practice, you can
use any newer version of MuJoCo! Just install it after installing LocoMuJoCo.

Download the Datasets
---------------------
Expand Down
32 changes: 22 additions & 10 deletions docs/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
import loco_mujoco
from loco_mujoco.environments import HumanoidTorque, HumanoidMuscle, UnitreeA1
from loco_mujoco.environments import HumanoidTorque, HumanoidMuscle, UnitreeA1, UnitreeG1
from mushroom_rl.utils.mujoco import *


Expand Down Expand Up @@ -136,7 +136,10 @@ def get_action_space_table_docs(env, use_muscles=False):
else:
motors_to_remove = []
except :
action_spec = env._get_action_specification(use_muscles)
if type(env) == UnitreeG1:
action_spec = env._get_action_specification()
else:
action_spec = env._get_action_specification(use_muscles)
_, motors_to_remove, _, _ = env._get_xml_modifications()

header = ["Index", "Name in XML", "Control Min", "Control Max", "Disabled"]
Expand All @@ -160,14 +163,14 @@ def get_action_space_table_docs(env, use_muscles=False):
if __name__ == "__main__":

# # Talos
env = loco_mujoco.LocoEnv.make("Talos", disable_arms=False, disable_back=False)
additional_info = [["Mass of the Weight", "0.0", "inf", "Only Enabled for Carry Task", "1", "Mass [kg]"],
["3D linear Forces between Right Foot and Floor", "0.0", "inf", "True", "3", "Force [N]"],
["3D linear Forces between Left Foot and Floor", "0.0", "inf", "True", "3", "Force [N]"]]
print(get_obs_space_table_docs(env, additional_info)[0],
"\nNumber of obs that are on by default: ", get_obs_space_table_docs(env, additional_info)[1], "\n")
print(get_action_space_table_docs(env)[0],
"\nNumber of actions that are on by default: ", get_action_space_table_docs(env)[1])
# env = loco_mujoco.LocoEnv.make("Talos", disable_arms=False, disable_back=False)
# additional_info = [["Mass of the Weight", "0.0", "inf", "Only Enabled for Carry Task", "1", "Mass [kg]"],
# ["3D linear Forces between Right Foot and Floor", "0.0", "inf", "True", "3", "Force [N]"],
# ["3D linear Forces between Left Foot and Floor", "0.0", "inf", "True", "3", "Force [N]"]]
# print(get_obs_space_table_docs(env, additional_info)[0],
# "\nNumber of obs that are on by default: ", get_obs_space_table_docs(env, additional_info)[1], "\n")
# print(get_action_space_table_docs(env)[0],
# "\nNumber of actions that are on by default: ", get_action_space_table_docs(env)[1])

# # Atlas
# env = loco_mujoco.LocoEnv.make("Atlas", disable_arms=False, disable_back=False)
Expand All @@ -191,6 +194,15 @@ def get_action_space_table_docs(env, use_muscles=False):
# print(get_action_space_table_docs(env)[0],
# "\nNumber of actions that are on by default: ", get_action_space_table_docs(env)[1])

# UnitreeG1
env = loco_mujoco.LocoEnv.make("UnitreeG1", disable_arms=False, disable_back=False)
additional_info = [["3D linear Forces between Right Foot and Floor", "0.0", "inf", "True", "3", "Force [N]"],
["3D linear Forces between Left Foot and Floor", "0.0", "inf", "True", "3", "Force [N]"]]
print(get_obs_space_table_docs(env, additional_info)[0],
"\nNumber of obs that are on by default: ", get_obs_space_table_docs(env, additional_info)[1], "\n")
print(get_action_space_table_docs(env)[0],
"\nNumber of actions that are on by default: ", get_action_space_table_docs(env)[1])

# Torque Humanoid
# env = loco_mujoco.LocoEnv.make("HumanoidTorque", disable_back=False, disable_arms=False)
# additional_info = [["3D linear Forces between Back Right Foot and Floor", "0.0", "inf", "True", "3", "Force [N]"],
Expand Down
19 changes: 19 additions & 0 deletions examples/imitation_learning/confs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ UnitreeH1:
use_noisy_targets: False
last_policy_activation: "identity"

UnitreeG1:
algorithm: "VAIL"
algorithm_config:
std_0: 0.5
info_constraint: 0.1
lr_beta: 0.00001
z_dim: 128
disc_only_states: True
disc_use_next_states: False
train_disc_n_th_epoch: 3
disc_batch_size: 2048
learning_rate_critic: 1.0e-4
learning_rate_disc: 5.0e-5
policy_entr_coef: 1.0e-3
max_kl: 5.0e-3
n_epochs_cg: 25
use_noisy_targets: False
last_policy_activation: "identity"

UnitreeA1.simple:
algorithm: "VAIL"
algorithm_config:
Expand Down
1 change: 1 addition & 0 deletions examples/imitation_learning/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
env_ids = ["Atlas.walk", "Atlas.carry",
"Talos.walk", "Talos.carry",
"UnitreeH1.walk", "UnitreeH1.run", "UnitreeH1.carry",
"UnitreeG1.walk", "UnitreeG1.run",
"HumanoidTorque.walk", "HumanoidTorque.run",
"HumanoidMuscle.walk", "HumanoidMuscle.run",
"UnitreeA1.simple", "UnitreeA1.hard"]
Expand Down
3 changes: 2 additions & 1 deletion examples/replay_datasets/record_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ def experiment(seed=0):
envs = LocoEnv.get_all_task_names()

for env in envs:

if "real" in env:
replay_params = dict(n_episodes=15, n_steps_per_episode=250, record=True) if "Unitree.hard" in env or \
".all" in env or ".carry" in env \
else dict(n_episodes=3, n_steps_per_episode=500, record=True)

if ("Humanoid" in env or "Atlas.walk" in env) and not "carry" in env:
if ("Humanoid" in env or "Atlas.walk" in env or "UnitreeG1" in env) and not "carry" in env:
env_params = dict(disable_arms=False)
else:
env_params = dict()
Expand Down
16 changes: 16 additions & 0 deletions examples/replay_datasets/replay_Unitree_G1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np

from loco_mujoco import LocoEnv


def experiment(seed=0):

np.random.seed(seed)

mdp = LocoEnv.make("UnitreeG1.run")

mdp.play_trajectory_from_velocity(n_episodes=3, n_steps_per_episode=500)


if __name__ == '__main__':
experiment()
25 changes: 25 additions & 0 deletions examples/simple_mushroom_env/example_unitree_g1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
from loco_mujoco import LocoEnv

# create the environment and task
env = LocoEnv.make("UnitreeG1.walk")

# get the dataset for the chosen environment and task
expert_data = env.create_dataset()

action_dim = env.info.action_space.shape[0]

env.reset()
env.render()
absorbing = False
i = 0

while True:
if i == 1000 or absorbing:
env.reset()
i = 0
action = np.random.randn(action_dim)
nstate, reward, absorbing, info = env.step(action)

env.render()
i += 1
2 changes: 1 addition & 1 deletion loco_mujoco/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.2.2'
__version__ = '0.3.0'

try:

Expand Down
Binary file not shown.
Binary file not shown.
8 changes: 5 additions & 3 deletions loco_mujoco/environments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ The status of a dataset can be seen down below. ✅ means it is already availabl
| ![out9](https://github.com/robfiras/loco-mujoco/assets/69359729/2c7aeb58-65a6-427c-8b12-197c96410cd8) | HumanoidMuscle4Ages.walk.2 </br> HumanoidMuscle4Ages.run.2 | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶 | Task of a (~5-6 year old) **Muscle** Humanoid Walking or Running Straight. |
| ![out9](https://github.com/robfiras/loco-mujoco/assets/69359729/600a917f-c784-4b5e-ac99-9472711de843) | HumanoidMuscle4Ages.walk.1 </br> HumanoidMuscle4Ages.run.1 | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶 | Task of a (~2 year old) **Muscle** Humanoid Walking or Running Straight. |
| ![out39](https://github.com/robfiras/loco-mujoco/assets/69359729/cf32520f-5a2e-401a-9f2e-b8033ef7109c) | HumanoidTorque.walk </br> HumanoidTorque.run </br> HumanoidTorque4Ages.walk.4 </br> HumanoidTorque.run </br> HumanoidTorque4Ages.run.4 | real: ✅ <br /> perfect: ✅ <br /> preference: 🔶| Task of an adult **Torque** Humanoid Walking or Running Straight. |
| ![out3](https://github.com/robfiras/loco-mujoco/assets/69359729/352f3594-8903-4eaf-a223-f751b590f4ec) | HumanoidTorque4Ages.walk.3 </br> HumanoidTorque4Ages.run.3 | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶 | Task of a (~12 year old) **Torque** Humanoid Walking or Running Straight. |
| ![out5](https://github.com/robfiras/loco-mujoco/assets/69359729/06c83af9-3c45-43a1-8173-aa1d8771fe4c) | HumanoidTorque4Ages.walk.2 </br> HumanoidTorque4Ages.run.2 | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶 | Task of a (~5-6 year old) **Torque** Humanoid Walking or Running Straight. |
| ![out3](https://github.com/robfiras/loco-mujoco/assets/69359729/5ec93baa-bed8-4d9f-b983-3bc12264b9b6) | HumanoidTorque4Ages.walk.1 </br> HumanoidTorque4Ages.run.1 | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶 | Task of a (~2 year old) **Torque** Humanoid Walking or Running Straight. |
| ![out3](https://github.com/robfiras/loco-mujoco/assets/69359729/352f3594-8903-4eaf-a223-f751b590f4ec) | HumanoidTorque4Ages.walk.3 </br> HumanoidTorque4Ages.run.3 | real: ✅ <br /> perfect: <br /> preference: 🔶 | Task of a (~12 year old) **Torque** Humanoid Walking or Running Straight. |
| ![out5](https://github.com/robfiras/loco-mujoco/assets/69359729/06c83af9-3c45-43a1-8173-aa1d8771fe4c) | HumanoidTorque4Ages.walk.2 </br> HumanoidTorque4Ages.run.2 | real: ✅ <br /> perfect: <br /> preference: 🔶 | Task of a (~5-6 year old) **Torque** Humanoid Walking or Running Straight. |
| ![out3](https://github.com/robfiras/loco-mujoco/assets/69359729/5ec93baa-bed8-4d9f-b983-3bc12264b9b6) | HumanoidTorque4Ages.walk.1 </br> HumanoidTorque4Ages.run.1 | real: ✅ <br /> perfect: <br /> preference: 🔶 | Task of a (~2 year old) **Torque** Humanoid Walking or Running Straight. |
| ![out8](https://github.com/robfiras/loco-mujoco/assets/69359729/fed0315c-921e-4b2e-a9c2-54b85198ef65) | UnitreeH1.walk | real: ✅ <br /> perfect: ✅ <br /> preference: 🔶| UnitreeH1 Straight Walking Task. |
| ![out9](https://github.com/robfiras/loco-mujoco/assets/69359729/ab0dec59-fc24-4763-8ff6-38d58ac3b3de) | UnitreeH1.run | real: ✅ <br /> perfect: ✅ <br /> preference: 🔶| UnitreeH1 Straight Running Task. |
| ![out3](https://github.com/robfiras/loco-mujoco/assets/69359729/851ff3c0-d05f-4de1-a00b-7b3204056e2f) | UnitreeH1.carry | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶| UnitreeH1 Carry Task. |
| ![out8](https://github.com/robfiras/loco-mujoco/assets/69359729/e9a33e94-65e4-48f5-8d7a-3d103c4ec7f5) | UnitreeG1.walk | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶| UnitreeG1 Straight Walking Task. |
| ![out9](https://github.com/robfiras/loco-mujoco/assets/69359729/57292ef1-c152-4cd3-b7c1-d9a1e0633481) | UnitreeG1.run | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶| UnitreeG1 Straight Running Task. |
| ![out7](https://github.com/robfiras/loco-mujoco/assets/69359729/22c7bb0c-ff92-4e99-a964-7654df6d22c4) | Talos.walk | real: ✅ <br /> perfect: ✅ <br /> preference: 🔶| Talos Straight Walking Task. |
| ![out3](https://github.com/robfiras/loco-mujoco/assets/69359729/0ba1f0e7-1f3d-4088-a44f-0a53bec1cf3a) | Talos.carry | real: ✅ <br /> perfect: 🔶 <br /> preference: 🔶| Talos Carry Task. |
| ![out13](https://github.com/robfiras/loco-mujoco/assets/69359729/1ff09d98-e46b-429c-ac07-87de58853d28) | Atlas.walk | real: ✅ <br /> perfect: ✅ <br /> preference: 🔶| Atlas Straight Walking Task. |
Expand Down
21 changes: 19 additions & 2 deletions loco_mujoco/environments/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, xml_handles, action_spec, observation_spec, collision_groups=
Constructor.
Args:
xml_handle : MuJoCo xml handle.
xml_handles : MuJoCo xml handles.
actuation_spec (list): A list specifying the names of the joints
which should be controllable by the agent. Can be left empty
when all actuators should be used;
Expand Down Expand Up @@ -86,6 +86,7 @@ def __init__(self, xml_handles, action_spec, observation_spec, collision_groups=

if type(xml_handles) != list:
xml_handles = [xml_handles]
self._xml_handles = xml_handles

if collision_groups is None:
collision_groups = list()
Expand Down Expand Up @@ -128,7 +129,7 @@ def __init__(self, xml_handles, action_spec, observation_spec, collision_groups=
self.mean_grf = self._setup_ground_force_statistics()

# dataset dummy
self._dataset= None
self._dataset = None

if traj_params:
self.trajectories = None
Expand Down Expand Up @@ -547,6 +548,22 @@ def load_dataset_and_get_traj_files(self, dataset_path, freq=None):

return trajectories

@property
def xml_handle(self):
""" Returns the XML handle of the environment. This will raise an error if the environment contains more
than one xml_handle. """

if len(self._xml_handles) > 1:
raise ValueError("This environment contains multiple models and hence multiple xml_handles. Use the "
"property \"xml_handles\" instead.")
return self._xml_handles[0]

@property
def xml_handles(self):
""" Returns all XML handles of the environment. """

return self._xml_handles

def _get_observation_space(self):
"""
Returns a tuple of the lows and highs (np.array) of the observation space.
Expand Down
Loading

0 comments on commit c2677fd

Please sign in to comment.