0
0
Pcb-designHow-ToBeginner · 3 min read

How to Upload Mission Using DroneKit: Simple Guide

To upload a mission using dronekit, create a list of Command objects representing waypoints, clear any existing mission, add new commands, and then upload them with vehicle.commands.upload(). This process sends the mission to the drone's autopilot for execution.
📐

Syntax

Uploading a mission in DroneKit involves these steps:

  • Clear existing mission: vehicle.commands.clear()
  • Add new commands: Use vehicle.commands.add(command) for each waypoint or command
  • Upload mission: Call vehicle.commands.upload() to send the mission to the drone

Each Command defines a waypoint or action with parameters like latitude, longitude, altitude, and command type.

python
vehicle.commands.clear()
vehicle.commands.add(command1)
vehicle.commands.add(command2)
...
vehicle.commands.upload()
💻

Example

This example connects to a drone, creates a simple mission with two waypoints, clears any existing mission, adds the new waypoints, and uploads the mission.

python
from dronekit import connect, VehicleMode, Command
from pymavlink import mavutil

# Connect to the vehicle
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# Clear existing mission
vehicle.commands.clear()

# Create mission commands
cmd1 = Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
               mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0,
               47.397742, 8.545594, 10)  # lat, lon, alt
cmd2 = Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
               mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0,
               47.397825, 8.545600, 10)

# Add commands to mission
vehicle.commands.add(cmd1)
vehicle.commands.add(cmd2)

# Upload mission to vehicle
vehicle.commands.upload()

print('Mission uploaded successfully')

# Close vehicle connection
vehicle.close()
Output
Mission uploaded successfully
⚠️

Common Pitfalls

  • Forgetting to clear existing missions before adding new commands can cause unexpected behavior.
  • Not calling vehicle.commands.upload() means the mission won't be sent to the drone.
  • Incorrect coordinate frames or command parameters can cause mission failure.
  • Always wait for the vehicle to be ready before uploading missions.
python
## Wrong way: Forgetting to clear and upload
vehicle.commands.add(cmd1)
vehicle.commands.add(cmd2)
# Missing vehicle.commands.clear() and vehicle.commands.upload()

## Right way:
vehicle.commands.clear()
vehicle.commands.add(cmd1)
vehicle.commands.add(cmd2)
vehicle.commands.upload()
📊

Quick Reference

Remember these key steps to upload a mission:

  • Clear existing mission with vehicle.commands.clear()
  • Add new Command objects with vehicle.commands.add()
  • Upload mission using vehicle.commands.upload()
  • Use correct MAVLink command types and coordinate frames

Key Takeaways

Always clear existing missions before adding new commands to avoid conflicts.
Add each waypoint or action as a Command object to the vehicle's command list.
Call vehicle.commands.upload() to send the mission to the drone's autopilot.
Ensure the vehicle is connected and ready before uploading the mission.
Use correct MAVLink command types and coordinate frames for reliable missions.