สถาปัตยกรรม PX4 และ ArduPilot

Software structure, parameters, flight modes, failsafes and geofences

Last updated:

Overview: two systems, one set of ideas

An autopilot is the software on a flight controller that reads the sensors, estimates position and attitude, computes commands and drives the motors hundreds of times a second. The two open-source autopilots most used in education and industry are PX4 and ArduPilot. Both support multirotors, fixed-wing aircraft, VTOL and ground vehicles, and both talk to a ground control station (GCS) using the MAVLink protocol.

Operators need to understand this structure for two reasons. Most flight problems are solved quickly once you know which layer the symptom comes from: sensors, estimation, control loops or failsafe settings. And the aircraft's behaviour when something goes wrong is set by parameters that we choose; it does not happen by itself.

From sensors to motors

Both systems follow a similar chain:

  1. Sensor drivers read the IMU, barometer, compass, GNSS and any extra sensors.
  2. The state estimator fuses all sources with an EKF into best estimates of position, velocity and attitude. PX4 uses EKF2; ArduPilot uses EKF3.
  3. Navigation and flight modes turn a mission or stick input into targets.
  4. Cascaded controllers run the position, velocity, attitude and rate loops.
  5. The mixer converts the required thrust and moments into individual motor commands for the ESCs.

They differ in how the software is organised. PX4 is split into independent modules such as the estimator, controllers and the commander that manages vehicle state. Modules exchange data through uORB, a publish/subscribe messaging system: one module publishes a topic and any interested module subscribes. Modules can be replaced or added without touching the others. PX4 runs on the NuttX real-time operating system.

ArduPilot has vehicle-specific code such as ArduCopter and ArduPlane on top of shared libraries, with a hardware abstraction layer (HAL) that hides board differences. Work is organised by a scheduler inside a main loop: urgent tasks such as the rate controller run every cycle, others run at rates listed in a task table. Copter's main loop defaults to 400 Hz.

Parameters: what actually defines behaviour

Parameters are settings stored in the flight controller's non-volatile memory. Each system has thousands, covering tuning gains, limits, port assignments and failsafes. Names usually start with a group prefix: in ArduPilot, ATC_ for attitude control and FENCE_ for geofencing; in PX4, MC_ for multicopter control and COM_ for the commander.

Three habits keep parameters under control. Save the complete parameter file before any change. Change one value or one group at a time, then test. Record the firmware version alongside the file, because names, units and defaults change between releases, so a file from another aircraft or another version should never be loaded wholesale.

Flight modes

A flight mode decides at which loop the pilot or the automation gives commands. Names differ slightly between the two systems; the ideas match.

LevelPX4ArduPilot CopterWhat the pilot commands
AttitudeStabilizedStabilizeLean angle and throttle
Altitude holdAltitudeAlt HoldLean angle and climb rate
Position holdPositionLoiterDesired velocity; centred sticks hold position
AutomaticMission, Hold, Return, LandAuto, Guided, RTL, LandThe system generates its own targets

Modes that rely on GNSS are unavailable when the position estimate is poor. The autopilot will refuse the mode or fall back to a lower one, which is why pilots must stay proficient in attitude modes.

Failsafes and geofences

A failsafe is a rule the autopilot applies on its own when an abnormal condition occurs: RC signal loss, GCS link loss, low battery or a failed estimator. Each has a trigger (for example, no heartbeat from the GCS for longer than a set time) and an action (RTL, land, or continue the mission). A heartbeat is a MAVLink message sent periodically to show that the other side is still present.

Some failsafes are disabled by default, including GCS link-loss failsafe in both systems (check the documentation for the version you fly). If you do not configure it, an aircraft flying an automatic mission keeps going after the station has lost contact.

A geofence is a virtual boundary that the autopilot checks continuously: an altitude ceiling, a circle around home, or polygons. ArduPilot distinguishes inclusion fences, which the aircraft must stay inside, from exclusion fences, which it must not enter. On a breach the aircraft performs the configured action such as Hold, RTL or Land. Because it needs distance to stop, the fence must sit inside the edge of the approved area.

Worked example: which failsafe fires first?

Example: link lost while flying outbound

Assume an approved area that is a 300 m circle around home. The drone flies outbound at 8 m/s at 40 m height, with 1 s response time, 3 m/s² braking and 3 m GNSS error. The GCS failsafe waits 5 s and then commands RTL. Average power is 400 W and the battery is 14.8 V, 5,000 mAh. All values are assumed.

  1. Fence placement: stopping distance = 8 × 1 + 8²/(2 × 3) = 8 + 10.7 = 18.7 m, plus 3 m GNSS error = 21.7 m. The fence must be no further than 300 − 21.7 = 278.3 m, so set it at 275 m.
  2. Link lost at 250 m: the GCS failsafe would fire after 5 s, by which time the drone would be 40 m further out at 290 m. But it reaches the 275 m fence in 25/8 = 3.1 s, so the fence acts first.
  3. Furthest point: 275 + 18.7 ≈ 293.7 m, or 296.7 m including position error, still inside 300 m.
  4. RTL energy: return 293.7/8 = 36.7 s, descend 40 m at 1.5 m/s = 26.7 s, loiter 5 s; total 68.4 s. Energy 400 × 68.4/3600 = 7.6 Wh out of 14.8 × 5 = 74 Wh, or 10.3%.

Failsafe layers back each other up, and which one fires first depends on position and speed at the moment of failure. Every value must be confirmed in SITL and in real tests on the firmware you fly, not taken from the calculation alone.

Common pitfalls

  • Assuming the drone will come home on link loss without checking that the failsafe is enabled.
  • Loading a whole parameter file from another aircraft or firmware version.
  • Changing many parameters at once, then not knowing which one changed the behaviour.
  • Drawing the fence exactly on the approved boundary with no allowance for stopping distance.
  • Keeping the default RTL altitude where buildings or trees are taller.
  • Raising the loop rate beyond what the board can handle without checking scheduler load.
  • Testing in SITL with a different version or parameter set from the real aircraft.

Continue in the lessons

Key references

  1. PX4 Autopilot. PX4 architectural overview. PX4 user guide (main). link
  2. PX4 Autopilot. Safety (failsafe) configuration. PX4 user guide (main). link
  3. ArduPilot Dev Team. Flight modes. ArduPilot Copter documentation. link
  4. ArduPilot Dev Team. GCS failsafe. ArduPilot Copter documentation. link
  5. ArduPilot Dev Team. Inclusion and exclusion fences. ArduPilot Copter documentation. link
  6. MAVLink Development Team. Heartbeat/connection protocol. MAVLink developer guide. link

Used in courses

How to cite this page

Drone Institute, Rangsit University. (2026). สถาปัตยกรรม PX4 และ ArduPilot. In UAS Technology Knowledge Hub (B.Tech.). https://rsu-uat.pk-research.work/en/kb/new/autopilot-px4-ardupilot/