Using SITL with Webots C/C++

Webots is a simulator mainly used for robotics. It is easy to build many vehicles using it. ArduPilot has Rover, Quadcopter, and Tricopters examples that have been built especially for this simulator.

You can download Webots simulator from www.cyberbotics.com. To run Webots just type webots in command line.

Running the Examples

  1. Open Webots using the command line.

  2. Download and open a vehicle from the vehicle examples folder such as webots_quadPlus.wbt.

  3. Compile the Robot Controller and WorldInfo physics plugin using Webots GUI by opening their respective source files (ardupilot_SITL_QUAD.c and sitl_physics_env.c) and running Build > Build. More info about building with Webots can be found here.

  4. Press Run on Webots GUI. Now the simulator is running.

  5. Run ArduPilot’s SITL using available scripts in the examples folder.

./libraries/SITL/examples/Webots/dronePlus.sh
or
./Tools/autotest/sim_vehicle.py -v ArduCopter -w --model webots-quad:127.0.0.1:5599 --add-param-file=libraries/SITL/examples/Webots/quadPlus.parm

Warning

It is important to run Webots before ArduPilot’s SITL , otherwise the socket connection may not establish.

As of writing, these instructions work with Webots 2021b. Newer versions may or may not work correctly.

Simulation Parameters

There are two types of parameters, the first type is passed to SITL and the second is configured in Webots.

SITL communicates with Webots using TCP sockets, so SITL should have the same port number as Webots. Usually you don’t need to change the default port 5599, but when you run multiple robots you will need to use different ports for each simulation instance.

Advantage of Webots

  1. Controllers can be written in c, c++, python, and MatLab.

  2. A lot of sensors exist.

  3. Ability to add custom physics to simulate things such as wind.

  4. Ability to add OpenStreetMap and run the simulator in environments very similar to reality.

How to Connect Your Own World with ArduPilot

WorldInfo

The following parameters are important to be set in WorldInfo

  • Field “basicTimeStep” = 1 or 2

  • Field “physics” is used to attach the physics plugin file “sitl_physics_env” which is used to simulate wind and drag in a very simple way.

Vehicle Robot

You can copy & paste the vehicle robot multiple times, each time you need to:

  1. give the new robot a new name.

  2. Field “CustomData” should be equal to robot index number i.e. 1,2,3,…etc.

  3. Field “controller” should is selected based on the vehicle used.

  4. Field “controllerArgs” specifies many important factors, mainly the TCP port which should be equal to SITL’s TCP port that will connect to this robot in the simulator.