Skip to content

Commit

Permalink
Add support for running the simulation with pixi, optionally with the…
Browse files Browse the repository at this point in the history
… ma97 linear solver (#1)
  • Loading branch information
traversaro authored Nov 29, 2024
1 parent c937d1a commit 4d2d60a
Show file tree
Hide file tree
Showing 11 changed files with 9,813 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SCM syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# build folders
build*
.build*
.pixi_install_prefix

# emacs
*~
Expand Down Expand Up @@ -159,3 +161,7 @@ cython_debug/
scripts/plotting/animations/**
scripts/plotting/figures/**
scripts/generate_animation_meshcat/website/**

# pixi environments
.pixi
*.egg-info
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,28 @@ https://github.com/user-attachments/assets/404c9af8-528e-43c2-abd2-138a98adfc04

## Reproducing the Experiments

You can reprocue the experiments in two ways: either with conda or pixi.

### Conda


To reproduce the experiments, we provide a conda environment for easy setup. Follow the steps below:

### 1. Install the Environment
#### 1. Install the Environment
Run the following command to create the conda environment:

```bash
conda env create -f environment.yml
```

### 2. Activate the Environment
#### 2. Activate the Environment
Activate the newly created environment:

```bash
conda activate dnn-mpc-env
```

### 3. Run the Simulation
#### 3. Run the Simulation
Start the experiment with:

```bash
Expand All @@ -63,6 +68,44 @@ When prompted, type `y` and press `Enter` to start the simulation. The humanoid

⚠️ **Known Issue:** The Gazebo real-time factor is scaled by a factor of 10. This is due to the use of the MUMPS linear solver in the IPOPT docker image. Alternative solvers (e.g., MA27) are available but cannot be redistributed.


### Pixi

To run the experiments with pixi on Linux, just download the repo and run:

~~~
git clone https://github.com/ami-iit/paper_romualdi_viceconte_2024_humanoids_dnn-mpc-walking
cd paper_romualdi_viceconte_2024_humanoids_dnn-mpc-walking
pixi run -e default run_simulation
~~~

This command will install all the dependencies, compiled the code and run the simulation. At that point, when prompted, type `y` and press `Enter` to start the simulation. The humanoid robot will begin walking, and you can observe its behavior in the Gazebo simulator.

⚠️ **Known Issue:** The Gazebo real-time factor is scaled by a factor of 10. This is due to the use of the MUMPS linear solver in the IPOPT docker image. If you have have access to a Coin-HSL license, you can use it following the instructions in the following, to reduce the Gazebo real-time factor scaling from 10 to 2.

To run the simulation using the Coin-HSL's `ma97` solver, follow the following steps:

1. Go to https://licences.stfc.ac.uk/product/coin-hsl, and:
- If you already have a license for Coin-HSL:
- Go to https://licences.stfc.ac.uk/account/orders and find the coin-hsl order.
- Download the coinhsl-2023.11.17.zip file and place it in the './coinhsl_src' folder of this repository.
- If you do not have a license for Coin-HSL:
- If you are an academic, request a license at https://licences.stfc.ac.uk/product/coin-hsl.
- If you are not an academic, purchase a license at https://licences.stfc.ac.uk/product/coin-hsl.
- Once your order is approved, download the coinhsl-2023.11.17.zip file and place it in the './coinhsl_src' folder.

Once the `coinhsl-2023.11.17.zip` archive is in the './coinhsl_src' folder, just run:

~~~
pixi run -e coinhsl run_simulation
~~~

This will execute the same steps of running `pixi run -e default run_simulation`, but additionally it will:
* compile `coinhsl` to be able to use the `ma97` linear solver,
* it will modify the configuration files to use `ma97`
* use a different Gazebo world model, to ensure a faster simulation.


---

## Maintainers
Expand Down
3 changes: 3 additions & 0 deletions coinhsl_src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# We do not want to accidentally push the non-distributable source files
# to the repo, so we add it in the .gitignore
coinhsl-2023.11.17.zip
9,124 changes: 9,124 additions & 0 deletions pixi.lock

Large diffs are not rendered by default.

483 changes: 483 additions & 0 deletions pixi.toml

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion run_simulation.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
#!/bin/bash

env

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

# Construct the full path to the 'world' file relative to the script's directory
WORLD_FILE="$SCRIPT_DIR/worlds/dnn_mpc_ergoCubGazeboV1_1/world"
# based on DNNMPC_LINEAR_SOLVER environment variable
if [ -z "${DNNMPC_LINEAR_SOLVER}" ] || [ "${DNNMPC_LINEAR_SOLVER}" = "default" ]; then
# Default case: if DNNMPC_LINEAR_SOLVER is not set or set to 'default', use the "slow"
# world file with RTF 0.1
WORLD_FILE="$SCRIPT_DIR/worlds/dnn_mpc_ergoCubGazeboV1_1/world_rtf_0_1"
elif [ "${DNNMPC_LINEAR_SOLVER}" = "coinhsl" ]; then
# If DNNMPC_LINEAR_SOLVER is set to 'coinhsl', use the "fast" world file with RTF 0.5
WORLD_FILE="$SCRIPT_DIR/worlds/dnn_mpc_ergoCubGazeboV1_1/world_rtf_0_5"
else
echo "Error: DNNMPC_LINEAR_SOLVER is set to an invalid value ('${DNNMPC_LINEAR_SOLVER}'). Valid values are 'default' or 'coinhsl'."
exit 1
fi

# Start a new detached tmux session named 'dnn-mpc' with root directory '~/'
tmux new-session -d -s dnn-mpc -c ~/
Expand Down
40 changes: 40 additions & 0 deletions scripts/pixi/check_and_extract_coinhsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import zipfile
import sys

# Define file and directories
file_path = './coinhsl_src/coinhsl-2023.11.17.zip'
output_dir = './.build-coinhsl'

def main():
if os.path.exists(file_path):
print(f"File '{file_path}' found. Proceeding to unzip...")

# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True)

# Unzipping the file
try:
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(output_dir)
print(f"File unzipped successfully to '{output_dir}'.")
except zipfile.BadZipFile:
print("Error: The file is not a valid ZIP archive.")
sys.exit(1)
else:
print(f"Error: File '{file_path}' does not exist.")
print("""
Please follow these steps to resolve the issue:
1. Go to https://licences.stfc.ac.uk/product/coin-hsl, and:
- If you already have a license for Coin-HSL:
- Go to https://licences.stfc.ac.uk/account/orders and find the coin-hsl order.
- Download the coinhsl-2023.11.17.zip file and place it in the './coinhsl_src' folder of this repository.
- If you do not have a license for Coin-HSL:
- If you are an academic, request a license at https://licences.stfc.ac.uk/product/coin-hsl.
- If you are not an academic, purchase a license at https://licences.stfc.ac.uk/product/coin-hsl.
- Once your order is approved, download the coinhsl-2023.11.17.zip file and place it in the './coinhsl_src' folder.
""")
sys.exit(1)

if __name__ == "__main__":
main()
31 changes: 31 additions & 0 deletions scripts/pixi/replace_mumps_with_coinhsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

def replace_mumps_with_ma97(file_path):
# Read the file
with open(file_path, 'r') as file:
content = file.read()

# Replace occurrences of 'mumps' with 'ma97'
updated_content = content.replace("mumps", "ma97")

# Write the updated content back to the file
with open(file_path, 'w') as file:
file.write(updated_content)

print(f"Replaced all occurrences of 'mumps' with 'ma97' in {file_path}")

# Get the CONDA_PREFIX environment variable
conda_prefix = os.getenv("CONDA_PREFIX")

if conda_prefix:
# Construct the file path
file_path = os.path.join(conda_prefix, "share/dnn_mpc/robots/ergoCubGazeboV1_1/dnn-mpc/centroidal_mpc.ini")

if os.path.exists(file_path):
replace_mumps_with_ma97(file_path)
else:
print(f"File does not exist: {file_path}")
os.exit(1)
else:
print("CONDA_PREFIX environment variable is not set.")
os.exit(1)
File renamed without changes.
64 changes: 64 additions & 0 deletions worlds/dnn_mpc_ergoCubGazeboV1_1/world_rtf_0_5
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<sdf version="1.6">
<world name="default">

<physics type="ode">
<max_step_size>0.001</max_step_size>
<real_time_factor>0.5</real_time_factor>
<real_time_update_rate>500</real_time_update_rate>
</physics>

<scene>
<shadows>false</shadows>
</scene>

<!-- Light -->
<include>
<uri>model://sun</uri>
</include>

<!-- Ground Plane -->
<include>
<uri>model://ground_plane</uri>
</include>

<model name="ergoCub">

<plugin name='torso_configuration_override' filename='libgazebo_yarp_configurationoverride.so'>
<yarpPluginConfigurationOverride plugin_name='controlboard_torso'> </yarpPluginConfigurationOverride>
<initialConfiguration>-0.00120142 0.110569 -0.0368365</initialConfiguration>
</plugin>

<plugin name='larm_configuration_override' filename='libgazebo_yarp_configurationoverride.so'>
<yarpPluginConfigurationOverride plugin_name='controlboard_left_arm_no_hand'> </yarpPluginConfigurationOverride>
<initialConfiguration>-0.0475749 0.10829 -0.192063 0.0540067 0 0 0</initialConfiguration>
</plugin>

<plugin name='rarm_configuration_override' filename='libgazebo_yarp_configurationoverride.so'>
<yarpPluginConfigurationOverride plugin_name='controlboard_right_arm_no_hand'> </yarpPluginConfigurationOverride>
<initialConfiguration>-0.0482403 0.103451 -0.203865 -0.00818984 0 0 0</initialConfiguration>
</plugin>

<plugin name='lleg_configuration_override' filename='libgazebo_yarp_configurationoverride.so'>
<yarpPluginConfigurationOverride plugin_name='controlboard_left_leg'> </yarpPluginConfigurationOverride>
<initialConfiguration> 0.111411 0.0242565 0.050721 -0.543941 -0.322059 -0.00373243</initialConfiguration>
</plugin>

<plugin name='rleg_configuration_override' filename='libgazebo_yarp_configurationoverride.so'>
<yarpPluginConfigurationOverride plugin_name='controlboard_right_leg'> </yarpPluginConfigurationOverride>
<initialConfiguration>0.0926136 0.0570012 0.0752004 -0.52194 -0.314711 -0.0492877</initialConfiguration>
</plugin>

<plugin name='externalwrench' filename='libgazebo_yarp_externalwrench.so'>
<yarpConfigurationFile>model://ergoCub/conf/gazebo_ergocub_robotname.ini</yarpConfigurationFile>
</plugin>

<include>
<uri>model://ergoCubGazeboV1_1</uri>
<pose>0.0 0.0 0.78 0.0 -0.1 0.0</pose>
</include>

</model>

</world>
</sdf>

0 comments on commit 4d2d60a

Please sign in to comment.