-
Notifications
You must be signed in to change notification settings - Fork 32
Dronekit mission_basic.py
Dronekit is a python library that allows the user to send mavlink messages to the vehicle. For this project, there will be four main sections for how a python script automates a vehicle's movement. The first is instantiation, the second is arm and takeoff, the third is movement, and the fourth is landing.
When the script is executed, it creates a vehicle object
vehicle = connect(connection_string, baud=57600, wait_ready=True)
where connection_string is a string of an IP address or a physical port on the raspberry pi. In this project, the connection_string will always be /dev/serial0
since we are connecting to the Pixhawk via the GPIO pins. You will also have to specify the baud rate, talked about in starting a vehicle. This line of code will poll for a response. If no connection is established within 30 seconds, the script will throw an error and exit out of the script.
Before the vehicle is allowed to move to a waypoint, the vehicle must poll to see if it is armable and if it is the Guided mode. If neither of these two conditions is satisfied, then the function will be stuck in a loop. Once the drone is armed and is in the Guided mode, then the drone begin executing the instructions it has recieved. For a greater description about what the arm and takeoff function does, look at arm_and_takeoff wiki page (selynna). Also, the vehicle has different modes, each of which has its purpose. To learn more about then click here.
There are two ways a drone can move, either it generates waypoints on the spot and incrementally tells the vehicle to go to each point. The other method is to generate the waypoints prior to movement and then to send the points all at once in the form of a mission. The latter method is the method we have chosen to use to automate movement for the vehicle. In our code, we have a generateWaypoints function that will generate two lists of waypoints, however, we want the second list, a list of waypoints in LLA (Longitude, Latitude, Altitude). With the list of waypoints, we pass them into the adds_mission function.
- Input: List of LLA waypoints
- Output: None adds_mission will construct multiple mavlink messages and send them all to the vehicle. First, the function will clear an existing commands / missinos on the pixhawk. Then, the first command it sends to the vehicle is the takeoff command (however it is ignored if the vehicle is already in the air). After that, the function takes the list of waypoints and iterates through each waypoint. For each waypoint, the function will create a mavlink message that makes the vehicle move to the given waypoint. Once the vehicle has added all of the points, the function will add another dummy waypoint to the list of commands to complete.
Once the Pixhawk has been loaded with all the waypoints, the script can either call arm_and_takeoff and attempt an automated takeoff, or don't call arm_and_takeoff, but a human would have to manually take off the vehicle. Once the vehicle is up in the air, the program will poll for the AUTO mode. This mode is necessary for the Pixhawk to execute the mission that was previously added by adds_mission. Once the AUTO mode has been triggered, the vehicle will begin it's mission. To check if the vehicle has finished there's a while loop that loops until the number of waypoints that the vehicle has visited is equal to the number of waypoints that were generated and passed into the adds_mission function. Once that condition is satisfied, the script will break out of the while loop and it will move onto the last stage.
All it takes to land is to change the mode of the vehicle to RTL (Return To Landing) with vehicle.mode = VehicleMode("RTL")
. Once the vehicle has changed its mode to RTL, it will make it's way back to the location where the vehicle was powered up. At the end of the script, vehicle.close()
is called to close the vehicle object and end the script.
- Project Overview
- Dependency List
- GCS JSON Message Formatting
- Dronekit mission_basic.py
- Continuous Integration with Travis
- Engineering Requirements
- Test Hierarchy
- Style Guide
- Glossary