Ardupilot Tuning Guide
Ardupilot Tuning Guide
Waypoint Navigation
Loiter Mode
Acceleration Up/Down
Stabilize Mode
Acro Mode
Filters incl. Gyro and Accelerometer Low Pass; RPM and FFT Harmonic Notches; FLTE, FLTD and FLTT
Hardware used
• AOS UL8 Frame
• Matek H7A3 Flight Controller (or
any FC with an Ardupilot target)
• 4in1 ESC
• M10 GPS and Compass module
• ELRS 2.4GHz Receiver
• DJI O3 Air Unit (also works with
O4)
Wiring – 4in1 ESC
• Wiring from the FC to ESC is very
important
• If you have not bought a “stack” then
you MUST carefully check the pin-outs
between FC and ESC
• Some combinations will apply reverse
polarity and burn your flight
controller on first power up! 😱
• If pinouts don’t match then you can
re-pin the plug using a pair of
tweezers 👍
Wiring – GPS + Compass
• Wiring from the FC to GPS is pretty
easy
• For Ardupilot you’ll need to connect
SCL-SCL, SDA-SDA, TX-RX, RX-TX, GND
and 5V
• Make a note of the number of the
serial port (TX/RX) for the GPS
• SCL/SDA are for the Compass
• TX/RX are for the GPS
Wiring – Receiver
• Wiring from the FC to ELRS is pretty
easy
• You’ll need to connect TX-RX, RX-TX,
GND and 5V
• Make a note of the number of the
serial port (TX/RX) for the Receiver
Wiring – DJI O3/O4
• Wiring from the FC to the Air Unit is
pretty easy
• You’ll need to connect TX-RX, RX-TX,
GND and PWR (7.4 – 26.4V)
• Make a note of the number of the
serial port (TX/RX) for the Air Unit
Setup – Flashing Ardupilot
• If your FC does not have Ardupilot installed
• https://firmware.ardupilot.org/
• Copter
• Check Latest for your target
• If you can’t find it there try Beta
• Download arducopter_with_bl.hex (with bootloader)
• Flash with STM32 Cube Programmer (full chip erase)
Mission Planner
• There is a log download bug with
the latest version of Mission
Planner 1.3.82
• Use 1.3.81 or apply Beta
Updates from the Help Page!
Setup – Frame Type
• Mission Planner > Setup Tab >
Mandatory Hardware > Frame
Type
• Calibrate Accel
• Reboot!
• Calibrate Level
Setup – Compass
• Mission Planner > Setup Tab >
Mandatory Hardware >
Compass
• Calibrate Radio
• Check Roll, Pitch, Yaw, Throttle
channels are correct
• Centre stick should be exactly
1500
• Low stick < 1000
• High stick > 2000
Setup – Radio Calibration
• Mission Planner > Setup Tab >
Mandatory Hardware > Radio
Calibration
• Calibrate Radio
• Check Roll, Pitch, Yaw, Throttle
channels are correct
• Centre stick should be exactly
1500
• Low stick < 1000
• High stick > 2000
Setup – Servo Output
• Mission Planner > Setup Tab >
Mandatory Hardware > Servo
Output
• Set servo outputs 1-4 as Motor
Outputs 1-4
• For typical 4in1 ESCs the
correct Servo Number and
Motor Number won’t match
• This will be addressed in Motor
Test later on
Setup – Serial Ports
• Mission Planner > Setup Tab >
Mandatory Hardware > Serial
Ports
• Set serial ports according to
your wiring
• Receiver -> RCIN, baud rate
shouldn’t matter
• GPS -> GPS, baud rate is usually
57600
• DJI O3/O4 -> Display Port , baud
rate is 115200
Setup – ESC Calibration
• Don’t click Calibrate ESCs this
can get your FC stuck in a loop
and cause issues with digital
ESCs that don’t support PWM
protocol (E.g. BlueJay)
• Set ESC Type to DShot300
• Spin when armed -> 0.05 to 0.1
• Spin minimum -> 0.1 to 0.15
• Spin maximum -> 1.0
Setup – Flight Modes
• Set up your flight mode switch
• You may want to change which
channel on your radio controls
flight modes
• Config > Full Parameter List >
FLTMODE_CH will accomplish
this
• Use Search!
Setup – Failsafe
• In general your Failsafe should
probably be RTL (Return To
Home and Land)
• Defaults are usually good but
check low battery voltage and
time
Setup – Battery Voltage
• Mission Planner > Setup Tab >
Optional Hardware > Battery Monitor
• The voltage measurement should be
correct by default if you’ve flashed the
right target
• The current measurement will depend
on the value of the current sense
resistor on the ESC
• Typical values
• 25 mOhm -> 40 Amps per Volt
• 10 mOhm -> 100 Amps per Volt
Setup – Motor Test
• Mission Planner > Setup Tab > Optional
Hardware > Motor Test
• REMOVE PROPS!
• For typical 4in1 ESCs the motor order will be
wrong!
• You must test and check that the correct motor
spins and that it spins in the right direction
according to your diagram
• Double check or you will have a big crash on
take-off!
• If you are using a typical Betaflight 4in1 ESC in
the usual orientation
• Servo 1 -> Motor 4
• Servo 2 -> Motor 1
• Servo 3 -> Motor 2
• Servo 4 -> Motor 3
Setup – Motor Test
• REMOVE PROPS!
• For typical 4in1 ESCs the motor order
will be wrong!
• You must test and check that the correct
motor spins and that it spins in the right
direction according to your diagram
• Double check or you will have a big
crash on take-off!
• If you are using a typical Betaflight 4in1
ESC in the usual orientation
• Servo 1 -> Motor 4
• Servo 2 -> Motor 1
• Servo 3 -> Motor 2
• Servo 4 -> Motor 3
Setup – Compass Interference
• Mission Planner > Setup Tab > Optional
Hardware > Compass/Motor Calibration
• Not essential but can be good to check
• Flip props over so drone is pulling down
onto the ground
• Run up to 50-75% throttle for 5-10 seconds
to see the effect on the compass reading
• If interference is less than 30% then that’s
acceptable
• Less than 60% might be OK but consider
relocating the compass away from motor
wires/battery cables
• More than 60% you should relocate the
compass
Gyro Settings
• Mission Planner > Config Tab >
Full Parameter List
• For F7 and H7 boards it can be
beneficial for flight performance
and tuning of smaller drones to
set
• INS_FAST_SAMPLE = 1
• INS_GYRO_RATE = 1 (2kHz)
• This avoids aliasing of motor
frequencies above 500Hz
• It should be set by default on
modern boards
Setup – Logging
• Mission Planner > Setup Tab >
Optional Hardware > FFT Setup
• Correct logging settings are
essential for tuning
• Sample count = 1024 or 2048
• Typically it is best to log only
IMU1 to avoid overloading and
logging drop-outs
• The logging bitmask should be set
as shown
• This captures all the data needed
for the tuning process
Setup – Logging
• Mission Planner > Config Tab >
Full Parameter List
• INS_LOG_BAT_OPT = 5
Hover Test!
• Do the hover test in the
Stabilized Flight Mode
• You may find that the Pitch Axis
is reversed compared to
Betaflight
• If so set parameter
RC2_REVERSED = 1 to fix this
Filter Tuning
Waypoint Navigation
Loiter Mode
Acceleration Up/Down
Stabilize Mode
Acro Mode
Filters incl. Gyro and Accelerometer Low Pass; RPM and FFT Harmonic Notches; FLTE, FLTD and FLTT
Download the log
• You can download logs within
Mission Planner > Data >
DataFlash Logs
• Logging space is finite so unless
you have a big SD card
periodically clean the logs
• Once the log has downloaded you
can review it within Mission
Planner
• Make a note of where your logs
are saved
• Usually \Documents\Mission
Planner\logs\QUADROTOR\1
Check RPM Data
• After a hover test check the RPM
data in the log
• As you can see I am getting random
spikes only on ESC[0]
• This is a conflict on the Servo Rewire Servo Output 1 to
Output 1 pin for the Matek H7A3 Servo Output 5
• If you see this:
• Consider rewiring and using a different
servo output pin for that motor👍
• Change SERVO_BLH_BDMASK to
ignore that channel 😑
• Use FFT rather than BDSHOT for
Harmonic Notch 👎
Setup - Harmonic Notches
• Mission Planner > Config Tab >
Full Parameter List
• Set INS_HNTCH_ENABLE = 1 to
show notch parameters
• INS_HNTCH_HMNCS = 7 for 3
harmonics (tri-blade props)
• INS_HNTCH_MODE = 3 (RPM)
• INS_HNTCH_OPTIONS = 0 (to
begin with)
Setup – Bi-Directional DShot for RPM (best)
• Set RPM1_TYPE = 5 for bidirectional DShot
• Set RPM1_ESC_MASK = 15 for all 4 motors
• Set SERVO_BLH_BDMASK = 15 for all 4 motors
• Set SERVO_BLH_POLES = N
• N = number of magnets in the motor
• 14 is typical for 4” to 10” motors
• 12 is typical for 3” motors
• If in doubt, count 😁
• Set SERVO_DSHOT_ESC =
• 1 for Kiss/AM32/BL32
• 2 for BlueJay
• All latest ESC FWs supports Extended DShot
Telemetry (EDT) so you can try 3 and 4 instead if
you want the extra information
Setup – Dynamic FFT (if no RPM available)
• Set FFT_ENABLE = 1 to enable FFT and show
parameters
• Set INS_HNTCH_MODE = 4 to use FFT to drive the
notches
• Set FFT_MAXHZ = X
• X = 0.8*Vbatt*KV/60
• Vbatt = Fully charged battery voltage
• KV = Motor KV
• Set FFT_MINHZ = Y
• Y = 500 / Dprop
• Dprop = Prop Diameter in Inches
• Set FFT_WINDOW_SIZE = 256 (F7) or 512 (H7)
• Resolution is INS_GYRO_RATE / FFT_WINDOW_SIZE
• ~8Hz for 256
• ~4Hz for 512
• You will benefit from FFT_WINDOW_SIZE = 1024 on an H7
if CPU speed allows!
Dynamic FFT uses gyro data to
What is Dynamic FFT Dynamic FFT uses gyro data to
locate noise peaks between a
locate noise peaks
minimum and maximum frequency
Turn on Notch
Tracking
Filter Review – IMU Spectrogram – RPM Filter
We probably don’t We could probably
• Tri-blade props typically need 3 need a 4th harmonic try without a second
harmonics, but sometimes only the as noise power is harmonic as well!
first and third are needed very low
INS_HNTCH_HMNCS = 7 (or 5)
• Bi-blade props typically need at
least 2 harmonics but sometimes
more, check logs!
• INS_HNTCH_HMNCS = 3 (or more)
Look at Post-Filter
Filter Review – IMU Spectrogram – RPM Filter
FFT vs RPM
• For Motor Noise RPM based
harmonic notch filtering is superior to
Dynamic FFT based filtering
• If you know the motor RPM you know
the exact noise frequency FFT
immediately with no delay
• With Dynamic FFT you have to
calculate it with a nasty trade-off, the
higher your frequency resolution the
lower your temporal resolution:
• For 2Hz frequency resolution you need
to sample for 0.5 seconds, and that’s a
long time in the world of notch filters!
RPM
FFT vs RPM
• Dynamic FFT is extremely useful in
addition to RPM filtering for
dealing with airframe resonance
• It can also be used for motor noise FFT
Derivative
Feedforward
𝑑
Target Rate 𝑑𝑡 Proportional
of rotation term
+ PID error
Actual Rate
- න 𝑑𝑡
Integral term PID
gains
Motor
mixer
of rotation
𝑑 Derivative term
𝑑𝑡 All the PID gains
live here
Proportional term
The P term acts like
the spring in a PID error
suspension strut
PID error
PID error PID error
PID error PID error
Actual
The D term acts like
the shock absorber
Actual in a suspension strut
Actual Actual
Actual Actual
Actual Actual
Derivative term
wants the Actual Actual
value to stay the
same and pushes
against any change.
P:D balance
• Just like in a suspension strut the balance
between the spring strength (P term) and the
size of the shock absorber (D term) is very
important
• The Ardupilot default P:D balance is usually a
suitable starting point but not always!
• The right balance between P and D terms is the
first step of a good PID tune
Integral term
PID error PID error PID error PID error PID error
Target
Target Target
Target Target
Target Target
The feedforward
term pushes in Target
proportion to the
absolute value of
the Target
Derivative Feedforward term
The derivative feedforward term
allows the PID controller to react
instantly before PID error builds up.
Target
Correctly set it helps reduce and even
eliminate delay between target and
Target actual values.
Target Target
Target Target
Target Target
The derivative
feedforward term Target
pushes in the
direction the target
is changing
P:I balance and D->P->I->DFF->FF tuning
approach
• In the same way as the D term prevents the P term oscillating the P
term prevents the I term oscillating
• As a result there is an ideal P:I ratio for a controller that allows the
maximum I term without oscillations
• This gives us the relationship D->P->I->DFF->FF which guides the
tuning process: D term first, then P term, I term, DFF and finally FF
Actual
Tuning P:D balance
deg/s
• Without DFF the Actual will
always lag the target, that’s OK
for now
👍
deg/s
Actual peak value > Target peak value
Too much P term relative to D term
deg/s
Actual peak value < Target peak value
Not enough P term relative to D term
Decrease P term relative to D term.
controllers
Acceleration Acceleration
• The difference between Desired East/West North/South
Desired
Angle
+ Angle error
x Proportional
Target
rate of
- term
rotation
Actual Angle
The Ardupilot Rate PID-FF-DFF Controller
Feedforward
Derivative
Feedforward
𝑑
Target Rate 𝑑𝑡 Proportional
of rotation term
+ PID error
Actual Rate
- න 𝑑𝑡
Integral term PID
gains
Motor
mixer
of rotation
𝑑 Derivative term
𝑑𝑡 All the PID gains
live here
Attitude Controller Tuning
• You can tune the P terms for
these controllers in the Extended
Tuning Tab
• A larger value will give a more
aggressive response to errors in
attitude
• Increase the value gradually until
you start to experience
oscillations then back down 20%
or so to ensure stability
Attitude Logging
• You can review the Desired vs
Actual angles in the ATT log
section
• Here you can check for
oscillations or overshoots as you
increase the Attitude P gain
• Tune each axis separately
Attitude Max Acceleration
• Ardupilot provides limits for the
maximum rate of angular
acceleration demanded by the
attitude controller
• These should be set according to
the capability of the drone
Maximum Lean Angles
Calculating Max Lean Angle
• The maximum lean angle should usually be
𝐹𝑚𝑎𝑥
set to ensure that the drone has enough
Thrust to maintain altitude and control even
at the maximum lean angle
−1
𝑊𝑁
𝜃𝑚𝑎𝑥 = cos ( )
0.8 ∗ 𝐹𝑚𝑎𝑥
• This equation may give large angles of 45° or
more
• For most applications a max angle of 30° is 𝑊𝑁
sufficient and larger values can be concerning
for pilots!
Setting Max Lean Angle
• Once the max lean angle has been decided upon set
up the maximum angles: 𝐹𝑚𝑎𝑥
Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down
Derivative
Feedforward
Target 𝑑
Vertical 𝑑𝑡 Proportional
Acceleration term
+ PID error
Actual
- න 𝑑𝑡
Integral term PID
gains
Motor
mixer
Vertical
Acceleration
𝑑 Derivative term
𝑑𝑡 All the PID gains
live here
Throttle Controller Tuning Flights
• Tuning flights for the Throttle
controller must be done in Altitude
Hold mode
• They will consist of sharp vertical
moves
• Rapid climb, rapid descent, rapid climb
etc.
• Because we are looking at
acceleration the drone doesn’t have
to change altitude very much and
the wobbles can be quite quick
Throttle Controller Logging
• You can review the Throttle
Controller Logs in the PIDA log
section
• As you can see the default
settings can be very oscillatory
as there is no D gain
• P = 0.5
• D=0
vertical velocity
Acceleration Acceleration
• This is simple proportional (P) East/West North/South
controller PSC_POSZ_P
Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down
Maximum braking
• LOIT_ACC_MAX the maximum acceleration controls
acceleration to correct position errors
how fast velocity can
• LOIT_ANG_MAX the maximum lean angle decrease
in position hold mode (usually set equal to
ANGLE_MAX)
• LOIT_BRK_ACCEL the maximum braking
acceleration when the stick is centred
• LOIT_BRK_DELAY the braking delay when Time
the stick is centred (often best set to 0)
Braking delay Braking Jerk controls
• LOIT_SPEED the maximum speed in Loiter controls how long
Mode how long it takes to
the stick must be reach maximum
• LOIT_BRK_JERK the maximum braking jerk centred before the deceleration. And how
(increasing this reduces drift when braking manoeuvre
stopping) long it takes to fully stop
begins at the end of a braking
manoeuvre.
Horizontal Velocity Controller
Waypoint Navigation
• Sitting above the angle
controllers is the horizontal Position Position Position
velocity controller East/West North/South Up/Down
path)
Rate Yaw Rate Roll Rate Pitch
Tuning Horizontal Kinematic Parameters
• The parameters with the biggest
effect on the horizontal movement Velocity
are LOIT_SPEED and PSC_JERK_XY
• LOIT_SPEED is more obvious, set
this to a suitable maximum speed
• PSC_JERK_XY is more subtle,
increase this to give a snappier
response to horizontal control Time
inputs in loiter mode
• Setting PSC_JERK_XY too high may
make the drone feel too aggressive
Vertical Position Controller
Waypoint Navigation
• Sitting above the vertical velocity
controller is the vertical position
controller Horizontal Position
Position
Up/Down
• This converts an error in the vertical
position into a target vertical Velocity
Horizontal Velocity
velocity Up/Down
path)
Rate Yaw Rate Roll Rate Pitch
Vertical Kinematic Path PILOT_SPEED_UP
PILOT_SPEED_DN
Velocity controls the maximum vertical
PILOT_ACCEL_Z controls speed under pilot control
the drone’s maximum
vertical acceleration
PSC_JERK_Z controls
how quickly the
drone reaches
maximum vertical
acceleration
PSC_JERK_Z controls
how quickly the
drone reaches
maximum vertical
acceleration
Time
Tuning Vertical Kinematic Parameters
• PILOT_SPEED_UP, PILOT_SPEED_DN
typically the max speed when
climbing is higher than when Velocity
descending
• PILOT_ACCEL_Z controls the
maximum vertical acceleration
• PSC_JERK_Z is more subtle, increase
this to reduce the delay on vertical
stick inputs and get to max vertical Time
acceleration quicker
• Setting PSC_JERK_Z too high may
make the drone feel too aggressive
on sudden vertical moves
Waypoint Navigation Controller
Waypoint Navigation
• The waypoint navigation
controller sits above all other and Position
Horizontal Position
controls how the drone behaves Up/Down
Loiter Controller
Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down
WPNAV_JERK
controls how the
acceleration tends
to zero towards the
maximum velocity
WPNAV_JERK
controls how
quickly the drone
reaches maximum
acceleration
Time
Horizontal Waypoint Kinematics WPNAV_SPEED
controls the
cruise speed in
waypoint mode
Waypoint
PSC_JERK_Z controls
how quickly the drone
reaches maximum
vertical acceleration
Time