# PID sampling time in modelingtoolkit

**URL:** https://discourse.julialang.org/t/pid-sampling-time-in-modelingtoolkit/134671
**Category:** Modelling & Simulations
**Tags:** package, control, mtk
**Created:** [December 21, 2025, 6:51pm UTC](https://discourse.julialang.org/t/pid-sampling-time-in-modelingtoolkit/134671 "2025-12-21T18:51:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![victor](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@victor](https://discourse.julialang.org/u/victor)
#### Post date: [December 21, 2025, 6:51pm UTC](https://discourse.julialang.org/t/pid-sampling-time-in-modelingtoolkit/134671/1 "2025-12-21T18:51:35Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [December 21, 2025, 11:37pm UTC](https://discourse.julialang.org/t/pid-sampling-time-in-modelingtoolkit/134671/2 "2025-12-21T23:37:19Z")

</div>

Not trivial, because [hybrid systems](https://docs.sciml.ai/ModelingToolkit/stable/API/model_building/#Hybrid-systems) (combining continuous and discrete elements) are not yet well-supported.

I would use the [integrator interface](https://docs.sciml.ai/DiffEqDocs/stable/basics/integrator/) 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](https://github.com/JuliaControl/DiscretePIDs.jl) .

But there might be better ways to do this.

---

<div class="post-metadata">

### Author: ![victor](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@victor](https://discourse.julialang.org/u/victor)
#### Post date: [December 22, 2025, 4:13pm UTC](https://discourse.julialang.org/t/pid-sampling-time-in-modelingtoolkit/134671/3 "2025-12-22T16:13:26Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [December 22, 2025, 4:36pm UTC](https://discourse.julialang.org/t/pid-sampling-time-in-modelingtoolkit/134671/4 "2025-12-22T16:36:06Z")

</div>

> [@victor](#):
>
> but it gets quite messy with multiple controllers

Example for a dual-loop PID controller with linearization: [SimpleKiteControllers.jl/src/parking\_controller.jl at main · OpenSourceAWE/SimpleKiteControllers.jl · GitHub](https://github.com/OpenSourceAWE/SimpleKiteControllers.jl/blob/main/src/parking_controller.jl)

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