A sample mission created using python
Too long, didn't read: For complex autonomous flights, create missions using python instead of mouse clicking each command on Mission Planner. For instance, go 1km straight and at each 10 meter, stop and took panoramic shoot. Source code is here.
Note to DIYDrones community: This is my first blog post, and although this is pretty simple and not complicated topic, I decided to start from low level - basic stuff. Forgive me since it is my first attempt :).
Before you begin reading this article, if you want to have a better understanding about drones, what they are, how they work, please refer to this excellent site and from there move on to the suggested pages.
Drones are (in this context) aerial vehicles that fly according to the operators' input or fly autonomously. We will focus on the latter. In autonomous flights, drone follows specific instructions that are put in order, combination of which are called a mission. Missions are prepared before the flight and uploaded to the flight controller. When activated, drone starts to execute the mission.
What is a Mission?
Missions are composed of discrete commands. Each command dictates a specific action.
When the autonomous mode is activated, the drone starts to execute the commands, beginning from the first command and after completing it, starts to execute the next command till all commands are executed or auto mode deactivated. Please have a look at http://copter.ardupilot.com/wiki/mission-command-list/ for detailed description about missions.
Some commands are:
When you combine these commands, it becomes a mission. For instance, takeoff, then go to the this point (point you clicked on a map), look at the stadium, take a photo, go to my house, and land.
It is all cool and fun to fly the drone autonomously. The mission based flights are precise, you tell the drone where to go at which speed, how much to wait, drop the cargo at specified point etc., and it will follow the orders as precise as the sensors allow. However, unfortunately these commands are supplied by hand. For instance, if you will prepare a mission consists of 100 waypoint (ie 100 point to visit), you have to supply those 100 points manually, modify each points altitude, delay time etc., which is pretty time consuming and there is an increased chance of making error during the preparation process. The exceptions are mapping, creating text, and create circular motion missions, which are automatically prepared by the mission planner based on your input parameters. But if you need to prepare another mission, you have to do the whole job.
The mission files are saved as text files and each line in the file represents a command: an ID of the action and its parameters. A sample line (one command) in a mission is shown below:
16 41.112469 27.740479 100
16 indicates it is 'waypoint' command, following 2 numbers are latitude and longitude (position), and final one is altitude.
I should say that it turns out the process is extremely easy, but the motivation for me to write and share the code is to make this even easier and make it ready to use whenever someone needs.
We produce the command in python file, save it in txt file which mission planner directly opens it as if it is planned using mission planners own user interface. The good thing is that you will see the visualization of your mission on the map and will access each command, so any error you made will be easy to catch.
Lets move to the sample code:
from automission import automission
import the module and create an instance 'my_mission'. It will represent our mission.
The coordinates and altitude that I will use at the beginning.
As it is seen, my first command is takeoff, it will takeoff to a 15 meters.
Next command is that I want it to go to the specified location and altitude.
Roi stands for region of interest, from now on drone the front of the drone (or camera) will look at this point regardless of where the drone is going.
for i in range(15):
my_mission.do_digicam_control() alt= alt+10
lat+=1 if i%4==0 else 0
lon+=1 if i%4==1 else 0
lat+=1 if i%4==2 else 0
lon-=1 if i%4==3 else 0
There is a loop with 15 cycle, at each cycle the altitude is increased 10 meters, and drone moves square-wave pattern. Moreover, at the each corner it takes photograph with the digicam command.
Finally we tell her to return to the home and land.
my_mission.write() saves the mission in as txt file. When we open it in Mission Planner (flight plan tab, load WP file button) here is our mission:
We've just created a mission! When we upload it to the drone and activate AUTO mode, it will follow these commands.
Here is another example. Slightly modifying the for loop, one can easily obtain a vortex;
increase=0.001for i in range(20):
lat+=increase if i in range(0,20,4) else 0
lon+=increase if i in range(1,20,4) else 0
lat-=increase if i in range(2,20,4) else 0
lon-=increase if i in range(3,20,4) else 0
What is next, and possible applications
The automission script and example codes can be accessed from GitHub: https://github.com/unnamed-idea/auto-mission-prepare-for-mission-pl...
This post can also be accessed from my site, http://talhakorkmaz.com/drone/preparing_auto_mission/