Jump to content



Featured Articles

Check out the latest featured articles.

File Library

Check out the latest downloads available in the File Library.

New Article

Product Viscosity vs. Shear

Featured File

Vertical Tank Selection

New Blog Entry

Low Flow in Pipes- posted in Ankur's blog

0

Python Control Library Step_Info Returning Nan For All Parameters

python control modelling

5 replies to this topic
Share this topic:
| More

#1 HWIK

HWIK

    Brand New Member

  • Members
  • 8 posts

Posted 08 October 2022 - 09:20 AM

Hi, I am running the following code for a unit step response in a closed loop transfer function on Python using the control library in python:

import control as c

kc = 0.9*3/23
d = c.pade(0.3)
Gp = c.tf([1],[1,1])*c.tf(d[0],d[1])
ti = 1
Gc = kc*c.tf([ti, 1], [ti, 0])
sys1 = Gc*Gp/(1+Gc*Gp)
data1 = c.step_info(sys1)
print(data1)

And the output I get:

{'RiseTime': nan, 'SettlingTime': nan, 'SettlingMin': nan, 'SettlingMax': nan, 'Overshoot': nan, 'Undershoot': nan, 'Peak': inf, 'PeakTime': inf, 'SteadyStateValue': nan}

Which isn't correct, as from plotting the step response the output profile is stable, and it parameters such as RiseTime and SettlingTime should be defined. I tried doing it in Matlab and I got specific answers for it. So why is this nan in Python?
Thanks for your time!



#2 Saml

Saml

    Gold Member

  • Members
  • 301 posts

Posted 08 October 2022 - 09:51 AM

May be this?

 

https://python-contr...ml#installation

 

 

Many parts of python-control will work without slycot, but some functionality is limited or absent, and installation of slycot is recommended. Users can check to insure that slycot is installed correctly by running the command

 

python -c "import slycot"

 



#3 HWIK

HWIK

    Brand New Member

  • Members
  • 8 posts

Posted 08 October 2022 - 10:09 AM

 

May be this?

 

https://python-contr...ml#installation

 

 

Many parts of python-control will work without slycot, but some functionality is limited or absent, and installation of slycot is recommended. Users can check to insure that slycot is installed correctly by running the command

 

python -c "import slycot"

 

 

Thanks for the suggestion! Unfortunately I tried doing that, but it didn't work.



#4 Saml

Saml

    Gold Member

  • Members
  • 301 posts

Posted 09 October 2022 - 07:07 PM

I suppose that in the following line you wanted to write the transfer function of a PI controller. I see many things here:

Gc = kc*c.tf([ti, 1], [ti, 0])

The parameters in the tf function are a polynomial in s, starting from the higher exponent.

 

For a PI controller, that function is (in your nomenclature where kc is the proportional constant)

 

Kc + Ki/s  where Ki is Kc/ti. Taking Kc outside of the equation, then your transfer function is

 

Kc * (1+s/ti)/s

 

So the parameters of the Gc transfer function should be:

 

[1,1/t] and [1,0]

 

When you write that line as

Gc = kc*c.tf([1,1/ti], [0, 1])

It yields

{'RiseTime': 0.2562817118891321, 'SettlingTime': 0.562166335756806, 'SettlingMin': 0.09475317415593856, 'SettlingMax': 0.10505836575875488, 'Overshoot': 0, 'Undershoot': 126.60098522167488, 'Peak': 0.1330049261083744, 'PeakTime': 0.0, 'SteadyStateValue': 0.10505836575875488}

Now, you would get better answers if you put comments on your code and clarify what the variables mean and what you are intending to do.

 

I am just guessing that by Kc you wanted to writh the proportional constant but don't have a clue of what 0.9*3/23 means. Why are you using a delay, what "ti" is (may mean temperature or time, initial or integral).

 

And... by the way. if Gp is the process and Gc is the controller, you have the the transfer function for the closed loop wrong. It is a guess, you don't mention what you are trying to model

 

