8000 Merge pull request #923 from KybernetikJo/doc-fix-create_statefbk_ios… · python-control/python-control@0a6146b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a6146b

Browse files
authored
Merge pull request #923 from KybernetikJo/doc-fix-create_statefbk_iosystem
< 8000 div width="60px" height="22px" class="Box-sc-g0xbh4-0 LoadingSkeleton-sc-695d630a-0 kHfwUD kRBfod">
2 parents 405bf77 + e65750a commit 0a6146b

File tree

2 files changed

+52
-35
lines changed

2 files changed

+52
-35
lines changed

control/statefbk.py

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ def acker(A, B, poles):
296296

297297

298298
def lqr(*args, **kwargs):
299-
"""lqr(A, B, Q, R[, N])
299+
r"""lqr(A, B, Q, R[, N])
300300
301301
Linear quadratic regulator design.
302302
303303
The lqr() function computes the optimal state feedback controller
304304
u = -K x that minimizes the quadratic cost
305305
306-
.. math:: J = \\int_0^\\infty (x' Q x + u' R u + 2 x' N u) dt
306+
.. math:: J = \int_0^\infty (x' Q x + u' R u + 2 x' N u) dt
307307
308308
The function can be called with either 3, 4, or 5 arguments:
309309
@@ -442,14 +442,14 @@ def lqr(*args, **kwargs):
442442

443443

444444
def dlqr(*args, **kwargs):
445-
"""dlqr(A, B, Q, R[, N])
445+
r"""dlqr(A, B, Q, R[, N])
446446
447447
Discrete-time linear quadratic regulator design.
448448
449449
The dlqr() function computes the optimal state feedback controller
450450
u[n] = - K x[n] that minimizes the quadratic cost
451451
452-
.. math:: J = \\sum_0^\\infty (x[n]' Q x[n] + u[n]' R u[n] + 2 x[n]' N u[n])
452+
.. math:: J = \sum_0^\infty (x[n]' Q x[n] + u[n]' R u[n] + 2 x[n]' N u[n])
453453
454454
The function can be called with either 3, 4, or 5 arguments:
455455
@@ -584,14 +584,14 @@ def create_statefbk_iosystem(
584584
xd_labels=None, ud_labels=None, gainsched_indices=None,
585585
gainsched_method='linear', control_indices=None, state_indices=None,
586586
name=None, inputs=None, outputs=None, states=None, **kwargs):
587-
"""Create an I/O system using a (full) state feedback controller.
587+
r"""Create an I/O system using a (full) state feedback controller.
588588
589589
This function creates an input/output system that implements a
590590
state feedback controller of the form
591591
592-
u = ud - K_p (x - xd) - K_i integral(C x - C x_d)
592+
.. math:: u = u_d - K_p (x - x_d) - K_i \int(C x - C x_d)
593593
594-
It can be called in the form
594+
It can be called in the form::
595595
596596
ctrl, clsys = ct.create_statefbk_iosystem(sys, K)
597597
@@ -603,9 +603,9 @@ def create_statefbk_iosystem(
603603
gains and a corresponding list of values of a set of scheduling
604604
variables. In this case, the controller has the form
605605
606-
u = ud - K_p(mu) (x - xd) - K_i(mu) integral(C x - C x_d)
606+
.. math:: u = u_d - K_p(\mu) (x - x_d) - K_i(\mu) \int(C x - C x_d)
607607
608-
where mu represents the scheduling variable.
608+
where :math:`\mu` represents the scheduling variable.
609609
610610
Parameters
611611
----------
@@ -614,7 +614,7 @@ def create_statefbk_iosystem(
614614
is given, the output of this system should represent the full state.
615615
616616
gain : ndarray or tuple
617-
If an array is given, it represents the state feedback gain (K).
617+
If an array is given, it represents the state feedback gain (`K`).
618618
This matrix defines the gains to be applied to the system. If
619619
`integral_action` is None, then the dimensions of this array
620620
should be (sys.ninputs, sys.nstates). If `integral action` is
@@ -623,18 +623,18 @@ def create_statefbk_iosystem(
623623
624624
If a tuple is given, then it specifies a gain schedule. The tuple
625625
should be of the form `(gains, points)` where gains is a list of
626-
gains :math:`K_j` and points is a list of values :math:`\\mu_j` at
627-
which the gains are computed. The `gainsched_indices` parameter
628-
should be used to specify the scheduling variables.
626+
gains `K_j` and points is a list of values `mu_j` at which the
627+
gains are computed. The `gainsched_indices` parameter should be
628+
used to specify the scheduling variables.
629629
630630
xd_labels, ud_labels : str or list of str, optional
631631
Set the name of the signals to use for the desired state and
632-
inputs. If a single string is specified, it should be a
633-
format string using the variable `i` as an index. Otherwise,
634-
a list of strings matching the size of xd and ud,
635-
respectively, should be used. Default is "xd[{i}]" for
636-
xd_labels and "ud[{i}]" for ud_labels. These settings can
637-
also be overriden using the `inputs` keyword.
632+
inputs. If a single string is specified, it should be a format
633+
string using the variable `i` as an index. Otherwise, a list of
634+
strings matching the size of `x_d` and `u_d`, respectively, should
635+
be used. Default is "xd[{i}]" for xd_labels and "ud[{i}]" for
636+
ud_labels. These settings can also be overridden using the
637+
`inputs` keyword.
638638
639639
integral_action : ndarray, optional
640640
If this keyword is specified, the controller can include integral
@@ -650,13 +650,13 @@ def create_statefbk_iosystem(
650650
gainsched_indices : int, slice, or list of int or str, optional
651651
If a gain scheduled controller is specified, specify the indices of
652652
the controller input to use for scheduling the gain. The input to
653-
the controller is the desired state xd, the desired input ud, and
654-
the system state x (or state estimate xhat, if an estimator is
655-
given). If value is an integer `q`, the first `q` values of the
656-
[xd, ud, x] vector are used. Otherwise, the value should be a
657-
slice or a list of indices. The list of indices can be specified
658-
as either integer offsets or as signal names. The default is to
659-
use the desired state xd.
653+
the controller is the desired state `x_d`, the desired input `u_d`,
654+
and the system state `x` (or state estimate `xhat`, if an
655+
estimator is given). If value is an integer `q`, the first `q`
656+
values of the `[x_d, u_d, x]` vector are used. Otherwise, the
657+
value should be a slice or a list of indices. The list of indices
658+
can be specified as either integer offsets or as signal names. The
659+
default is to use the desired state `x_d`.
660660
661661
gainsched_method : str, optional
662662
The method to use for gain scheduling. Possible values are 'linear'
@@ -677,10 +677,10 @@ def create_statefbk_iosystem(
677677
-------
678678
ctrl : NonlinearIOSystem
679679
Input/output system representing the controller. This system
680-
takes as inputs the desired state `xd`, the desired input
681-
`ud`, and either the system state `x` or the estimated state
680+
takes as inputs the desired state `x_d`, the desired input
681+
`u_d`, and either the system state `x` or the estimated state
682682
`xhat`. It outputs the controller action `u` according to the
683-
formula :math:`u = u_d - K(x - x_d)`. If the keyword
683+
formula `u = u_d - K(x - x_d)`. If the keyword
684684
`integral_action` is specified, then an additional set of
685685
integrators is included in the control system (with the gain
686686
matrix `K` having the integral gains appended after the state
@@ -690,7 +690,7 @@ def create_statefbk_iosystem(
690690
691691
clsys : NonlinearIOSystem
692692
Input/output system representing the closed loop system. This
693-
systems takes as inputs the desired trajectory `(xd, ud)` and
693+
system takes as inputs the desired trajectory `(x_d, u_d)` and
694694
outputs the system state `x` and the applied input `u`
695695
(vertically stacked).
696696
@@ -721,6 +721,23 @@ def create_statefbk_iosystem(
721721
System name. If unspecified, a generic name <sys[id]> is generated
722722
with a unique integer id.
723723
724+
Examples
725+
--------
726+
>>> import control as ct
727+
>>> import numpy as np
728+
>>>
729+
>>> A = [[0, 1], [-0.5, -0.1]]
730+
>>> B = [[0], [1]]
731+
>>> C = np.eye(2)
732+
>>> D = np.zeros((2, 1))
733+
>>> sys = ct.ss(A, B, C, D)
734+
>>>
735+
>>> Q = np.eye(2)
736+
>>> R = np.eye(1)
737+
>>>
738+
>>> K, _, _ = ct.lqr(sys,Q,R)
739+
>>> ctrl, clsys = ct.create_statefbk_iosystem(sys, K)
740+
724741
"""
725742
# Make sure that we were passed an I/O system as an input
726743
if not isinstance(sys, NonlinearIOSystem):

control/stochsys.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@
3636

3737
# contributed by Sawyer B. Fuller <minster@uw.edu>
3838
def lqe(*args, **kwargs):
39-
"""lqe(A, G, C, QN, RN, [, NN])
39+
r"""lqe(A, G, C, QN, RN, [, NN])
4040
4141
Linear quadratic estimator design (Kalman filter) for continuous-time
4242
systems. Given the system
4343
4444
.. math::
4545
46-
x &= Ax + Bu + Gw \\\\
46+
dx/dt &= Ax + Bu + Gw \\
4747
y &= Cx + Du + v
4848
4949
with unbiased process noise w and measurement noise v with covariances
5050
51-
.. math:: E{ww'} = QN, E{vv'} = RN, E{wv'} = NN
51+
.. math:: E\{w w^T\} = QN, E\{v v^T\} = RN, E\{w v^T\} = NN
5252
5353
The lqe() function computes the observer gain matrix L such that the
5454
stationary (non-time-varying) Kalman filter
5555
56-
.. math:: x_e = A x_e + B u + L(y - C x_e - D u)
56+
.. math:: dx_e/dt = A x_e + B u + L(y - C x_e - D u)
5757
5858
produces a state estimate x_e that minimizes the expected squared error
5959
using the sensor measurements y. The noise cross-correlation `NN` is
@@ -195,7 +195,7 @@ def dlqe(*args, **kwargs):
195195
196196
with unbiased process noise w and measurement noise v with covariances
197197
198-
.. math:: E{ww'} = QN, E{vv'} = RN, E{wv'} = NN
198+
.. math:: E\{w w^T\} = QN, E\{v v^T\} = RN, E\{w v^T\} = NN
199199
200200
The dlqe() function computes the observer gain matrix L such that the
201201
stationary (non-time-varying) Kalman filter

0 commit comments

Comments
 (0)
0