# systune

Tune fixed-structure control systems

## Syntax

• ```[CL,fSoft] = systune(CL0,SoftReqs)``` example
• ```[CL,fSoft,gHard] = systune(CL0,SoftReqs,HardReqs)``` example
• ```[CL,fSoft,gHard] = systune(CL0,SoftReqs,HardReqs,options)```
• ```[CL,fSoft,gHard,info] = systune(___)```

## Description

example

``````[CL,fSoft] = systune(CL0,SoftReqs)``` tunes the free parameters of the control system model, `CL0`, to best meet the soft tuning requirements. The best achieved soft constraint values are returned as `fSoft`. Note:   For tuning Simulink® models with `systune`, use `slTuner` to create an interface to your Simulink model. You can then tune the control system with `systune` for `slTuner` (requires Simulink Control Design™).```

example

``````[CL,fSoft,gHard] = systune(CL0,SoftReqs,HardReqs)``` tunes the control system to best meet the soft tuning requirements subject to satisfying the hard tuning requirements (constraints). It returns the best achieved values for the soft and hard constraints. ```
``````[CL,fSoft,gHard] = systune(CL0,SoftReqs,HardReqs,options)``` specifies options for the optimization.```
``````[CL,fSoft,gHard,info] = systune(___)``` also returns detailed information about each optimization run. All input arguments described for the previous syntaxes also apply here.```

## Examples

collapse all

### Tune Control System to Soft Requirements

Tune a cascaded control system to meet requirements of reference tracking and disturbance rejection.

The cascaded control system of the following illustration includes two tunable controllers, the PI controller for the inner loop, , and the PID controller for the outer loop, .

The blocks and mark analysis-point locations. These are locations at which loops can be opened or signals injected for the purpose of specifying requirements for tuning the system.

Tune the free parameters of this control system to meet the following requirements:

• The output signal, , tracks the reference signal, , with a response time of 10 seconds and a steady-state error of 1%.

• A disturbance injected at is suppressed at by a factor of 10.

Create tunable Control Design Blocks to represent the controllers, and numeric LTI models to represent the plants. Also, create `AnalysisPoint` blocks to mark the points of interest in each feedback loop.

```G2 = zpk([],-2,3); G1 = zpk([],[-1 -1 -1],10); C20 = ltiblock.pid('C2','pi'); C10 = ltiblock.pid('C1','pid'); X1 = AnalysisPoint('X1'); X2 = AnalysisPoint('X2'); ```

Connect these components to build a model of the entire closed-loop control system.

```InnerLoop = feedback(X2*G2*C20,1); CL0 = feedback(G1*InnerLoop*C10,X1); CL0.InputName = 'r'; CL0.OutputName = 'y'; ```

`CL0` is a tunable `genss` model. Specifying names for the input and output channels allows you to identify them when you specify tuning requirements for the system.

Specify tuning requirements for reference tracking and disturbance rejection.

```Rtrack = TuningGoal.Tracking('r','y',10,0.01); Rreject = TuningGoal.Gain('X2','y',0.1); ```

The `TuningGoal.Tracking` requirement specifies that the signal at `'y'` track the signal at `'r'` with a response time of 10 seconds and a tracking error of 1%.

The `TuningGoal.Gain` requirement limits the gain from the implicit input associated with the `AnalysisPoint` block, `X2`, to `'y'`. (See `AnalysisPoint`.) Limiting this gain to a value less than 1 ensures that a disturbance injected at `X2` is suppressed at the output.

Tune the control system.

```[CL,fSoft] = systune(CL0,[Rtrack,Rreject]); ```
```Final: Soft = 1.24, Hard = -Inf, Iterations = 105 ```

`systune` converts each tuning requirement into a normalized scalar value, f. The command adjusts the tunable parameters of `CL0` to minimize the f values. For each requirement, the requirement is satisfied if f < 1 and violated if f >1. `fSoft` is the vector of minimized f values. The largest of the minimized f values is displayed as `Soft`.

The output model `CL` is the tuned version of `CL0`. `CL` contains the same Control Design Blocks as `CL0`, with current values equal to the tuned parameter values.

Validate that the tuned control system meets the tracking requirement by examining the step response from `'r'` to `'y'`.

```stepplot(CL) ```

The step plot shows that in the tuned control system, `CL`, the output tracks the input with approximately the desired response time.

Validate the tuned system against the disturbance rejection requirement by examining the closed-loop response to a signal injected at `X2`.

```CLdist = getIOTransfer(CL,'X2','y'); stepplot(CLdist); ```

