cascaded pids

113 visualizzazioni
Passa al primo messaggio da leggere

Mohamad Rajab Alkhashman

da leggere,
5 apr 2021, 05:12:2805/04/21
a DIY PID Control
Hi
How can I have two cascaded pids in my code.

Pieter S

da leggere,
5 apr 2021, 05:31:4005/04/21
a diy-pid...@googlegroups.com
Hi,

You can initiate two instances of pid controller object (ie. myPID1 and myPID2),  each with its own parameters.

Probably the inner control loop will be the faster, you may need to map output of outer to input of inner loop.

Share your control diagram/programming effort.







On Mon, 05 Apr 2021, 11:12 Mohamad Rajab Alkhashman, <mohamadr...@gmail.com> wrote:
Hi
How can I have two cascaded pids in my code.

--
You received this message because you are subscribed to the Google Groups "DIY PID Control" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diy-pid-contr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/6d11624f-3a3a-4a9c-b970-3dc1c8a5a277n%40googlegroups.com.

Mohamad Rajab

da leggere,
5 apr 2021, 06:02:3305/04/21
a diy-pid...@googlegroups.com

Hi

 

Thanks for your help but can you tell me how to map output of outer to input of inner loop in the code.

There is my code.

 

 

 

Skickades från E-post för Windows 10

1.PNG
2.PNG
3.PNG

Pieter S

da leggere,
5 apr 2021, 06:21:4405/04/21
a diy-pid...@googlegroups.com
PID myPIDx(&Inputx, &Outputx, &Setpointx,Kpx,Kix,Kdx, DIRECT);
I.e.: x=[1=fast,2=slow]
Your PID's share same output, setpoint?

You need to have seperate parameters.

The slower outer loop output, is then the faster inner loop setpoint, and the inner loop output is used in analogwrite.

You can call the slower loop myPID2.compute() only once for say 10 myPID1.compute().

The aim is to get the inner loop to be stable, while the outer loop do minimum inner loop setpoint changes.

Maybe share your controlsystem diagram? 




Mohamad Rajab Alkhashman

da leggere,
5 apr 2021, 06:30:1705/04/21
a diy-pid...@googlegroups.com
I have the same setpoint and output.

20210405_122931.jpg

Pieter S

da leggere,
5 apr 2021, 06:39:4905/04/21
a diy-pid...@googlegroups.com
Yes, that's why I request your control set up/diagram. 


Not sure if your problem is a cascaded problem.

Mohamad Rajab Alkhashman

da leggere,
5 apr 2021, 06:46:5105/04/21
a diy-pid...@googlegroups.com
20210405_124553.jpg

Brett Beauregard

da leggere,
5 apr 2021, 07:04:4305/04/21
a DIY PID Control
what think Pieter is saying is that you may not need cascade to control the level in the bottom tank.

Cascade is primarily a disturbance rejection strategy.  It will be useful if the upper tank gives you some early warning to a disturbance that affects the lower tank (fluctuations in the inlet flow, for example).

If it doesn't, you could just control the bottom tank based on one sensor and call it a day.

To see up cascade in code, you need a separate set of variables wired in to the inner pid. Say &input2, &output2, &setpoint2.

The, somewhere in void loop{} do setpoint2=output1;

You could alternately just make setpoint2 and output1 the same variable (maybe called "out1sp2"). That would be more robust, but maybe a little harder to follow when debugging.


Pieter S

da leggere,
5 apr 2021, 10:00:0505/04/21
a diy-pid...@googlegroups.com
image.png


Not sure about physical layout of system (assume as in figure above) :- 

Try something like this?

PID1 setpoint1 is (SP1 + output2)  

SP1 and SP2 are the required water levels of tank 1 and 2 respectively.

Set PID2 sample time slower than PID1's sample time (say 10x ??) to allow for approximate settling of PID1

Pump (motor) only activated by output1. 

Be careful of delay() and calls to peripherals - it may screw up your pid cycle time - rather use the Waterlevel1 and ..2 variables than calling sensx.ping_cm again?

Share your results (graphs) with us?



Mohamad Rajab

da leggere,
5 apr 2021, 14:43:2605/04/21
a diy-pid...@googlegroups.com

Thank you very much for your help

 

Skickades från E-post för Windows 10

 

Från: Pieter S
Skickat: den 5 april 2021 16:00
Till: diy-pid...@googlegroups.com
Ämne: Re: [diy-pid-control] cascaded pids

 

Brett Beauregard

da leggere,
5 apr 2021, 15:13:4305/04/21
a DIY PID Control
To avoid confusion, I'll note that Pieter and I named pid1 and pid2 backwards from each other. 

Pieter S

da leggere,
6 apr 2021, 00:34:2606/04/21
a diy-pid...@googlegroups.com
Thanks Brett

yes,  the err is mine.

Seems industry standard / litterature takes the first PID (outer loop) as master or primary (1) and the second (inner loop) PID - surprise-surprise - as secondary (2). 

It pays to take notice of standards (even for hobby, school projects).

Regards,




Brett Beauregard

da leggere,
6 apr 2021, 06:27:3806/04/21
a DIY PID Control
Pieter, I think that the guy who posts the detailed flowchart gets to decide what things are called!  I was mapping my nomenclature to your great answer.

To avoid things like this, my preference is to use the "inner/outer" convention, but there's no "rule".  

Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi