Simulation of a two wheeled self balancing robot, this time using MuJoCo. The robot uses a Linear–quadratic regulator (LQR) controller to maintain balance. In this example the MuJoCo simulation view is embedded in a Qt application (PySide6) to provide UI widgets for controlling the robot.
After implementing the same simulation using PyBullet (see here), I found that PyBullet support for Stable-Baselines3 / Gymnasium was a little lacking. It made sense to switch to MuJoCo given how early on this project is.
Clone the repo
git clone https://github.com/lachlanhurst/balance-robot-mujoco-sim.git
cd balance-robot-mujoco-sim
It's recommended to use the conda environment file included in this repository; these commands will create and activate a new robot-mujoco-simulation conda env.
conda env create -f conda-environment.yaml
conda activate robot-mujoco-simulation
The LQR parameters are already included in the source code. There is no need to re-calculate these parameters unless the physical characteristics of the robot change (as defined in robot-02.xml).
If you do need to re-calculate these parameters follow the process defined in the PyBullet simulation repo.
The following command will run the simulation. Note: the robot-mujoco-simulation must be activated
python src/simulation/simulate_robot.py
Jean Elsner put together this great simple example on how to embed a MuJoCo simulation within a PySide6 application.
