This repository contains Python code for a simple simulation of a hopping rigid body with model predictive control. The simulator uses RK4 integration.
- Clone this directory wherever you want.
git clone https://github.com/bbokser/hopper-mpc-inertial.git
- Make sure both Python 3.8 and pip are installed.
sudo apt install python3.8
sudo apt-get install python3-pip
python3.8 -m pip install --upgrade pip
- I recommend setting up a virtual environment for this, as it requires the use of a number of specific Python packages.
sudo apt-get install python3.8-venv
cd hopper-mpc-inertial
python3.8 -m venv env
For more information on virtual environments: https://docs.python.org/3/library/venv.html
- Activate the virtual environment, and then install numpy, scipy, matplotlib, sympy, cvxpy, and argparse.
source env/bin/activate
python3.8 -m pip install numpy scipy matplotlib cvxpy argparse tqdm casadi transforms3d
Don't use sudo here if you can help it, because it may modify your path and install the packages outside of the venv.
Here is some example code:
cd hopper-mpc-inertial/src
source env/bin/activate
python3.8 run.py 2f --runtime=2000
This simulates the "robot" for 2 seconds with the y-axis body frame output force constraint to zero. The output is a set of plots tracking the behavior over time.
python3.8 run.py 3f --curve
This simulates the "robot" for 5 seconds (the default) without the y-axis force constraint. The --curve argument adds curvature to the reference trajectory.