`getIOTransfer` extracts the closed-loop response from the specified inputs to outputs. In general, `getIOTransfer` and `getLoopTransfer` are useful for validating a control system tuned with `systune`.

You can also use `viewSpec` to compare the responses of the tuned control system directly against the tuning requirements, `Rtrack` and `Rreject`.

```viewSpec([Rtrack,Rreject],CL) ```

### Tune Control System to Both Hard and Soft Requirements

Tune a cascaded control system to meet requirements of reference tracking and disturbance rejection. These requirements are subject to a hard constraint on the stability margins of the inner and outer loops.

The cascaded control system of the following illustration includes two tunable controllers, the PI controller for the inner loop, , and the PID controller for the outer loop, .

The blocks and mark analysis-point locations. These are locations at which you can open loops or inject signals for the purpose of specifying requirements for tuning the system.

Tune the free parameters of this control system to meet the following requirements:

• The output signal, , tracks the reference signal at with a response time of 5 seconds and a steady-state error of 1%.

• A disturbance injected at is suppressed at the output, , by a factor of 10.

Impose these tuning requirements subject to hard constraints on the stability margins of both loops.

Create tunable Control Design Blocks to represent the controllers and numeric LTI models to represent the plants. Also, create `AnalysisPoint` blocks to mark the points of interest in each feedback loop.

```G2 = zpk([],-2,3); G1 = zpk([],[-1 -1 -1],10); C20 = ltiblock.pid('C2','pi'); C10 = ltiblock.pid('C1','pid'); X1 = AnalysisPoint('X1'); X2 = AnalysisPoint('X2'); ```

Connect these components to build a model of the entire closed-loop control system.

```InnerLoop = feedback(X2*G2*C20,1); CL0 = feedback(G1*InnerLoop*C10,X1); CL0.InputName = 'r'; CL0.OutputName = 'y'; ```

`CL0` is a tunable `genss` model. Specifying names for the input and output channels allows you to identify them when you specify tuning requirements for the system.

Specify tuning requirements for reference tracking and disturbance rejection.

```Rtrack = TuningGoal.Tracking('r','y',5,0.01); Rreject = TuningGoal.Gain('X2','y',0.1); ```

The `TuningGoal.Tracking` requirement specifies that the signal at `'y'` tracks the signal at `'r'` with a response time of 5 seconds and a tracking error of 1%.

The `TuningGoal.Gain` requirement limits the gain from the implicit input associated with the `AnalysisPoint` block `X2` to the output, `'y'`. (See `AnalysisPoint`.) Limiting this gain to a value less than 1 ensures that a disturbance injected at `X2` is suppressed at the output.

Specify tuning requirements for the gain and phase margins.

```RmargOut = TuningGoal.Margins('X1',18,60); RmargIn = TuningGoal.Margins('X2',18,60); RmargIn.Openings = 'X1'; ```

`RmargOut` imposes a minimum gain margin of 18 dB and a minimum phase margin of 60 degrees. Specifying `X1` imposes that requirement on the outer loop. Similarly, `RmargIn` imposes the same requirements on the inner loop, identified by `X2`. To ensure that the inner-loop margins are evaluated with the outer loop open, include the outer-loop analysis-point location, `X1`, in `RmargIn.Openings`.

Tune the control system to meet the soft requirements of tracking and disturbance rejection, subject to the hard constraints of the stability margins.

```SoftReqs = [Rtrack,Rreject]; HardReqs = [RmargIn,RmargOut]; [CL,fSoft,gHard] = systune(CL0,SoftReqs,HardReqs); ```
```Final: Soft = 1.13, Hard = 0.97731, Iterations = 182 Some closed-loop poles are marginally stable (decay rate near 1e-07) ```

`systune` converts each tuning requirement into a normalized scalar value, f for the soft constraints and g for the hard constraints. The command adjusts the tunable parameters of `CL0` to minimize the f values, subject to the constraint that each g < 1.

The displayed value `Hard` is the largest of the minimized g values in `gHard`. This value is less than 1, indicating that both the hard constraints are satisfied.

Validate the tuned control system against the stability margin requirements.

```figure; viewSpec(HardReqs,CL) ```

The `viewSpec` plot confirms that the stability margin requirements for both loops are satisfied by the tuned control system at all frequencies. The red liness represent the actual stability margins of the tuned system. The blue lines represent the margin used in the optimization calculation, which is an upper bound on the actual margin.

Examine whether the tuned control system meets the tracking requirement by examining the step response from `'r'` to `'y'`.

```figure; stepplot(CL,20) ```

The step plot shows that in the tuned control system, `CL`, the output tracks the input but the response is somewhat slower than desired and the tracking error may be larger than desired. For further information, examine the tracking requirement directly with `viewSpec`.

