Main Content

Test an Existing MPC Controller with Simulink

This topic shows how to test an existing model predictive controller by adding it to a Simulink® model.

  1. Open your Simulink model.

  2. Add an MPC Controller block to the model.

  3. If your controller includes measured disturbances, add the md inport to the MPC Controller block.

    Double-click the MPC Controller block.

    In the Block Parameters dialog box, on the General tab, select Measured disturbance (md).

    General tab of the Block Parameters dialog box, of the MPC Controller block mask

    Click OK.

  4. Connect the plant and controller signals in the Simulink model. Connect:

    • The plant inputs to the manipulated variable (mv) inport of the MPC Controller block.

    • The plant measured outputs to the measured output (mo) inport of the MPC Controller block.

    • The measured disturbances, if any, to the plant and to the measured disturbance (md) inport of the MPC Controller block.

    • Any unmeasured disturbances or unmeasured outputs to their corresponding plant inport and outport.

    • The reference signals to the reference (ref) inport of the MPC Controller block.

    • Connect any signal that you would like to visualize (such for example the plant outputs) to Scope (Simulink) blocks.

    Simulink model of a plant in a feedback loop with an MPC controller. Both blocks receive a Measured Disturbance signal as one of their inputs.

  5. Specify the controller.

    Double-click the MPC Controller block.

    In the Block Parameters dialog box, in the MPC Controller field, specify the name of an mpc controller from the MATLAB® workspace.

    MPC COntroller field of the Block Parameters dialog box.

    Click OK.

  6. (Optional) Modify the controller.

    After specifying a controller in the MPC Controller block, you can modify the controller:

    • Using MPC Designer:

      • In the Block Parameters dialog box, click Design.

      • In MPC Designer, tune the controller parameters.

      • In the MPC Designer tab, in the Result section, click Export Controller > Update Block Only.

        The app exports the updated controller to the MATLAB workspace.

    • Using commands to modify the controller object in the MATLAB workspace.

  7. Run the Simulink model. Verify that the simulation terminates without errors and that the signals in the loop behave as expected.

Tip

If you do not have a Simulink model of your plant, you can generate one that uses your MPC controller to control its internal plant model. For more information, see Generate Simulink Model from MPC Designer.

See Also

Apps

Functions

Objects

Blocks

Related Examples

More About