PID autotune
- AndreyB
- Site Admin
- Posts: 14333
- Joined: Wed Aug 28, 2013 1:28 am
- Location: Jersey City
- Github Username: rusefillc
- Slack: Andrey B
PID autotune
Too many PIDs already and tuning each manually is just too painful. We need some sort of PID autotune. Anyone has ideas?
What would be a good real or virtual process to play with on a bench? What PID autotune do we want to use?
This would be used for idle PID, alternator PID and else.
See http://pages.mtu.edu/~tbco/cm416/cctune.html
See https://ir.nctu.edu.tw/bitstream/11536/27727/1/000183931000005.pdf
See https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method
See https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/temperature.cpp#L222
What would be a good real or virtual process to play with on a bench? What PID autotune do we want to use?
This would be used for idle PID, alternator PID and else.
See http://pages.mtu.edu/~tbco/cm416/cctune.html
See https://ir.nctu.edu.tw/bitstream/11536/27727/1/000183931000005.pdf
See https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method
See https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/temperature.cpp#L222
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Re: PID autotune
In order to auto-tune a PID controller, it may be necessary to determine the expected behavior of the controlled element. There are several different distinct types of behavior, even in an engine.
Let's start with idle:
We want to achieve a target-rpm and what we can control is idle-air (also timing and fuel, but let's keep it simple for now). Idle air determines torque. The torque counteracts losses like friction and pumping losses. If our engine had no losses, even a minimal amount of torque would spin it to infinity rpms. We also have an energy storage device: our rotating masses, clutch, flywheel and crankshaft. The energy storage will resist change. If we open the idle valve, the rpms will go up slowly. If we close it they will drop slowly. The greater the rotating masses, the more slowly the changes. This is the reason why luxury engines get big flywheels- to smooth things out.
Now, if our losses decrease suddenly (i.E. turning off the AC), the torque applied is greater than the torque needed to overcome friction and our engine rpms will increase. This will not happen instantaneously, because energy is stored in the rotation. Since losses increase with rpm, at some rpm the losses will be sufficient to consume all out torque and we have a stable situation again. Similar effects would happen with a sudden increase in losses (turning on the AC, adding electric consumers and thus load to the alternator etc. The rpms will drop until the new losses are small enough to be counter-balancing the torque.
And since everybody loves a visual aid, here is one: This type behavior is called pt1 if memory serves right. It's reasonably benign to control, since the energy-storage device helps us slow things down. This seems to be the type of DUC (Device Under Control) that the Cohen Coon method, as mentioned in the paper linked above, would be good for.
An electronic equivalent to this type of DUC would be an RC network: Equivalents:
U in -> Idle-Air setting
R1 together with C1 simulates the energy storage in the rotation masses
R2 simulates the friction losses (lower R-> higher losses)
U out -> engine rpm
Implementing Cohen Coon should work well for this type behavior.
More on other types of DUCs soon.....
Let's start with idle:
We want to achieve a target-rpm and what we can control is idle-air (also timing and fuel, but let's keep it simple for now). Idle air determines torque. The torque counteracts losses like friction and pumping losses. If our engine had no losses, even a minimal amount of torque would spin it to infinity rpms. We also have an energy storage device: our rotating masses, clutch, flywheel and crankshaft. The energy storage will resist change. If we open the idle valve, the rpms will go up slowly. If we close it they will drop slowly. The greater the rotating masses, the more slowly the changes. This is the reason why luxury engines get big flywheels- to smooth things out.
Now, if our losses decrease suddenly (i.E. turning off the AC), the torque applied is greater than the torque needed to overcome friction and our engine rpms will increase. This will not happen instantaneously, because energy is stored in the rotation. Since losses increase with rpm, at some rpm the losses will be sufficient to consume all out torque and we have a stable situation again. Similar effects would happen with a sudden increase in losses (turning on the AC, adding electric consumers and thus load to the alternator etc. The rpms will drop until the new losses are small enough to be counter-balancing the torque.
And since everybody loves a visual aid, here is one: This type behavior is called pt1 if memory serves right. It's reasonably benign to control, since the energy-storage device helps us slow things down. This seems to be the type of DUC (Device Under Control) that the Cohen Coon method, as mentioned in the paper linked above, would be good for.
An electronic equivalent to this type of DUC would be an RC network: Equivalents:
U in -> Idle-Air setting
R1 together with C1 simulates the energy storage in the rotation masses
R2 simulates the friction losses (lower R-> higher losses)
U out -> engine rpm
Implementing Cohen Coon should work well for this type behavior.
More on other types of DUCs soon.....
Re: PID autotune
See page 61 of this process controller
https://cdn.automationdirect.com/static/manuals/solocontrolm/solocontrolm.pdf
Basically the auto-tune turns the output 100% on until it passes the target. Then it changes to 0% output, and waits until it crosses the set value. Then it turns on 100% again. When it does this, it finds the cycle time and amplitude then calculates the magic numbers. This auto-tune approach has been fairly good for many process controlled items like a temperature controlled room. I'm not sure how they generate the magic numbers, but I figured this would be a good reference.
https://cdn.automationdirect.com/static/manuals/solocontrolm/solocontrolm.pdf
Basically the auto-tune turns the output 100% on until it passes the target. Then it changes to 0% output, and waits until it crosses the set value. Then it turns on 100% again. When it does this, it finds the cycle time and amplitude then calculates the magic numbers. This auto-tune approach has been fairly good for many process controlled items like a temperature controlled room. I'm not sure how they generate the magic numbers, but I figured this would be a good reference.
Welcome to the friendlier side of internet crazy
- AndreyB
- Site Admin
- Posts: 14333
- Joined: Wed Aug 28, 2013 1:28 am
- Location: Jersey City
- Github Username: rusefillc
- Slack: Andrey B
Re: PID autotune
Some data andreika has asked for: turning radiator fan on and off and looking at how RPMs would react.
At some point half through the video I've turned off alternator PID control, so on the second half of the video we can also see how fast VBatt reacts to radiator fan turned on or off.
https://svn.code.sf.net/p/rusefi/code/misc/logs/2003_mazda_miata/2017-07-25_22.03.13_radiator_fan_on_off.msl.7z
At some point half through the video I've turned off alternator PID control, so on the second half of the video we can also see how fast VBatt reacts to radiator fan turned on or off.
https://svn.code.sf.net/p/rusefi/code/misc/logs/2003_mazda_miata/2017-07-25_22.03.13_radiator_fan_on_off.msl.7z
- Attachments
-
- screenshot.png (56.96 KiB) Viewed 14539 times
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Re: PID autotune
These links might be of interest.
http://scilab.ninja/study-modules/scilab-control-engineering-basics/module-4-pid-control/
Using Scilab-XCOS to simulate PID controller.ogv - YouTube
https://www.youtube.com/watch?v=CC6yONnLSlY
x2c appears to be a graphical math tool perhaps scilab at the core, which can run on a STM32 nucleo board.
http://www.mechatronic-simulation.org/x2c/x2c-home/
http://www.mechatronic-simulation.org/stm32-nucleo-board/
http://scilab.ninja/study-modules/scilab-control-engineering-basics/module-4-pid-control/
Using Scilab-XCOS to simulate PID controller.ogv - YouTube
https://www.youtube.com/watch?v=CC6yONnLSlY
x2c appears to be a graphical math tool perhaps scilab at the core, which can run on a STM32 nucleo board.
http://www.mechatronic-simulation.org/x2c/x2c-home/
http://www.mechatronic-simulation.org/stm32-nucleo-board/
Welcome to the friendlier side of internet crazy
- AndreyB
- Site Admin
- Posts: 14333
- Joined: Wed Aug 28, 2013 1:28 am
- Location: Jersey City
- Github Username: rusefillc
- Slack: Andrey B
Re: PID autotune
Will just mention it here - DTN0003_Introduction_to_PID_Control.pdf
See https://rusefi.com/forum/viewtopic.php?p=29364#p29366
See https://rusefi.com/forum/viewtopic.php?p=29364#p29366
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
- AndreyB
- Site Admin
- Posts: 14333
- Joined: Wed Aug 28, 2013 1:28 am
- Location: Jersey City
- Github Username: rusefillc
- Slack: Andrey B
Re: PID autotune
Not auto tune but very cool
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Re: PID autotune
This was posted by @mck1117 in slack, it's being posted here to keep an archived copy of it longer term. Slack goes away after a while. The attached is a printed PDF copy of the below link.
https://warwick.ac.uk/fac/cross_fac/iatl/reinvention/archive/volume5issue2/hornsey
https://warwick.ac.uk/fac/cross_fac/iatl/reinvention/archive/volume5issue2/hornsey
- Attachments
-
- A_Review_of_Relay_Auto-tuning_Methods_for_the_Tuning_of_PID-type_Controllers.pdf
- (3.27 MiB) Downloaded 369 times
Welcome to the friendlier side of internet crazy
Re: PID autotune
This page seems to be a quicker way of explaining the relay auto-tune method. PDF copy attached.
https://pages.mtu.edu/~tbco/cm416/Atune.html
https://pages.mtu.edu/~tbco/cm416/Atune.html
- Attachments
-
- Autotune_(Relay)_Tuning_Method_.pdf
- (85.25 KiB) Downloaded 357 times
Welcome to the friendlier side of internet crazy
-
- running engine in first post
- Posts: 1494
- Joined: Mon Jan 30, 2017 2:05 am
- Location: Seattle-ish
Re: PID autotune
Good find - that's a nice concise description of what I've implemented.kb1gtt wrote: ↑Sat Apr 11, 2020 10:22 amThis page seems to be a quicker way of explaining the relay auto-tune method. PDF copy attached.
https://pages.mtu.edu/~tbco/cm416/Atune.html
Re: PID autotune
Did you implement the Ziegler and Nichols method for the PID's that come out of the relay auto-tune method? I'll have to check a process controller I use at work in a temperature chamber we have. I recall it's PID's were very low P, with high I and even higher D. The PID's were crazy, but the end result works very well. It's common that temperature process controllers invert the gain. So perhaps that really is Ziegler, but from memory it didn't seem like it was close to what I expected. I suspect it's some other guess at the PID's.
Welcome to the friendlier side of internet crazy
-
- running engine in first post
- Posts: 1494
- Joined: Mon Jan 30, 2017 2:05 am
- Location: Seattle-ish
Re: PID autotune
Yes - that's what you do with them. The testing (oscillation) yields the ultimate gain (K_u) and oscillation period (T_u) that you then plug in to Zeigler-Nichols. Here's the code that computes kP/kI/kD from Ku/Tu - it should be pretty legible even for non-programmers: https://github.com/rusefi/rusefi/blob/6481b9df0a5def72335904d7753d40729c90ceb2/firmware/controllers/actuators/electronic_throttle.cpp#L260kb1gtt wrote: ↑Sun Apr 12, 2020 12:56 amDid you implement the Ziegler and Nichols method for the PID's that come out of the relay auto-tune method? I'll have to check a process controller I use at work in a temperature chamber we have. I recall it's PID's were very low P, with high I and even higher D. The PID's were crazy, but the end result works very well. It's common that temperature process controllers invert the gain. So perhaps that really is Ziegler, but from memory it didn't seem like it was close to what I expected. I suspect it's some other guess at the PID's.
- AndreyB
- Site Admin
- Posts: 14333
- Joined: Wed Aug 28, 2013 1:28 am
- Location: Jersey City
- Github Username: rusefillc
- Slack: Andrey B
Re: PID autotune
We really need a step by step user documentation and some video tutorial
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Re: PID autotune
I hope this video will help you in setting up your ETB ...
using ETBpid Autotune options ...
using ETBpid Autotune options ...