This repo contains the code for controlling both a real and a simulated two wheeled inverted pendulum robot via ROS2.
- PID
- Linear Quadratic Regulator
- Linear Quadratic Integral Regulator
- Least Square Linear Quadratic Regulator
- Adaptive Linear Quadratic Regulator (MIT rule)
- Sliding Mode
- RL policy via IsaacGym
- Nonlinear MPC via Acados
- Iterative Linear Quadratic Regulator
- Iterative Linear Quadratic Regulator via Crocoddyl
- Predictive Sampling
- Extended Kalman Filter
It includes the following folders and subfolders:
-
python_scripts
: most of the ROS2 nodes call some classes here -
coppeliasim_simulation
: scenes used for simulating the robot -
ros2_ws
: collection of ROS2 nodes for controlling the robot and some external folders such assimExtROS2
andros2_bubble_rob
(dependencies for CoppeliaSim)
-
ROS2 Humble
-
CoppeliaSim for simulations
- clone the repo recursively
git clone --recurse-submodules https://github.com/giulioturrisi/Self-Balancing-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 twip_env && source your_path_to/Self-Balancing-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/Self-Balancing-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/Self-Balancing-Robot/python_scripts/controllers/acados/lib"
export ACADOS_SOURCE_DIR="/your_path_to/Self-Balancing-Robot/python_scripts/controllers/acados"
- Open Coppeliasim and run the scene
self_balancing_robot.ttt
in the folder coppeliasim_simulation
./coppeliaSim.sh -f your_path_to/Self-Balancing-Robot/coppeliasim_simulation/self_balancing_robot.ttt
- on a new terminal
ros2 run controllers <control_node>
where in <control_node> you can choose the type of controller you want.
- to command the robot with a joystick
ros2 launch teleop_twist_joy teleop-launch.py joy_config:='xbox'
Still working in progress, the real robot does not exist yet. Recently added IsaacGym to learn an RL policy (Self-Balancing-Robot-IsaacGym)!