# Setting up a simulation environment

**URL:** <https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892>\
**Category:** Blue Robotics Software\
**Tags:** sitl, simulate\
**Created:** [July 2, 2018, 7:04pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892 "2018-07-02T19:04:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paranoia](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Paranoia](https://discuss.bluerobotics.com/u/Paranoia)\
**Post date:** [July 2, 2018, 7:04pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/1 "2018-07-02T19:04:16Z")

</div>

Hey!

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.

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 3, 2018, 10:59pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/2 "2018-07-03T22:59:16Z")

</div>

Hello,

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](http://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.

## Installation

To configure and run SITL for the first time in your computer, take a look in [**Running SITL**](http://ardupilot.org/dev/docs/sitl-simulator-software-in-the-loop.html) 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.

```sh
cd ardupilot/ArduSub

```

To execute SITL with `sim_vehicle.py`.

```sh
sim_vehicle.py -L RATBeach --out=udp:0.0.0.0:14550 --map --console

```

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

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/7/7e841b5c3405ca9c99e6493d7e4fffa2d029c6c1.jpg)

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

```sh
sim_vehicle.py --help

```

### Running ArduSub SITL with Gazebo

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

1. Install [freebuoyancy\_gazebo](https://github.com/bluerobotics/freebuoyancy_gazebo#install) plugin for buoyancy simulation.

2. Install [ardupilot\_gazebo/add\_link](https://github.com/patrickelectric/ardupilot_gazebo/tree/add_link#usage-) 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

4. Execute ArduPilot SITL

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

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/6/6e34936637682cc0a61dde9a9ce7977c230f21a9.jpg)

---

<div class="post-metadata">

**Author:** ![Paranoia](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Paranoia](https://discuss.bluerobotics.com/u/Paranoia)\
**Post date:** [July 7, 2018, 6:01am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/3 "2018-07-07T06:01:23Z")

</div>

Hey,

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.

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [July 9, 2018, 5:47pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/4 "2018-07-09T17:47:10Z")

</div>

ping @patrickelectric

---

<div class="post-metadata">

**Author:** ![Paranoia](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Paranoia](https://discuss.bluerobotics.com/u/Paranoia)\
**Post date:** [July 11, 2018, 1:32am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/5 "2018-07-11T01:32:56Z")

</div>

@patrickelectric I was referred to this page by a helpful person on the gazebo answers site: [Gazebo : Tutorial : Which combination of ROS/Gazebo versions to use](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?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 11, 2018, 12:32pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/6 "2018-07-11T12:32:34Z")

</div>

Hi,

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 ?

---

<div class="post-metadata">

**Author:** ![Paranoia](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Paranoia](https://discuss.bluerobotics.com/u/Paranoia)\
**Post date:** [July 12, 2018, 1:13pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/7 "2018-07-12T13:13:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 12, 2018, 2:08pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/8 "2018-07-12T14:08:59Z")

</div>

Hi,

> 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.

 ![Screenshot%20from%202017-12-21%2000-37-41](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/c/ceb95bcbf80e068d9a4cb13962feef67d71f64ff.png)  
 ![Screenshot%20from%202017-11-27%2013-55-25](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/d/d52522d41bc91152fcd4a7dd5f729ebe391cd616.jpg)

> 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.

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 12, 2018, 8:34pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/9 "2018-07-12T20:34:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paranoia](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Paranoia](https://discuss.bluerobotics.com/u/Paranoia)\
**Post date:** [July 14, 2018, 8:26am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/10 "2018-07-14T08:26:47Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/e/ee7bd6ca0e7836af7b1b053a34d0f0478a3faf1c.jpg)

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/7/783e02cc639044467cfa6290278c155e30507f21.png)

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 16, 2018, 2:06pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/11 "2018-07-16T14:06:25Z")

</div>

This problem was solved in the last version of the QGC development branch.  
[https://github.com/mavlink/qgroundcontrol/pull/6718](https://github.com/mavlink/qgroundcontrol/pull/6718)

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

- [Windows (QGroundControl-installer.exe)](https://s3-us-west-2.amazonaws.com/qgroundcontrol/builds/master/QGroundControl-installer.exe)
- [MAC OS (QGroundControl.dmg)](https://s3-us-west-2.amazonaws.com/qgroundcontrol/builds/master/QGroundControl.dmg)
- [Linux (QGroundControl.AppImage)](https://s3-us-west-2.amazonaws.com/qgroundcontrol/builds/master/QGroundControl.AppImage)
- [Android (QGroundControl.apk)](https://s3-us-west-2.amazonaws.com/qgroundcontrol/builds/master/QGroundControl.apk)

**This links are not BlueRobotics QGC Version**

---

<div class="post-metadata">

**Author:** ![Paranoia](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Paranoia](https://discuss.bluerobotics.com/u/Paranoia)\
**Post date:** [July 18, 2018, 1:07am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/12 "2018-07-18T01:07:31Z")

</div>

Thanks

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?

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/c/c5e80ccf9ce8502bb3e36c025d514b1ce2303114.jpg)  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/d/d88149245216d52804c3e09df4d8b6cfb735577f.jpg)

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?

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [July 18, 2018, 1:22am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/13 "2018-07-18T01:22:50Z")

</div>

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

> [@patrickelectric](#):
>
> You should be able to create a mission without problems with QGC.

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

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 18, 2018, 2:57pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/14 "2018-07-18T14:57:39Z")

</div>

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](https://discuss.bluerobotics.com/uploads/short-url/fZshH8ydJqnhSpeDsAq3dzlddHy.params) (24.3 KB) The parameters that I use in this gif:

 ![deepin-screen-recorder_Select%20area_20180718114426](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/7/7922baf955d224ec0a28ceeed856c524d7fe0f63.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.

---

<div class="post-metadata">

**Author:** ![AbelDavid](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@AbelDavid](https://discuss.bluerobotics.com/u/AbelDavid)\
**Post date:** [August 17, 2018, 11:28am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/15 "2018-08-17T11:28:02Z")

</div>

When I run

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

```

I get the following error when I start the Simulation.

```auto
BUILD SUMMARY
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: Run ArduSub
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: Run MavProxy
SIM_VEHICLE: "mavproxy.py" "--master" "tcp:127.0.0.1:5760" "--sitl" "127.0.0.1:5501" "--out" "127.0.0.1:14550" "--out" "127.0.0.1:14551" "--out" "udp:0.0.0.0:14550" "--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.

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [August 17, 2018, 1:54pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/16 "2018-08-17T13:54:21Z")

</div>

Please, follow our SITL documentation in [ardusub.com](https://www.ardusub.com/developers/sitl.html).

---

<div class="post-metadata">

**Author:** ![AbelDavid](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@AbelDavid](https://discuss.bluerobotics.com/u/AbelDavid)\
**Post date:** [August 19, 2018, 7:28am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/17 "2018-08-19T07:28:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [August 19, 2018, 1:11pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/18 "2018-08-19T13:11:33Z")

</div>

Hi Abel,

It appears that you are using ubuntu or any linux distro. Did you installed all dependencies via [install some required packages](http://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html#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](http://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html#add-some-directories-to-your-search-path-facultative) ? 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](http://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html#cloning-with-the-command-line).

---

<div class="post-metadata">

**Author:** ![AbelDavid](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@AbelDavid](https://discuss.bluerobotics.com/u/AbelDavid)\
**Post date:** [August 20, 2018, 4:37am UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/19 "2018-08-20T04:37:56Z")

</div>

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

Thanks @patrickelectric

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [August 20, 2018, 1:09pm UTC](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892/20 "2018-08-20T13:09:42Z")

</div>

Hi Abel,

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

[Next page](https://discuss.bluerobotics.com/t/setting-up-a-simulation-environment/2892.md?page=2)
