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)
- 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…
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.
- Update brew:
- 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
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
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
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.
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!
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!
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.