On the 3DR Solo, we can fly missions manually with the controller, or we can fly automated missions with a ground control station (GCS). By 'automated' we mean the aircraft is not controlled by manual input to the controller's sticks as usual, but rather it is controlled by the autopilot. We give the autopilot a series of points on a map, called waypoints, which make up a mission. We can then start the mission, monitor the aircraft's progress, and send it new commands in-flight, from the GCS.
Before we go and fly automated missions in the real world, it's a good idea to simulate the missions first. It's a good idea because a simulator makes it easy for you to get comfortable with automated missions before taking your precious drone outside for its first automated flight.
For the Solo, there's a nice way of doing that, using the same Tower app on an Android tablet that we will be using for real-world missions. This applies whether we are defining the mission on Tower, or writing a Python script to define the mission.
In this article, I will take you through the process of setting up your simulation environment for Solo missions. I'm going to assume you have access to a Windows PC, but it's also easy to do the same thing on OS X and Linux.
DroneKit is an open source library for creating your own flying robot applications. Through its interface (also known as an API), you can send commands to the flying robot, and monitor the robot's position and altitude. This means that you can use a GCS such as Tower to define and run your Solo missions, but you can also write a program to do that as well. This is useful because you might want to fly special moves that are difficult to define on a tablet, or you might want to have control of the Solo's onboard computer and sensors for extra-special missions.
Python is a great language for many applications, and especially good for robotics. That's why it is the language used by the DroneKit team. If you haven't already started writing scripts in Python, learning to use it to control flying robots is time well spent, and fun too.
Download and install the latest 2.7 from here:
You might be wondering why not use Python 3. Support for Python 3 in DroneKit is coming, but it's not here yet. The example scripts are still written for Python 2.7. As DroneKit is an open source project, you would be most welcome to contribute to it!
SITL stands for 'software-in-the-loop'. It means that in our simulation setup we will be using the same software that controls a real Solo, which is called ArduPilot Copter. That means we can be sure that how the software behaves in the simulation will be quite close to how it performs in the real world, except for the weather, and obstacles like trees, of course.
To install dronekit-sitl, we will use the Python package manager, called pip.
pip install dronekit-sitl -UI
MAVProxy is a very useful piece of software for our flying robot programming toolbox. It's a GCS but it's also a plumbing construction set for drone applications. Its name comes from the messaging protocol used by ArduPilot, called MAVLink, where MAV stands for 'micro air vehicle'.
Install the latest version at:
There's a lot of useful information about MAVProxy here.
On your Android tablet, make sure the latest version of Tower is installed. Use the Play Store app to install Tower, and 3DR Services.
Find out your tablet's IP address
Tower provides a number of ways of connecting to the vehicle (in this case, our simulated vehicle). We'll be using UDP to communicate between MAVProxy and Tower. We will tell MAYProxy on the PC to send UDP packets to Tower on the tablet, which is going to be listening on port 14550. To do that, we need to know the tablet's IP address.
Go to Settings -> About device -> Status. There you should be able to find the tablet's IP address.
It will be different in your case, but for me it's 10.0.0.91. We'll use that in the next step.
Preparing Tower on your tablet
When you start Tower, you should see a screen similar to this one.
Change the protocol to UDP if it isn't already selected. Touch the three dots to specify the port we'll listen to for UDP messages.
Touch 'UDP Server Port' and enter 14550 for the port number.
Start the simulator
Now we're ready to start the simulator on the PC. By default, it will listen on port 5760 for connections.
Next we will start MAVProxy, telling it to connect to the simulator on port 5760, and to send its output to the tablet on port 14550, where Tower will be listening. Make sure to substitute the tablet's IP address in the --out parameter.
In a Command Prompt separate to the one where we started the simulator:
"C:\Program Files (x86)\MAVProxy\mavproxy.exe” --master tcp:127.0.0.1:5760 —out udpout:10.0.0.91:14550
If all is going to plan, on the Windows PC you should see command prompts with the output of the simulator and MAVProxy, which should be connected, and MAVProxy waiting for a connection from Tower.
Connect with Tower
On the Android tablet, in Tower, connect to MAVProxy and the simulator. Now you're all set to plan a mission and execute it, as if you were flying a real Solo.
Here's the setup we just created.
To try it out, define a very simple mission with three waypoints.
Upload the mission to the (simulated) vehicle. When you do that, Tower will automatically add takeoff and return-to-launch (RTL) commands to the mission.
When you're ready to fly the mission, touch 'Arm' and 'Auto'. You will see the aircraft's altitude increase to the mission altitude, in this case 80 meters above ground level (AGL).
The blue rectangle under the aircraft in the display represents what the aircraft's camera can see on the ground, which is useful for ground surveys, and something we'll use in later projects.
In the next article, I'll build on the simulator setup here and take you through the process of writing a Python script to run an automated mission. Until then, take your time and get to know Tower with the simulator.