This repository contains Python code for a simple simulation of a hopping point mass with model predictive control. The simulator uses RK4 integration (alternatively, you can directly use the DT system).
- Clone this directory wherever you want.
git clone https://github.com/bbokser/hopper-mpc-point.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-simple
python3.8 -m venv envFor 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 argparseDon'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-point/src
source env/bin/activate
python3.8 run.py 2 mpcThis simulates the "robot" in 2D with mpc. The output is a set of plots tracking the behavior over time.
To simulate with mpc in 3D:
python3.8 run.py 3 mpc
To simulate with trajectory optimized open loop control:
python3.8 run.py 2 openloop
python3.8 run.py 3 openloop