BlueROV2 MPC
This work implements a NMPC controller for BlueROV2 with ROS.
Prerequisites
- Python 3.7
- ROS (ROS noetic recommended)
- uuv simulator
- MAVROS
- Acados
We also provide its docker image to save you some time.
Getting started
-
Install python 3.7 and its dependencies
sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt install -y python3.7 apt-get install -y python3-pip pip3 install numpy matplotlib scipy future-fstrings casadi>=3.5.1 setuptools sudo apt-get install -y python3.7-tk
-
Install Acados
git clone https://github.com/acados/acados.git cd acados git submodule update --recursive --init mkdir -p build cd build cmake -DACADOS_WITH_QPOASES=ON -DACADOS_WITH_OSQP=OFF/ON -DACADOS_INSTALL_DIR=<path_to_acados_installation_folder> .. make install -j4 pip install -e ~/acados/interfaces/acados_template echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/root/acados/lib"' >> ~/.bashrc echo 'export ACADOS_SOURCE_DIR="/root/acados"' >> ~/.bashrc source ~/.bashrc
-
Install ros uuv-simulator packages
sudo apt-get install -y ros-noetic-geodesy mkdir -p ~/catkin_ws/src && \ cd ~/catkin_ws/src && \ git clone --branch noetic https://github.com/arturmiller/uuv_simulator.git
-
Install then compile this package
cd ~/catkin_ws/src && \ git clone --branch noetic https://github.com/arturmiller/uuv_simulator.git
Please edit CMakelists.txt here and here if you put your acados in otherwise directory. Modify the line
set(acados_include "~/acados/include")
andset(acados_lib "~/acados/lib")
Then do
cd ~/catkin_ws/src/bluerov2/bluerov2_dobmpc/scripts && \ yes | python3 generate_c_code.py
and
cd ~/catkin_ws/src/bluerov2/bluerov2_mpc/scripts && \ yes | python3 generate_c_code.py
The last commands basically run generate_c_code.py at here and here.
Finally, do
cd ~/catkin_ws && catkin_make
Start simulation without controller
Ocean_waves in uuv simulator is set as default world.
Quick start to initialize the Gazebo world and add blueROV2 vehicle
roslaunch bluerov2_gazebo quick_start.launch
Or start with thruster manager
roslaunch bluerov2_gazebo start_with_thruster_manager.launch
With thruster manager, forces and moments can be published to topic /bluerov2/thruster_manager/input.
Start simulation with PID controller
Start PID controller with teleop (using joystick)
roslaunch bluerov2_gazebo start_pid_demo_with_teleop.launch
Or start PID Controller without teleop
roslaunch bluerov2_gazebo start_pid_demo.launch
Further trajectory tracking tasks can be done with uuv_control_utils package, such as following linear trajectory
roslaunch uuv_control_utils send_waypoints_file.launch uuv_name:=bluerov2 interpolator:=linear
Or following helical trajectory
roslaunch uuv_control_utils start_helical_trajectory.launch uuv_name:=bluerov2 n_turns:=2
Start simulation with MPC controller
A demonstration of starting MPC controler to follow circular trajectory can be launched by
roslaunch bluerov2_gazebo start_mpc_demo.launch
The bluerov2_mpc package also includes more trajectory following tasks such as following leminscate path and self defined waypoints.
Disturbance generator
The uuv simulator provides disturbance generation functions for testing the vehicle.
A demonstration of starting simulation with random current disturbances can be launched by
roslaunch bluerov2_gazebo start_pid_with_current.launch (with PID controller)
roslaunch bluerov2_gazebo start_mpc_with_current.launch (with MPC controller)
Disturbances can also be generated by using ROS service call
rosservice call /hydrodynamics/set_current_velocity_model "{mean: 0.0, min: 0.0, max: 0.0, noise: 0.0, mu: 0.0}"
rosservice call /hydrodynamics/set_current_horz_angle_model "{mean: 0.0, min: 0.0, max: 0.0, noise: 0.0, mu: 0.0}"
rosservice call /hydrodynamics/set_current_vert_angle_model "{mean: 0.0, min: 0.0, max: 0.0, noise: 0.0, mu: 0.0}"