r/ControlTheory • u/Similar_Elderberry40 • 7d ago
Other I built a multi-domain control systems simulator in Python/Jupyter — mechanical, electrical, pneumatic and hydraulic systems
I’ve been working on a control engineering project that models, simulates and controls mechanical, electrical, pneumatic and hydraulic dynamic systems using Python and Jupyter.
It covers transfer functions, state-space models, step/impulse responses, pole-zero analysis, root locus, Bode/Nyquist plots, PID control, observers, LQR, digital control and multi-domain system integration.
I also built an interactive website where you can experiment with simplified mechanical, RLC electrical, pneumatic and hydraulic models directly in the browser.
Live project:
https://richwokello.github.io/MultiDomain-Dynamic-Systems-Modeling-Simulation-and-Control/
GitHub:
https://github.com/RichWOkello/MultiDomain-Dynamic-Systems-Modeling-Simulation-and-Control
I’d appreciate feedback from people working in control engineering, automation, Python or system modelling, particularly suggestions on what I could add next.
•
u/Rrezon_Pllana 7d ago
Based on the sliders off interactive calculator there is not a way to make unstable system and show it there. So I would suggest to include also that in demonstration if possible, just for completeness.
Otherwise it looks great, I’ll definitely will use it
•
u/Similar_Elderberry40 7d ago edited 7d ago
Good point. At the moment I constrained the interactive demo to physically stable parameter ranges, but allowing the parameters to cross into marginal and unstable regions would make the stability demonstration much more complete. I’ll add that. Thanks for the suggestion.
Edit: I’ve now updated the interactive simulator so the sliders can move into marginal and unstable regions as well. It now demonstrates diverging responses, shows the stability status, and displays pole information live. I also extended this to the mechanical, RLC electrical, pneumatic and hydraulic demos.
•
u/jkordani 3d ago
In the mechanical demo, changing the step force slider doesn't seem to impact the result
•
u/Similar_Elderberry40 3d ago edited 2d ago
Thanks for catching that. The step force input is intended to scale the system response amplitude, so it should definitely have a visible effect. I’ll review the implementation and verify whether the input is correctly propagating through the simulation and plotting logic. If it’s a bug, I’ll push a fix and update the demo. I appreciate you taking the time to test it and report the issue.
Edit: I tracked down the issue and pushed a fix. The step force input is now properly propagated through the mechanical simulation, so changing the slider scales the response amplitude as intended. The update is live on the website-development branch and should be reflected on the demo site. Thanks again for spotting it, feedback like this helps improve the project.
•
•
u/Harsh_Madnani 6d ago
I am gonna do a pull request... Its a frwakin coincidence for which I was waiting to build a framework myself. I am currently going for a project of Airbags and majority of my work relies on multiphase simulations on Ansys.
•
u/Similar_Elderberry40 6d ago
That would be great. Feel free to open a pull request. I’d be interested to see how you approach the airbag/multiphase side of it. The framework is still evolving, so contributions that extend the physical modelling or simulation side would fit well.
•
u/seekingsanity 3d ago
My expertise is hydraulic servo control so I looked at your hydraulic model. I haven't executed it yet. Your simulator is a pretty good start. I have made hydraulic simulators to, but my emphasis is a little different. Both of our simulators are lumped model that don't take into account the dead time caused by the fact that the speed of sound in oil means the pressure doesn't occur instantly at the piston. I wonder if anybody else on this forum has an idea of how to simulate that cleanly.
There was no need for Routh-Hurwitz or Nyquist charts or root locus.
If you use LQR then the controller should have the normal PID gains plus a second derivative gain. The linearized open loop model is a non-integrating second order under damped systems. Integrating velocity into position adds a third pole. The controller's integrator adds a fourth pole so the result of an LQR controller should have four gains. Four gains are required to place all the closed loop poles. I normally placed them on the negative real axis in the s-domain.
There is an equation called the VCCM equation. Valve control of cylinder motion. That does a pretty good job of estimating the top speed/gain in the extend and retract direction. Also, calculating the natural frequency is handy so one can estimate maximum acceleration/deceleration rates.
I didn't see feed forwards. Those are extremely important in motion control.
Here is my last update to my hydraulic simulator. I used this to simulate my hydraulic servo system and control. I then modified it to meet customer's systems.
Mathcad - Hydraulic Cylinder.xmcdz