0% found this document useful (0 votes)
191 views133 pages

Ardupilot Tuning Guide

The document provides a comprehensive guide on setting up and configuring a drone using Ardupilot, detailing hardware requirements, wiring instructions, and setup procedures for various components. It includes steps for calibration, flight modes, logging, and tuning filters to optimize flight performance. Additionally, it covers troubleshooting tips and best practices for ensuring safe and effective operation of the drone.

Uploaded by

bogunchiktop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views133 pages

Ardupilot Tuning Guide

The document provides a comprehensive guide on setting up and configuring a drone using Ardupilot, detailing hardware requirements, wiring instructions, and setup procedures for various components. It includes steps for calibration, flight modes, logging, and tuning filters to optimize flight performance. Additionally, it covers troubleshooting tips and best practices for ensuring safe and effective operation of the drone.

Uploaded by

bogunchiktop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Hardware and Set-up

Waypoint Navigation

Loiter Mode

Position East/West Position North/South Altitude Hold Mode

Velocity East/West Velocity North/South Position Up/Down

Acceleration East/West Acceleration North/South Velocity Up/Down

Acceleration Up/Down

Stabilize Mode

Angle Roll Angle Pitch Angle Yaw

Acro Mode

Rate Roll Rate Pitch Rate Yaw

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

• Frame Class > Quadcopter


• Frame Type > X (probably) or V
Setup – Initial Tune Parameters
• Mission Planner > Setup Tab >
Mandatory Hardware > Initial
Tune Parameters

• Airscrew Size > Prop Diameter


• Battery Cell Count
• Battery Chemistry
• Add suggested settings for 4.0+
Setup – Board Alignment
• Mission Planner > Config Tab > Full Parameter List > AHRS_ORIENTATION
• You only need to change this if your board orientation is different to the
manufacturers default
Setup – Accel Calibration
• Mission Planner > Setup Tab >
Mandatory Hardware > Accel
Calibration

• Calibrate Accel
• Reboot!
• Calibrate Level
Setup – Compass
• Mission Planner > Setup Tab >
Mandatory Hardware >
Compass

• Onboard Mag Calibration >


Start
• Reboot!
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 – 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

Position East/West Position North/South Altitude Hold Mode

Velocity East/West Velocity North/South Position Up/Down

Acceleration East/West Acceleration North/South Velocity Up/Down

Acceleration Up/Down

Stabilize Mode

Angle Roll Angle Pitch Angle Yaw

Acro Mode

Rate Roll Rate Pitch Rate Yaw

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

• Dynamic FFT looks at a sample of


data from the gyro to try an
determine the presence of noise
peaks and their frequency
• This can be used to drive notch
filters to reduce the effect of
noise
• It is slower and less precise than
RPM data for motor noise
• It can be useful for frame
resonances but is CPU intensive
Filter Review – Load Log
• Open your log in ArduPilot
WebTools Filter Review:
https://firmware.ardupilot.org/
Tools/WebTools/FilterReview/
• Check that the Flight Data
Graph looks correct and there
are no gaps (logging drop outs)
Filter Review – IMU Spectrum
• Scroll Down to the IMU
Spectrum
• With my logging settings you
should be able to see
• Pre-Filter Gyro Data
• Post-Filter Gyro Data
• Notch Tracking
• You will also see the effect of
the Gyro Low Pass filter
reducing the noise power at
high frequencies
Gyro Low Pass Filter (INS_GYRO_FILTER)
• The Gyro in a Drone is sensitive
both to the rigid body
movements of the drone
(signal) but also to vibrations
(noise)
• Vibration is generated by the
spinning motors and props
(and some payloads)
• Resonance of the drone’s
airframe and payload can also
amplify certain frequencies
Gyro Low Pass Filter (INS_GYRO_FILTER)
• The energy in vibrations (noise) is
usually much higher than the
energy in the rigid body
movement of the drone (signal)!
• Fortunately the real movements
are at a low frequency and the
vibrations are at higher
frequencies
• The Gyro Low Pass Filter takes
advantage of this to reduce the
noise without compromising the Real movements of Vibrations are usually
signal too much! the drone are usually above ~50Hz but
below ~30Hz depend on Prop RPM!
Gyro Low Pass Filter (INS_GYRO_FILTER)
• Unfortunately the Gyro Low
Pass Filter has some trade-offs
• Any low pass filter attenuates
high frequencies but also adds
delay
• The lower the 3dB cut-off
frequency of the filter the
more delay is added
• This delay slows the reaction of
the drone to air turbulence and
control inputs
Tuning the Gyro Low Pass Filter
• We want to gradually increase the
cut-off frequency of the Gyro low
pass filter as high as possible
without letting noise through
• Our main adversary is the
fundamental motor frequency /
lowest frame resonance
• We want this peak to be below
-50dB in the post-filter data
• We will tackle this peak using
Ardupilot’s Harmonic Notch
Filters
RPM Based Harmonic Notch
Filtering
Harmonic Notch Filter (INS_HNTCH_)
• As well as broad band high An example of a
frequency noise drones also noise peak
experience peaks of noise at
specific frequencies
• These peaks are created by the
rotation frequency of the
motors and airframe
resonances
• Peaks of noise are best handled
by notch filtering
Harmonic Notch Filter (INS_HNTCH_)
A notch filter
• Notch filters provide a very high combined with the
gyro lowpass filter
degree of attenuation of noise
around a target frequency
• They create much less delay than
an equivalent low pass filter
• The narrower the notch the less
delay it creates but the more Target the notch filter
precisely the target frequency onto the noise peak
must match the noise peak
• Tuning notch filters is about
targeting narrow notches
precisely where there are noise
peaks
Filter Review – IMU Spectrogram
• The IMU Spectrogram is used to
validate and tune the Harmonic
Notch Filters
• It shows the noise power at
different frequencies over time
• Zooming in to a few seconds of
Hovering allows us to look at the
key features (Turn off Notch Turn off Notch
tracking for now) Tracking for now
RPMhover ≈ Vbatt ∙ KV ∙ Thover
Filter Review – IMU Spectrogram

