Skip to content

Control algorithms for a self balancing robot (two wheeled inverted pendulum) using ROS2

Notifications You must be signed in to change notification settings

giulioturrisi/Self-Balancing-Robot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This repo contains the code for controlling both a real and a simulated two wheeled inverted pendulum robot via ROS2.

List of available controllers

  1. PID
  2. Linear Quadratic Regulator
  3. Linear Quadratic Integral Regulator
  4. Least Square Linear Quadratic Regulator
  5. Adaptive Linear Quadratic Regulator (MIT rule)
  6. Sliding Mode
  7. RL policy via IsaacGym
  8. Nonlinear MPC via Acados
  9. Iterative Linear Quadratic Regulator
  10. Iterative Linear Quadratic Regulator via Crocoddyl
  11. Predictive Sampling

List of available state estimators

  1. Extended Kalman Filter

Repository structure

It includes the following folders and subfolders:

  1. python_scripts: most of the ROS2 nodes call some classes here

  2. simulations: scenes used for simulating the robot (CoppeliaSim or Mujoco)

  3. ros2_ws: collection of ROS2 nodes for controlling the robot and some external folders such as simExtROS2 and ros2_bubble_rob(dependencies for CoppeliaSim)

Build on Linux

  1. clone the repo recursively
git clone --recurse-submodules https://github.com/giulioturrisi/Self-Balancing-Robot.git
  1. install miniforge (x86_64)

  2. create an environment using the file in the folder installation/conda:

    conda env create -f mamba_environment.yml
  1. follow the instruction here to install ros-humble

  2. add in your .bashrc

alias twip_env="conda activate twip_env && source your_path_to/Self-Balancing-Robot/ros2_ws/install/setup.bash"
  1. 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
  1. (Optional 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"
  1. (Optional if you want CoppeliaSim) download CoppeliaSim and put in your .bashrc
export COPPELIASIM_ROOT_DIR=your_path_to/CoppeliaSim

How to run the simulation

  1. on a new terminal
ros2 run controllers <control_node>                     

where in <control_node> you can choose the type of controller you want.

  1. If using Mujoco
ros2 run simulations run_mujoco_simulation                   
  1. If using Coppeliasim, launch it 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 
  1. to command the robot with a joystick
ros2 launch teleop_twist_joy teleop-launch.py joy_config:='xbox'

Status

Still working in progress, the real robot does not exist yet.

About

Control algorithms for a self balancing robot (two wheeled inverted pendulum) using ROS2

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages