m-lundberg / simple-pid

A simple and easy to use PID controller in Python
MIT License
799 stars 217 forks source link

Duplicate state after updating measurement #76

Open mungewell opened 1 year ago

mungewell commented 1 year ago

Hi, I am doing some testing and noticed that the internal state did not change after I updated the measurement value, is this normal?

00:02:00:03 517.3335 0.5173335 (0.5173335, 5.173335e-19, 0.0)
00:03:00:01 510.3335 0.8164169 (0.5103335, 0.3062001, -0.0001166667)
00:04:00:02 669.6335 1.380269 (0.6696335, 0.7079802, 0.002655)
00:05:00:05 826.2334 2.040783 (0.8262335, 1.211982, 0.002567212)
00:06:00:04 960.8334 2.040783 (0.8262335, 1.211982, 0.002567212) <------------
00:07:00:04 1104.033 3.63215 (1.104033, 2.525782, 0.002334454)
00:08:00:04 1216.533 4.474111 (1.216534, 3.255702, 0.001875)
00:09:00:01 1347.133 5.413293 (1.347134, 4.063982, 0.002176666)
00:10:00:03 1482.533 6.438293 (1.482534, 4.953503, 0.002256667)
00:11:00:02 1593.534 7.505007 (1.593534, 5.909623, 0.001850008)
00:12:00:04 1721.934 8.684042 (1.721934, 6.960003, 0.002104918)
00:13:00:01 1828.434 8.684042 (1.721934, 6.960003, 0.002104918) <-------------

In this data the 1st column is effectively time (HH:MM:SS:FF) and you will notice that I am slowly updating every 60s or so. I have limitations in my system which means I need to slow the PID down for now as I can't adjust the control too quickly... I have plans to improve this soon. 2nd data is the measurement (time delta in us), 3rd is out (adjustment to PIO clock divider)

My control loop is slowed by the speed which I can write data to the OLED screen on my Pico. It is only grabbing a measurement around 3Hz, and also averaging that to remove jitter noise from servicing the interrupts which are used to create timestamp.

gonzalo-bulnes commented 1 year ago

Maybe a naive question: might your measurement have happened faster than the sampling rate @mungewell ?

You haven't said how you've configured the PID, but I suppose that if sample_time was x and your measurement happened at time t < x, then the PID wouldn't have updated the output.