# Known disturbances in JuliaSimControl MPC

**URL:** <https://discourse.julialang.org/t/known-disturbances-in-juliasimcontrol-mpc/119810>\
**Category:** Modelling & Simulations\
**Tags:** juliasim\
**Created:** [September 24, 2024, 1:58pm UTC](https://discourse.julialang.org/t/known-disturbances-in-juliasimcontrol-mpc/119810 "2024-09-24T13:58:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertrand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertrand/32/212196_2.png) [@bertrand](https://discourse.julialang.org/u/bertrand)\
**Post date:** [September 24, 2024, 1:58pm UTC](https://discourse.julialang.org/t/known-disturbances-in-juliasimcontrol-mpc/119810/1 "2024-09-24T13:58:38Z")

</div>

Hi,

I’m writing an MPC with known external disturbances using JuliaSimControl.  
I’m currently passing the known disturbances `w` as part of the parameter vector into the dynamics function, i.e.

```julia
function dynamics(x, u, p, t)
    tvec, w = p.t, p.w

    i = findfirst(>=(t), tvec)
    u_tot = [u[1:nu]; w[:, i]]
    # Assumes linear system for simplicity
    return A * x + B * u_tot
end

```

and then `p` gets updated at every time step.

Now I want to use an EKF for state estimation, and saw the `ObserverInput` type also has a field `w` for known disturbances. So know I wonder what the recommended way for passing around known disturbances is in JuliaSimControl?

Any help appreciated 🙂

---

<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:** [September 24, 2024, 3:37pm UTC](https://discourse.julialang.org/t/known-disturbances-in-juliasimcontrol-mpc/119810/2 "2024-09-24T15:37:00Z")

</div>

Hello 👋

There are currently no observers that have support for the `w` argument. You could still make use of known external disturbances by performing the steps inside `MPC.step!` manually, those are

- Run the `correct!` step of the observer (measurement update) with `u_tot` as input (if `w` is relevant to the measurement update)
- Create the ControllerInput and pass it to `MPC.optimize!` using something like this

```julia
controllerinput = ControllerInput(MPC.state(prob.observer), prob.xr, w, u)
controlleroutput = optimize!(prob, controllerinput, p, t; kwargs...)

```

- Run the prediction step (`predict!`) of the observer with `u_tot` as input.

The dynamics that is used in the observer needs to be adapted to accept this larger `u` as input for this to work.

Does this make sense? It’s on the roadmap to add support for the `w` argument, but since we use observers from the library LowLevelParticleFilters.jl which do not have this argument, there is some interface work to be done that hasn’t taken place yet.

---

<div class="post-metadata">

**Author:** ![bertrand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertrand/32/212196_2.png) [@bertrand](https://discourse.julialang.org/u/bertrand)\
**Post date:** [September 25, 2024, 7:48am UTC](https://discourse.julialang.org/t/known-disturbances-in-juliasimcontrol-mpc/119810/3 "2024-09-25T07:48:22Z")

</div>

I think it makes sense, yes. Thank you! If I get stuck I’ll just post again 😉

In general, fantastic work that you’ve been doing with the control packages in Julia 👏

---

<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:** [September 25, 2024, 8:00am UTC](https://discourse.julialang.org/t/known-disturbances-in-juliasimcontrol-mpc/119810/4 "2024-09-25T08:00:49Z")

</div>

> [@bertrand](#):
>
> In general, fantastic work that you’ve been doing with the control packages in Julia

Thank you 😍
