Send Double-Lane Change Scene Data
This example shows you how to use the Simulation 3D Message Set block to communicate with the 3D visualization environment when you run the double-lane change maneuver. Specifically, you use the Simulation 3D Message Set block to control the traffic signal light. For the minimum hardware required to run the example, see the Unreal Engine Simulation Environment Requirements and Limitations.
Run a Double-Lane Change Maneuver
With the 3D visualization environment enabled, run a double-lane change maneuver.
Create and open a working copy of the double-lane change reference application project.
Enable the 3D visualization environment. In the Visualization subsystem, open the 3D Engine block mask and select Enabled. Apply the changes and save the model.
Alternatively, at the MATLAB® command prompt, enter this code.
Run the maneuver for 30 seconds. View the simulation in the AutoVrtlEnv window.
Use Simulation 3D Message Set Block to Control Traffic Signal Light
Navigate to the Visualization > 3D Engine subsystem. Right-click the 3D Engine block and select Mask > Look Under Mask. In the Visualization > 3D Engine > 3D Engine subsystem, insert these blocks:
Simulation 3D Message Set
Repeating Sequence Stair
Set the Simulation 3D Message Set block parameters so that the block sends traffic signal data to the double-lane change scene. Set these block parameters, apply the changes, and save the model.
Signal name, SigName to
Sample time to
This table provides the scene traffic signal light color that corresponds to the
WriteMsgvalue in the Double Lane Change scene.
Simulation 3D Message Set Block
Alternatively, at the MATLAB command prompt, enter this code.
Set the Repeating Sequence Stair block parameters to send a command that corresponds to red, yellow, and green traffic light signals. Set these block parameters, apply the changes, and save the model.
Vector of output values: to
[0 0 0 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2].'
Sample time to
Output data type to
Alternatively, at the MATLAB command prompt, enter this code. Apply the block changes and save the model.
Connect the blocks as shown. Confirm the block parameters and signal connections. Save the model.
Verify that the Simulation 3D Message Set block executes before the Simulation 3D Scene Configuration block. That way, Simulation 3D Message Set prepares the signal data before the Unreal Engine® 3D visualization environment receives it. To check the block execution order, right-click the blocks and select Properties. On the General tab, confirm these Priority settings:
Simulation 3D Scene Configuration —
Simulation 3D Message Set —
For more information about execution order, see Control and Display Execution Order.
Run the maneuver. As the simulation runs, in the AutoVrtlEnv window, you can see the
TrafficLight1light change from red to yellow to green.
Time Range (s)