# TuningGoal.Margins class

Package: TuningGoal

Stability margin requirement for control system tuning

## Description

Use the `TuningGoal.Margins` requirement object to specify a tuning requirement for the gain and phase margins of a SISO or MIMO feedback loop. You can use this requirement for validating a tuned control system with `viewSpec`. You can also use the requirement for control system tuning with tuning commands such as `systune` or `looptune`.

After you create a requirement object, you can further configure the tuning requirement by setting Properties of the object.

After using the requirement to tune a control system, you can visualize the requirement and the tuned value using the `viewSpec` command. For information about interpreting the margins goal, see Interpreting Stability Margins in Control System Tuning.

## Construction

```Req = TuningGoal.Margins(location,gainmargin,phasemargin)``` creates a tuning requirement that specifies the minimum gain and phase margins at the specified location in the control system.

### Input Arguments

 `location` Location in the control system at which the minimum gain and phase margins apply, specified as a string or cell array of strings. These strings identify one or more analysis locations in the control system to tune. What locations are available depends on what kind of system you are tuning:If you are tuning a Simulink® model of a control system, you can use any linear analysis point marked in the model, or any linear analysis point in an `slTuner` interface associated with the Simulink model. Use `addPoint` to add analysis points to the `slTuner` interface. Use `getPoints` to get the list of analysis points available in an `slTuner` interface to your model.If you are tuning a generalized state-space (`genss`) model of a control system, you can use any `AnalysisPoint` location in the control system model. For example, the following code creates a PI loop with an analysis point at the plant input `'u'`. ```AP = AnalysisPoint('u'); G = tf(1,[1 2]); C = ltiblock.pid('C','pi'); T = feedback(G*AP*C,1); ```You can use the string `'u'` to refer to the analysis point at the plant input. Use `getPoints` to get the list of analysis points available in a `genss` model. The margin requirements apply to the point-to-point, open-loop transfer function at the specified loop-opening location. That transfer function is the open-loop response obtained by injecting signals at the specified location, and measuring the return signals at the same point. If `location` is a cell array, then the margin requirement applies to the MIMO open-loop transfer function. `gainmargin` Required minimum gain margin for the feedback loop, specified as a scalar value in dB. For MIMO feedback loops, the gain margin is based upon the notion of disk margins, which guarantee stability for concurrent gain and phase variations of ±`gainmargin` and ±`phasemargin` in all feedback channels. See `loopmargin` for more information about disk margins. `phasemargin` Required minimum phase margin for the feedback loop, specified as a scalar value in degrees. For MIMO feedback loops, the phase margin is based upon the notion of disk margins, which guarantee stability for concurrent gain and phase variations of ±`gainmargin` and ±`phasemargin` in all feedback channels. See `loopmargin` for more information about disk margins.

## Properties

 `GainMargin` Required minimum gain margin for the feedback loop, specified as a scalar value in decibels (dB). The value of the `GainMargin` property is set by the `gainmargin` input argument when you create the `TuningGoal.Margins` requirement. `PhaseMargin` Required minimum phase margin for the feedback loop, specified as a scalar value in degrees. The value of the `PhaseMargin` property is set by the `phasemargin` input argument when you create the `TuningGoal.Margins` requirement. `ScalingOrder` Controls the order (number of states) of the scalings involved in computing MIMO stability margins. Static scalings (```ScalingOrder = 0```) are used by default. Increasing the order may improve results at the expense of increased computations. Use `viewSpec` to assess the gap between optimized and actual margins. If this gap is too large, consider increasing the scaling order. See Interpreting Stability Margins in Control System Tuning. Default: 0 (static scaling) `Focus` Frequency band in which tuning requirement is enforced, specified as a row vector of the form `[min,max]`. Set the `Focus` property to limit enforcement of the requirement to a particular frequency band. For best results with stability margin requirements, pick a frequency band extending about one decade on each side of the gain crossover frequencies. For example, suppose `Req` is a `TuningGoal.Margins` requirement that you are using to tune a system with approximately 10 rad/s bandwidth. To limit the enforcement of the requirement, use the following command:`Req.Focus = [1,100];` Default: `[0,Inf]` for continuous time; `[0,pi/Ts]` for discrete time, where `Ts` is the model sample time. `Location` Location at which the minimum gain and phase margins apply, specified as a string or cell-array of strings. These strings identify one or more analysis-point locations in the control system to tune. The value of the `Location` property is set by the `location` input argument when you create the `TuningGoal.Margins` requirement. `Models` Models to which the tuning requirement applies, specified as a vector of indices. Use the `Models` property when tuning an array of control system models with `systune`, to enforce a tuning requirement for a subset of models in the array. For example, suppose you want to apply the tuning requirement, `Req`, to the second, third, and fourth models in a model array passed to `systune`. To restrict enforcement of the requirement, use the following command: `Req.Models = 2:4;` When `Models = NaN`, the tuning requirement applies to all models. Default: `NaN` `Openings` Feedback loops to open when evaluating the requirement, specified as a cell array of strings that identify loop-opening locations. The tuning requirement is evaluated against the open-loop configuration created by opening feedback loops at the locations you identify. If you are using the requirement to tune a Simulink model of a control system, then `Openings` can include any linear analysis point marked in the model, or any linear analysis point in an `slTuner` interface associated with the Simulink model. Use `addPoint` to add analysis points and loop openings to the `slTuner` interface. Use `getPoints` to get the list of analysis points available in an `slTuner` interface to your model. If you are using the requirement to tune a generalized state-space (`genss`) model of a control system, then `Openings` can include any `AnalysisPoint` location in the control system model. Use `getPoints` to get the list of analysis points available in the `genss` model. Default: `{}` `Name` Name of the requirement object, specified as a string. For example, if `Req` is a requirement: `Req.Name = 'LoopReq';` Default: `[]`

