Main Content

Create App Designer Instrument Panels by Using Simulink Real-Time Components

The Simulink® Real-Time™ components in App Designer ease creation of App Designer instrument panels for real-time applications. By using the Simulink Real-Time components, you can add frequently used operations, such as select target and load real-time application, as controls on your instrument panel with minimal programming of callback functions.

This example shows how the Simulink Real-Time components in App Designer help you develop instrument panels that are reusable. When you examine the callback code in the example, see that only code that connects instruments from the real-time application to controls in the instrument panel uses block path information that is specific to the real-time application. This approach makes it easier to reuse instrument panels as the interface for other real-time applications.

For more information, see Develop Apps Using App Designer. You also can create instrument panel applications without using App Designer. For more information, see Develop Apps Programmatically.

To create an App Designer instrument panel by using Simulink Real-Time components:

  1. Open the App Designer. In MATLAB®, select Home > New > App. Or, in the MATLAB Command Window, type:

    appdesigner

    Then, select New > Blank App

  2. From the Simulink Real-Time group in the Component Library, add real-time application components to the instrument panel. For this instrument panel, add:

    • Target Selector

    • Connect

    • Load

    • Start/Stop

    • Stop Time

    • Parameter Table

    • Signal Table

  3. From the Instrumentation group in the Component Library, add Instrumentation components to the instrument panel. For this instrument panel, add Knob and Gauge.

  4. From the Common group in the Component Library, add common components to the instrument panel. For this instrument panel, add Axes.

  5. Arrange the instrument panel to appear as shown in this instrument panel.

    Image of instrument panel for slrt_ex_osc real-time application

  6. Select the Knob instrument and change the Limits to 0,20 in the Inspector tab of the Component Browser.

  7. Select the Gauge instrument and change the Limits to -1.5,1.5 in the Inspector tab of the Component Browser.

  8. Save the instrument panel as myInstPanel_slrt_ex_osc.mlapp.

To add callback code to your App Designer instrument panel and test the instrument panel as a UI to a real-time application:

  1. Change to the Code View tab.

  2. In the Component Browser, select node myInstPanel_slrt_ex_osc. Select Callbacks. From the StartupFcn drop-down list, select <add StartupFcn callback>.

  3. Add callback code to connect the instruments to the real-time application. Paste this callback code into the startup function callback of the instrument panel application. This code connects the instruments to the real-time application slrt_ex_osc.

    % define the real-time application file to load
    app.LoadButton.Application = 'slrt_ex_osc';
    
    % define parameters
    app.ParameterTable.Parameters = struct( ...
      'BlockPath', {'slrt_ex_osc/Signal Generator', ...
                    'slrt_ex_osc/Signal Generator'}, ...
      'ParameterName', {'Amplitude', ...
                        'Frequency'});
    
     % set up parameter tuner
     myParamFreq = slrealtime.ui.tool.ParameterTuner(app.UIFigure);
     myParamFreq.Component = app.Knob;
     myParamFreq.BlockPath = 'slrt_ex_osc/Signal Generator';
     myParamFreq.ParameterName = 'Frequency';
    
     % define signals
     app.SignalTable.Signals = struct( ...
        'BlockPath', {'slrt_ex_osc/Signal Generator', ...
                      'slrt_ex_osc/Transfer Fcn'}, ...
        'PortIndex', {1,1});
    
    % Create slrealtime.Instruments and connect gauge
    instMyGauge = slrealtime.Instrument();
    instMyGauge.connectScalar(app.Gauge, 'slrt_ex_osc/Transfer Fcn', 1);
    
    % Create slrealtime.Instruments and connect axes
    instMyAxes = slrealtime.Instrument();
    instMyAxes.connectLine(app.UIAxes, 'XfrFnc');
    
    % Create InstrumentManager object and add gauge
    instMgr = slrealtime.ui.tool.InstrumentManager(app.UIFigure);
    instMgr.Instruments = [instMyGauge, instMyAxes];
  4. Save the instrument panel.

  5. In MATLAB, open the slrt_ex_osc model. In the Command Window, type:

    open_system(fullfile(matlabroot,'toolbox',...
        'slrealtime','examples','slrt_ex_osc'))
  6. Build the real-time application. In the Simulink Editor, select Real-Time > Run on Target.

  7. After the model builds and the real-time application runs, in the App Designer, run the instrument panel application.

  8. From the instrument panel application, connect to the target computer, load the real-time application slrt_ex_osc, set the stop time at 10 seconds, and start the real-time application.

    The instrument panel controls indicate signal and parameter values for the real-time application. Start the real-time application, use the knob to change the parameter value, and see the affect on the output.

  9. When done observing the operation of the instrument panel, close the app and close the App Designer.

See Also

| | | | | | | | | | | | | | | | |

Related Examples

More About