AC_WPNav is the waypoint navigation controller used by ArduCopter’s Auto, Guided, and related flight modes. It accepts destination waypoints — either asDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Ardupilot/ardupilot/llms.txt
Use this file to discover all available pages before exploring further.
Location objects or NED position vectors — and continuously advances a target position along a smooth trajectory until the vehicle arrives. The library does not directly command motors; instead it feeds position, velocity, and acceleration targets into AC_PosControl, which in turn commands AC_AttitudeControl. Terrain following, object avoidance (via AC_WPNav_OA), and spline paths are all first-class features.
Relationship to AC_PosControl
AC_WPNav holds a reference to AC_PosControl and delegates all thrust calculation to it. The split of responsibility is:
- AC_WPNav — trajectory generation: advance a target point along the route, enforce speed/acceleration/jerk limits, detect waypoint arrival.
- AC_PosControl — control law: compare the target position/velocity/acceleration against the AHRS estimate and compute the roll/pitch angles and thrust vector that will track the target.
AC_WPNav calls _pos_control setters every loop to update the target state, then vehicle code reads back get_roll_rad(), get_pitch_rad(), and get_yaw_rad() (or get_thrust_vector()) from AC_WPNav’s wrapper accessors and passes them to AC_AttitudeControl.
Trajectory generation
Two trajectory types are available, selected per mission segment:S-curve (default)
Jerk-limited kinematic profiles with separate horizontal and vertical S-curves. Three overlapping curve objects (
_scurve_prev_leg, _scurve_this_leg, _scurve_next_leg) allow lookahead blending so the vehicle slows precisely at the waypoint radius without stopping unless required.Spline
Hermite spline paths that pass smoothly through waypoints without stopping. The current and next spline segments (
_spline_this_leg, _spline_next_leg) are computed from set_spline_destination_NED_m(). Used when MAV_CMD_NAV_SPLINE_WAYPOINT is in the mission.Key methods
wp_and_spline_init_m()
wp_and_spline_init_m()
Initializes the waypoint and spline controller. Sets speed and acceleration limits, computes jerk and snap constraints from the attitude controller’s capabilities, and establishes the starting point for the first leg. Must be called before setting any destination.
set_wp_destination_NED_m()
set_wp_destination_NED_m()
Sets the waypoint destination as an NED position vector in meters from the EKF origin. If A
is_terrain_alt is true, the Z component is interpreted as altitude above terrain rather than above the origin. The controller reinitializes the current leg automatically if a previous navigation was in progress.Location-based overload is also available:update_wpnav()
update_wpnav()
reached_wp_destination()
reached_wp_destination()
Returns true once the vehicle has come within the waypoint acceptance radius (
WPNAV_RADIUS) of the destination. The flag is set by advance_wp_target_along_track() and cleared when a new destination is set.get_wp_distance_to_destination_m()
get_wp_distance_to_destination_m()
Returns the current horizontal distance in meters between the vehicle and the active waypoint destination.
get_wp_bearing_to_destination_rad()
get_wp_bearing_to_destination_rad()
Returns the bearing from the vehicle’s current position to the destination waypoint, in radians clockwise from North.
set_speed_NE_ms() / set_speed_up_ms() / set_speed_down_ms()
set_speed_NE_ms() / set_speed_up_ms() / set_speed_down_ms()
Runtime speed overrides. These update the active trajectory limits so that a
DO_CHANGE_SPEED mission command or a GCS speed override takes effect immediately on the current leg.set_pause() / set_resume()
set_pause() / set_resume()
Pauses or resumes progression along the active waypoint track. While paused, the target position stops advancing and the vehicle decelerates to hover at the paused location. Used by object avoidance when an obstacle is detected.
Key parameters
Speed limits
| Parameter | Description | Default |
|---|---|---|
WPNAV_SPEED | Default horizontal speed (cm/s) | 500 |
WPNAV_SPEED_UP | Default climb rate (cm/s) | 250 |
WPNAV_SPEED_DN | Default descent rate (cm/s) | 150 |
Geometric limits
| Parameter | Description | Default |
|---|---|---|
WPNAV_RADIUS | Waypoint acceptance radius (cm) | 200 |
WPNAV_ACCEL | Horizontal acceleration (cm/s²) | 250 |
WPNAV_ACCEL_C | Corner acceleration for turns (cm/s²) | 0 (2× ACCEL) |
WPNAV_ACCEL_Z | Vertical acceleration (cm/s²) | 100 |
WPNAV_JERK | Maximum jerk for S-curve shaping (m/s³) | 1.0 |
Terrain following
| Parameter | Description |
|---|---|
WPNAV_RFND_USE | Enable rangefinder for terrain following (1 = enabled) |
WPNAV_TER_MARGIN | Altitude margin before aborting terrain following (m) |
Terrain following integration
Terrain altitude commands set_is_terrain_alt = true. Each call to advance_wp_target_along_track() then queries either the rangefinder (via set_rangefinder_terrain_U_m()) or the AP_Terrain database to find the current terrain height and adjusts the vertical target accordingly. If neither source is available, update_wpnav() returns false and the calling mode should abort or revert to absolute altitude.
get_terrain_source():
TERRAIN_FROM_RANGEFINDER— real-time, short-range, no map required.TERRAIN_FROM_TERRAINDATABASE— uses theAP_TerrainSD card database for long-range terrain awareness.
Integration with AP_Mission
AP_Mission is responsible for decoding MAV_CMD_NAV_WAYPOINT and similar commands and calling into AC_WPNav. The typical call sequence from ArduCopter/mode_auto.cpp is:
Relationship to AC_Loiter
AC_Loiter is a separate controller (also backed by AC_PosControl) that holds position when no waypoint destination is active. It handles pilot stick inputs for position offset and braking. AC_WPNav and AC_Loiter share the same AC_PosControl instance but are never active simultaneously.
Source location
libraries/AC_WPNav/AC_WPNav.h — waypoint navigation controllerlibraries/AC_AttitudeControl/AC_PosControl.h — position controller used internally