```figure; viewSpec(Rtrack,CL) ```

The actual tracking error crosses into the shaded area between 1 and 10 rad/s, indicating that the requirement is not met in this regime. Thus, the tuned control system cannot meet the soft tracking requirement, time subject to the hard constraints of the stability margins. To achieve the desired performance, you may need to relax one of your requirements or convert one or more hard constraints to soft constraints.

## Input Arguments

collapse all

### `CL0` — Control system to tunegeneralized state-space model | model array

Control system to tune, specified as a generalized state-space (`genss`) model or array of models with tunable parameters. To construct `CL0`:

1. Parameterize the tunable elements of your control system. You can use predefined structures, such as `ltiblock.pid`, `ltiblock.gain`, and `ltiblock.tf`. Alternatively, you can create your own structure from elementary tunable parameters (`realp`).

2. Build a closed-loop model of the overall control system as an interconnection of fixed and tunable components. To do so, use model interconnection commands such as `feedback` and `connect`. Use `AnalysisPoint` blocks to mark additional signals of interest for specifying and assessing tuning requirements.

Specify an array of tunable `genss` models that have the same tunable parameters for robust tuning of a controller against a set of plant models.

### `SoftReqs` — Soft tuning requirements (objectives)vector of `TuningGoal` requirement objects

Soft tuning requirements (objectives) for tuning the control system, specified as a vector of `TuningGoal` requirement objects, such as `TuningGoal.Tracking`, `TuningGoal.StepTracking`, or `TuningGoal.Margins`

`systune` tunes the tunable parameters of the control system to minimize the soft tuning requirements. This tuning is subject to satisfying the hard tuning requirements (if any).

### `HardReqs` — Hard tuning requirements (constraints)`[]` (default) | vector of `TuningGoal` requirement objects

Hard tuning requirements (constraints) for tuning the control system, specified as a vector of `TuningGoal` requirement objects, such as `TuningGoal.Tracking`, `TuningGoal.StepTracking`, or `TuningGoal.Margins`.

`systune` converts each hard tuning requirement to a normalized scalar value. `systune` then optimizes the free parameters minimize those normalized values. A hard requirement is satisfied if the normalized value is less than 1.

### `options` — Options for tuning algorithm`systuneOptions` object

Options for the tuning algorithm, specified as an options set you create with `systuneOptions`. Available options include:

• Number of additional optimizations to run. Each optimization starts from random initial values of the free parameters.

• Tolerance for terminating the optimization.

• Flag for using parallel processing.

## Output Arguments

collapse all

### `CL` — Tuned control systemgeneralized state-space model

Tuned control system, returned as a generalized state-space (`genss`) model. This model has the same number and type of tunable elements (Control Design Blocks) as `CL0`. The current values of these elements are the tuned parameters. Use `getBlockValue` or `showTunable` to access values of the tuned elements.

If you provide an array of control system models to tune as the input argument, `CL0`, `systune` tunes the parameters of all the models simultaneously. In this case, `CL` is an array of tuned `genss` models. For more information, see Robust Tuning Using Multiple Plant Models at Command Line.

### `fSoft` — Best achieved soft constraint valuesvector

Best achieved soft constraint values, returned as a vector. `systune` converts the soft requirements to a function of the free parameters of the control system. The command then tunes the parameters to minimize that function subject to the hard constraints. (See Algorithms.) `fSoft` contains the best achieved value for each of the soft constraints. These values appear in `fSoft` in the same order that the constraints are specified in `SoftReqs`. `fSoft` values are meaningful only when the hard constraints are satisfied.

### `gHard` — Best achieved hard constraint valuesvector

Best achieved hard constraint values, returned as a vector. `systune` converts the hard requirements to a function of the free parameters of the control system. The command then tunes the parameters to drive those values below 1. (See Algorithms.) `gHard` contains the best achieved value for each of the hard constraints. These values appear in `gHard` in the same order that the constraints are specified in `HardReqs`. If all values are less than 1, then the hard constraints are satisfied.

### `info` — Detailed information about optimization runsstructure

Detailed information about each optimization run, returned as a data structure. In addition to examining detailed results of the optimization, you can use `info` as an input to `viewSpec` when validating a tuned MIMO system. `info` contains scaling data that `viewSpec` needs for correct evaluation of MIMO open-loop requirements such as loop shapes and stability margins.

The fields of `info` are:

### `Run` — Run numberscalar

Run number, returned as a scalar. If you use the `RandomStart` option of `systuneOptions` to perform multiple optimization runs, `info` is a struct array, and `info.Run` is the index.

