Member-only story

How to Write your own Flight Controller Software — Part 3

The PID Loop

--

In Part 1 of our series we spoke about the flight controller PID Loop. It is worth revisting that now (see Figure 1). In previous parts we have spoken about how we decode the remote control input, r(t), and how we generate our PWM control for the ESC, u(t).

In Part 3, we will look at the roll, pitch and yaw inputs from the IMU and combining that with r(t) to get our error signal , e(t), which is fed into our PID loop. We will output the desired setpoint and PID loop output to the Reefwing Configurator to assist with tuning.

Figure 1. Flight Controller Loop.

The Flight Controller loop design will determine how well our drone flies and how aggressively the control inputs are converted to motor outputs. By tweaking the parameters of our PID loop we will be able to produce a flight model which is slow and stately or fast and agile. Which is appropriate depends on the purpose of the drone mission. If you are doing cinematography you dont want a lot of abrupt changes but if you are flying acrobatics you do.

In addition to tweaking the gain constants in our PID controller, we can adjust the response of our flight model by having different modes. For example:

  • Rate or Acrobatic Mode — which uses only feedback from the gyroscope in the PID loop and doesn’t attempt to self level; or
  • Stable Mode — which uses both gyroscope, accelerometer and magnetometer (if available) to help smooth the flight model. You would also normally self level in this mode.

Some Theory

The objective is a control system which adjusts the output to meet a desired state, often called the setpoint. The PID controller is a closed loop system. That means it uses feedback from its sensor to work out if the output is the same as the setpoint. Unlike simple control algorithms, the PID controller is capable of manipulating the process inputs based on the history and rate of change of the signal. This gives a more accurate and stable control…

--

--

David Such
David Such

Written by David Such

Reefwing Software · Embedded Systems Engineer · iOS & AI Development · Robotics · Drones · Arduino · Raspberry Pi · Flight Control

No responses yet