How to DroneKit SITL

How to DroneKit SITL

Share it!

Software in the loop, is a software testing technique that will help you test your software using simulations before doing it with real/physical systems. ASAM defines a generic simulator interface as:

Definition of an API between test automation systems and test-benches such as HIL-systems (hardware-in-the-loop) or SIL-systems (software-in-the-loop). Provides access to the simulation model, ECU internal measurement and calibration data, diagnostics data, the electrical error simulation unit and the ECU network. API is described as a technology-independent UML model.

In the case of our beloved drones, we will use SIL techniques to crash them virtually before attempting to test our software on real expensive hardware.

Thanks to the developer team from 3DR, they have developed a full simulator that allows you to run APM Plane, Copter or Rover 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 code without hardware.

The main issue is that sometimes it gets tricky to make it work… or to make it properly…

This small guide will help people who is having problems make it work (also for me when installing it on new systems :P)

Assumptions:

  • This guide is for Mac users (maybe I’ll make a post for windows…)
  • If you have a android tablet, it will work as well (as complement)
  • You know basic stuff on Mac (like using terminal, brew, pip)
  • Brew, pip and python installed

Having said that, lets start the process…

 

Installation.

 

We need basically 3 things, dronekit, dronekit-sitl and mavproxy. MAVProxy is a command-line UAV ground station software package for MAVLink based systems. MAVLink is the “language” that our beloved drones talk.

Steps:

  • Update brew:

brew update

  • Update your pip:

pip install --upgrade pip

  • Install Dronekit:

pip install dronekit

  • Install SITL:

pip install dronekit-sitl

  • Install MAVProxy (execute line by line:

brew tap homebrew/science

brew install wxmac wxpython opencv

pip uninstall python-dateutil

pip install numpy pyparsing

pip install MAVProxy

Usage.

 

The most simplistic usage for this set of tools, is to send commands to a simulated vehicle to take off and land… and see on the screen how is doing it.

To achieve this, we need to create a virtual vehicle and then connect MAVProxy to it, and make MAVProxy spread the information to several devices/applications.

Create a vehicle (on one terminal):

 

dronekit-sitl copter --home=55.870595,-4.287639,0,0

vehicle-sitl

Allow me to explain what I’m doing on this command:

  • copter -> SITL can do plane, copter, rover… I’m making this virtual vehicle a multicopter.
  • –home=55.870595,-4.287639,0,0 -> Making the home of the vehicle outside of the building I work.

 

Start MAVProxy (on a different terminal):

 

mavproxy.py --master=tcp:127.0.0.1:5760 --out=udpout:192.168.1.9:14550 --out=udpout:127.0.0.1:14550 --out=udpout:127.0.0.1:14549

mavproxy-starting

Allow me to explain what I’m doing on this long command:

  • –master=tcp:127.0.0.1:5760 -> I here we declare how to connect this mavproxy instance with the virtual vehicle (drone-kit-sitl creates a TCP connection with a specific port and waits until something connects… In our case, MAVproxy will connect to it.
  • –out=udpout:192.168.1.9:14550 -> I’m making mavproxy proxy all of the information is receiving from the virtual vehicle to a particular IP using UDP… this IP happens to be the one of my tablet. So, as long as my tablet is connected to ALTAX-network, it will be receiving the information of the virtual vehicle.
  • –out=udpout:127.0.0.1:14550 -> Same as above but using localhost, so… mavproxy will proxy the information to my mac using UDP… sounds kinda weird, but this is for using another application like “APM Planner” or “qgroundcontrol” and see the same information as the tablet will see.

 

Open applications:

 

Now, whats rest to do is open a application that will show us “graphically” how the vehicle is doing… just as if it was REAL!! so, go and open “qgroundcontrol” on the mac…

And on the tablet, open “Tower”, and change the telemetry connection type from “usb” to “udp”… thats it!

qgroundcontrol on the mac and tower on the tablet
qgroundcontrol on the mac and tower on the tablet

Take off!

 

Ok, let make the vehicle move or do something fun… execute this lines (as they are written, literally) on the terminal window that is running MAVProxy:

  • mode guided
  • arm throttle
  • takeoff 1000

With this commands you will make the vehicle start flying till it reaches 1000 meters (mental!!!) and then wait, or “loiter”, of course, the battery will start to run out, but no worries, is virtual!

qgroundcontrol - I took this screeshoot when the vehicle was at almost 400 meters
qgroundcontrol – I took this screeshoot when the vehicle was at almost 400 meters

 

Tower app reporting the vehicle was a 1km height.
Tower app reporting the vehicle was a 1km height.

 

If you want your vehicle to land, then just type: “mode land”

Congratulations, you just made a virtual vehicle take off, fly to 1000 meters and then hit ground at 0.509052 m/s. Go have a beer, you earn it.

 

Share it!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.