1818
1919from . import config
2020from .exception import ControlNotImplemented
21- from .namedio import _process_indices , _process_control_disturbance_indices
21+ from .namedio import _process_indices , _process_labels , \
22+ _process_control_disturbance_indices
23+
2224
2325# Define module default parameter values
2426_optimal_trajectory_methods = {'shooting' , 'collocation' }
@@ -859,11 +861,11 @@ def _output(t, x, u, params={}):
859861 return res .inputs [:, 0 ]
860862
861863 # Define signal names, if they are not already given
862- if not kwargs .get ('inputs' ):
864+ if kwargs .get ('inputs' ) is None :
863865 kwargs ['inputs' ] = self .system .state_labels
864- if not kwargs .get ('outputs' ):
866+ if kwargs .get ('outputs' ) is None :
865867 kwargs ['outputs' ] = self .system .input_labels
866- if not kwargs .get ('states' ):
868+ if kwargs .get ('states' ) is None :
867869 kwargs ['states' ] = self .system .ninputs * \
868870 (self .timepts .size if self .basis is None else self .basis .N )
869871
@@ -1125,6 +1127,15 @@ def create_mpc_iosystem(
11251127 returning the current input to be applied that minimizes the cost
11261128 function while satisfying the constraints.
11271129
1130+ Other Parameters
1131+ ----------------
1132+ inputs, outputs, states : int or list of str, optional
1133+ Set the names of the inputs, outputs, and states, as described in
1134+ :func:`~control.InputOutputSystem`.
1135+ name : string, optional
1136+ System name (used for specifying signals). If unspecified, a generic
1137+ name <sys[id]> is generated with a unique integer id.
1138+
11281139 Notes
11291140 -----
11301141 Additional keyword parameters can be used to fine tune the behavior of
@@ -1676,9 +1687,9 @@ def compute_estimate(
16761687 # xhat, u, v, y for all previous time points. When the system update
16771688 # function is called,
16781689 #
1679- # TODO: change output_labels to output_fmtstr and use output instead
1680- #
1681- def create_mhe_iosystem ( self , output_labels = None , ** kwargs ):
1690+ def create_mhe_iosystem (
1691+ self , estimate_labels = None , measurement_labels = None ,
1692+ control_labels = None , inputs = None , outputs = None , ** kwargs ):
16821693 """Create an I/O system implementing an MPC controller
16831694
16841695 This function creates an input/output system that implements a
@@ -1688,12 +1699,24 @@ def create_mhe_iosystem(self, output_labels=None, **kwargs):
16881699
16891700 Parameters
16901701 ----------
1691- output_labels : str, optional
1692- Set the name of the estimator outputs (state estimate). If a
1693- single string is specified, it should be a format string using
1694- the variable `i` as an index. Otherwise, a list of strings
1695- matching the size of the system state should be used. Default
1696- is "xhat[{i}]".
1702+ estimate_labels : str or list of str, optional
1703+ Set the name of the signals to use for the estimated state
1704+ (estimator outputs). If a single string is specified, it
1705+ should be a format string using the variable ``i`` as an index.
1706+ Otherwise, a list of strings matching the size of the estimated
1707+ state should be used. Default is "xhat[{i}]". These settings
1708+ can also be overriden using the `outputs` keyword.
1709+ measurement_labels, control_labels : str or list of str, optional
1710+ Set the name of the measurement and control signal names
1711+ (estimator inputs). If a single string is specified, it should
1712+ be a format string using the variable ``i`` as an index.
1713+ Otherwise, a list of strings matching the size of the system
1714+ inputs and outputs should be used. Default is the signal names
1715+ for the system outputs and control inputs. These settings can
1716+ also be overriden using the `inputs` keyword.
1717+ **kwargs, optional
1718+ Additional keyword arguments to set system, input, and output
1719+ signal names; see :func:`~control.InputOutputSystem`.
16971720
16981721 Returns
16991722 -------
@@ -1721,20 +1744,24 @@ def create_mhe_iosystem(self, output_labels=None, **kwargs):
17211744 _process_control_disturbance_indices (
17221745 self .system , self .control_indices , self .disturbance_indices )
17231746
1724- # Figure out the labels to use
1725- # TODO: allow overwrite via kwargs + change parameter name
1726- if isinstance (output_labels , str ):
1727- # Generate labels using the argument as a format string
1728- output_labels = [output_labels .format (i = i )
1729- for i in range (self .system .nstates )]
1747+ # Figure out the signal labels to use
1748+ estimate_labels = _process_labels (
1749+ estimate_labels , 'estimate' ,
1750+ [f'xhat[{ i } ]' for i in range (self .system .nstates )])
1751+ outputs = estimate_labels if outputs is None else outputs
17301752
1731- # TODO: allow overwrite via kwargs
1732- sensor_labels = [self .system .output_labels [i ]
1733- for i in range (self .system .noutputs )]
1734- input_labels = [self .system .input_labels [i ] for i in self .ctrl_idx ]
1753+ measurement_labels = _process_labels (
1754+ measurement_labels , 'measurement' , self .system .output_labels )
1755+ control_labels = _process_labels (
1756+ control_labels , 'control' ,
1757+ [self .system .input_labels [i ] for i in self .ctrl_idx ])
1758+ inputs = measurement_labels + control_labels if inputs is None \
1759+ else inputs
17351760
17361761 nstates = (self .system .nstates + self .system .ninputs
17371762 + self .system .noutputs ) * self .timepts .size
1763+ if kwargs .get ('states' ):
1764+ raise ValueError ("user-specified state signal names not allowed" )
17381765
17391766 # Utility function to extract elements from MHE state vector
17401767 def _xvec_next (xvec , off , size ):
@@ -1781,9 +1808,8 @@ def _mhe_output(t, xvec, uvec, params={}):
17811808 return self .system ._rhs (t , xhat [:, - 1 ], u_v [:, - 1 ])
17821809
17831810 return ct .NonlinearIOSystem (
1784- _mhe_update , _mhe_output , states = nstates ,
1785- inputs = sensor_labels + input_labels ,
1786- outputs = output_labels , dt = self .system .dt , ** kwargs )
1811+ _mhe_update , _mhe_output , dt = self .system .dt ,
1812+ states = nstates , inputs = inputs , outputs = outputs , ** kwargs )
17871813
17881814
17891815# Optimal estimation result
0 commit comments