You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Kasetsart University: Control Engineering with Julia](https://dewdotninja.github.io/julia/control/julia_control.html)
103
-
-[Czech Technical University: Optimal and Robust Control](https://hurak.github.io/orr/). [github repo](https://github.com/hurak/orr/tree/main)
104
-
-
103
+
-[Czech Technical University: Optimal and Robust Control](https://hurak.github.io/orr/). See also [github repo](https://github.com/hurak/orr/tree/main).
Copy file name to clipboardExpand all lines: lib/ControlSystemsBase/src/synthesis.jl
+35-17Lines changed: 35 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
"""
2
-
lqr(sys, Q, R)
3
-
lqr(Continuous, A, B, Q, R, args...; kwargs...)
4
-
lqr(Discrete, A, B, Q, R, args...; kwargs...)
2
+
lqr(sys, Q, R; extra = Val(false))
3
+
lqr(Continuous, A, B, Q, R, args...; extra = Val(false), kwargs...)
4
+
lqr(Discrete, A, B, Q, R, args...; extra = Val(false), kwargs...)
5
5
6
6
Calculate the optimal gain matrix `K` for the state-feedback law `u = -K*x` that
7
7
minimizes the cost function:
@@ -18,6 +18,8 @@ To obtain also the solution to the Riccati equation and the eigenvalues of the c
18
18
19
19
To obtain a discrete-time approximation to a continuous-time LQR problem, the function [`c2d`](@ref) can be used to obtain corresponding discrete-time cost matrices.
20
20
21
+
If `extra = Val(true)`, the function returns `K, P, p`, where `P` is the solution to the Riccati equation (Lyapunov function `x'P*x`), and `p` are the eigenvalues of `A-BK`.
22
+
21
23
# Examples
22
24
Continuous time
23
25
```julia
@@ -64,14 +66,14 @@ This function requires
64
66
- `R` must be positive definite
65
67
- The pair `(Q,A)` must not have any unobservable modes on the imaginary axis (cont) / unit circle (disc), e.g., there must not be any integrating modes that are not penalized by `Q`. if this condition does not hold, you may get the error "The Hamiltonian matrix is not dichotomic".
66
68
"""
67
-
functionlqr(::ContinuousType, A, B, Q, R, args...; kwargs...)
68
-
S, _, K =arec(A, B, R, Q, args...; kwargs...)
69
-
return K
69
+
functionlqr(::ContinuousType, A, B, Q, R, args...; extra::Val{E}=Val(false), kwargs...)where E
70
+
S, p, K, args...=arec(A, B, R, Q, args...; kwargs...)
71
+
E ? (K, S, p, args...) : K
70
72
end
71
73
72
-
functionlqr(::DiscreteType, A, B, Q, R, args...; kwargs...)
73
-
S, _, K =ared(A, B, R, Q, args...; kwargs...)
74
-
return K
74
+
functionlqr(::DiscreteType, A, B, Q, R, args...; extra::Val{E}=Val(false), kwargs...)where E
75
+
S, p, K, args...=ared(A, B, R, Q, args...; kwargs...)
76
+
E ? (K, S, p, args...) : K
75
77
end
76
78
77
79
@deprecatelqr(A::AbstractMatrix, args...; kwargs...) lqr(Continuous, A, args...; kwargs...)
@@ -80,9 +82,9 @@ end
80
82
81
83
82
84
"""
83
-
kalman(Continuous, A, C, R1, R2)
84
-
kalman(Discrete, A, C, R1, R2; direct = false)
85
-
kalman(sys, R1, R2; direct = false)
85
+
kalman(Continuous, A, C, R1, R2; extra=Val(false))
86
+
kalman(Discrete, A, C, R1, R2; extra=Val(false), direct = false)
87
+
kalman(sys, R1, R2; extra=Val(false), direct = false)
86
88
87
89
Calculate the optimal asymptotic Kalman gain for the linear-Gaussian model
88
90
```math
@@ -93,26 +95,42 @@ y &= Cx + v
93
95
```
94
96
where `w` is the dynamics noise with covariance `R1` and `v` is the measurement noise with covariance `R2`.
95
97
96
-
If `direct = true`, the observer gain is computed for the pair `(A, CA)` instead of `(A,C)`. This option is intended to be used together with the option `direct = true` to [`observer_controller`](@ref). Ref: "Computer-Controlled Systems" pp 140. `direct = false` is sometimes referred to as a "delayed" estimator, while `direct = true` is a "current" estimator.
98
+
In discrete time, the returned Kalman gain `K` is designed to be used with (`direct = false`)
99
+
```math
100
+
x(t+1|t) = (A-KC)x(t|t-1) + Bu(t) + Ky(t)
101
+
```
102
+
and (`direct = true`)
103
+
```math
104
+
x(t+1|t+1) = (A-KC)x(t|t) + Bu(t) + Ky(t+1)
105
+
```
106
+
107
+
If `direct = true`, the observer gain is computed as ``K_d = R_∞C^T (R_2 + CR_∞ C^T)^{-1}`` instead of ``K = A K_d``. This option is intended to be used together with the option `direct = true` to [`observer_controller`](@ref). Ref: "Computer-Controlled Systems" pp 140. `direct = false` is sometimes referred to as a "delayed" estimator, while `direct = true` is a "current" estimator.
97
108
98
109
To obtain a discrete-time approximation to a continuous-time LQG problem, the function [`c2d`](@ref) can be used to obtain corresponding discrete-time covariance matrices.
99
110
100
111
To obtain an LTISystem that represents the Kalman filter, pass the obtained Kalman feedback gain into [`observer_filter`](@ref). To obtain an LQG controller, pass the obtained Kalman feedback gain as well as a state-feedback gain computed using [`lqr`](@ref) into [`observer_controller`](@ref).
101
112
102
-
The `args...; kwargs...` are sent to the Riccati solver, allowing specification of cross-covariance etc. See `?MatrixEquations.arec/ared` for more help.
113
+
If `extra = Val(true)`, the function returns `K, R∞, p`, where `R∞` is the solution to the Riccati equation (the stationary prediction-error covariance matrix, the covariance of ``x̃(t|t-1)``), and `p` are the eigenvalues of `A-KC`. In this case, the _filtering error_ covariance is given by ``(I-KC) R∞``, i.e., the covariance of ``x̃(t|t)``.
114
+
115
+
The `args...; kwargs...` are sent to the Riccati solver, allowing specification of cross-covariance etc. See `?ControlSystemsBase.MatrixEquations.arec/ared` for more help.
103
116
104
117
# FAQ
105
118
This function requires
106
119
- `R1` must be positive semi-definite
107
120
- `R2` must be positive definite
108
121
- The pair `(A,R1)` must not have any uncontrollable modes on the imaginary axis (cont) / unit circle (disc), e.g., there must not be any integrating modes that are not affected through `R1`. if this condition does not hold, you may get the error "The Hamiltonian matrix is not dichotomic".
122
+
123
+
# Extended help
124
+
`MatrixEquations.ared` solves the Riccati equation corresponding to the direct form, but returns the ``K`` matrix for the indirect form. The solution to the Riccati equation is the stationary prediction-error covariance matrix ``R_∞``, and the filtering error covariance is given by ``(I-A^{-1}KC) R_∞``. If using the direct form, the filter-error covariance is given by ``(I-K_d C) R_∞``
109
125
"""
110
-
functionkalman(te, A, C, R1,R2, args...; direct =false, kwargs...)
126
+
functionkalman(te, A, C, R1,R2, args...; direct =false, extra::Val{E}=Val(false), kwargs...) where E
0 commit comments