MAVLINKHUD

Smart RTL Mode (Copter)

Executive Summary

Smart RTL (Return to Launch) is a sophisticated variation of the standard RTL mode. Instead of flying a straight line home at a fixed altitude, it backtracks along the exact path the vehicle traveled. This is invaluable when flying around obstacles (like behind a building or under trees) where a straight-line return would result in a crash.

Theory & Concepts

1. The Breadcrumb Algorithm

Smart RTL is a classic Breadcrumb algorithm.
Diagram comparing a raw flight path with a SmartRTL pruned path.

  • The Problem: GPS signals only tell you where you are, not where it's safe to fly.
  • The Logic: "If I flew through here successfully 2 minutes ago, it's probably safe to fly through here again now."
  • Path Pruning: To avoid wasting memory on every tiny movement, ArduPilot uses the Douglas-Peucker Algorithm. It analyzes the path and keeps only the "Corner" points, discarding redundant points on a straight line.

2. Safeguard vs. Beeline

Standard RTL is a "Beeline"—it takes the shortest distance. Smart RTL is a "Safeguard"—it takes the proven distance. ArduPilot will choose the proven distance whenever possible to maximize airframe safety.

Hardware Dependency Matrix

Smart RTL is resource-intensive and relies on precise tracking.

Sensor Requirement Code Implementation Notes
GPS CRITICAL Requires a 3D Lock to record the path points. If GPS is lost during flight, path recording stops.
Compass CRITICAL Required for heading control during the return.
Memory CRITICAL The flight controller allocates a specific buffer (SRTL_POINTS) to store the path.

Control Architecture (Engineer's View)

Smart RTL relies on the AP_SmartRTL library to record and optimize the path in real-time.

  1. Path Recording:
    • As you fly, the controller records your position every SRTL_ACCURACY meters (default 2m).
    • It stores these as 3D vectors in a ring buffer.
  2. Path Optimization (Pruning):
    • To save memory, a background task constantly "prunes" the path.
    • Simplification: It removes points that form a straight line (Ramer-Douglas-Peucker algorithm).
    • Loop Closing: If you fly in a circle and cross your own path, it "cuts the loop," discarding the circle segments. This ensures the return path is always the shortest safe route back.
  3. Execution:
    • When engaged, the vehicle pauses, climbs to RTL_ALT (optional), and then flies the recorded waypoints in reverse order.
    • Once it reaches the arming point, it performs a standard Land.

Failsafe Logic

  • Buffer Overflow: If the buffer fills up (e.g., a very long, complex flight), the system stops recording new points.
    • Warning: Users should monitor the SRTL messages. If the buffer is full, Smart RTL might not bring you all the way back to the latest point, but it will still backtrack the recorded path.
    • Hard Failsafe: If SRTL cannot initialize (e.g., bad GPS at takeoff), the system automatically falls back to Standard RTL or Land.
  • GPS Loss: If GPS is lost in flight, the path becomes invalid. Smart RTL will fail to engage, forcing a fallback to Land/AltHold.

Key Parameters

Parameter Default Description
SRTL_ACCURACY 2.0 (m) Min distance between recorded points.
SRTL_POINTS 300 Max number of points to record. 300 points @ 2m spacing = ~600m of unique path (loops don't count).
RTL_ALT 1500 (cm) Minimum return altitude.
RTL_SPEED 0 Return speed (0 = WPNAV_SPEED).

Source Code Reference

Practical Guide: Testing Smart RTL

Before trusting your drone to backtrack autonomously, verify the buffer logic.

1. The "U" Test

  1. Take off in Loiter.
  2. Fly 20m forward.
  3. Fly 20m Right.
  4. Fly 20m Back (forming a 'U' shape).
  5. Engage Smart RTL.
  6. Observation: The drone should fly Forward -> Left -> Backward (retracing the U).
  7. Failure: If it flies diagonally straight to home, Smart RTL failed (or buffer was empty) and it fell back to Standard RTL.

2. The Loop Cut

  1. Fly a complete circle (starting and ending at the same spot).
  2. Fly 10m away.
  3. Engage Smart RTL.
  4. Observation: The drone should fly straight back to the circle start point, ignoring the loop. This confirms the pruning algorithm is saving memory.