## Algorithms

When you tune a control system using a `TuningGoal` object to specify a tuning requirement, the software converts the requirement into a normalized scalar value f(x), where x is the vector of free (tunable) parameters in the control system. The software then adjusts the parameter values to minimize f(x) or to drive f(x) below 1 if the tuning requirement is a hard constraint.

For the `TuningGoal.Margins` requirement, f(x) is given by:

$f\left(x\right)={‖2\alpha S-\alpha I‖}_{\infty }.$

S = D–1[I – L(s,x)]–1D is the scaled sensitivity function.

L(s,x) is the open-loop response being shaped.

D is an automatically-computed loop scaling factor.

α is a scalar parameter computed from the specified gain and phase margin.

## Examples

collapse all

### SISO Margin Requirement Evaluated with Additional Loop Opening

Create a margin requirement for the inner loop of the following control system. The requirement imposes a minimum gain margin of 5 dB and a minimum phase margin of 40 degrees.

Create a model of the system. To do so, specify and connect the numeric plant models `G1` and `G2`, and the tunable controllers `C1` and `C2`. Also specify and connect the `AnalysisPoint` blocks `AP1` and `AP2` that mark points of interest for analysis and tuning.

```G1 = tf(10,[1 10]); G2 = tf([1 2],[1 0.2 10]); C1 = ltiblock.pid('C','pi'); C2 = ltiblock.gain('G',1); AP1 = AnalysisPoint('AP1'); AP2 = AnalysisPoint('AP2'); T = feedback(G1*feedback(G2*C2,AP2)*C1,AP1); ```

Create a tuning requirement object.

```Req = TuningGoal.Margins('AP2',5,40); ```

This requirement imposes the specified stability margins on the feedback loop identified by the `AnalysisPoint` channel `'AP2'`, which is the inner loop.

Specify that these margins are evaluated with the outer loop of the control system open.

```Req.Openings = {'AP1'}; ```

Adding `'AP1'` to the `Openings` property of the tuning requirements object ensures that `systune` evaluates the requirement with the loop open at that location.

Use `systune` to tune the free parameters of `T` to meet the tuning requirement specified by `Req`. You can then use `viewSpec` to validate the tuned control system against the requirement.

### MIMO Margin Requirement in Frequency Band

Create a requirement that sets minimum gain and phase margins for the loop defined by three loop-opening locations in a control system to tune. Because this loop is defined by three loop-opening locations, it is a MIMO loop.

The requirement sets a minimum gain margin of 10 dB and a minimum phase margin of 40 degrees, within the band between 0.1 and 10 rad/s.

```Req = TuningGoal.Margins({'r','theta','phi'},10,40); ```

The names `'r'`, `'theta'`, and `'phi'` must specify valid loop-opening locations in the control system that you are tuning.

Limit the requirement to the frequency band between 0.1 and 10 rad/s.

``` Req.Focus = [0.1 10]; ```