Skip to content

Instantly share code, notes, and snippets.

Embed
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.
Source: https://gist.github.com/patrickelectric/60a1d300e0afadf85066cc5d8e3d51ff
http://discuss.bluerobotics.com/t/ardusub-simulation-sitl/481/30
-------------------------------------------------------------------------------------------------------------------------
INSTALLATION:
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: http://gazebosim.org/tutorials/?tut=plugins_hello_world
Create new directory/catkin workspace:
mkdir -p ~/bluerov_simulation/catkin_ws_bluerov/src
cd catkin_ws_bluerov
catkin_make
First step: install freebuoyancy plugin (https://github.com/bluerobotics/freebuoyancy_gazebo)
cd ~/bluerov_simulation
git clone https://github.com/bluerobotics/freebuoyancy_gazebo.git
mkdir -p freebuoyancy_gazebo/build
cd freebuoyancy_gazebo/build/
cmake ../
make
export GAZEBO_PLUGIN_PATH=${GAZEBO_PLUGIN_PATH}:~/bluerov_simulation/freebuoyancy_gazebo/build
Second step: install ardupilot_gazebo (https://github.com/patrickelectric/ardupilot_gazebo/tree/add_link#usage-)
/!\ 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 https://github.com/patrickelectric/ardupilot_gazebo.git
git branch -a (to check branch is add_link as long as not merged)
cd ardupilot_gazebo
mkdir build
cd build
cmake ../
make
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/setup.sh' >> ~/.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 (https://gist.github.com/patrickelectric/60a1d300e0afadf85066cc5d8e3d51ff and http://discuss.bluerobotics.com/t/ardusub-simulation-sitl/481/11)
cd ~/bluerov_simulation/catkin_ws_bluerov/src
git clone https://github.com/patrickelectric/bluerov_ros_playground
cd bluerov_ros_playground
source gazebo.sh
echo 'export GAZEBO_PLUGIN_PATH=${GAZEBO_PLUGIN_PATH}:~/bluerov_simulation/freebuoyancy_gazebo/build' >> gazebo.sh
echo "source ~/bluerov_simulation/catkin_ws_bluerov/src/bluerov_ros_playground/gazebo.sh" >> ~/bluerov_simulation/catkin_ws_bluerov/devel/setup.bash
cd ~/bluerov_simulation/catkin_ws_bluerov
catkin_make --pkg bluerov_ros_playground
source devel/setup.sh
Fourth step: install SITL (http://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html)
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 https://github.com/kdkalvik/bluerov-ros-pkg
cd ~/bluerov_simulation/catkin_ws_bluerov/src
git clone https://github.com/kdkalvik/bluerov-ros-pkg.git
cd ..
cd ..
catkin_make
Install QGroundControl https://docs.qgroundcontrol.com/en/getting_started/download_and_install.html
Download app image
cp QGroundControl.AppImage ~
chmod +x ./QGroundControl.AppImage
./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 https://github.com/mavlink/mavros/blob/master/mavros/README.md#installation :
sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-extras
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
chmod +x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh
Also remove all .git submodules inside the subfolders so that you can handle the whole bluerov_simulation workspace in one git repo.
-------------------------------------------------------------------------------------------------------------------------
REGULAR USE - FIRST SIMULATIONS WITH ONLY ROV:
#1 start SITL:
cd ~/bluerov_simulation/ardupilot/ArduSub
source ~/.bashrc
sim_vehicle.py -f gazebo-bluerov2 -I 0 -j4 -D -L RATBeach --console
SITL is now running, you can use it according to documentation http://ardupilot.github.io/MAVProxy/html/getting_started/mavinit.html (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
source gazebo.sh
gazebo --verbose worlds/my_underwater.world -u
OR do the following to launch gazebo with ROS:
roscore & rosrun gazebo_ros gazebo --verbose worlds/my_underwater.world -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 my_circle.py output:=screen
rosbag record /gazebo/model_states /tf /mavros/imu/data -O my_drone_data.bag
REGULAR USE - SECOND SIMULATIONS WITH LIDAR:
-------------------------------------------------------------------------------------------------------------------------
TROUBLESHOOTING:
-> 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 underwater.world...), 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: https://answers.ros.org/question/274047/error-using-depth-sensor-in-gazebo-7/
-> 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. http://answers.gazebosim.org/question/4153/gazebo-crashes-immediately-using-roslaunch-after-installing-gazebo-ros-packages/ 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.