compute

buzz.compute

Functions

calcFullResults(results_list[, io_scales])

Calculates the full results for a list of optimal controllers.

calcOpt(EMPFF, control_in, wn_in, meas_out, ...)

Calculates the optimal controller for a given EMPFF system.

color_map_color(value[, cmap_name, vmin, ...])

Maps a value to a color using a specified colormap.

connectK(bunch)

Connects the controller to the plant in a closed-loop configuration.

connectKOL(bunch)

Connects the controller to the plant in an open-loop configuration.

getK_Usable(K, EMPFF_full[, plant_orig])

Uses the original plant to get the real usable controller.

sfround(x, sig)

Rounds a number to a certain number of significant figures.

Details

calcFullResults(results_list, io_scales=Bunch(), **kwargs)[source]

Calculates the full results for a list of optimal controllers.

Parameters:
  • results_list (list) – List of wield.Bunch objects containing the results of the optimal controller calculation.

  • io_scales (wield.Bunch, optional) – Bunch object containing input-output scales. Defaults to Bunch().

  • **kwargs – Additional keyword arguments.

Returns:

List of wield.Bunch objects containing the full results of the optimal controller calculation.

Return type:

list

Output Bunch Keys:
  • plant: The original plant of the system. This is the EMPFF system.

  • K: The calculated controller.

  • control_in: List of control input names.

  • meas_out: List of measurement output names.

  • wn_in: List of white noise input names.

  • FOM_out: List of figure of merit output names.

  • Zinf: List of infinite zeros.

  • solver: The solver used for the optimization.

  • F1_gain: Gain for the first figure of merit.

  • F2_gain: Gain for the second figure of merit.

  • gamma: Gamma parameter for the optimization.

  • iscontrollable: Boolean indicating if the system is controllable.

  • isobservable: Boolean indicating if the system is observable.

  • plant_scaled: The scaled plant.

  • K_prebal: The controller before balancing.

  • K_usable: The usable controller.

  • K_usable_zpk: The usable controller in ZPK form.

  • isKstable: Boolean indicating if the controller is stable.

  • CL: The closed-loop system.

  • CL_all_io: The closed-loop system with all inputs and outputs.

  • OL: The open-loop system.

  • OL_all_io: The open-loop system with all inputs and outputs.

  • plot_omega: The frequency range for plotting (rad/s).

  • isCLstable: Boolean indicating if the closed-loop system is stable.

  • RMS_cal: Calibration factor for RMS plots.

  • RMS_cal_F1: Calibration factor for the first figure of merit.

  • RMS_cal_F2: Calibration factor for the second figure of merit.

  • F1_H2_Norm: H2 norm for the first figure of merit.

  • F2_H2_Norm: H2 norm for the second figure of merit.

  • h2noise: H2 noise values.

  • FR_OL_mag: Magnitude of the open-loop frequency response.

  • FR_OL_ph: Phase of the open-loop frequency response.

  • FR_OL_ph_unwrapped: Unwrapped phase of the open-loop frequency response.

  • FR_OL_omega: Frequency values for the open-loop response (rad/s).

  • FR_OL_omega_Hz: Frequency values in Hz for the open-loop response (Hz).

  • FR_CL_mag: Magnitude of the closed-loop frequency response.

  • FR_CL_ph: Phase of the closed-loop frequency response.

  • FR_CL_ph_unwrapped: Unwrapped phase of the closed-loop frequency response.

  • FR_CL_omega: Frequency values for the closed-loop response (rad/s).

  • FR_CL_omega_Hz: Frequency values in Hz for the closed-loop response (Hz).

  • FR_WN: Frequency response for white noise inputs.

  • colormap_norm: Normalization for the colormap.

  • linestyle: Line style for plotting.

  • linecolor: Line color for plotting.

  • linecolor_colormap: Colormap for line color.

  • gm: Gain margin (dB).

  • pm: Phase margin (degrees).

  • wcg: Gain crossover frequency (rad/s).

  • wcp: Phase crossover frequency (rad/s).

  • current_range: Current range for the system.

  • diff_range: Difference in range.

  • abs_diff_range: Absolute difference in range.

  • range: Calculated range.

  • range_PSD_Hz: Frequency values for the range PSD (Hz).

  • range_PSD: Range PSD values.

  • FOM1_wn_PSD: PSD for the first figure of merit with white noise.

  • FOM1_wn_PSD_Hz: Frequency values for the first figure of merit PSD (Hz).

  • FOM1_wn_ASD: ASD for the first figure of merit with white noise.

  • FOM1_wn_ASD_Hz: Frequency values for the first figure of merit ASD (Hz).

  • total_DARM_PSD: Total DARM PSD. This is in strain^2/Hz.

  • total_DARM_PSD_Hz: Frequency values for the total DARM PSD (Hz).

  • total_DARM_ASD: Total DARM ASD. This is in meters/rtHz.

  • total_DARM_ASD_Hz: Frequency values for the total DARM ASD (Hz).

  • total_DARM_ASD_strain: Total DARM ASD in strain/rtHz.

  • range_from_PSD: Range calculated from the PSD.

  • diff_range_PSD: Difference in range calculated from the PSD.

  • abs_diff_range_PSD: Absolute difference in range calculated from the PSD.

  • label1: First label for plotting.

  • label2: Second label for plotting.

  • color_param: Parameter used for coloring the plot.

  • rms_marker: Marker for RMS plots.

