Main Content

Tune Custom Masked Subsystems

This example shows how to enable custom masked subsystems in Control System Designer. Once configured, you can tune a custom masked subsystem in the same way as any supported blocks in Simulink® Control Design™. For more information, see What Blocks Are Tunable?

Lead-Lag Library Block

For this example, you tune the Lead-Lag Controller block in the scdexblks library.


This block implements a compensator with a single zero, a single pole, and a gain. To configure the controller, you can specify the following block parameters.

  • Gain (K)

  • Zero Frequency (Wz)

  • Pole Frequency (Wp)

The Lead-Lag Controller block implements the following transfer function.


Configure Subsystem for Control System Designer

To configure a masked subsystem for tuning with Control System Designer, you specify a configuration function. In this example, the block uses the configuration function in scdleadexample.m. To open this file, at the MATLAB® command line, type edit scdleadexample.

This function returns a structure with the following fields.

  • TunableParameters — Structure array with one element for each tunable parameter (gain, zero, pole)

  • EvalFcn — Handle to function that converts block parameters to zero-pole-gain form

  • InvFcn — Handle to function that computes block parameters given zero-pole-gain values

  • Constraints — Structure specifying constraints on the block, such as the number of poles and zeros

  • Inport — Port number for the controller input

  • Outport — Port number for the controller output

The scdleadexample configuration function specifies the following constraints for the controller block.

  • There is only one pole allowed (MaxPoles constraint)

  • There is only one zero allowed (MaxZeros constraint)

  • The gain is tunable (isStaticGainTunable constraint)

To use a configuration function, specify it as the SCDConfigfcn callback function for the block. To do so, right-click the Lead-Lag Controller block and select Properties. Then, in the Block Properties dialog box, on the Callbacks tab, set SCDConfigFcn to scdleadexample.

Alternatively, you can set SCDConfigFcn using the set_param function.


Once you set the block configuration function, you can tune the controller using Control System Designer.

Speed Control System

The scdspeedctrlleadlag model uses the Lead-Lag Controller block to tune the feedback loop in Single Loop Feedback/Prefilter Compensator Design.


To open Control System Designer, in the Simulink model window, on the Apps tab, in the Apps gallery, click Control System Designer.

In the Edit Architecture dialog box, on the Blocks tab, click Add Blocks. Then, in the Select Blocks to Tune dialog box, click Feedback Controller, and select Lead-Lag Controller.

Click OK.

In the Edit Architecture dialog box, on the Signals tab, the analysis points defined in the Simulink model are automatically added as Locations.

On the Linearization Options tab, in the Operating Point drop-down list, select Model Initial Condition.

Click OK.

Create new plots to view the step responses while tuning the controllers. In Control System Designer, select New Plot > New Step.

In the New Step dialog box, in the Select response to plot drop-down menu, select New input-output transfer response. Configure the response as shown in the following figure.

To view the response, click Plot.

Tune Compensator

The Control System Designer app contains four methods to tune a control system.

  • Graphically tune the compensator poles, zeros, and gains using open-loop/closed-loop Bode, root locus, or Nichols editor plots. Click Tuning Methods, and select an editor under Graphical Tuning.

  • Optimize compensator parameters using both time-domain and frequency-domain design requirements (requires Simulink Design Optimization™ software). Click Tuning Methods, and select Optimization Based Tuning. For more information, see Enforcing Time and Frequency Requirements on a Single-Loop Controller Design (Simulink Design Optimization).

  • Compute initial compensator parameters using automated tuning based on parameters such as closed-loop time constants. Click Tuning Methods, and select either PID Tuning, IMC Tuning, Loop Shaping (requires Robust Control Toolbox™ software), or LQG Design.

Complete Design

The design requirements for the reference step response in Single Loop Feedback/Prefilter Compensator Design can be met with the following Lead-Lag Controller block parameters.

  • Gain = 0.0075426

  • Zero Frequency (rad/s) = 2

  • Pole Frequency (rad/s) = 103.59

The following figure shows the closed-loop system response for these controller parameters.

Update Simulink Model

To write the compensator parameters back to the Simulink model, click Update Blocks. You can then test your design on the nonlinear model.


See Also

Related Topics