# Relationship between OptimalControl.jl and ControlSystems.jl

**URL:** https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959
**Category:** Modelling & Simulations
**Tags:** question, control
**Created:** [July 12, 2024, 9:53am UTC](https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959 "2024-07-12T09:53:23Z")
**Posts on this page:** 6
**Page:** 1

<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: [July 12, 2024, 9:53am UTC](https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959/1 "2024-07-12T09:53:23Z")

</div>

At JuliaCon 2024 I learned about the package [OptimalControl.jl](https://control-toolbox.org/docs/optimalcontrol/stable/index.html) and related.

To install them, you need to add a custom registry:

```julia
pkg> registry add https://github.com/control-toolbox/ct-registry.git
pkg> add OptimalControl

```

What is the relationship to [ControlSystems.jl](https://juliacontrol.github.io/ControlSystems.jl/stable/) ?

Do they solve different problems, or is there an overlap?

For example, both can be used to solve an LQR problem:

- [LQR-design](https://juliacontrol.github.io/ControlSystems.jl/stable/examples/example/#LQR-design) with `ControlSystems.jl`
- [LQR example](https://control-toolbox.org/docs/optimalcontrol/stable/tutorial-lqr-basic.html) with `OptimalControl.jl`

What are the advantages and disadvantages of these two packages?

---

<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: [July 12, 2024, 11:26am UTC](https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959/2 "2024-07-12T11:26:36Z")

</div>

One is a tool for classical linear feedback control, whereas the other is a tool for numerical trajectory optimization. There is very little overlap and no relation.

---

<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: [July 12, 2024, 11:41am UTC](https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959/3 "2024-07-12T11:41:48Z")

</div>

So LQR has a very different meaning in the context of linear feedback control and in the context of trajectory optimization?

---

<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: [July 12, 2024, 11:44am UTC](https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959/4 "2024-07-12T11:44:01Z")

</div>

No, but lqr in Controlsystems.jl solvers a very particular version of an lqr problem, in trajectory optimization you can specify the flavor of your cost and time horizon etc, but get a trajectory as result rather than a feedback gain.

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [July 13, 2024, 12:27pm UTC](https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959/5 "2024-07-13T12:27:46Z")

</div>

Indeed, the LQ in LQR suggests that a **L** inear dynamical system, and **Q** uadratic cost function are considered (the **R** stands for regulation). In this regard, the label just specifies the class of a problem, not the way to solve it.

One way we can solve the LQR problem is to formulate and solve a related optimization problem (a quadratic program) in which the control trajectory is the outcome. This gives an open-loop control, which is not particularly useful in practice. There are, however, techniques how to introduce feedback into such scheme, for example the receding horizon control (aka model predictive control). Advantage of this approach is that constraints on the control and state variables can be easily added (true, strictly speaking in presence of constraints the system is no longer linear, but we like to call it linear anyway – constrained linear system).

In the special case when there are no constraints, there is an alternative – and a very elegant and efficient – way to solve the problem. An associated Riccati equation (differential one in the finite final time case, algebraic one in the infinite final time case) can be formulated and solved, which then gives the coefficients for a proportional state feedback controller. An extremely powerful and useful result. It can be that some in the control systems community automatically associate the LQR problem with the Riccati equation based way of solving it.

---

<div class="post-metadata">

### Author: ![jbcaillau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbcaillau/32/206767_2.png) [@jbcaillau](https://discourse.julialang.org/u/jbcaillau)
#### Post date: [September 30, 2025, 12:20pm UTC](https://discourse.julialang.org/t/relationship-between-optimalcontrol-jl-and-controlsystems-jl/116959/6 "2025-09-30T12:20:38Z")

</div>

Dear @ufechner7, dear all, seizing the opportunity of OptimalControl.jl latest release to provide some more details:

> [@\[ANN\] New release of OptimalControl.jl](https://discourse.julialang.org/t/ann-new-release-of-optimalcontrol-jl/132764):
>
> It is a pleasure to announce the new release of [OptimalControl.jl](https://control-toolbox.org/OptimalControl.jl) (v1.1). Intended to solve optimal control problems on ODEs, the package features: a [friendly DSL](https://control-toolbox.org/OptimalControl.jl/stable/manual-abstract.html) both [direct](https://control-toolbox.org/OptimalControl.jl/stable/manual-solve.html) (optimisation) and [indirect](https://control-toolbox.org/OptimalControl.jl/stable/example-double-integrator-time.html#Indirect-method) (aka. shooting) methods [solving on GPU](https://control-toolbox.org/OptimalControl.jl/stable/manual-solve-gpu.html) a bunch of examples: [tutorials](https://control-toolbox.org/Tutorials.jl), [applications](https://control-toolbox.org/MagneticResonanceImaging.jl/stable/saturation.html) and [collection of problems](https://control-toolbox.org/OptimalControlProblems.jl) Give it a try, and if ever the syntax below does not look familiar enough slightly_smiling_face… ocp = @def begin t ∈ [0, 1], time x ∈ R², state u ∈ R, control x(0)…

As pointed by @baggepinnen the package is indeed devoted to trajectory (= solution to ODEs) optimisation, either by direct methods (transcription into nonlinear programs) or indirect methods (multiple shooting on Hamiltonian flows). There are already very nice tools, in particular for direct solving, in other languages (such as Casadi, GPOPS…) or in Julia ([InfiniteOpt.jl](https://infiniteopt.github.io/InfiniteOpt.jl)…) We try to propose a user friendly unified approach for both direct and indirect approaches, including the differential geometric tools needed to do so (check, _e.g._, [Goddard tuto](https://control-toolbox.org/Tutorials.jl/stable/tutorial-goddard.html)). We build upon cutting edge modeller-solver pairs such as ADNLPModels.jl / ExaModels.jl with Ipopt / MadNLP.jl (the latter now allowing to solve control problems on GPU) for the direct part, on OrdinaryDiffEq.jl and AD tools (ForwardDiff.jl + DI) for the indirect one (+ ongoing discussions with @rveltz to leverage [BifurcationKit.jl](https://github.com/bifurcationkit/BifurcationKit.jl) for continuation). The DSL leverages the very nice package [MLStyle.jl](https://thautwarm.github.io/MLStyle.jl) by @thautwarm.

Optimal control of ODEs is all about dynamical systems, optimisation… and use cases: there are several tutorials and applications in the package [documentation](https://control-toolbox.org/OptimalControl.jl), and we welcome issues and PRs 🙂. More to come, with ongoing benchmarks on [OptimalControlProblems.jl](https://control-toolbox.org/OptimalControlProblems.jl).
