PID sampling time in modelingtoolkit

Hi. I’ve built a modelingtoolkit model to simulate my process system. It uses PID controllers, the issue is that the control system has a sampling time of 1s. This has a huge effect on the parameters for the controller and the level of control they can have. How would you simulate this in modelingtoolkit?

Not trivial, because hybrid systems (combining continuous and discrete elements) are not yet well-supported.

I would use the integrator interface and implement the controller in Julia (without MTK) and only your process in MTK. For the controller, you could, for example, use GitHub - JuliaControl/DiscretePIDs.jl: Discrete-time PID controllers in Julia .

But there might be better ways to do this.

Thanks, that’s what I was thinking, but it gets quite messy with multiple controllers etc

Example for a dual-loop PID controller with linearization: SimpleKiteControllers.jl/src/parking_controller.jl at main · OpenSourceAWE/SimpleKiteControllers.jl · GitHub

I don’t find it messy, but your mileage might vary.