This is a clean single file implementations of control algorithms (modal control, LQR, MPC).
Important
All controllers are avaliable for hot-plug for segway only now.
Important
simulator <-> ZMQ <-> controller
python3 -m venv ./venv
source venv/bin/activate
pip install -r requirements.txt
sudo apt-get install build-essential cmake git libzmq3-dev libeigen3-dev
Model and gains can be found in (lqr, modal control, closed-form MPC)
python model.pyTo simulate with mujoco (with system state vizualizetion)
python simulator.py & python rt-plotter.pyNote. For ubuntu 26.04 and wayland use PYGLFW_LIBRARY_VARIANT=wayland python simulator.py
Examples of controllers:
-
LQR with standup
- C++
g++ controllers/lqr_controller_with_standup.cpp -o controllers/lqr_controller_with_standup -lzmq -O3
./controllers/lqr_controller_with_standup
- Python
python controllers/lqr_controller_with_standup.py
-
MPC with standup
-
C++
- prerequisites
Install quadratic problem (osqp) solver
git clone --recursive -b v1.0.0 https://github.com/oxfordcontrol/osqp.git cd osqp && mkdir build && cd build cmake -G "Unix Makefiles" .. cmake --build . cmake --build . --target install
Install eigen wrapper for osqp
git clone --recursive -b v0.11.0 https://github.com/robotology/osqp-eigen.git cd osqp-eigen && mkdir build && cd build cmake .. && make && make install
- building
cd controllers/mpc && mkdir build && cd build && cmake .. && make
- next, from root dir of the repo, run
python simulator.py & ./controllers/mpc/build/mpc
-
Thanx to Antonov Evgeniy for model and modal control.

