Recent

Author Topic: PID controller  (Read 1079 times)

ccrause

  • Hero Member
  • *****
  • Posts: 856
PID controller
« on: January 20, 2023, 03:51:40 pm »
I recently wanted to apply PID control to an electric heater, but to my surprise I couldn't locate something already written in Pascal. I whipped up a PID implementation with some of the more common variations of parameters and control forms here.  Anyone is welcome to use the code.  Tips and tricks to improve the general behaviour of the controller would be appreciated.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: PID controller
« Reply #1 on: January 20, 2023, 04:35:11 pm »
Very nice, thanks!

I used PID controllers in both industrial and embedded world, but prefer Fuzzy Logic for more complex stuff when I want to avoid PID overshooting/undershooting and smoothly reach set point, when rules based expert knowledge is available for something I want to automate, and when multiple inputs and multiple outputs are needed. All these can not be achieved with conventional PID. Of course, if you already have tuning experience and none of the above requirements then PID is quickest to implement.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: PID controller
« Reply #2 on: January 20, 2023, 07:10:01 pm »
I used PID controllers in both industrial and embedded world, but prefer Fuzzy Logic for more complex stuff when I want to avoid PID overshooting/undershooting and smoothly reach set point, when rules based expert knowledge is available for something I want to automate, and when multiple inputs and multiple outputs are needed. All these can not be achieved with conventional PID. Of course, if you already have tuning experience and none of the above requirements then PID is quickest to implement.
Indeed PID is not the answer to all control problems  :)

For the situations where PID control are appropriate, it should be easy and straight forward to configure the class for the problem at hand. My aim is to include sensible default rules rules for things such as output limiting, integral windup and derivative filtering so that a casual user of the code can just focus on tuning the main controller constants.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: PID controller
« Reply #3 on: January 20, 2023, 11:09:28 pm »
Very nice, thanks!

I used PID controllers in both industrial and embedded world, but prefer Fuzzy Logic for more complex stuff when I want to avoid PID overshooting/undershooting and smoothly reach set point, when rules based expert knowledge is available for something I want to automate, and when multiple inputs and multiple outputs are needed. All these can not be achieved with conventional PID. Of course, if you already have tuning experience and none of the above requirements then PID is quickest to implement.

You need to apply a little D in the PID! :o
The only true wisdom is knowing you know nothing

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: PID controller
« Reply #4 on: January 22, 2023, 11:12:10 am »
You might want to use the CyberUnits Bricks library. It includes classes for proportional, integral and derivative elements. The main purpose of this class library is simulation of biological feedback loops in living organisms, but it should be usable for the implementation of technical control systems as well.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: PID controller
« Reply #5 on: January 23, 2023, 05:38:13 am »
You might want to use the CyberUnits Bricks library. It includes classes for proportional, integral and derivative elements. The main purpose of this class library is simulation of biological feedback loops in living organisms, but it should be usable for the implementation of technical control systems as well.
Thanks jwdietrich, I was not aware of this library.

 

TinyPortal © 2005-2018