# Controls variables for ODESystem

**URL:** <https://discourse.julialang.org/t/controls-variables-for-odesystem/78204>\
**Category:** Modelling & Simulations\
**Tags:** documentation, control, modelingtoolkit\
**Created:** [March 21, 2022, 10:06am UTC](https://discourse.julialang.org/t/controls-variables-for-odesystem/78204 "2022-03-21T10:06:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jedforrest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jedforrest/32/37502_2.png) [@jedforrest](https://discourse.julialang.org/u/jedforrest)\
**Post date:** [March 21, 2022, 10:06am UTC](https://discourse.julialang.org/t/controls-variables-for-odesystem/78204/1 "2022-03-21T10:06:20Z")

</div>

Hi all,

I’m looking through the [documentation](https://mtk.sciml.ai/stable/systems/ODESystem/#System-Constructors) on ODESystems in ModelingToolkit and came across the `ctrls` (control parameters) argument for ODESystems:

> - `ctrls`  
> Control parameters (some subset of `ps` ).

This sounds like something I’m after, but I can’t seem to find any examples in the documentation of this argument being used explicitly.

My questions:

1. Are there any existing examples of how to use control variables like this for ODESystems?
2. Can these control variables be any external function? Something like that exists [here](https://mtk.sciml.ai/stable/tutorials/ode_modeling/#Specifying-a-time-variable-forcing-function), but I don’t know if this works here too
3. Since these control variables are a subset of the parameters, can any parameter be selected as a control variable after the model is built, or do these need to be defined beforehand?

Thanks!

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 13, 2022, 6:31am UTC](https://discourse.julialang.org/t/controls-variables-for-odesystem/78204/2 "2022-05-13T06:31:08Z")

</div>

The functionality attached to the `ctrls` field is not very well developed at the moment. You may have a look at the example that starts [here](https://github.com/SciML/ModelingToolkit.jl/blob/6b92d37c6f7cd57cb5d4036123f6e5787cc212a5/test/input_output_handling.jl#L108) by defining

```julia
@variables u(t) [input=true] 

```

followed by

```julia
f, dvs, ps = ModelingToolkit.generate_control_function(model, expression=Val{false}, simplify=true)

```

which generates a tuple of functions `f` where `f[1]` is a function on the form

```julia
ẋ = f(x, u, p, t)

```

where x is the state and u the control input. Note that this functionality is still quite limited and this is why it’s not yet fully documented.

For simulation of systems with control inputs using MTK, see [this example](https://help.juliahub.com/Control/#Example:-PID-control-with-ModelingToolkit)