### `Iterations` — Total number of iterationsscalar

Total number of iterations performed during run, returned as a scalar. This value is the number of iterations performed in each run before the optimization terminates.

### `fBest` — Best overall soft constraint valuescalar

Best overall soft constraint value, returned as a scalar. `systune` converts the soft requirements to a function of the free parameters of the control system. The command then tunes the parameters to minimize that function subject to the hard constraints. (See Algorithms.) `info.fBest` is the maximum soft constraint value at the final iteration. This value is meaningful only when the hard constraints are satisfied.

### `gBest` — Best overall hard constraint valuescalar

Best overall hard constraint value, returned as a scalar. `systune` converts the hard requirements to a function of the free parameters of the control system. The command then tunes the parameters to drive those values below 1. (See Algorithms.) `info.gBest` is the maximum hard constraint value at the final iteration. This value must be less than 1 for the hard constraints to be satisfied.

### `fSoft` — Individual soft constraint valuesvector

Individual soft constraint values, returned as a vector. `systune` converts each soft requirement to a normalized value that is a function of the free parameters of the control system. The command then tunes the parameters to minimize that value subject to the hard constraints. (See Algorithms.) `info.fSoft` contains the individual values of the soft constraints at the end of each run. These values appear in `fSoft` in the same order that the constraints are specified in `SoftReqs`.

### `gHard` — Individual hard constraint valuesvector

Individual hard constraint values, returned as a vector. `systune` converts each hard requirement to a normalized value that is a function of the free parameters of the control system. The command then tunes the parameters to minimize those values. A hard requirement is satisfied if its value is less than 1. (See Algorithms.) `info.gHard` contains the individual values of the hard constraints at the end of each run. These values appear in `gHard` in the same order that the constraints are specified in `HardReqs`.

### `MinDecay` — Minimum decay rate of closed-loop polesvector

Minimum decay rate of closed-loop poles, returned as a vector.

By default, closed-loop pole locations of the tuned system are constrained to satisfy Re(p) < –10–7. Use the `MinDecay` option of `systuneOptions` to change this constraint.

### `Blocks` — Tuned values of tunable blocks and parametersstructure

Tuned values of tunable blocks and parameters in the tuned control system, `CL`, returned as a structure. You can also use `getBlockValue` or `showBlockValue` to access the tuned parameter values.

### `LoopScaling` — Optimal diagonal scaling for MIMO tuning requirementsstate-space model

Optimal diagonal scaling for evaluating MIMO tuning requirements, returned as a state-space model.

When applied to multiloop control systems, `TuningGoal.LoopShape` and `TuningGoal.Margins` can be sensitive to the scaling of the loop transfer functions to which they apply. This sensitivity can lead to poor optimization results. `systune` automatically corrects scaling issues and returns the optimal diagonal scaling matrix `d` as a state-space model in `info.LoopScaling`.

The loop channels associated with each diagonal entry of `D` are listed in `info.LoopScaling.InputName`. The scaled loop transfer is `D\L*D`, where `L` is the open-loop transfer measured at the locations `info.LoopScaling.InputName`.

collapse all

### Algorithms

x is the vector of tunable parameters in the control system to tune. `systune` converts each soft and hard tuning requirement `SoftReqs(i)` and `HardReqs(j)` into normalized values fi(x) and gj(x), respectively. `systune` then solves the minimization problem:

Minimize $\underset{i}{\mathrm{max}}{f}_{i}\left(x\right)$ subject to $\underset{j}{\mathrm{max}}{g}_{j}\left(x\right)<1$, for ${x}_{\mathrm{min}}.

xmin and xmax are the minimum and maximum values of the free parameters of the control system.

`systune` returns the control system with parameters tuned to the values that best solve the minimization problem. `systune` also returns the best achieved values of fi(x) and gj(x), as `fSoft` and `gHard` respectively.

For information about the functions fi(x) and gj(x) for each type of constraint, see the reference pages for each `TuningGoal` requirement object.

`systune` uses the nonsmooth optimization algorithms described in [1].

`systune` computes the H norm using the algorithm of [2] and structure-preserving eigensolvers from the SLICOT library. For more information about the SLICOT library, see http://slicot.org.

## References

[1] Apkarian, P. and D. Noll, "Nonsmooth H-infinity Synthesis." IEEE Transactions on Automatic Control, Vol. 51, No. 1, (2006), pp. 71–86.

[2] Bruisma, N.A. and M. Steinbuch, "A Fast Algorithm to Compute the H-Norm of a Transfer Function Matrix," System Control Letters, Vol. 14, No, 4 (1990), pp. 287–293.