@@ -187,33 +187,49 @@ time optimal controller. For the second two forms, the :func:`dlqr`
187187function can be used. Additional arguments and details are given on
188188the :func: `lqr ` and :func: `dlqr ` documentation pages.
189189
190- .. todo ::
191- Convert the following code to testcode
190+ .. testsetup :: kalman
191+
192+ sys = ct.rss(2, 2, 2)
193+ Qu = np.eye(2)
194+ Qv = np.eye(2)
195+ Qw = np.eye(2)
196+ Qx = np.eye(2)
197+
198+ timepts = np.linspace(0, 10)
199+ U = ct.white_noise(timepts, Qv)
200+ Y = ct.white_noise(timepts, Qw)
201+
202+ X0 = np.zeros(2)
203+ P0 = np.eye(2)
192204
193205The :func: `create_estimator_iosystem ` function can be used to create
194206an I/O system implementing a Kalman filter, including integration of
195207the Riccati ODE. The command has the form
196208
197- .. code ::
209+ .. testcode :: kalman
198210
199211 estim = ct.create_estimator_iosystem(sys, Qv, Qw)
200212
201213The input to the estimator is the measured outputs `Y ` and the system
202214input `U `. To run the estimator on a noisy signal, use the command
203215
204- .. code ::
216+ .. testcode :: kalman
205217
206- resp = ct.input_output_response(est , timepts, [Y, U], [X0, P0])
218+ resp = ct.input_output_response(estim , timepts, [Y, U], [X0, P0])
207219
208220If desired, the :func: `correct ` parameter can be set to False
209- to allow prediction with no additional sensor information::
221+ to allow prediction with no additional sensor information:
222+
223+ .. testcode :: kalman
210224
211225 resp = ct.input_output_response(
212- estim, timepts, 0, [X0, P0], param ={'correct': False})
226+ estim, timepts, 0, [X0, P0], params ={'correct': False})
213227
214228The :func: `create_estimator_iosystem ` and
215229:func: `create_statefbk_iosystem ` functions can be used to combine an
216- estimator with a state feedback controller::
230+ estimator with a state feedback controller:
231+
232+ .. testcode :: kalman
217233
218234 K, _, _ = ct.lqr(sys, Qx, Qu)
219235 estim = ct.create_estimator_iosystem(sys, Qv, Qw, P0)
@@ -229,13 +245,19 @@ estimated state :math:`\hat x` (output of `estim`):
229245
230246 The closed loop controller `clsys ` includes both the state
231247feedback and the estimator dynamics and takes as its input the desired
232- state :math: `x_\text {d}` and input :math: `u_\text {d}`::
248+ state :math: `x_\text {d}` and input :math: `u_\text {d}`:
249+
250+ .. testcode :: kalman
251+ :hide:
252+
253+ Xd = np.zeros((2, timepts.size))
254+ Ud = np.zeros((2, timepts.size))
255+
256+ .. testcode :: kalman
233257
234258 resp = ct.input_output_response(
235259 clsys, timepts, [Xd, Ud], [X0, np.zeros_like(X0), P0])
236260
237- .. todo ::
238- Add example (with plots?)
239261
240262
241263Maximum Likelihood Estimation
@@ -374,5 +396,17 @@ problems:
374396 optimal.gaussian_likelihood_cost
375397 optimal.disturbance_range_constraint
376398
377- .. todo ::
378- Add example: LQE vs MHE (from CDS 112)
399+ Examples
400+ ========
401+
402+ The following examples illustrate the use of tools from the stochastic
403+ systems module. Background information for these examples can be
404+ found in the FBS2e supplement on `Optimization-Based Control
405+ <https://fbswiki.org/wiki/index.php/OBC> `_).
406+
407+ .. toctree ::
408+ :maxdepth: 1
409+
410+ Kalman filter (kinematic car) <examples/kincar-fusion >
411+ (Extended) Kalman filtering (PVTOL) <examples/kalman-pvtol >
412+ Moving horizon estimation (PVTOL) <examples/mhe-pvtol >
0 commit comments