News for hackers. Stuff that matters.
Re:Tune Your PID Controller by londons_explore on Wednesday May 26, 2021 @10:22AM (#27290827)
I wish this site expanded a little to model a few things present in most real world systems:

* Limits. Nearly all systems have a maximum and minimum input value. That should be modelled so behaviours when the limit is reached can be modelled. For example, a car has a top speed - and any further pressing of the accelerator will not make it go faster, but a PID loop will keep integrating any error, causing the system to not behave as expected.

* 'Slack/Hysterisis'

* Asymmetric systems - the force applied when pushing a system may not be the same as pulling.

I really want a system where data can be thrown in like this, and it fit a model to the data and suggest not only PID values, but other types of controller which would be a better fit.

Re:Tune Your PID Controller by pidtuner on Wednesday May 26, 2021 @10:28AM (#27290902)
Developer here, you are right. I have also considered such systems, but my free time is limited, so for the moment I just implemented the most basic case.

Simulating limits will be included in the next release.

Hysteresis is something more difficult, so will not handle any time soon.

Asymmetric systems can be handled by gain-scheduling the PID (make a model for each region and schedule the gains), this is approachable in the middle term.

Re:Tune Your PID Controller by londons_explore on Wednesday May 26, 2021 @11:58AM (#27292192)
While you're here... It would be nice to have examples of common systems with little diagrams.

Eg. "Heater output to get to desired temperature", "Motor PWM to get to specified position", etc. Perhaps each with a little diagram/animation showing the input, the output, and some example data.

Re:Tune Your PID Controller by pidtuner on Wednesday May 26, 2021 @12:43PM (#27292790)
Maybe the youtube videos help with this? https://www.youtube.com/channel/UCkRD7FztiFOdX50BUsOkcSQ
Re:Tune Your PID Controller by DoingIsLearning on Wednesday May 26, 2021 @12:38PM (#27292699)
Great work!

Could you go into a bit more detail regarding the webassembly implementation in:

pidtuner.github.io/pid/v1.0.6/pid_tuner_wasm.wasm

Is it in C, C++, rust? Could you give a brief description of the internal logic?

Re:Tune Your PID Controller by pidtuner on Wednesday May 26, 2021 @12:41PM (#27292756)
Thanks. It is C++ code using Armadillo for linear algebra and BLAS/LAPACK subroutines. Source code is a bit messy, but will try to clean it up and put it on a different repo when I find the time.

The most complex part is the identification algorithm, which uses this algorithm: https://math.stackexchange.com/questions/1428566/fit-sum-of-...

Re:Tune Your PID Controller by elcritch on Wednesday May 26, 2021 @02:46PM (#27294491)
Oh, awesome! I’ve got to do some pid tuning this week. I’ll definitely be interested in the raw C code.

I wonder if it could be portable to a microcontroller Are the blas routines expensive or large matrices?

Re:Tune Your PID Controller by pidtuner on Thursday May 27, 2021 @04:25AM (#27300597)
The code is C++ code, It could be ported to an MCU if there is a fairly recent C* compiler (C11+). But the algorithms are quite expensive, there are multiple matrix inversions, the size of the matrices been as large as the data you put in into the tool. typically between 500 and 10000 data points.
Re:Tune Your PID Controller by gugagore on Wednesday May 26, 2021 @03:38PM (#27295077)
In a world where one can do so much computation, I would really like to see more adaptive control techniques.

The I in PID is the only adaptive part. You can think of it as an estimator of an additive term that arises from e.g. friction or forces due to gravity.

But what about estimating e.g. a multiplicative term? It seems we should be able to do much better than PID, but without needing to commit all the way to a model-based method or reinforcement learning.

I wish there were some materials for how to move just beyond PID, but textbook treatments of LQR or MPC cannot even handle the I in PID.

Re:Tune Your PID Controller by pidtuner on Thursday May 27, 2021 @03:52AM (#27300444)
The problem with many adaptive control techniques is that is very difficult to prove the closed loop stability and performance margins, because such systems are highly nonlinear and we do not have yet the mathematics to provide simple guarantees (for example, I would not get into an aircraft where the control systems have not been rigorously, mathematically, designed)

The integral problem of LQR and MPC is indeed not the first topic discussed on textbooks, but there has been a solution for that for year, called "disturbance model". You you can have an "adaptive MPC" following some design procedures. Check out this reference:

https://folk.ntnu.no/skoge/prost/proceedings/ifac2014/media/...

Re:Tune Your PID Controller by gugagore on Thursday May 27, 2021 @04:22AM (#27300581)
Thanks for the reference. I agree that the solution to getting I action is to model the disturbance, and augment the state. The system certainly becomes uncontrollable in the augmented state space.

I've run into a conceptual problem when using this approach with [infinite-horizon] LQR to try to recover what looks like a PID controller, which IIRC is due to the control u not necessarily converging to 0. This is expected, to counteract a constant disturbance, but it means that the sum doesn't converge.

I only skimmed the reference, but I did not find a discussion of this issue.

Re:Tune Your PID Controller by pidtuner on Thursday May 27, 2021 @04:27AM (#27300607)
The trick is that, even though the augmented state is uncontrollable, you still use it in the predictions, so the MPC algorithm can still compensate for it. Take a look at the before-last graph in the paper, see how that technique improves predictions after learning the real-time disturbances.
Re:Tune Your PID Controller by gugagore on Thursday May 27, 2021 @07:19AM (#27301615)
That's not what I was concerned about. The subspace that's uncontrollable is the disturbance components of the state, which I don't care to control anyway.
Re:Tune Your PID Controller by pidtuner on Thursday May 27, 2021 @07:29AM (#27301697)
Not to control, but to compensate. This is what the I action in the PID does, compensate for un-modeled disturbances
Re:Tune Your PID Controller by salty_biscuits on Wednesday May 26, 2021 @05:20PM (#27296252)
You can always add an extra variable to your state space model to handle an integrated qty...
Re:Tune Your PID Controller by iptpus on Wednesday May 26, 2021 @09:21PM (#27298269)
The asymmetric systems example is very true. When I did high school robotics, our robot one year had a large, heavy elevator. I made it so going up used a PID controller and going down was just a constant resistive force (since it was already too fast when falling via gravity).
Re:Tune Your PID Controller by hatsunearu on Wednesday May 26, 2021 @12:06PM (#27292290)
You generally need some sort of state space/optimal controls theory to robustly solve problems like that.
Re:Tune Your PID Controller by dognotdog on Wednesday May 26, 2021 @12:23PM (#27292485)
"anti-windup" is usually implemented for PID controllers to avoid increasing the I part infinitely, and linear state-space controls do suffer from the same problem in naive implementations.
Re:Tune Your PID Controller by elcritch on Wednesday May 26, 2021 @02:48PM (#27294508)
Isn’t the windup normally just a min/max type function? Any suggestions for testing an anti-windup code in an implementation?
Re:Tune Your PID Controller by dognotdog on Wednesday May 26, 2021 @03:26PM (#27294955)
Yes, usually just clamp the integrator's accumulator value so that when the actuator is outside the linear control regime (eg. maxing out motor current because we're in the end-stop), the output of the controller doesn't continue increasing to infinity.

(Another way is stopping integration when control output is at its physical limit, usually in addition to a numeric limit.)

As with all other PID parameters, this is something you'd have to figure out more-or-less empirically.

Testing with hardware would be checking that controller outputs stop increasing while the actuator is blocked away from its target value, usually running with much reduced speed/current etc limits. Ideally, of course, run unit tests and SIL, before trying it on actual hardware.

Re:Tune Your PID Controller by gugagore on Wednesday May 26, 2021 @03:31PM (#27295011)
It's a bit more subtle than that.

What saturates is the actuator. You could choose a single minimum/maximum value for the integrator, but it could be better ye to have a value that depends dynamically on how much room there is left in the actuator output.

For example, if the actuator is saturated, the integral term should not be increasing. That could happen at different values of the integral, so there is not a single min/max.

Re:Tune Your PID Controller by pidtuner on Thursday May 27, 2021 @03:55AM (#27300455)
I suggest to take a look to the canonical PID implementation of the Arduino library. It includes a simple but effective anti-windup mechanism:

http://brettbeauregard.com/blog/2011/04/improving-the-beginn...

Re:Tune Your PID Controller by pidtuner on Wednesday May 26, 2021 @12:45PM (#27292836)
The tuning rules from Skoge provide very decent robustness margins. (https://folk.ntnu.no/skoge/publications/2001/tuningpaper_ren...)