This repo contains the code for controlling both a real and a simulated flywheel pendulum robot via ROS2.
- Feedback Linearization
- Linear Quadratic Regulator
- Adaptive Linear Quadratic Regulator
- Nonlinear MPC via Acados
- Nonlinear MPC via Casadi
- Iterative Linear Quadratic Regulator
It includes the following folders:
-
python_scripts
: most of the ROS2 nodes call some classes here -
coppeliasim_simulation
: scenes used for simulating the robot with CoppeliaSim -
ros2_ws
: collection of ROS2 nodes for controlling the robot
-
ROS2 Humble
- clone the repo recursively
git clone --recurse-submodules https://github.com/giulioturrisi/Flywheel-Pendulum-Robot.git
-
install miniforge (x86_64)
-
create an environment using the file in the folder installation/conda:
conda env create -f mamba_environment.yml
-
follow the instruction here to install ros-humble
-
download CoppeliaSim
-
add in your .bashrc
alias twip_env="conda activate flywheel_env && source your_path_to/Flywheel-Pendulum-Robot/ros2_ws/install/setup.bash"
export COPPELIASIM_ROOT_DIR=your_path_to/CoppeliaSim
- start your environment and go in ros2_ws
twip_env
cd your_path_to/Flywheel-Pendulum-Robot/ros2_ws
rosdep install -y -r -q --from-paths src --ignore-src --rosdistro humble
ulimit -s unlimited
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
- if you need acados, go inside the acados/acados folder and press
mkdir build
cd build
cmake -DACADOS_WITH_QPOASES=ON -DACADOS_WITH_OSQP=ON ..
make install -j4
pip install -e ./../interfaces/acados_template
then in your .bashrc, add
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/your_path_to/Flywheel-Pendulum-Robot/python_scripts/controllers/acados/lib"
export ACADOS_SOURCE_DIR="/your_path_to/Flywheel-Pendulum-Robot/python_scripts/controllers/acados"
- Open Coppeliasim and run the scene
scene.ttt
in the folder coppeliasim_simulation
./coppeliaSim.sh -f your_path_to/Flywheel-Pendulum-Robot/coppeliasim_simulation/scene.ttt
- on a new terminal
ros2 run controllers <control_node>
where in <control_node> you can choose the type of controller you want.
The CAD files are from the wonderful project based on SimpleFoc