|
29 | 29 | from .timeresp import _check_convert_array, _process_time_response, \ |
30 | 30 | TimeResponseData |
31 | 31 |
|
32 | | -__all__ = ['NonlinearIOSystem', 'InterconnectedSystem', |
| 32 | +__all__ = ['NonlinearIOSystem', 'InterconnectedSystem', 'nlsys', |
33 | 33 | 'input_output_response', 'find_eqpt', 'linearize', |
34 | 34 | 'interconnect'] |
35 | 35 |
|
@@ -1133,6 +1133,100 @@ def check_unused_signals( |
1133 | 1133 | return dropped_inputs, dropped_outputs |
1134 | 1134 |
|
1135 | 1135 |
|
| 1136 | +def nlsys( |
| 1137 | + updfcn, outfcn=None, inputs=None, outputs=None, states=None, **kwargs): |
| 1138 | + """Create a nonlinear input/output system. |
| 1139 | +
|
| 1140 | + Creates an :class:`~control.InputOutputSystem` for a nonlinear system by |
| 1141 | + specifying a state update function and an output function. The new system |
| 1142 | + can be a continuous or discrete time system. |
| 1143 | +
|
| 1144 | + Parameters |
| 1145 | + ---------- |
| 1146 | + updfcn : callable |
| 1147 | + Function returning the state update function |
| 1148 | +
|
| 1149 | + `updfcn(t, x, u, params) -> array` |
| 1150 | +
|
| 1151 | + where `x` is a 1-D array with shape (nstates,), `u` is a 1-D array |
| 1152 | + with shape (ninputs,), `t` is a float representing the currrent |
| 1153 | + time, and `params` is a dict containing the values of parameters |
| 1154 | + used by the function. |
| 1155 | +
|
| 1156 | + outfcn : callable |
| 1157 | + Function returning the output at the given state |
| 1158 | +
|
| 1159 | + `outfcn(t, x, u, params) -> array` |
| 1160 | +
|
| 1161 | + where the arguments are the same as for `upfcn`. |
| 1162 | +
|
| 1163 | + inputs : int, list of str or None, optional |
| 1164 | + Description of the system inputs. This can be given as an integer |
| 1165 | + count or as a list of strings that name the individual signals. |
| 1166 | + If an integer count is specified, the names of the signal will be |
| 1167 | + of the form `s[i]` (where `s` is one of `u`, `y`, or `x`). If |
| 1168 | + this parameter is not given or given as `None`, the relevant |
| 1169 | + quantity will be determined when possible based on other |
| 1170 | + information provided to functions using the system. |
| 1171 | +
|
| 1172 | + outputs : int, list of str or None, optional |
| 1173 | + Description of the system outputs. Same format as `inputs`. |
| 1174 | +
|
| 1175 | + states : int, list of str, or None, optional |
| 1176 | + Description of the system states. Same format as `inputs`. |
| 1177 | +
|
| 1178 | + dt : timebase, optional |
| 1179 | + The timebase for the system, used to specify whether the system is |
| 1180 | + operating in continuous or discrete time. It can have the |
| 1181 | + following values: |
| 1182 | +
|
| 1183 | + * dt = 0: continuous time system (default) |
| 1184 | + * dt > 0: discrete time system with sampling period 'dt' |
| 1185 | + * dt = True: discrete time with unspecified sampling period |
| 1186 | + * dt = None: no timebase specified |
| 1187 | +
|
| 1188 | + name : string, optional |
| 1189 | + System name (used for specifying signals). If unspecified, a |
| 1190 | + generic name <sys[id]> is generated with a unique integer id. |
| 1191 | +
|
| 1192 | + params : dict, optional |
| 1193 | + Parameter values for the systems. Passed to the evaluation |
| 1194 | + functions for the system as default values, overriding internal |
| 1195 | + defaults. |
| 1196 | +
|
| 1197 | + Returns |
| 1198 | + ------- |
| 1199 | + sys : :class:`NonlinearIOSystem` |
| 1200 | + Nonlinear input/output system. |
| 1201 | +
|
| 1202 | + See Also |
| 1203 | + -------- |
| 1204 | + ss, tf |
| 1205 | +
|
| 1206 | + Example |
| 1207 | + ------- |
| 1208 | + >>> def kincar_update(t, x, u, params): |
| 1209 | + ... l = params.get('l', 1) # wheelbase |
| 1210 | + ... return np.array([ |
| 1211 | + ... np.cos(x[2]) * u[0], # x velocity |
| 1212 | + ... np.sin(x[2]) * u[0], # y velocity |
| 1213 | + ... np.tan(u[1]) * u[0] / l # angular velocity |
| 1214 | + ... ]) |
| 1215 | + >>> |
| 1216 | + >>> def kincar_output(t, x, u, params): |
| 1217 | + ... return x[0:2] # x, y position |
| 1218 | + >>> |
| 1219 | + >>> kincar = ct.nlsys( |
| 1220 | + ... kincar_update, kincar_output, states=3, inputs=2, outputs=2) |
| 1221 | + >>> |
| 1222 | + >>> timepts = np.linspace(0, 10) |
| 1223 | + >>> response = ct.input_output_response( |
| 1224 | + ... kincar, timepts, [10, 0.05 * np.sin(timepts)]) |
| 1225 | + """ |
| 1226 | + return NonlinearIOSystem( |
| 1227 | + updfcn, outfcn, inputs=inputs, outputs=outputs, states=states, **kwargs) |
| 1228 | + |
| 1229 | + |
1136 | 1230 | def input_output_response( |
1137 | 1231 | sys, T, U=0., X0=0, params=None, |
1138 | 1232 | transpose=False, return_x=False, squeeze=None, |
|
0 commit comments