Look for a red line at Look for a red line at


Look for a red line at 2∙Fmotor (this is likely 3∙Fmotor (this is likely
RPMhover/60 = Fmotor to be strong for to be strong for
2-blade props) 3-blade props)

Red at very low


frequency is rigid-
body movement of
the drone
Filter Review – IMU Spectrogram – RPM Filter

The second harmonic The third harmonic Do we need a 4th


If RPM Notches are will sit on top of will sit on top of harmonic?
set up correctly you 2 ∙ Fmotor 3 ∙ Fmotor
should see a notch
right on top of FMotor

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

Some noise is still Significant noise is


getting through at still getting through
3∙Fmotor at Fmotor ! 😱

Turn off Notch


tracking
RPM Filtering
• At the moment the Notches are
tracking the Average of all 4 Central CoG,
all motors at
motor RPMs same RPM in
hover
• This works great if all 4 motors Yaw input
causes big
are at the same RPM (perfect Motor RPM
CoG and no Yaw inputs) differentials

• However often the motors will be


spinning at different RPMs (even Off centre
in a stable hover if CoG is not CoG, front and
rear motors at
perfect) different RPMs
Multi-Source RPM Filter
• The solution is to use Ardupilot’s Multi-
Source RPM filtering to apply a separate
notch to each motor RPM
• INS_HNTCH_BW = INS_HNTCH_FREQ / 4
(reduce the bandwidth of each notch to
keep latency under control with 4x as many
notches)
• INS_HNTCH_OPTIONS = 6 to enable Multi-
Source and update the notches at the loop
rate (important for narrower notches)
• Recalculate the filters to see the effect
on Notch Tracking
Multi-Source RPM Filter

Notice the extra Extra Notches are


notches are slightly covering previously
spread out around unfiltered vibrations
3∙Fmotor around Fmotor
Tuning the RPM Filter
• Once you have good coverage of
motor noise with the RPM filters
we can tune them for best
performance and minimum delay
Here the
• INS_HNTCH_FREQ should be set noise starts
around 80Hz
at the frequency at which motor
noise starts to become a problem
• This can be found by slowly
throttling up from zero and
looking at the log
Tuning the RPM Filter
• INS_HNTCH_BW should be
reduced as far as possible
• Go until you start seeing motor
noise bleeding through in the
post filter data then step back a
bit from there (~10%)

Here you can see noise


coming though despite
notches being correctly
applied
FFT Based Harmonic Notch
Filtering
What is the Dynamic FFT?
• FFT stands for Fast Fourier
Transform
• It takes a chunk of gyro data
(~0.5 seconds) and uses it to
calculate the amount of energy
at each frequency
• The frequency of the biggest
peak(s) detected can then be
passed to the harmonic notch
filters
Fast Fourier Transform
RPM

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

when RPM data is not available


