Skip to content

Code

The Low-Frequency Motion Control (LFMC) framework comprises three main code repositories:

  • LFMC-Gym: Code for training LFMC policies using Raisim.
  • LFMC-CVal: Deployment code written in C++ along with Raisim test example.
  • LFMC-PyVal: Python base deployment code along with PyBullet and Raisim test.

Training

The training code is based on Raisim and an adaptation of RaisimGymTorch. The environment is written in C++ while the actual training happens in Python. The current example provided in the repository has been tuned to train a 25 Hz locomotion policy for the ANYmal C robot in roughly 30 minutes on a standard computer with an 8-core Intel i9-9900k CPU @ 3.6 GHz and an NVIDIA RTX 2080 Ti.

Extended Training Code

We aim to release an extended version of the provided training code in January 2023. This will include support for Recurrent and Dynamics-Encoding network architectures.

Prerequisites

The training code depnds on Eigen which can be installed in Ubuntu like so:

sudo apt-get install libeigen3-dev

You will also need to have installed Raisim. Please refer to the Raisim documentation for install instructions. Based on the documentation, we will assume that Raisim has been installed in a directory called $LOCAL_INSTALL.

Clone

To clone lfmc_gym, use the following command. Note that, this repository depends upon a neural network implementation written in C++ called networks_minimal and is included as a submodule. Ensure you use --recurse-submodule flag while cloning the repository.

git clone --recurse-submodules git@github.com:ori-drs/lfmc_gym.git

Alternatively, you can clone the networks_minimal repository in the dependencies directory.

cd lfmc_gym
git clone git@github.com:gsiddhant/networks_minimal.git dependencies/networks_minimal

We use the header branch of this repository.

cd dependencies/networks_minimal
git checkout header
cd ../..

Build

A setup.py script is handles the necessary dependencies and C++ builds. It is recommended that you use a virtual environment. If python3-venv is not already installed, use the following command.

sudo apt-get install python3-venv

Assuming you are in the project root directory $LFMC_GYM_PATH, create and source a virtual environment.

cd $LFMC_GYM_PATH
python3 -m venv venv
source venv/bin/activate

The relevant build and installs can then be done using

python setup.py develop

Usage

The environment provided is called anymal_velocity_command and is used to train a velocity command tracking locomotion policy. Before you start training, launch the RaisimUnity visualizer and check the Auto-connect option. The training can then be started using

python scripts/anymal_velocity_command/runner.py

After about 5k training iterations, you should observed a good velocity tracking behavior. The checkpoints are stored in the $LFMC_GYM_PATH/data/anymal_velocity_command/<date-time> directory. To test the trained policy, use the provided script.

python scripts/anymal_velocity_command/tester.py

Detailed usage instructions have been provided in the repository readme.

Deployment - C++

We provide a C++ based deployment repository, called lfmc_cval, for executing the trained policies. The git repository contains two branches. The master branch provides an execution example that requires Raisim while the library branch contains the minimal implementation of the controller.

Prerequisites

The deployment code depnds on Eigen and YAML-CPP. These can be installed in Ubuntu like so:

sudo apt-get install libeigen3-dev libyaml-cpp-dev

To execute the example, you will also need to have installed Raisim. Please refer to the Raisim documentation for install instructions. Based on the documentation, we will assume that Raisim has been installed in a directory called $LOCAL_INSTALL.

Clone

To clone lfmc_cval, use the following command. Note that, this repository depends upon a neural network implementation written in C++ called networks_minimal and is included as a submodule. Ensure you use --recurse-submodule flag while cloning the repository.

git clone --recurse-submodules git@github.com:ori-drs/lfmc_cval.git

Build

Upon cloning the repository, we build the library and executable in the build folder.

cd lfmc_cval
mkdir build && cd build

Note that, for CMake to be able to find Raisim, you need to ensure that $LOCAL_INSTALL is an accessible environment variable and directs to the Raisim install location. You can either execute the following command in your current shell or add it to your .bashrc.

export LOCAL_INSTALL=<raisim-install-directory>

Assuming, Raisim has been correctly set up, you can then build the package.

cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4

Execute

To run the example code, you will first have to launch the RaisimUnity visualizer. Make sure you have checked the Auto-connect option in RaisimUnity and then execute the following command.

./command_tracking

Deployment - Python

The Python based deployment repository is called lfmc_pyval and can be used with both PyBullet and RaisimPy. Switching between the two engines is extremely simple.

Prerequisites

This is optional and is only applicable if you would like to use RaisimPy. Ensure that you have compiled it and that $PYTHONPATH contains the RaisimPy install location.

export PYTHONPATH=$PYTHONPATH:<raisim-install-directory>/lib

Clone

To clone lfmc_pyval, use the following command. The Python version does not depend on other repositories.

git clone git@github.com:ori-drs/lfmc_pyval.git

Install

A setup.py script is provided with the Python package which handles all the necessary dependencies. It is recommended that you use a virtual environment.

If python3-venv is not already installed, use the following command.

sudo apt-get install python3-venv

Now create and source a virtual environment.

cd lfmc_pyval
python3 -m venv venv
source venv/bin/activate

The dependencies can then be installed by

pip install -e .

This will install numpy, torch, pybullet, and pyyaml along with their dependencies.

Execute

To run the included example, just use the following command.

python scripts/command_tracking.py

This will execute the locomotion policy in PyBullet. To switch to RaisimPy, simply edit the first line in the simulation configuration file. The file is called simulation.yaml and can be found at $LFMC_PYVAL_PATH/configuration/simulation.yaml. By default, this is what Line 1 reads.

engine: pybullet # Options: [raisim, pybullet]
To switch to Raisim, change it to
engine: raisim # Options: [raisim, pybullet]

Assuming RaisimUnity has been launched for visualization, you can execute the command_tracking.py script just as before. The example will now utilize the Raisim engine.

python scripts/command_tracking.py