calcOpt(EMPFF, control_in, wn_in, meas_out, FOM_out, params, Zinf=None, solver='LQG', plant_orig=None, BH_solver=None, BH_kw={}, debug_mode=False, **kwargs)[source]

Calculates the optimal controller for a given EMPFF system. This function is a wrapper for the solvers.LQGsolverset and BH1_solvers.BH1solverset functions. It calculates the optimal controller for a given EMPFF system and a set of parameters. The parameters can be a list of values to sweep over or a single value. The function returns a list of wield.Bunch objects containing the results of the optimal controller calculation. Each item in the list is a new controller.

Parameters:
  • EMPFF (wield.MIMO) – A MIMO system object to be controlled. This system can be assembled using the control library.

  • control_in (list) – List of control input names.

  • wn_in (list) – List of white noise input names.

  • meas_out (list) – List of measurement output names.

  • FOM_out (list) – List of figure of merit output names.

  • params (dict) – Dictionary of parameters to sweep over. Valid keys are ‘F1_gain’, ‘F2_gain’, and ‘gamma’.

  • Zinf (list, optional) – List of infinite zeros. Defaults to None.

  • solver (str, optional) – Solver to use for the optimization. Options are ‘LQG’, ‘BH’, ‘mix’, or ‘HB’. Defaults to ‘LQG’.

  • plant_orig (wield.SISO, optional) – The original plant of the system. Adds the real usable controller to the results as K = K’P’/P. This is only needed if the plant was modified when making the original EMPFF. Defaults to None.

  • BH_solver (function, optional) – Custom BH solver function. Defaults to None.

  • BH_kw (dict, optional) – Additional keyword arguments for the BH solver. Defaults to {}.

  • debug_mode (bool, optional) – If True, enables debug mode with additional print statements. Defaults to False.

  • **kwargs – Additional keyword arguments.

Returns:

List of wield.Bunch objects containing the results of the optimal controller calculation. Each item in the list is a new controller.

Return type:

list

Output Bunch Keys:
  • plant: The original plant of the system. This is the EMPFF system.

  • control_in: List of control input names.

  • wn_in: List of white noise input names.

  • meas_out: List of measurement output names.

  • FOM_out: List of figure of merit output names.

  • Zinf: List of infinite zeros.

  • solver: The solver used for the optimization.

  • F1_gain: Gain for the first figure of merit.

  • F2_gain: Gain for the second figure of merit.

  • gamma: Gamma parameter for the optimization.

  • iscontrollable: Boolean indicating if the system is controllable.

  • isobservable: Boolean indicating if the system is observable.

  • plant_scaled: The scaled plant.

  • K_prebal: The controller before balancing.

  • K: The calculated controller.

  • K_usable: The usable controller.

  • K_usable_zpk: The usable controller in ZPK form.

  • isoptimal: Boolean indicating if the controller is optimal.

  • igsq: Integrated squared gain.

  • isKstable: Boolean indicating if the controller is stable.

  • isCLstable: Boolean indicating if the closed-loop system is stable.

color_map_color(value, cmap_name='winter', vmin=0, vmax=1, lognorm=False, outside_color='lightgrey')[source]

Maps a value to a color using a specified colormap.

Parameters:
  • value (float or list) – The value(s) to map to a color.

  • cmap_name (str, optional) – The name of the colormap to use. Defaults to “winter”.

  • vmin (float, optional) – The minimum value for the colormap. Defaults to 0.

  • vmax (float, optional) – The maximum value for the colormap. Defaults to 1.

  • lognorm (bool or matplotlib.colors.Normalize, optional) – If True, use a logarithmic normalization. Defaults to False.

  • outside_color (str, optional) – The color to use for values outside the colormap range. Defaults to ‘lightgrey’.

Returns:

The color(s) corresponding to the value(s).

Return type:

str or list

connectK(bunch)[source]

Connects the controller to the plant in a closed-loop configuration.

Parameters:

bunch (wield.Bunch) – A Bunch object containing the plant and controller information.

Returns:

A tuple containing the closed-loop system (CL) and the closed-loop system with all inputs and outputs (CL_all_io). The CL system is truncated to only include the control input and measurement output

Return type:

tuple

connectKOL(bunch)[source]

Connects the controller to the plant in an open-loop configuration.

Parameters:

bunch (wield.Bunch) – A Bunch object containing the plant and controller information.

Returns:

A tuple containing the open-loop system (OL) and the open-loop system with all inputs and outputs (OL_all_io).

Return type:

tuple

getK_Usable(K, EMPFF_full, plant_orig=None)[source]

Uses the original plant to get the real usable controller. This is only needed if the plant was modified when making the original EMPFF.

Parameters:
  • K (wield.MIMO) – The controller to be used.

  • EMPFF_full (wield.MIMO) – The full EMPFF system.

  • plant_orig (wield.MIMO, optional) – The original plant of the system. Defaults to None.

Returns:

A tuple containing the usable controller (K_usable) and the usable controller in ZPK form (K_usable_zpk).

Return type:

tuple

sfround(x, sig)[source]

Rounds a number to a certain number of significant figures.

Parameters:
  • x (float) – The number to round.

  • sig (int) – The number of significant figures to round to.

Returns:

The rounded number.

Return type:

float