Main Content

Create Instrument Panel for Testing Highway Lane Following Controller

This example shows how to use the Simulink® Real-Time™ App Generator to create an App Designer instrument panel for the test system described in Automate Testing for Highway Lane Following Controller (Automated Driving Toolbox). You can more easily operate apply the automated testing and control the real-time application on the target computer by using an instrument panel.

Open Simulink Project and Models

Open the lane following with PID controller Simulink project LaneFollowingPIDController.prj.

unzip(fullfile('LaneFollowingPIDController.zip'))
proj = openProject(pwd);

Open Models and Build Real-Time Application

Open the target computer model and the development computer model. Configure the IP addresses of UDP blocks to match your system configuration.

These commands configure block parameters in target computer model RTHLFControllerTarget for development computer IP address: 192.168.7.2

open_system('RTHLFControllerTarget');
set_param('RTHLFControllerTarget/UDP Data Receive/UDP Receive: Lanes  /UDP Receive','fmAddress','192.168.7.2')
set_param('RTHLFControllerTarget/UDP Data Receive/UDP Receive: Longitudinal Velocity /UDP Receive1','fmAddress','192.168.7.2')
set_param('RTHLFControllerTarget/UDP Data Receive/UDP Receive: Reset Flag/UDP Receive2','fmAddress','192.168.7.2')
set_param('RTHLFControllerTarget/UDP Data Receive/UDP Receive: Set Velocity/UDP Receive2','fmAddress','192.168.7.2')
set_param('RTHLFControllerTarget/UDP Data Receive/UDP Receive: Tracks/UDP Receive','fmAddress','192.168.7.2')
set_param('RTHLFControllerTarget/UDP Data Send/UDP Send: Controller Intermediate Signals','toAddress','192.168.7.2')
set_param('RTHLFControllerTarget/UDP Data Send/UDP Send: Controller Output','toAddress','192.168.7.2')

These commands configure block parameters in development computer model RTHLFControllerHost for target computer IP address: 192.168.7.5

open_system('RTHLFControllerHost');
set_param('RTHLFControllerHost/UDP Data Receive/Receive Controller Output/UDP Receive: Controller outputs','fmAddress','192.168.7.5')
set_param('RTHLFControllerHost/UDP Data Receive/Receive Intermediate Signals/UDP Receive: Controller intermediate signals','fmAddress','192.168.7.5')
set_param('RTHLFControllerHost/UDP Data Send/UDP Send: Lane Detections','toAddress','192.168.7.5')
set_param('RTHLFControllerHost/UDP Data Send/UDP Send: Longitudinal Velocity','toAddress','192.168.7.5')
set_param('RTHLFControllerHost/UDP Data Send/UDP Send: Reset Flag','toAddress','192.168.7.5')
set_param('RTHLFControllerHost/UDP Data Send/UDP Send: Set Velocity','toAddress','192.168.7.5')
set_param('RTHLFControllerHost/UDP Data Send/UDP Send: Tracks','toAddress','192.168.7.5')

Build the real-time application from the PID controller model RTHLFControllerTarget by using the Run on Target button on the Real-Time tab in the Simulink editor. Or, you can use the project shortcut helperBuildRealTimeApplication. In the Command Window, type:

run 'helperBuildRealTimeApplication';

Open App Generator and Bind Signals and Parameters to Instrument in App

As described in Simulink Real-Time App Generator, you can start creating an App Designer instrument panel from the real-time application MLDATX file.

1. Open the Simulink Real-Time App Generator by using the command slrtAppGenerator in the Command Window.

2. Select New > New. Then, select the real-time application MLDATX file LaneFollowingPIDController/Work/RTHLFControllerTarget.mldatx.

3. In the Signals And Parameters pane, select all of the parameters in the Workspace group. Click the add button to add these parameters to the Bindings tab.

4. For each parameter, set the Control Type to Parameter Table and select a unique name for the control. For example, use the name comp_Kp_setVerErr for the Kp_setVerErr parameter.

5. In the Signals And Parameters pane, select all of the relative signals (for example, relativeDistance) from the Named Signals group. Click the add button to add these signals to the Bindings tab.

6. For each signal, set the Control Type to Axes and select a unique name for the control. For example use the name comp_relativeDistance for the relativeDistance signal.

7. To save the app settings for the App Generator session and return later to continue working with it, you can save the settings to a MAT file by using the Save button. After adding the parameters and signals, selecting their controls, and providing control names, click the Generate App button to create the App Designer instrument panel app MLAPP file for the real-time application.

8. To continue developing the instrument panel, open the MLAPP file in App Designer.

Open App Designer Instrument Panel

The instrument panel that you create by using the App Generator provides a starting point for instrument panel development and makes it easier to work with instrumented signals and parameters by binding them to controls in the instrument panel app.

This example includes an App Designer instrument panel app that was created by using the Simulink Real-Time App Generator. The generator was used for selecting the real-time application MLDATX file and binding signals and parameter from the application to controls in the instrument panel.

For more information about creating instrument panel apps by using the App Generator, see Simulink Real-Time App Generator.

To open the app, in the project App folder, double-click on the app RTHLFControllerTarget_SLRTInstrumentPanel MLAPP file. Or, you can run the project shortcut helperOpenAppDesignerInstrumentPanel. In the Command Window, type:

proj = openProject(pwd);
run 'helperOpenAppDesignerInstPanel';

Use App Designer Instrument Panel to Control Real-Time Application

To run the simulation, run the development computer model simulation, then immediately start the target computer real-time application.

1. Start the instrument panel app.

2. By using the app, select the target computer and load the real-time application.

3. Start the simulation of the development computer model RTHLFControllerHost.

4. Start the run of the target computer real-time application RTHLFControllerTarget.

5. Use the instrument panel app to control the real-time application.

Deploy Standalone Executable App Designer Instrument Panel

From your App Designer instrument panel, you can compile a standalone executable instrument panel. For more information, see Create Standalone Instrument Panel App by Using Application Compiler.

Close Models, App, and Project

After exploring the App Designer instrument panel app and the Simulink project, close the project in MATLAB®. Closing the project closes all open files related to the project. If you prefer, you can close the models and project from the Command Window by typing:

bdclose('all');