Instead of

Gc*Gp/(1+Gc*Gp)

The correct one , if Gc is the transfer function of a PI controller is:

Gp/(1+Gc*Gp)

If that is the case, the results are

{'RiseTime': 2.220933139341779, 'SettlingTime': 4.18058002699629, 'SettlingMin': 0.8064923681896231, 'SettlingMax': 0.8949416342412453, 'Overshoot': 0, 'Undershoot': 4.959759304365055, 'Peak': 0.8937741215508875, 'PeakTime': 6.907755278982151, 'SteadyStateValue': 0.8949416342412453}

Edited by Saml, 09 October 2022 - 07:09 PM.


#5 HWIK

HWIK

    Brand New Member

  • Members
  • 8 posts

Posted 10 October 2022 - 06:30 AM

 

I suppose that in the following line you wanted to write the transfer function of a PI controller. I see many things here:

Gc = kc*c.tf([ti, 1], [ti, 0])

The parameters in the tf function are a polynomial in s, starting from the higher exponent.

 

For a PI controller, that function is (in your nomenclature where kc is the proportional constant)

 

Kc + Ki/s  where Ki is Kc/ti. Taking Kc outside of the equation, then your transfer function is

 

Kc * (1+s/ti)/s

 

So the parameters of the Gc transfer function should be:

 

[1,1/t] and [1,0]

 

When you write that line as

Gc = kc*c.tf([1,1/ti], [0, 1])

It yields

{'RiseTime': 0.2562817118891321, 'SettlingTime': 0.562166335756806, 'SettlingMin': 0.09475317415593856, 'SettlingMax': 0.10505836575875488, 'Overshoot': 0, 'Undershoot': 126.60098522167488, 'Peak': 0.1330049261083744, 'PeakTime': 0.0, 'SteadyStateValue': 0.10505836575875488}

Now, you would get better answers if you put comments on your code and clarify what the variables mean and what you are intending to do.

 

I am just guessing that by Kc you wanted to writh the proportional constant but don't have a clue of what 0.9*3/23 means. Why are you using a delay, what "ti" is (may mean temperature or time, initial or integral).

 

And... by the way. if Gp is the process and Gc is the controller, you have the the transfer function for the closed loop wrong. It is a guess, you don't mention what you are trying to model

 

Instead of

Gc*Gp/(1+Gc*Gp)

The correct one , if Gc is the transfer function of a PI controller is:

Gp/(1+Gc*Gp)

If that is the case, the results are

{'RiseTime': 2.220933139341779, 'SettlingTime': 4.18058002699629, 'SettlingMin': 0.8064923681896231, 'SettlingMax': 0.8949416342412453, 'Overshoot': 0, 'Undershoot': 4.959759304365055, 'Peak': 0.8937741215508875, 'PeakTime': 6.907755278982151, 'SteadyStateValue': 0.8949416342412453}

Thanks for the reply Saml, I now do realize that the problem may be quite abstract given that I did not include much of an explanation on what is being done there. But your interpretation of the variables and how they are set up is indeed correct.

We were given this problem as part of a process control class, where we were just given the process transfer function (Gp) and we are asked to design a feedback PI controller according to a given set of rules, which to me yielded the values given in kc (proportional gain) and ti (integral time delay) given in the code.

Unfortunately I don't see how you arrive to your controller transfer function: 

Gc = kc*c.tf([1,1/ti], [0, 1])

Which would give: kc*(s+1/ti)/1, which is not in accordance with an ideal PI controller transfer function.

 

Furthermore, for a feedback loop setup I believe the transfer function I give is correct, where do you lose the Gc term in the numerator?

UZeXK.png

So I still don't see where the problem would be in the code given in the question.



#6 Saml

Saml

    Gold Member

  • Members
  • 301 posts

Posted 18 October 2022 - 07:54 AM

It is not what you believe. It is the problem you are trying to solve. That you don't tell.

 

The scheme you show is not how a PI feedback controller works.






Similar Topics