0
0
Pcb-designHow-ToBeginner · 4 min read

How to Create Autonomous Mission in ArduPilot: Step-by-Step Guide

To create an autonomous mission in ArduPilot, define a sequence of mission items such as waypoints and commands, then upload them to the drone using MAVLink or a ground control station. The drone will execute these commands automatically when switched to auto mode.
📐

Syntax

An autonomous mission in ArduPilot consists of a list of mission items. Each mission item includes:

  • command: The action to perform (e.g., waypoint, takeoff, land).
  • params: Parameters for the command like coordinates or altitude.
  • frame: Coordinate frame reference (usually global or relative).
  • auto_continue: Whether to proceed to the next item automatically.

These items are sent to the drone via MAVLink messages or created using a ground control station like Mission Planner.

python
mission_item = {
    'command': 'NAV_WAYPOINT',
    'param1': 0,  # Hold time in seconds
    'param2': 0,  # Acceptance radius
    'param3': 0,  # Pass radius
    'param4': 0,  # Yaw angle
    'x': 47.397742,  # Latitude
    'y': 8.545594,   # Longitude
    'z': 10          # Altitude in meters
}
💻

Example

This example shows how to create and upload a simple mission with two waypoints using pymavlink in Python. The drone will take off, fly to two GPS points, then land.

python
from pymavlink import mavutil

# Connect to the vehicle
master = mavutil.mavlink_connection('udp:127.0.0.1:14550')
master.wait_heartbeat()

# Clear existing mission
master.mav.mission_clear_all_send(master.target_system, master.target_component)

# Define mission items
mission_items = [
    # Takeoff to 10 meters
    mavutil.mavlink.MAVLink_mission_item_message(
        master.target_system, master.target_component, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
        mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 0, 10),
    # Waypoint 1
    mavutil.mavlink.MAVLink_mission_item_message(
        master.target_system, master.target_component, 1, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
        mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, 47.397742, 8.545594, 10),
    # Waypoint 2
    mavutil.mavlink.MAVLink_mission_item_message(
        master.target_system, master.target_component, 2, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
        mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, 47.398000, 8.546000, 10),
    # Land
    mavutil.mavlink.MAVLink_mission_item_message(
        master.target_system, master.target_component, 3, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
        mavutil.mavlink.MAV_CMD_NAV_LAND, 0, 0, 0, 0, 0, 0, 47.398000, 8.546000, 0),
]

# Send mission count
master.mav.mission_count_send(master.target_system, master.target_component, len(mission_items))

# Send each mission item
for item in mission_items:
    msg = master.recv_match(type=['MISSION_REQUEST'], blocking=True)
    seq = msg.seq
    master.mav.send(mission_items[seq])

# Confirm mission upload
master.recv_match(type=['MISSION_ACK'], blocking=True)

print('Mission uploaded successfully.')
Output
Mission uploaded successfully.
⚠️

Common Pitfalls

  • Incorrect coordinate frames: Using the wrong frame (e.g., local vs global) can cause the drone to fly to wrong locations.
  • Missing mission items: Forgetting to include a takeoff or land command can cause mission failure.
  • Not waiting for acknowledgments: Sending mission items too fast without waiting for requests can cause upload errors.
  • Altitude errors: Setting altitude too low or negative can cause unsafe behavior.
python
## Wrong: Sending mission items without waiting for MISSION_REQUEST
master.mav.mission_count_send(master.target_system, master.target_component, len(mission_items))
for item in mission_items:
    master.mav.send(item)  # No waiting for request

## Right: Wait for MISSION_REQUEST before sending each item
master.mav.mission_count_send(master.target_system, master.target_component, len(mission_items))
for i in range(len(mission_items)):
    msg = master.recv_match(type=['MISSION_REQUEST'], blocking=True)
    master.mav.send(mission_items[msg.seq])
📊

Quick Reference

Key commands for autonomous missions in ArduPilot:

CommandDescription
MAV_CMD_NAV_TAKEOFFTake off to specified altitude
MAV_CMD_NAV_WAYPOINTFly to a GPS waypoint
MAV_CMD_NAV_LANDLand at specified location
MAV_CMD_NAV_RETURN_TO_LAUNCHReturn to home position
MAV_CMD_DO_CHANGE_SPEEDChange speed during mission

Key Takeaways

Define mission items with commands and parameters to create an autonomous mission.
Upload missions using MAVLink, waiting for mission requests before sending each item.
Include takeoff and land commands to ensure safe mission execution.
Use correct coordinate frames and altitudes to avoid navigation errors.
Test missions in simulation before flying real drones.