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:
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.
Alternatively, you can clone the networks_minimal
repository in
the dependencies directory.
We use the header
branch of this repository.
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.
Assuming you are in the project root directory $LFMC_GYM_PATH
,
create and source a virtual environment.
The relevant build and installs can then be done using
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
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.
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:
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.
Build
Upon cloning the repository, we build the library and executable in the
build
folder.
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
.
Assuming, Raisim has been correctly set up, you can then build the package.
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.
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.
Clone
To clone lfmc_pyval
, use the following command. The Python
version does not depend on other repositories.
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.
Now create and source a virtual environment.
The dependencies can then be installed by
This will install numpy
, torch
, pybullet
, and
pyyaml
along with their dependencies.
Execute
To run the included example, just use the following command.
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.
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.