Main Content

ParameterTuner

Create parameter tuner component for App Designer component in instrument panel UI

Since R2021b

Description

example

hPTuner = slrealtime.ui.tool.ParameterTuner(hFigure) creates a parameter tuner component for an App Designer component on an instrument panel uifigure figure. After connecting the parameter tuner to an App Designer component (such as a knob), the App Designer component gets or sets data in the real-time application in the same manner as Simulink Real-Time components available in the App Designer. The parameter tuner component pulls the current parameter value from the target when:

  • The instrument panel first starts and an application is loaded on the selected target computer.

  • The target selected by the instrument panel changes and an application is loaded on the selected target computer.

  • An application is loaded on the selected target computer.

  • The parameter is changed from an external source, such as the command line, Explorer, other instrument panels on the selected target computer.

If the current value of the parameter is changed from an external source and is invalid for the Parameter Tuning component (for example, it is out of range of the knob), the Parameter Tuning component displays a warning icon covering the component. Changing the parameter from an external source to some valid value for the component removes the warning icon.

When the ECU page and XCP page selections do not match, the mismatch disables the App Designer ParameterTable component and ParameterTuner component. You can enable operation of these components by coordinating ECU page and XCP page selection in the real-time application. Use the getECUPage, setECUPage, getXCPPage, and setXCPPage functions. Or, use the explorer Enable Parameter Table button. This button is context sensitive and appears when explorer detects a page selection mismatch.

For information about parameter tuner properties, see slrealtime.ui Properties.

Examples

collapse all

Create an App Designer component and connect it to a block in a real-time application for parameter tuning. Changing the value of the component pushes the value to the real-time application on the target computer.

% Create figure 
hFig = uifigure(); 
% Create a hKnob 
hKnob = uiknob(hFig); 
% Create Parameter Tuning object 
hParamTuner = slrealtime.ui.tool.ParameterTuner(hFig); 
hParamTuner.Component = hKnob; 
hParamTuner.BlockPath = 'testmodel/Constant6'; 
hParamTuner.ParameterName = 'Value';

In Connect App Designer Component for Parameter Tuning, the code shows how to connect the ParameterTuner component to a value on a block. Instead, you can use slightly different code to connect the ParameterTuner component to a variable or parameter in the workspace. In the code for the component, the BlockPath is empty, and the ParameterName is the parameter name instead of the property of the block to tune. The syntax for the code could be:

% Create Parameter Tuning object
hParamTuner = slrealtime.ui.tool.ParameterTuner(hFig);
hParamTuner.Component = hKnob;
hParamTuner.BlockPath = '';
hParamTuner.ParameterName = 'myParameter'; 

The changeComponentValue function enables you to change the value of the parameter that is connected to the ParameterTuner component. Using this function to change the value of the component pushes the value to the real-time application on the target computer.

% Create figure 
hFig = uifigure(); 
% Create a hKnob 
hKnob = uiknob(hFig); 
% Create Parameter Tuning object 
hParamTuner = slrealtime.ui.tool.ParameterTuner(hFig); 
hParamTuner.Component = hKnob; 
hParamTuner.BlockPath = 'slrt_ex_osc/Signal Generator'; 
hParamTuner.ParameterName = 'Amplitude';
changeComponentValue(hParamTuner,2)
getparam(tg, 'slrt_ex_osc/Signal Generator', 'Amplitude')
ans =

     2

The ConvertToComponent transforms the real-time application value into something that can be displayed by the knob. In this example, the strings "High", "Medium", and "Low". The ConvertToTarget transforms the knob values into something that can be written to the real-time application. In this example, the values 10, 5, and 1.

This was generated by App Generator.

function out_val = convertLabelToValue(in_val, values, labels)
    out_val = values(strcmp(in_val, labels));
end

function out_val = convertValueToLabel(in_val, values, labels)
    out_val = labels(arrayfun(@(x)isequal(in_val, x), values));
end

Signal_Generator_Amplitude_values = [10 5 1];
Signal_Generator_Amplitude_labels = {'High','Medium','Low'};

slrtcomp = slrealtime.ui.tool.ParameterTuner(app.UIFigure, ...
                                             'TargetSource', ...
                                             targetSelector);
slrtcomp.Component = app.Signal_Generator_Amplitude;
slrtcomp.BlockPath = 'slrt_ex_osc/Signal Generator';
slrtcomp.ParameterName = 'Amplitude';
slrtcomp.ConvertToComponent = @(val)app.convertValueToLabel(val, ...
                                  Signal_Generator_Amplitude_values, ...
                                  Signal_Generator_Amplitude_labels);
slrtcomp.ConvertToTarget = @(val)app.convertLabelToValue(val, ...
                                  Signal_Generator_Amplitude_values, ...
                                  Signal_Generator_Amplitude_labels);

Input Arguments

collapse all

The hFigure argument identifies the uifigure to which you are adding the UI component.

Example: hFig = uifigure()

Data Types: function_handle

Output Arguments

collapse all

The hPTuner argument is the handle to the parameter tuner component that you create for the App Designer component.

Version History

Introduced in R2021b