Task 1
Pathing
Stage 1: Takeoff
There are two components to the takeoff sequence. The drone must first takeoff from the initial position to an altitude of 100 metres. The drone will then traverse to waypoint Alpha.
Create a CSV file to store the location (in latitude and longitude) of waypoint Alpha.
Create a takeoff command to climb to 5 metres.
Add a command to go to waypoint Alpha at an altitude of 100 metres.
Append these commands to the command sequence
Stage 2: Running Laps
The drone will run laps around waypoint Alpha to waypoint Bravo. A full lap consists of flying from waypoint Alpha to Bravo to Alpha. The drone must fly around the waypoints.
Create a CSV file to store the location of 4 points. The 4 points will be used to mark the locations to run a lap around waypoints Alpha and Bravo.
Create a list of commands to follow the waypoints 1 → 2 → 3 → 4. This represents a lap for the drone.
Â
Set a hardcoded value (let’s call this N) to determine the number of laps the drone will run in task 1.
Get the mission to follow a lap, add it to the mission N number of times, add a command to return to launch (RTL) and upload the mission to the drone.
So the command sequence will have a takeoff command, a command to go to waypoint Alpha, and then the commands to run N number of laps.
Note: For the last lap, the program will need to append location 1 to the command sequence. This way, the drone will complete the last lap rather than stop at location 4.
When the mission is uploaded to the drone, an evaluate function will run periodically. The purpose of the evaluation function is to determine if the drone should continue running laps or if it should clear the current mission and land (see the Landing section below). Below is a list of factors the program must consider to decide if it should land or continue running laps.
Time: If we are let’s say 5 minutes away from the end of the flight time then we land. We will use a hardcoded value to determine how much time we will allocate for landing.
Battery: TODO confirm if this automatically causes RTL.
Stage 3: Landing
If the program determines it is time for the drone to land, the landing sequence will be initiated.
Clear the current mission on the drone.
Create a RTL command.
Add the RTL command to the drone’s command sequence.
Upload the new mission which only contains the RTL command.
Implementation
Create a DroneKit vehicle object.
# Wait ready is false as the drone may be on the ground
drone = dronekit.connect(CONNECTION_ADDRESS, wait_ready = False)
Create a dictionary that maps waypoint name (e.g. Alpha) to its latitude and longitude in decimal degrees. This will be done in the main function.
Create a CSV file to store the waypoint name and its corresponding latitude, longitude
Call the
load_waypoint_name_to_coordinates_map
module to read the waypoint CSV file and convert it into a dictionary.
Create a dictionary that maps the locations 1, 2, 3, and 4 to its latitude and longitude in decimal degrees. TODO: We will want to come up with better names that location 1, 2, 3, and 4. This will be done in the main function.
Create a CSV file to store the waypoint name and its corresponding latitude, longitude
Call the
load_waypoint_name_to_coordinates_map
module to read the waypoint CSV file and convert it into a dictionary.
Create a module that appends a takeoff command to the beginning of the drone’s command sequence and an RTL command at the end of the drone’s command sequence. (Note: this is similar to the
add_takeoff_and_landing_command
module but the RTL command is added instead of LAND command).Create a module that adds the laps N number of times (N is the hardcoded number of laps that is set)
First, we need to convert the dictionary that maps waypoint names to world coordinates (latitude and longitude) to a list of coordinates. This can be done by calling the
waypoints_dict_to_list
module.Create a list that specifies the route the drone needs to take in order to run N laps
Turn the list of waypoints to DroneKit commands. This can be done with the
waypoints_to_commands
module.
In the main function, we can get the list of DroneKit commands to run laps by calling the module described in point 5, and append the takeoff and RTL command to the command sequence by the module described in point 4.
Upload the mission to the drone. This is done in the main function. This can be done with the
upload_commands
module.Create a module that gets information from the drone and determines if the drone should RTL or continue with the mission. This module will return a boolean value that represents if the drone should land or not.
To account for the time constraint, take the start time in as a parameter and subtract it from the current time to get the time difference. We can set a threshold for how much time we want to allocate for landing and see if we are past that threshold).
Create a module that clears the drone’s current mission and sends an RTL command. The
upload_commands
function can be used to upload to the drone.In the main function, we can have an infinite while loop that has a delay of x number of seconds (x is a hardcoded value) and call the module described in point 8. If module returns true, then break out of the infinite loop and call the module described in point 9.
Conditions to Force Early RTL
Running out of time
Battery low (we have 12000mah, need to determine how much energy to keep for safe landing. Guessing ~ 1000 mAh for now)
Critical system failure →