generic PID controller in C #14043
Replies: 1 comment 2 replies
-
@v923z , I just noticed Your post (haven't got notification about topic). So primary code in micropython in repo is R&D but verified and tested (in thermal process control: pottery kiln) in two ways:
End of project is C (it is already easy to migrate), Code (with all preprocessing steps) is prepared for full customizable PLC pid-controller implementation (like Simens Simatic PLC standard PID solution) with additional functionalities. In MP project, I used floating point and do not use here "tricks" use in commercial solution (i.e store parameters as integers for example, Kp=1.5 (float) , we can save as Kp=1500 and in any function calculation just divide by 1000 ( just like in some commercials product (Hitachi PLC and other). About speed - target for my project was thermal process control- so it type of slow. if You want fast sampling (processing) then: -> cut of all necessary functionalities ( antiwindup, selectors etc, implement noise filtering as fixed point calculation (watch out for), simplify all preprocessing.
It is all about control stability. For fixed control implementation (as driver) it is possible to implement calculation as fixed point, but then all approximation should be tested against stability and errors progression, and calculation overflow. (see How to Build a Fixed-Point PI Controller That Just Works |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I know that there are quite a few PID controllers implemented in
python
(an excellent example can be found under https://github.com/2dof/esp_control/tree/main), but I have also seen the benchmarks, which indicated that they wouldn't be fast enough for my application, so I cobbled something together in C. I wanted to have something that is system-agnostic and fast. The concept is explained here https://github.com/v923z/micropython-ulab/blob/pid2/docs/ulab-pid.ipynb, while the code is in https://github.com/v923z/micropython-ulab/tree/pid2/code/pid. Before merging this, I'd like to have some sort of feedback on what extra functionality could be useful, what could be improved upon etc.Beyond moving the PID loop itself to C, I wanted to get rid of two very annoying steps in the controller: the conversion between floating point results and the input/output devices, which most probably consume integers. Second, look-up tables and complicated functions for the sensor data.
So, for this reason, the controller shares its buffers with the input/output devices, where the conversion automatically takes place, and no data have to be passed between
python
methods. Sensor data are converted by means of a simple Taylor series expansion of the sensor + system transfer function.All properties of the controller can be accessed via dot setters/getters, and time differences are measured by the loop itself. The
python
pseudo-code looks like thisBeta Was this translation helpful? Give feedback.
All reactions