This repo implements a Model Predictive Controller (MPC) for a quadrotor, using Acados library. The MPC is implemented in Python and C++.
Clone this repository:
git clone hhttps://github.com/RPS98/mpc.git
cd mpc
Follow the instructions in the Acados documentation to compile the library.
git clone https://github.com/acados/acados.git
cd acados
git submodule update --recursive --init
mkdir -p build
cd build
cmake -DACADOS_WITH_QPOASES=ON ..
# add more optional arguments e.g. -DACADOS_WITH_OSQP=OFF/ON -DACADOS_INSTALL_DIR=<path_to_acados_installation_folder> above
make install -j4
export ACADOS_ROOT_DIR="<path_to_acados_folder>"
export PYTHONPATH=$PYTHONPATH:"$ACADOS_ROOT_DIR/interfaces/acados_template/"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$ACADOS_ROOT_DIR/acados/lib"
export ACADOS_SOURCE_DIR="$ACADOS_ROOT_DIR/acados"
For manual installation follow these instructions:
- Download binaries from https://github.com/acados/tera_renderer/releases/download/v0.0.34/t_renderer-v0.0.34-linux
- Copy them in <path_to_acados_folder>/acados/bin
- Strip the version and platform from the binaries: as t_renderer-v0.0.34-X -> t_renderer
- Enable execution privilege on the file "t_renderer" with:
chmod +x $ACADOS_ROOT_DIR/bin/t_renderer
pip install -e <acados_root>/interfaces/acados_template
The MPC is implemented in Python and C++. The Python code generates the C code for the MPC. To generate the C code, run the following command:
export PYTHONPATH=$PYTHONPATH:"<path_to_this_repo>"
python3 mpc/mpc_controller.py
To build this repostory, follow the instructions from the root folder:
mkdir -p build
cd build
make -j4
You can run the MPC using the Python interface, from the root folder:
python3 examples/run_example.py
Note
dynamic_trajectory_generator dependency is required to run the example. Clone the repository and add the path to the LD_LIBRARY_PATH.
You can build the C++ interface and run the MPC using the C++ interface, from the root folder:
mkdir -p build
cd build
cmake ..
make -j4 -DBUILD_EXAMPLES=ON
You can run the example:
./build/examples/acados_mpc_run_example