(RPM data should be available!)
• It is much more difficult to get
working perfectly and requires
careful tuning with logs
FFT for Frame Resonance (NOTCH 2)
• FFT_ENABLE = 1
• FFT_MAXHZ the upper limit where problematic
frame resonances are seen
• FFT_MINHZ the lower limit where frame
resonances are seen
• FFT_NUM_FRAMES = 0 - 3
average FFT frames together to reduce noise
(not usually needed for large FFT_WINDOW)
• FFT_OPTIONS = 1 to apply gyro lowpass and
RPM filters before doing the FFT
• FFT_WINDOW = 1024 if CPU load allows or as
high as possible
• INS_HNTC2_MODE = 4 to use FFT for the
second notch (First notch is RPM)
FFT for Frame Resonance (NOTCH 2)
• INS_HNTC2_ENABLE= 1 to enable the second notch
• INS_HNTC2_MODE = 4 to use Dynamic FFT
• INS_HNTC2_FREQ = FFT_MINHZ the lower limit
where frame resonances are seen
• INS_HNTC2_BW = INS_HNTC2_FREQ / 2 start here
initially, then tune
• INS_HNTC2_REF = 1 no scaling required
• INS_HNTC2_FM_RAT = 1 prevent the notch going
below INS_HNTC2_FREQ
• INS_HNTC2_HMNCS = 1 we are looking to target a
frame resonances and they don’t typically have
harmonics
• INS_HNTC2_OPTS = 0 for one frame resonance
• INS_HNTC2_OPTS = 2 Use Multi-Source for multiple
resonances
FmaxHz ≈ 0.8 ∙ Vbatt ∙ KV / 60
FFT for Motor Noise (NOTCH 1)
• FFT_ENABLE = 1
• FFT_MAXHZ slightly above the
fundamental motor frequency at full
throttle
• FFT_MINHZ the lowest frequency
where motor noise is seen at low
throttle
• FFT_NUM_FRAMES = 0
FFT needs to be reactive to changing
RPM
• FFT_OPTIONS = 1 to apply low pass
filters before doing the FFT
• FFT_WINDOW = 1024 if CPU load allows
or as high as possible
FFT for Motor Noise (NOTCH 1)
• INS_HNTCH_ENABLE= 1 to enable the first
notch
• INS_HNTCH_MODE = 4 to use Dynamic FFT
• INS_HNTCH_FREQ = FFT_MINHZ the lowest
frequency where motor noise is seen at low
throttle
• INS_HNTCH_BW = INS_HNTCH_FREQ / 2
start here initially, then tune
• INS_HNTCH_REF = 1 no scaling required
• INS_HNTCH_FM_RAT = 1 prevent the notch
going below INS_HNTCH_FREQ
• INS_HNTCH_HMNCS = 7 for tri-blade props
(3 harmonics)
Tuning FFT Notch Filters
• INS_HNTC2_BW should be reduced
as far as possible (just like the RPM
notches)
• Go until you start seeing the Here you can the FFT notch
resonance bleeding through in the being correctly applied for
post filter data then step back a bit motor noise (no frame
from there (~10%) resonance on AOS UL8 😁)
• The FFT is less precise than RPM
data so FFT notch bandwidth will
always be greater
What about Static/Throttle Notches?
• I don’t advise using static or throttle notches
• They are a brittle filtering approach because they can be rendered
completely ineffective by changes such as
• Changing Props
• Operating Altitude
• Manufacturing tolerances on frames
• Payload
• RPM (HNTCH) [ + FFT (HNTC2) ] based notch settings are effective across
multiple drones of the same design even if parts and payloads change
• If you’re using FFT for motor noise (no RPM data) then you may need to
use a static notch for any frame resonance
Tuning the Gyro Low Pass Filter
• Now that our notch filters are
well tuned we should be able
to gradually increase the cut-
off frequency of the Gyro low
pass filter
• INS_GYRO_FILTER in the Full
Parameter List
• Increase it as far as possible
whilst keeping post-filter noise
below about -50dB or lower
Tuning the Gyro Low Pass Filter
• When raising INS_GYRO_FILTER
listen for any oscillations
• Also check the motor temperature
after a short hover
• Audible oscillations or hot motors
may indicate insufficient filtering
• They may also be due to a poor
PID tune
• Check logs to identify the source
PID Tuning
Waypoint Navigation
Background
Position Position Position
• Ardupilot uses a cascade of PID East/West North/South Up/Down
controllers to control the drone
• To get good autonomous flight Velocity
East/West
Velocity
North/South
Velocity
Up/Down
performance each of these PID
loops needs to be tuned Acceleration Acceleration
• We will start from the bottom East/West North/South
and work our way up
Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down

Rate Yaw Rate Roll Rate Pitch


Ardupilot Autotune
• Ardupilot has a couple of Auto Tuning
functions which try to find good PID
values for the Rate and Angle
Controllers
• These tools can produce tunes suitable
for hobby use on small drones
• They will struggle on larger drones and
produce suboptimal tunes which can
be dangerously unflyable!
• A methodical manual tuning approach
will produce better results more safely
• This is what we will cover in this guide
The PID-FF-DFF controller
• Ardupilot’s PID-FF-DFF controller consists of five main parts
• P is the proportional term
• I is the integral term
• D is the derivative term
• FF is the Feedforward term
• DFF is the Derivative Feedforward term
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
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

PID error PID error

The bigger the error PID error


the harder the P
term pushes back
towards the Target
Derivative term

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

PID error PID error PID error PID error

Integral term adds


up the error over
time and pushes
back harder and
harder the longer
the error persists
The feedforward term helps
Feedforward term overcome resistance that increases in
proportion to the target value. It’s
very useful for the vertical velocity
controller where gravity creates
exactly this effect.
Target

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

D-term P-term I-term


There are 3 Rate Controllers in Ardupilot
• One each for roll, pitch and yaw
• They all work the same way
• However, the derivative term on the yaw axis is usually set to 0
because the lack of authority on the yaw axis means it is usually over
damped and does not require an additional derivative term
Tuning flight tips
• PID tuning flights consist of sharp wobbles on all 3 axis
• When you do sharp moves make sure that you keep hold of the stick
as it returns to centre
• If you release the sticks, they can bounce around the centre as they
spring back which will make the quad oscillate (and might make you
think you have too much P gain when you don’t)
• You can do these sharp moves in Stabilize or Altitude Hold mode (but
not Loiter)
PID Review – Load Log
• Open your log in ArduPilot
WebTools PID Review:
https://firmware.ardupilot.org/
Tools/WebTools/PIDReview/
• Check that the Flight Data
Graph looks correct and there
are no gaps (logging drop outs)
• Select PID ROLL, PITCH or YAW
to look at
PID Review – Reading time series data
• Time domain data is
unreadable at the default zoom
level
• Zoom into the parts of the log
where you wobbled the drone
on the selected axis
PID Review – Reading time series data
• At this zoom level we can see
the individual movements
• The goal is to get the Actual
and Target lines to sit perfectly
on top of each other
• It is possible to tune P:D
balance only using time series
data
• This is useful as for some
controllers time series is all we
have easy access to
Target

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

Actual peak value = Target peak value


P:D balance is correct

deg/s
Actual peak value < Target peak value
Not enough P term relative to D term
Decrease P term relative to D term.

Tuning P:D balance


• It’s also possible to do this
analysis using the step
response in PIDReview
• You may find this view easier
but the information is the same Decrease P term relative to D term.

Increase P term relative to D term.

The red line is the goal! A tiny


bit of overshoot is OK but
absolutely no oscillation.
Tuning P:D balance
• What is important is the P:D ratio not
the individual values
• I would suggest only changing the P
term during this stage of P:D balance
tuning to keep things simple
• You can do this in Mission Planner >
Config > Extended Tuning
• Unless you have a symmetric drone
unlock Pitch and Roll Values and tune
each axis separately
Troubleshooting Oscillation
• If you are suffering from
oscillations that don’t improve
when you reduce the P term this
could be 2 things:
• D term oscillation: High D gains
can self-oscillate independent of
the P term, to fix this reduce both
the D and P terms in steps of 10%
• Excessive filter delay can also
cause oscillations, double check
that you cannot improve your
gyro filter settings
Absolute PID Gain Tuning
PID Gain Tuning
• Once the P:D Balance of the drone has
been found we want to increase the
overall PID gain to reduce PID error
• They way to do this is to increase P, I
and D by the same multiple
• Pnew = Pold *1.1
• Inew = Iold *1.1
• Dnew = Dold *1.1
• This keeps P:D and P:I ratios the same
👍
• Keep increasing until you start to see
oscillations in the logs then back down
10-20%
• Each axis should be adjusted separately
PID Gain Tuning
• In many cases you will see a
drastic improvement in flight
performance from increasing
overall PID gains 😁
P:I Balance Tuning
• I term typically has a wide tuning
window
• It is not always necessary to directly
tune the I term (except as part of
overall PID gain tuning)
• However, theoretically increasing
the I term can give target tracking
improvements
• I term should be increased until
there is evidence of I term
oscillations in the logs then backed
down 10-20%
• Each axis should be adjusted
separately
Yaw Axis
• The Yaw axis doesn’t usually
need a D term for typical
Multicopters
• This means that only the P:I
balance and overall gains need
to be tuned
• Before increasing P and I gains
consider reducing the Yaw Error
filtering for smaller quads
Rate PID Tuning
• At this stage you should have an excellent Rate PID tune on your
drone
• If the Rate tune is good then tuning the higher level controllers will be
straightforward
• Hopefully you are already seeing a big improvement in the flight
behaviour in all modes
Attitude (Stabilize) Control Tuning
Attitude Controller Background
Waypoint Navigation
• The Attitude Controller controls
the Angle of the drone relative to Position Position Position
the ground for the Pitch and Roll East/West North/South Up/Down

axes and North for the Yaw axis


Velocity Velocity Velocity
• These are simple proportional East/West North/South Up/Down

controllers
Acceleration Acceleration
• The difference between Desired East/West North/South

and Actual Angle is multiplied by


a factor to give the target rate of Angle Yaw Angle Roll Angle Pitch
Acceleration
Up/Down
rotation
Rate Yaw Rate Roll Rate Pitch
The Ardupilot Angle PID Controller

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: 𝐹𝑚𝑎𝑥

• ANGLE_MAX is the max angle allowed in all modes


• PSC_ANGLE_MAX is the max angle allowed in
position hold mode (set = 0 to use ANGLE_MAX)
• LOIT_ANGLE_MAX is the max pilot requested angle
allowed in loiter mode (set = 0 to use 2/3 of
ANGLE_MAX)
• I would generally recommend:
• ANGLE_MAX = 30 𝑊𝑁
• PSC_ANGLE_MAX = 0 (same as ANGLE_MAX)
• LOIT_ANGLE_MAX = 30 (same as ANGLE_MAX)
Throttle PID Controller
Throttle Controller Background
Waypoint Navigation
• The Throttle Controller controls
the Altitude of the drone Position Position Position

• It converts a requested vertical


East/West North/South Up/Down

acceleration into a motor output Velocity Velocity Velocity

• It includes P-I-D-FF-DFF terms East/West North/South Up/Down

just like the rate controllers and Acceleration Acceleration


is tuned in the same way East/West North/South

Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down

Rate Yaw Rate Roll Rate Pitch


The Ardupilot Throttle Controller
Feedforward

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

P Term Oscillation due


to zero default D gain
Throttle Controller Logging
• Reducing the P gain and adding
some D gain will eliminate the
oscillations
• In this log (an 8” drone) the P:D
balance is around 50:1
• P = 0.25
• D = 0.005

Some delay and undershoot


but oscillations are eliminated
Throttle Controller D-term Noise
• As with the Rate Controllers it’s
important to check that the D
term is not too noisy
• Excessive D term noise can be
addressed by decreasing the
PSC_ACCZ_FLTD cut-off
frequency (0 means disabled)
• If needed start with ~20Hz
D term is acceptable here with
SNR ≈ 10 and FLTD disabled
Throttle Controller Feedforward
• Similar to Yaw the Throttle
controller can benefit from a
positive Feedforward term
• A larger positive vertical
acceleration naturally requires a
higher throttle setting
• FF provides this without the
need for error between the
Target and Actual values FF increases motor output when larger
• Try PSC_ACCZ_FF = 0.05 to start vertical acceleration is requested
with
Throttle Controller Derivative Feedforward
DFF reduces delay between Target and
Actual
• The Throttle controller can benefit
from a positive Derivative
Feedforward term
• As with the other Rate controllers
derivative feedforward helps
reduce the delay between the
Target and Actual curves
• It is tuned in the same way as for
the rate controllers, increase DFF
to reduce delay, too much causes
Actual to lead Target and
overshoot
Check DFF signal to noise ratio at least ~10. If not
consider decreasing PSC_ACCZ_FLTT cut-off frequency
Vertical Velocity Controller
Waypoint Navigation
• Sitting above the throttle
controller is the vertical velocity Position Position Position
controller East/West North/South Up/Down

• This is another PID controller Velocity Velocity Velocity


PSC_VELZ_ P, I, D, FF, FLTE, FLTD East/West North/South Up/Down

• There is no derivative Acceleration Acceleration


feedforward or target filtering in East/West North/South

the vertical velocity controller


Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down

Rate Yaw Rate Roll Rate Pitch


Vertical Velocity Controller
• To Tune the vertical velocity
controller you can use the data in
• CTUN > DCRt (Desired climb rate)
• CTUN > CRt (Climb Rate)

• If the Throttle Controller is well


tuned you may not need to add
much D term at all
• You should not typically need to
add any Feedforward (FF) or I
term into this controller Here tracking is good and overshoot is
minimal, slightly reduce P term
Vertical Position Controller
Waypoint Navigation
• Sitting above the vertical velocity
controller is the vertical position Position
Horizontal Position
controller Up/Down

• This converts an error in the Velocity


Horizontal Velocity
vertical position into a target Up/Down

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

Rate Yaw Rate Roll Rate Pitch


Vertical Position Controller
• To Tune the vertical velocity
controller you can use the data in
• CTUN > DAlt (Desired altitude)
• CTUN > Alt (Altitude)

• The only parameter to adjust is


PSC_POSZ_P increase it to track the
desired altitude more aggressively
• Watch for overshoot/oscillation
Here tracking is good and overshoot is
which indicates PSC_POSZ_P is too minimal, P term is appropriate
high
Loiter Controller
Waypoint Navigation
• Sitting above the angle
controllers is the loiter controller Position
Horizontal Position
• This converts the target
Up/Down

horizontal acceleration into pitch Velocity


Horizontal Velocity
and roll angles Up/Down

• It also contains several


Loiter Controller
parameters which control the
drone’s movement in loiter mode
Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down

Rate Yaw Rate Roll Rate Pitch


Parameters
• LOIT_ACC_MAX the maximum acceleration to correct position errors
• LOIT_ANG_MAX the maximum lean angle 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 the stick is centred (often
best set to 0)
• LOIT_SPEED the maximum speed in Loiter Mode
• LOIT_BRK_JERK the maximum braking jerk
Jerk, Acceleration, Maximum velocity
controls the drone’s

Max velocity Velocity


top speed

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

• This converts a target horizontal Velocity


Horizontal Velocity
velocity into a target acceleration Up/Down

• This is another PID controller Acceleration Acceleration


PSC_VELXY_ P, I, D, FF, FLTE, FLTD East/West North/South

• There is no derivative Acceleration


Angle Yaw Angle Roll Angle Pitch
feedforward or target filtering in Up/Down

the horizontal velocity controller


Rate Yaw Rate Roll Rate Pitch
Horizontal Position Controller
Waypoint Navigation
• Sitting above the horizontal velocity
controller is the horizontal position
controller Horizontal Position
Position
Up/Down
• This converts an error in the
horizontal position into a target Velocity
Horizontal Velocity
horizontal velocity Up/Down

• This is a simple proportional (P)


controller PSC_PSCXY_P Loiter Controller

• However there are many


parameters which limit the velocity Angle Yaw Angle Roll Angle Pitch
Acceleration
and acceleration targets (kinematic 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

• This is a simple proportional (P)


controller PSC_PSCZ_P Loiter Controller

• However there are many


parameters which limit the velocity Angle Yaw Angle Roll Angle Pitch
Acceleration
and acceleration targets (kinematic 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

when autonomously navigating


Velocity
Horizontal Velocity
Up/Down

Loiter Controller

Acceleration
Angle Yaw Angle Roll Angle Pitch
Up/Down

Rate Yaw Rate Roll Rate Pitch


Waypoint Navigation Parameters
• The waypoint navigation
parameters can be found in
• Mission Planner > Config > Full
Parameter List
Horizontal Waypoint Kinematics WPNAV_SPEED
controls the cruise
Velocity speed in waypoint
WPNAV_ACCEL controls mode
the drone’s maximum
horizontal acceleration

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

WPNAV_ACCEL_C controls the


drone’s maximum centripetal
WPNAV_RADIUS controls how
cornering acceleration. If set to
close the drone needs to get
0 then use 2x WPNAV_ACCEL
to the waypoint before the
waypoint is marked as hit and
the drone moves to the next
Vertical Waypoint Kinematics WPNAV_SPEED_UP
WPNAV_SPEED_DN
Velocity controls the vertical
speed in waypoint
WPNAV_ACCEL_Z
mode
controls the drone’s
maximum horizontal
acceleration
PSC_JERK_Z controls how
the acceleration tends to
zero towards the maximum
vertical velocity

PSC_JERK_Z controls
how quickly the drone
reaches maximum
vertical acceleration

Time

You might also like