⏵Hardware and PCB design course: https://www.philslab.net/courses
Source code available here: https://github.com/pms67/PID
How to implement a PID controller in software using C, discussing theory and practical considerations. Demonstration of PID controller code using a custom flight simulator.
If you're enjoying my content, please consider becoming a patron: / phils94
[NOTE] Something I forgot to mention in the video! Note on 'derivativeonmeasurement': Since the 'error signal' effectively going into the differentiator does not depend on the setpoint: e[n] = 0 measurement, and therefore (e[n] e[n 1]) = (0 measurement) (0 prevMeasurement) = Kd * (measurement prevMeasurement). Note the minus sign compared to derivativeonerror!
I've made the change in the Git repo before you would have had to use a negative Kd gain to get the same result. Now you can, as normal with derivativeonerror, use a positive Kd gain as usual.
Additional note: The derivative lowpass filter can be controlled by the constant 'tau', which is the time constant of the filter (3dB frequency in Hz, fc = 1 / (2*pi*tau)). A larger value of tau means the signal is filtered more heavily. As tau approaches zero, the differentiator approaches a 'pure differentiator' with no filtering.
[TIMESTAMPS]
00:00 Introduction
00:39 Control system basics
02:40 PID representation in continuous domain
04:57 Converting from the continuous to the discrete domain
06:11 PID controller difference equation
07:35 Practical considerations
10:48 Basic software structure
11:53 Implementation in C
18:46 Example: Flight simulator using PID controller code
ID: QIBvbJtYjWuHiTG0uCoK