MAVLINKHUD

ZigZag Mode (Copter)

Executive Summary

ZigZag Mode is a specialized semi-autonomous mode designed for agricultural spraying or lawn-mowing patterns. It allows a pilot to define two points (A and B) and then automatically fly back and forth between them, optionally stepping sideways by a fixed distance (SID_DIST) after each pass.

Theory & Concepts

1. Systematic Coverage (The Lawnmower Pattern)

Systematic coverage is a common robotics problem.

  • The Problem: How to ensure 100% of a field is sprayed without gaps?
  • The Logic: You define a "Baseline" (A to B). You then "Offset" that baseline by a fixed distance (e.g. 5m) for each pass.
  • The Math: ArduPilot uses Parallel Vector Projection. It calculates the perpendicular vector to your path and shifts your target waypoint along that vector.

2. A-B Referencing

ZigZag simplifies the interface for the pilot. Instead of creating a complex mission with 100 waypoints, you only need to fly to two spots. The "A-B" logic allows the drone to generate the rest of the mission "on the fly" in the air, making it extremely efficient for field work where the boundaries might change slightly between flights.

Hardware Dependency Matrix

ZigZag requires precise positioning to fly straight lines.

Sensor Requirement Code Implementation Notes
GPS CRITICAL Required to define Points A and B and to navigate the line between them.
Compass CRITICAL Required for heading and grid alignment.
Barometer REQUIRED Used for altitude hold (Z-axis).

Control Architecture (Engineer's View)

ZigZag combines Loiter (for setup) and WPNav (for execution).

  1. Setup Phase (Loiter):
    • The vehicle flies in a Loiter-like manual mode.
    • Pilot uses an Auxiliary Switch (ZIGZAG_SaveWP) to capture the current GPS coordinates as Point A or Point B.
  2. Execution Phase (WPNav):
    • When triggered, the vehicle calculates a vector from A to B.
    • It uses the AC_WPNav library to fly a straight line to the destination.
    • Sideways Step: If configured, it calculates a perpendicular vector (cross_product) to the line AB and moves ZIGZAG_SIDE_DIST meters before starting the next pass.

Pilot Interaction

  • Switch 1 (Mode): Select ZigZag Mode on the flight mode switch.
  • Switch 2 (Save): A 3-position switch assigned to ZIGZAG_SaveWP (61).
    • Low: Save Point A.
    • Mid: Manual Control.
    • High: Save Point B.
  • Switch 3 (Auto) [Optional]: A switch assigned to ZIGZAG_Auto (62) to toggle the automatic back-and-forth behavior.

Failsafe Logic

  • GPS Loss: If GPS is lost, the mode cannot function. It will trigger a standard EKF Failsafe (Land/AltHold).
  • Boundary: There are no hard geofences specific to ZigZag, but the standard Fence is active.

Key Parameters

Parameter Default Description
ZIGZAG_SIDE_DIST 0 (m) Distance to step sideways after each pass. 0 = Manual switching only.
ZIGZAG_DIRECTION 0 0=Forward/Right, 1=Forward/Left... Defines the step direction.
WPNAV_SPEED 500 Speed of the auto-line flight.

Source Code Reference