Home        Store        Docs        Blog

Setting up a simulation environment



I was wondering if someone could help me out setting up a simulation environment for testing missions or guided-mode dronekit python scripts.

So far I understand that there is a SITL file in the install directory for ardusub. I was wondering what other components of this do I need to successful send the simulated drone commands, and more specifically what each component does? And for example would I link the SITL to gazebo? I saw that there is a gazebo plugin on the bluerobotics github, do I need this and what exactly does it do ?

I’m sorry if these questions are elementary, it is just I’m struggling to find a tutorial specific to ardusub.

(Patrick José Pereira) #2


Sorry for taking so long to reply. I did a small documentation to help you with your simulation environment, this same documentation will be added in ardusub.com in the future.

S.I.T.L (Software In The Loop)

SITL is a simulator that allows you to run ArduSub without any hardware. It is a build of the autopilot code using an ordinary C++ compiler, giving you a native executable that allows you to test the behaviour of the vehicle.


To configure and run SITL for the first time in your computer, take a look in Running SITL ArduPilot documentation.

Running ArduSub SITL

This part assumes that you have already set up SITL on your machine.
First is necessary to be inside ArduSub folder.

cd ardupilot/ArduSub

To execute SITL with sim_vehicle.py.

sim_vehicle.py -L RATBeach --out=udp: --map --console

After that, ArduSub SITL will compile and start to run, you’ll be able to connect it with QGroundControl and control it.

For more information about sim_vehicle.py and the options available, check:

sim_vehicle.py --help

Running ArduSub SITL with Gazebo

To run ArduSub SITL with Gazebo, it’s necessary to:

  1. Install freebuoyancy_gazebo plugin for buoyancy simulation.

  2. Install ardupilot_gazebo/add_link plugin for ardupilot-gazebo communication. add_link is a branch that provides actuation over sdf links, after the git clone, it’s necessary to run git checkout add_link.

  3. Run BlueRov2 Gazebo model

    1. Download bluerov_ros_playground

      git clone https://github.com/patrickelectric/bluerov_ros_playground
    2. Run Gazebo model

      cd bluerov_ros_playground
      source gazebo.sh
      gazebo worlds/underwater.world -u
      # Start the simulation
  4. Execute ArduPilot SITL

    sim_vehicle.py -f gazebo-bluerov2 -L RATBeach --out=udp: --console

The console will start to display the output if the connection was successful.



I really appreciate the help! So I’m trying to setup Gazebo but I keep running into low level problems. Particularly with building the freebuoyancy plugin. I cannot seem to find a version number for which that plugin was designed for. The cpp file in the src folder makes me think it is not the current version as it is not using ignition math. Seeing as the next step says to use 7 or 8 I guess it is not the latest version.

So I try to install Gazebo 8.2, but even then I’m running into more low level problems particularly with missing/mismatching libraries. Do they have an easier way of installing Gazebo 8.2 like they do for 9? I keep getting stuck. I would appreciate any more guidance if possible.

(Jacob) #4

ping @patrickelectric


@patrickelectric I was referred to this page by a helpful person on the gazebo answers site: http://gazebosim.org/tutorials?tut=ros_wrapper_versions

Not sure if these are easier/cleaner installations though I will try that soon. Should I go for gazebo 7 or 8? I also noticed that the freebuouyancy plugin was designed to use without ROS, should this be of concern to me even if I install a gazebo package with ROS? Is there any particular reason that the plugin has been built not to use ROS?

What distribution of ROS works best with ardusub?

(Patrick José Pereira) #6


Sorry for taking so long to reply, I was O.o.O in this last days.
I did this tutorial with Gazebo 8. It’s necessary to have all versions of all necessary libraries compatible between them, and that’s a big pain to solve sometimes depending of the OS.
What is the operating system that you are using and which version ?


I have tried your tutorial on Ubuntu 16 Xenial and gazebo7 and was able to get gazebo linked with the SITL. I was not able to set waypoints and upload a mission to the rov but manual mode worked fine. Since you said you made the tutorial in gazebo8 I’ll try to set that up and see if I get the same sort of errors before I say anything more.

I’m assuming most things are compatible with Xenial and I should stick on Xenial for development purposes?

Thanks a ton for all the support!

Note to others who may be stuck:
I tried to install gazebo 8 from source because I could not find the gazebo8 package when using apt. This was because I was on Ubuntu 18 Bionic Beaver. The only supported gazebo version on Bionic is gazebo9. I had to look through the packages file in the osrf online repository to find this out. When I backtracked to Ubuntu 16 Xenial, everything worked fine because the gazebo7 and gazebo8 packages exist on that distro, and you should be able to follow the tutorial above and everything worked well. There were a few hiccups but nothing massive like when compiling from source.

(Patrick José Pereira) #8


I was not able to set waypoints and upload a mission to the rov but manual mode worked fine.

You should be able to create a mission without problems with QGC, this is a test that I did:
Some points are not great because of the tunning.

I’m assuming most things are compatible with Xenial and I should stick on Xenial for development purposes?

