ssutil¶
buzz.ssutil
Functions
|
Given a system this function will return a system whose output is the sum of two or more outputs of the original system |
|
Add a delay to a system |
|
|
|
To compute a reduced order model (Ar,Br,Cr,Dr) for an original state-space representation (A,B,C,D) by using either the square-root or the balancing-free square-root Singular Perturbation Approximation (SPA) model reduction method for the alpha-stable part of the system. |
|
Plot the bode plot of a MIMO system |
|
Connect two state space systems and combine their name dictionaries |
Get the controllability matrix of a system |
|
|
|
|
duplicate the output of a system. |
|
|
|
|
|
Given a system, this function returns the gain margin of the system. |
|
Get the number of inputs and outputs of a model. |
|
Check the controllability of a system |
|
Check if the system is a descriptor system. |
|
check if the system is of the buzz.ss.MIMOStateSpace type |
|
Check the observability of a system |
|
check if the system is siso |
|
Check if a system is stable |
|
List the poles of a system. |
|
List the zeros of a system. |
|
load a system from a file |
|
Load the zeros, poles, and gain of a system from a file. |
|
makeFullModel takes all the principle systems for the EMPFF model and combines them into a single system. This function is used to combine the plant, the environment noise, the measurement noise, and the two FOMs into a single system. This function is used to combine the plant, the environment noise, the measurement noise, and the two FOMs into a single system. The function will also adjust the plant to make it strictly proper if it is not already. The function will also check that the plant, the environment noise, the measurement noise, and the two FOMs are all stable. |
|
makeSPOFF takes all the principle systems for the SPOFF model and combines them into a single system. |
|
Make a system with iod and mod. |
|
Make a given state-space model stable by shifting the eigenvalues of the A matrix. |
|
Merge a list of systems into one system. |
|
Minreal function for Bunch systems |
|
Connect a list of systems together. |
|
Make the negative of a system. |
|
Normalize the maximum gain of a system to 1. |
|
Get the observability matrix of a system |
|
Get the order of the system |
|
|
|
Take an iod and remove the inputs and outputs specified by the indices and or names provided in the inputs_to_remove and outputs_to_remove lists |
|
Rename an input or output |
|
|
|
Save the zeros, poles, and gain of a system to a file. |
|
Save the system to a file. |
|
Scale an input or output |
|
Switch the inputs and outputs of the system |
|
Transpose the system |
|
Reduce a system to the specified inputs and outputs while removing unobservable states |
|
Details
- addOutputs(sys, outputs: list = None, newnames=None, iod=None)[source]¶
Given a system this function will return a system whose output is the sum of two or more outputs of the original system
- Parameters:
sys (control.ss or Bunch) – State space model or bunch system with mod as attribute
outputs (list) – list of outputs to add together or list of lists of outputs to add together. Default to None #list of lists not implemented yet
newnames (list or str, optional) – list of names for the new outputs. Defaults to None.
iod (dict, optional) – input/output dictionary. Defaults to None.
- Returns:
Bunch with mod and iod as attributes
- Return type:
Bunch
- add_delay(sys, delay)[source]¶
Add a delay to a system
- Parameters:
sys (wield.siso) – SISO system to add a delay to
delay (float) – The delay to add to the system in seconds.
- Returns:
SISO system with the delay added
- Return type:
wield.siso
- balance_sys_gain(sys, func='ab09nd', method='sqrt', equil=True, iod=None, verbose=False, **kwargs)[source]¶
To compute a reduced order model (Ar,Br,Cr,Dr) for an original state-space representation (A,B,C,D) by using either the square-root or the balancing-free square-root Singular Perturbation Approximation (SPA) model reduction method for the alpha-stable part of the system. - From SLICOT Documentation for ab09nd (https://www.slicot.org/objects/software/shared/doc/AB09ND.html)
- Parameters:
sys (Bunch) – Bunch system with mod as attribute.
func (str, optional) – Function to use for reduction. ‘ab09nd’: use the ab09nd function. ‘ab09md’: use the ab09md function. ‘tb01id’: use the tb01id function. ‘ab09ad’: use the ab09ad function. Defaults to ‘ab09nd’.
method (str, optional) – Method to use for reduction. ‘sqrt’: use the square-root SPA method. ‘bfsqrt’: use the balancing-free square-root SPA method. Defaults to ‘sqrt’.
equil (bool, optional) – If True, preliminarily equilibrates the triplet (A,B,C). Defaults to True.
iod (dict, optional) – input/output dictionary. Defaults to None.
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace.
- Return type:
wield.bunch
- bode(sys, ax=None, plotting_omega=None, label=None, omega_limits=None, UG_line=False, axB=None, **kwargs)[source]¶
Plot the bode plot of a MIMO system
- Parameters:
sys (wield.MIMO or wield.SISO) – MIMO system to plot
ax (_type_, optional) – The axes to plot on. Defaults to None.
plotting_omega (np.array, optional) – Plotting omega. Defaults to None.
label (string, optional) – Label for the plot trace. Defaults to None.
omega_limits (list, optional) – Limits for the omega. Defaults to None.
UG_line (bool, optional) – If true, a unity gain line will be plotted. Defaults to False.
axB (_type_, optional) – The axes to plot on. Depreciated replaced by ax. Defaults to None.
- Returns:
the axis to plot on
- Return type:
_type_
- connect(SS1, SS1_dict, SS2, SS2_dict, con_names)[source]¶
Connect two state space systems and combine their name dictionaries
- Parameters:
SS1 (control.statesp.StateSpace) – first state space system
SS1_dict (dict) – dictionary of names of the first state space system
SS2 (control.statesp.StateSpace) – second state space system
SS2_dict (dict) – dictionary of names of the second state space system
con_names (list) – list of connections between the two state space systems
- Returns:
combined state space system with connections between the two systems dictionary: dictionary of names and indices of the combined state space system
- Return type:
control.statesp.StateSpace
- controllabilityMatrix(sys)[source]¶
Get the controllability matrix of a system
- Parameters:
sys (wield.MIMO | wield.SISO) – MIMO or SISO system to get the controllability matrix of
- Returns:
controllability matrix of the system
- Return type:
np.array
- duplicate_io(sys, io, iogain=None)[source]¶
duplicate the output of a system. This adds a C and D row to the system
- Parameters:
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace.
- Return type:
wield.bunch
- get_margin(sys, input=None, output=None)[source]¶
Given a system, this function returns the gain margin of the system.
- Parameters:
sys – (Bunch): Bunch system with mod as attribute and iod as attribute. iod is optional in the bunch (array | list): array of system data to use for the gain margin of the form [mag, phase, omega]
input (int, optional) – Input to use for the gain margin. Defaults to None.
output (int, optional) – Output to use for the gain margin. Defaults to None.
- Returns:
Gain margin of the system phase_margin (float): Phase margin of the system in degrees
- Return type:
gain_margin (float)
- isControllable(sys)[source]¶
Check the controllability of a system
- Parameters:
sys (wield.MIMO | wield.SISO) – MIMO or SISO system to check the controllability of
- Returns:
True if the system is controllable, False if the system is not controllable
- Return type:
- isDescriptor(sys, error=True, print_error=True)[source]¶
Check if the system is a descriptor system. A descriptor system is a system where the E matrix is not None and not all zeros.
- Parameters:
sys (wield.MIMO | wield.SISO) – MIMO or SISO system to check if it is a descriptor system
error (bool, optional) – If True, an error will be raised if the system is not a descriptor system. Defaults to True.
- Returns:
True if the system is a descriptor system, False if the system is not a descriptor system
- Return type:
- isMIMO(sys)[source]¶
check if the system is of the buzz.ss.MIMOStateSpace type
- Parameters:
sys (any) – system to check
- Returns:
True if the system is of the buzz.ss.MIMOStateSpace type, False if not
- Return type:
Bool
- isObservable(sys)[source]¶
Check the observability of a system
- Parameters:
sys (wield.MIMO | wield.SISO) – MIMO or SISO system to check the observability of
- Returns:
True if the system is observable, False if the system is not observable
- Return type:
- isSISO(sys)[source]¶
check if the system is siso
- Parameters:
sys (wield.siso) – SISO system to check
- Returns:
True if the system is SISO, False if the system is not SISO
- Return type:
- isStable(sys)[source]¶
Check if a system is stable
- Parameters:
sys (Bunch or MIMO, SISO sys) – System where the A matrix of it’s state space can be accesses by sys.A or sys.mod.A
- Returns:
True if stable, False if unstable
- Return type:
- listpoles(sys)[source]¶
List the poles of a system.
- Parameters:
sys (Bunch or MIMO, SISO sys) – System where the A matrix of it’s state space can be accesses by sys.A or sys.mod.A
- Returns:
List of poles
- Return type:
np.array
- listzeros(sys)[source]¶
List the zeros of a system. Adapted from python control library
- Parameters:
sys (Bunch or MIMO, SISO sys) – System where the A matrix of it’s state space can be accesses by sys.A or sys.mod.A
- Returns:
List of zeros
- Return type:
- loadSys(fname)[source]¶
load a system from a file
- Parameters:
fname (string) – the filename of the file to load
- Returns:
the system that was loaded
- Return type:
wield statespace
- load_zpk(fname='sys_zpk.yml', asZPK=False, **kwargs)[source]¶
Load the zeros, poles, and gain of a system from a file.
- Parameters:
- Returns:
system with zeros, poles, and gain loaded from the file. Includes the iod if present in file. If asZPK is true, the system will be returned as a zeros, poles, and gain model.
- Return type:
wield state space
- makeFullModel(E, P, M, F1, F2, extras=False, EM=None, Zinf=True, diagnostic=False, delay=None, balance=False, include_F1=True, Ein=None, Eout=None, Min=None, Mout=None, Pin=None, Pout=None, F1in=None, F1out=None, F2in=None, F2out=None)[source]¶
makeFullModel takes all the principle systems for the EMPFF model and combines them into a single system. This function is used to combine the plant, the environment noise, the measurement noise, and the two FOMs into a single system. This function is used to combine the plant, the environment noise, the measurement noise, and the two FOMs into a single system. The function will also adjust the plant to make it strictly proper if it is not already. The function will also check that the plant, the environment noise, the measurement noise, and the two FOMs are all stable.
>>>>>>> dev
- Args:
E (Wield State Space): The state space model of the environment noise P (Wield State Space): The state space model of the plant M (Wield State Space): The state space model of the measurement noise F1 (Wield State Space): The first FOM. This is normally the shaped FOM. It would be better to keep this one as the shaped FOM. F2 (Wield State Space): The second FOM. This is normally the flat FOM. It would be better to keep this one as the flat FOM. extras (string, bool, optional): Weather or not to add extra outputs for high frequency/low frequency FOMS. If output is ‘F3’, then the function will add an output after the controller that is equilivelant to actuator cost passed through F1. If extras is ‘F3_withP’, then the function will add an output after the controller that is equilivelant to actuator cost passed through the plant and F1. Defaults to False. EM (Wield State Space, optional): A two input two output system that combines the environment noise and the measurement noise. This is only used if the environmental noise and the measurement noise are interconected. For example in the LIGO test mass control case the shaking from seismic desturbances also shakes the shadow sensors so the environmental noise also effects the measurement noise. Defaults to None. Zinf (bool, optional): Weather to add a Z infinity input to the system. Defaults to True. diagnostic (bool, optional): Weather to print diagnostic information. Defaults to False. delay (float, optional): The delay of the system. Defaults to None. balance (bool, optional): If true the function will use the balance_sys_gain function to balance the system. Defaults to False. include_F1 (bool, optional): If False, it will drop the F1 FOM output. Typically only used when using the F3 FOM output. Defaults to True. Ein (string, optional): The name of the input to the environment noise system. Defaults to None. Eout (string, optional): The name of the output to the environment noise system. Defaults to None. Min (string, optional): The name of the input to the measurement noise system. Defaults to None. Mout (string, optional): The name of the output to the measurement noise system. Defaults to None. Pin (string, optional): The name of the input to the plant. Defaults to None. Pout (string, optional): The name of the output to the plant. Defaults to None. F1in (string, optional): The name of the input to the F1 system. Defaults to None. F1out (string, optional): The name of the output to the F1 system. Defaults to None. F2in (string, optional): The name of the input to the F2 system. Defaults to None. F2out (string, optional): The name of the output to the F2 system. Defaults to None.
- Returns:
Wield State Space: The combined EMPFF system
- makeSPOFF(S, P, O, F1, F2, extras=False, SO=None, Zinf=True, diagnostic=False, delay=None, balance=False, include_F1=True, Ein=None, Eout=None, Min=None, Mout=None, Pin=None, Pout=None, F1in=None, F1out=None, F2in=None, F2out=None)[source]¶
makeSPOFF takes all the principle systems for the SPOFF model and combines them into a single system. This function is used to combine the plant, the environment noise, the measurement noise, and the two FOMs into a single system. This function is used to combine the plant, the environment noise, the measurement noise, and the two FOMs into a single system. The function will also adjust the plant to make it strictly proper if it is not already. The function will also check that the plant, the environment noise, the measurement noise, and the two FOMs are all stable.
- makeSys(mod, iod, wield=True, dt=0.0001)[source]¶
Make a system with iod and mod.
Note: This is legacy code and should be replaced with wieldSys
- Parameters:
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace. or wield.control.mimo: system with the input output dictionary if wield is True
- Return type:
wield.bunch
- make_stable(sys)[source]¶
Make a given state-space model stable by shifting the eigenvalues of the A matrix. if system is stable, it will return the same system.
- Parameters:
ss_model (control.StateSpace) – The state-space model to be made stable.
- Returns:
A new state-space model that is stable.
- Return type:
Wield MIMO SS
- mergeSys(sysList: list, dictList, inlist=None, outlist=None)[source]¶
Merge a list of systems into one system.
- minreal(sys, *args, **kwargs)[source]¶
Minreal function for Bunch systems
- Parameters:
sys (Bunch) – Bunch system with mod as attribute
- Returns:
Bunch system with mod as attribute
- Return type:
Bunch
- multiconnect(sysList: list, conlist, dictList=None, balance=False, concentrate=False)[source]¶
Connect a list of systems together. This is a wrapper for the control.connect function. This function also appends input output dictionaries together.
- Parameters:
sysList (list) – A list of systems or of Bunch objects including dictionaries.
conlist (list) – A list of connections. This is a list of lists of the form [[input1, output1], [input2, output2]]. The inputs and outputs can be either strings or integers. If they are strings, they must be in the input output dictionary of one of the models.
dictList (list, optional) – A list of dictionaries. Defaults to None.
balance (bool, optional) – Whether to balance the gain of each individual system using the balance_sys_gain() function. Defaults to True.
- Returns:
Bunch with mod and iod as attributes
- Return type:
Bunch
- negsys(sys, iod=None)[source]¶
Make the negative of a system. Given a system with inputs u and outputs y, this function returns a system with output -y for inputs u.
- Parameters:
sys (Bunch) – Bunch system with mod as attribute and iod as attribute. iod is optional in the bunch
iod (dict, optional) – input/output dictionary. Defaults to None.
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace.
- Return type:
wield.bunch
- normalize_gain(sys, norm=1, tol_percent=1, tol_mag=None, previous_scale=1, return_scale=False, method='L_inf', interval=[0.001, 10000.0])[source]¶
Normalize the maximum gain of a system to 1. This is done by dividing the system by the gain of the system.
- Parameters:
sys (Bunch) – Bunch system with mod as attribute.
norm (float, optional) – The value to normalize the gain to. Defaults to 1.
tol_percent (float, optional) – The tolerance for the gain. Defaults to 1.
previous_scale (float, optional) – The previous scale of the system used for recursive scaling. Defaults to 1.
return_scale (bool, optional) – Whether to return the gain applied to normalize the sys as well as the system. Defaults to False.
method (str, optional) – The method to use to normalize the gain. ‘L_inf’: use the L_inf norm. ‘fq_resp’: uses wields frequency response. Defaults to ‘L_inf’.
interval (list, optional) – The interval to use for the frequency response. Not used if method is ‘L_inf’. Defaults to [1e-3, 1e4].
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace.
- Return type:
wield.bunch
- observabilityMatrix(sys)[source]¶
Get the observability matrix of a system
- Parameters:
sys (wield.MIMO | wield.SISO) – MIMO or SISO system to get the observability matrix of
- Returns:
observability matrix of the system
- Return type:
np.array
- order(sys)[source]¶
Get the order of the system
- Parameters:
sys (wield.MIMO | wield.SISO) – MIMO or SISO system to get the order of
- Returns:
order of the system
- Return type:
- removeIodIndices(iod, inputs_to_remove, outputs_to_remove)[source]¶
Take an iod and remove the inputs and outputs specified by the indices and or names provided in the inputs_to_remove and outputs_to_remove lists
- Parameters:
- Returns:
Input/output dictionary with the removed inputs and outputs
- Return type:
- rename_io(sys, oldname, newname)[source]¶
Rename an input or output
- Parameters:
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace.
- Return type:
wield.bunch
- save_zpk(sys, fname='sys_zpk.yml', safe=True)[source]¶
Save the zeros, poles, and gain of a system to a file. If the system is a State Space model, it will be converted to a zeros, poles, and gain model.
- Parameters:
sys (wield.SISO) – SISO system to save.
fname (str, optional) – The filename and path where the system should be saved. Defaults to ‘sys_zpk.yml’.
safe (bool, optional) – If true, the system will be loaded to check if there are differences. Only save if the new file is different than the old one. This safety feature is useful for storing the models in git, without churning the index since binary matlab files can be different for no material reason. Defaults to True.
- savesys(sys, name='savedsys.mat', safe=True)[source]¶
Save the system to a file.
- Safe:
defaults False. If true, then load the system to check if there are differences. Only save if the new file is different than the old one. This
safety feature is useful for storing the models in git, without churning the index since binary matlab files can be different for no material reason.
- scale_io(sys, ioname, gain)[source]¶
Scale an input or output
- Parameters:
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace.
- Return type:
wield.bunch
- transpose(sys)[source]¶
Transpose the system
- Parameters:
sys (Bunch) – Bunch system with mod as attribute
- Returns:
Returns the local name space for the function including the state space model as mod, input output dictionary as iod, and namespace.
- Return type:
wield.bunch
- truncate_io(sys, inputs, outputs, iod=None, minreal=False, balance_gain=False)[source]¶
Reduce a system to the specified inputs and outputs while removing unobservable states
- Parameters:
sys (control.ss or bunch) – State space model or bunch system with mod and iod as attribute
iod (dict, optional) – Input/output dictionary to be provided if sys does not have an ido attribute. Defaults to None.
minreal (bool, optional) – Whether the system should be reduced using the control.minreal function. Defaults to False.
balance_gain (bool, optional) – Whether the system should be reduced using the ssutil.balance_sys_gain function. Defaults to False.
- Returns:
Bunch with mod and iod as attributes
- Return type:
Bunch