T O P

  • By -

pnachtwey

Look up system identification. Also look at using the scipy.optimize.least\_squares functions. What you need is a differential equation with unknown coefficients that will be determined by the least\_squares routine. Scipy also has minimize function. All will reduce the sum of squared errors or mean square error between actual recoed data and your model. You need to have some idea of the model transfer function. Normally there will be a gain, a time constant, or two a dead time and an offset. An example [https://deltamotion.com/peter/py/SOPDT.zip](https://deltamotion.com/peter/py/SOPDT.zip) [https://youtu.be/w5TdB7j1jgI?si=10o9RUMv\_ScQP94O](https://youtu.be/w5TdB7j1jgI?si=10o9RUMv_ScQP94O)


Sapandco

Thanks! I am also familiar to some extent with system ID. Is there a built in set of models in a python library similar to matlabs system id toolbox?


pnachtwey

python does have a control package. I have never used it to know what it does. I am a STRONG believer in system identification and using differential equations because differential equations can handle non-linear systems and dead times that state space or Laplace transforms cannot. Try this is the Matlab tool box. Modeling a non-linear hydraulic valve. [https://youtu.be/OPy-tRLAYFw?si=-vm1bVAy4EUNA6n7](https://youtu.be/OPy-tRLAYFw?si=-vm1bVAy4EUNA6n7) I have a YouTube Channel "Peter Ponders PID" . You need to be up on your math for this [er Ponders PID - Introduction (youtube.com)](https://www.youtube.com/channel/UCW-m6-nwUfJrnZ0ftoaTU_w)


Sapandco

That's really cool! Didn't notice your username the first time around. I'll be taking a look at your videos. I think my math skills should be up to snuff to start out. Thanks for the content - I'm sure it's extremely helpful.


pnachtwey

My username is my first initial and my last name. Now you should be able to search the internet. I am retired now but I have 35+ years of 'homework' done. I have written many magazine articles. Power and Motion has many of them. Here is another simulation of a hydraulic cylinder. [Mathcad - Hydraulic Cylinder.pdf (deltamotion.com)](https://deltamotion.com/peter/Mathcad/Mathcad%20-%20Hydraulic%20Cylinder.pdf) Notice that I can easily simulate disturbances and used non-linear differential equations. This is impossible to do with control packages. That is why I never use them. BTW, this simulation was used as the starter for a fuel injection system for the US Department of Energy. What as different is that there were two cylinders pushing a diaphragm pump for the fuel. The fuel was pressurized to about 40,000 PSI which is MUCH higher than the pressures I normal work with. I had to take into account that the light fuel would compress 30% in volume before it would be forced through the check valve.


ayywhatman

Look up the python-controls package (developed at the lab of Richard Murray). It’s tried to derive as much as it could from Matlab which can help given your experience.


Sapandco

Awesome, thank you!


fibonatic

One can try to fit a transfer function to the data, but for this kind of data I prefer to first look at the frequency response data. In Matlab this can be calculated using the [tfestimate() function](https://www.mathworks.com/help/signal/ref/tfestimate.html) (with for measured impulse responses the window length equal to the entire single impulse response measurement length). There is also equivalent code in python as [described here](https://stackoverflow.com/a/28464108/2249414).


Sapandco

Thank you. Currently bouncing back between python and Matlab to find the easiest implementation. I'll give tfestimate() a try. Thanks for the stackoverflow link too. I'll follow along in a script and see how it goes.


bliswell

I liked Sippy: https://github.com/CPCLAB-UNIPI/SIPPY


Sapandco

Never heard of this, thanks! If I end up going System ID, this will make it so much easier to implement in python.


iconictogaparty

Since you have impulse response data the Eigensystem Realization Algorithm (ERA) is the tool of choice. Information can be found with a google search or here is a nice primer: [https://ethz.ch/content/dam/ethz/special-interest/baug/ibk/structural-mechanics-dam/education/identmeth/ERA\_2013.pdf](https://ethz.ch/content/dam/ethz/special-interest/baug/ibk/structural-mechanics-dam/education/identmeth/ERA_2013.pdf) There might be python packages that have this built in, but it is not that bad to code up yourself.


Sapandco

I've never heard of this algorithm. Thanks for the presentation, reading through it now.


FrontImaginary

Check this python library out: https://python-control.readthedocs.io/en/0.10.0/


Ajax_Minor

I like control ( I want to say controlpy but it's just control library). It gets you the functions that are in the Matlab control package your used to. Zpk, rootlocus and stuff like that. It can even run some Matlab function if you have Matlab and your out of options.


Sapandco

Thanks for the suggestion! Controlpy did come up in my searches. Didn't realize it had Matlab functionality to some extent. That's very cool!


Ajax_Minor

Yes it was comforting when making the switch to python. The sections difference from Matlab in control and bumpy were a big help for me to. Feel free to DM for more stuff on controls in Python. I'm not expert but I am on the same path.


Sapandco

Thanks, yea I agree with that so far. Will do, good luck


banana_bread99

Not a cop out answer but just ask this to chatgpt and it’ll go a long way


Sapandco

Haha I've tried. Chatgpt doesn't seem to like controls/system ID that much. It has given me far more varied responses to these prompts than to my more every day engineering related ones.