It’s compatible with any operating system that can run gazebo 8.
I’ll try to update the tutorial to be compatible with Ubuntu 18.04 (last LTS) and probably 16.04 as well.

(Patrick José Pereira) #9

I did tests with ubuntu 16.04 and 18.04, using Gazebo 7 and Gazebo 8, everything is working fine.


So I’m getting the following error when trying to upload a mission. I also attached my terminals in which I ran ardupilot and gazebo.

This is on gazebo8 on Ubuntu 16.04 now.

(Patrick José Pereira) #11

This problem was solved in the last version of the QGC development branch.

QGroundControl maintains this download links to allow test and usage of the last updates in main code.

This links are not BlueRobotics QGC Version



I let the ROV run in auto mode to go form the home position to the first waypoint. It seems to be struggling to get there at all. I guess I wanted to check if I’m doing something wrong or if this is expected behavior?

Also my ROV doesn’t seem to have a texture like in your screenshot though I believe I did everything as you said. Not sure why this is the case. Your screenshot has that frame in front of the ROV what looks like it is what the camera is seeing, is this the case? Is it possible to get that camera feed back into QGC?

(Jacob) #13

The auto/gps modes are still in development (not stable).

I do not believe this is the case with the stable revs.

(Patrick José Pereira) #14

You should run it in “Auto mode”, and as you can see, the parameters need to be corrected. (In the first image it shows the ROV upside down).

You can download here: bluerov_sitl_fast.params (24.3 KB) The parameters that I use in this gif:

It’s running like in The Fast and the Furious mode, but a bit of tuning will make it better.

Also my ROV doesn’t seem to have a texture like in your screenshot though I believe I did everything as you said.

I need confirm that, but probably is related to your gazebo version.

Your screenshot has that frame in front of the ROV what looks like it is what the camera is seeing, is this the case? Is it possible to get that camera feed back into QGC?

The image with the camera is a picture of the bluerov_playground simulation module, it was not from the SITL, but we are working to stream the gazebo camera to QGC.

(Abel Varghese David) #15

When I run

cd ardupilot/ArduSub
sim_vehicle.py -L RATBeach --out=udp: --map --console

I get the following error when I start the Simulation.

Build directory: /home/abel/src/ardupilot/build/sitl
Target       Text     Data  BSS    Total  
bin/ardusub  1415339  1938  36864  1454141

Build commands will be stored in build/sitl/compile_commands.json
'build' finished successfully (1.237s)
SIM_VEHICLE: Using defaults from (/home/abel/src/ardupilot/Tools/autotest/default_params/sub.parm)
SIM_VEHICLE: "/home/abel/src/ardupilot/Tools/autotest/run_in_terminal_window.sh" "ArduSub" "/home/abel/src/ardupilot/build/sitl/bin/ardusub" "-S" "-I0" "--home" "33.810313,-118.393867,0,270" "--model" "vectored" "--speedup" "1" "--defaults" "/home/abel/src/ardupilot/Tools/autotest/default_params/sub.parm"
SIM_VEHICLE: "mavproxy.py" "--master" "tcp:" "--sitl" "" "--out" "" "--out" "" "--out" "udp:" "--map" "--console"
RiTW: Starting ArduSub : /home/abel/src/ardupilot/build/sitl/bin/ardusub -S -I0 --home 33.810313,-118.393867,0,270 --model vectored --speedup 1 --defaults /home/abel/src/ardupilot/Tools/autotest/default_params/sub.parm
Traceback (most recent call last):
  File "/home/abel/src/ardupilot/Tools/autotest/sim_vehicle.py", line 1072, in <module>
    start_mavproxy(cmd_opts, frame_infos)
  File "/home/abel/src/ardupilot/Tools/autotest/sim_vehicle.py", line 701, in start_mavproxy
    run_cmd_blocking("Run MavProxy", cmd, env=env)
  File "/home/abel/src/ardupilot/Tools/autotest/sim_vehicle.py", line 455, in run_cmd_blocking
    p = subprocess.Popen(cmd, **kw)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
SIM_VEHICLE: Killing tasks

Please help.

(Patrick José Pereira) #16

Please, follow our SITL documentation in ardusub.com.

(Abel Varghese David) #17

I have followed the SITL documentation but still I get the same error.

(Patrick José Pereira) #18

Hi Abel,

It appears that you are using ubuntu or any linux distro. Did you installed all dependencies via install some required packages ? Can you check if mavproxy is installed with whereis mavproxy or pip list | grep mavproxy -i.
If mavproxy is not installed, please run the ubuntu install packages script or install the packages manually.

Also, have you done the add some directories to your search path ? You can check this with echo $PATH | grep ardupilot, it will show the */ardupilot/Tools/autotest.
If you don’t have the ardupilot path in your PATH env variable, please check the previous link and cloning with the command line.

(Abel Varghese David) #19

@patrickelectric yup you were right, it was the mavproxy that did not get installed while running the script.
Now it working fine.

Thanks @patrickelectric

(Patrick José Pereira) #20

Hi Abel,

I’m glad that you figured this out, please let me know if you need any further help.