Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tutorial on how to set up Gazebo simulations of the BlueROV2 (model provided by BlueElectrics), using SITL and ArduSub, and a package provided by kdkalvik for use with mavros.
This folder provides simulation of the BlueROV2 using Gazebo for the dynamics and ArduPilot SITL for the communication and ground control.
The plugins do not depend on ROS so no need to build them inside a catkin workspace or to worry about ROS at the time of creating this. Tutorial for installing Gazebo plugins:
Create new directory/catkin workspace:
mkdir -p ~/bluerov_simulation/catkin_ws_bluerov/src
cd catkin_ws_bluerov
First step: install freebuoyancy plugin (
cd ~/bluerov_simulation
git clone
mkdir -p freebuoyancy_gazebo/build
cd freebuoyancy_gazebo/build/
cmake ../
export GAZEBO_PLUGIN_PATH=${GAZEBO_PLUGIN_PATH}:~/bluerov_simulation/freebuoyancy_gazebo/build
Second step: install ardupilot_gazebo (
/!\ once add_link branch in github repo has been approved and merged with master you can remove the -b add_link from git clone command! The documentation links khancyr's instead of patrickelectric's repo which has the add_link branch waiting to be merged!
cd ~/bluerov_simulation
git clone -b add_link
git branch -a (to check branch is add_link as long as not merged)
cd ardupilot_gazebo
mkdir build
cd build
cmake ../
sudo make install
sudo cp -a /usr/lib/x86_64-linux-gnu/gazebo-7.0/plugins/ /usr/lib/x86_64-linux-gnu/gazebo-7/
(copy from location in which the files were installed, to where the other plugin installed its own and where our make file will be looking for them)
echo 'source /usr/share/gazebo/' >> ~/.bashrc
echo 'export GAZEBO_MODEL_PATH=~/bluerov_simulation/ardupilot_gazebo/models' >> ~/.bashrc
echo 'export GAZEBO_RESOURCE_PATH=~/bluerov_simulation/ardupilot_gazebo/worlds:${GAZEBO_RESOURCE_PATH}' >> ~/.bashrc
source ~/.bashrc
Third step: install the BlueROV2 simulations ( and
cd ~/bluerov_simulation/catkin_ws_bluerov/src
git clone
cd bluerov_ros_playground
echo 'export GAZEBO_PLUGIN_PATH=${GAZEBO_PLUGIN_PATH}:~/bluerov_simulation/freebuoyancy_gazebo/build' >>
echo "source ~/bluerov_simulation/catkin_ws_bluerov/src/bluerov_ros_playground/" >> ~/bluerov_simulation/catkin_ws_bluerov/devel/setup.bash
cd ~/bluerov_simulation/catkin_ws_bluerov
catkin_make --pkg bluerov_ros_playground
source devel/
Fourth step: install SITL (
cd ~/bluerov_simulation
Then follow tutorial. Before launching SITL, run make in the arudpilot directory, and don't forget to source ~/.bashrc before running sim_vehicle.
Fifth step: set up a MAVROS package to communicate easily with the rover, following the tutorial
cd ~/bluerov_simulation/catkin_ws_bluerov/src
git clone
cd ..
cd ..
Install QGroundControl
Download app image
cp QGroundControl.AppImage ~
chmod +x ./QGroundControl.AppImage
Set it up according to the previous kdkalvik tutorial (comm links add UDP port with number 14552)
Install Mavros using binary installation in :
sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-extras
chmod +x ./
sudo ./
Also remove all .git submodules inside the subfolders so that you can handle the whole bluerov_simulation workspace in one git repo.
#1 start SITL:
cd ~/bluerov_simulation/ardupilot/ArduSub
source ~/.bashrc -f gazebo-bluerov2 -I 0 -j4 -D -L RATBeach --console
SITL is now running, you can use it according to documentation (to test if it is running, do param show once second terminal is done running)
#2 once first one is waiting for heartbeat, view the world in Gazebo:
cd ~/bluerov_simulation/catkin_ws_bluerov/src/bluerov_ros_playground
gazebo --verbose worlds/ -u
OR do the following to launch gazebo with ROS:
roscore & rosrun gazebo_ros gazebo --verbose worlds/ -u
CLICK ON PLAY at the bottom left of the Gazebo GUI
#3 use the Mavros package (same as apm_sitl.launch from mavros package in ErleRobotics simulations, can be inside launch file for future use):
cd ~/bluerov_simulation/catkin_ws_bluerov
source devel/setup.bash
roslaunch rover apm.launch
(might take a while, might show lots of errors and warnings, don't do anything until says .. is using GPS)
-> to skip this step include the apm.launch file in the roslaunch in nex step!
#4 run whichever scripts you want (bundled in a roslaunch) using the mavros topics:
roslaunch bluerov_ros_playground my_bluerov.launch
rosrun bluerov_ros_playground output:=screen
rosbag record /gazebo/model_states /tf /mavros/imu/data -O my_drone_data.bag
-> Sometimes Gazebo finds/doesn't find sun: retry a few times until it finds it, maybe source again and do gazebo before sitl, keep restarting. Will maybe be better when it's launched by ROS...
-> If SITL does not go all the way to MAV> and the XTerm says address already used, aborting launch you probably still have some SITL windows open, close them and start again.
-> Resource not found for existing package: clean build or rosdep update or source, if rospack package_name does not find it you're probably using a directory instead of a package name.
-> Gazebo crashing because of plugins, meshes, worlds etc: check everywhere that the paths are right. A lot of times the freefloating plugin was used instead of freebuoyancy, or the paths for the mesh and the world were wrong (inside launch files, inside, and the paths for resources and plugins in general had to be added to the gazebo paths. Correct all of those issues one by one, and at part from the light that is only found 1 out of 3 times it should run!
-> Gazebo crashing with the message Attached && "A new DepthBuffer for a RenderTarget was created, but after creation" "it says it's incompatible with that RT"' failed:
-> SITL and Gazebo not connecting: change FCU and GCS params in the apm.launch file to match the apm_sitl.launch (in simulation repo)
-> SITL stuck at waiting for heartbeat: Gazebo is paused, hit play in the gui (bottom left) or unpause it from a script!!
-> Gazebo crushes when launched with roslaunch: stop, source again, killall gzserver and try again. can help??????
-> there is another Gazebo/ROS process running: killall gzserver and killall gzclient, killall roscore...
-> when using Gazebo with ros, shared libraries are not found: surely another program inbetween has over written the path, run export LD_LIBRARY_PATH=/opt/ros/kinetic/lib
-> to first test your setup, send commands like arm throttle, rc 4 1300 to sitl and see if gazebo reacts to it. If so, then only the mavros part is still a problem. Check that the addresses used in apm.launch match the ones used by sitl (SIM_VEHICLE at the beginning of the console), and make sure your SYSID_MGCS parameter is correct (1 for control by ArduPilot such as circle mode, 255 for control by you through rc override for example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.