Main Content

Send and Receive Double-Lane Change Scene Data

This example shows you how to use the Simulation 3D Message Set and Simulation 3D Message Get blocks to communicate with the 3D visualization environment when you run the double-lane change maneuver. Specifically, you use the:

  • Simulation 3D Message Get block to retrieve which barrels the vehicle hits during the maneuver.

  • 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.

  1. Create and open a working copy of the double-lane change reference application project.

  2. 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.

     See Code That Enables 3D Environment

  3. Run the maneuver for 25 seconds. View the simulation in the Simulation 3D Viewer. As the vehicle completes the maneuver, it hits the barrel.

    3D image of double-lane change scene

     See Code That Runs Simulation

Use Simulation 3D Message Get Block to Retrieve Barrel Data

Use the Simulation 3D Message Get block to retrieve which barrels the vehicle hits during the maneuver. By default, the maneuver uses the double-lane change scene.

  1. 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 Get

    • Display

  2. Set the Simulation 3D Message Get block parameters so that the block retrieves barrel data from the double-lane change scene. Set these block parameters, apply the changes, and save the model.

    • Signal name, SigName to NumOfBarricadesHit

    • Data type, DataType to boolean

    • Message size, MsgSize to [1 8]

    • Sample time to -1

    Simulation 3D Message Get block parameters dialog box

    Alternatively, at the MATLAB command prompt, enter this code.

     See Code That Sets Parameters

  3. Connect the Simulation 3D Message Get and Display blocks as shown. Confirm the block parameters. Save the model.

    Simulink model with a Simulation 3D Scene Configuration block and a Simulation 3D Message Get block connected to a Display block.

  4. Verify that the Simulation 3D Scene Configuration block executes before the Simulation 3D Message Get block. That way, the Unreal Engine® 3D visualization environment prepares the data before the Simulation 3D Message Get block 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 Configuration0

    • Simulation 3D Message Get1

    For more information about execution order, see Control and Display Execution Order.

  5. Run the maneuver. As the simulation runs, the display block updates with the ReadMsg boolean value 1 when the vehicle hits the corresponding barrel.

    Display block displaying a column with the number, one, highlighted in a red box.

    The results indicate that the vehicle hits Drum01Node67 at the end of the maneuver.

    This table provides the Double Lane Change scene barrel name that corresponds to the ReadMsg array element.

    Simulation 3D Message Get Block ReadMsg Value

    Unreal® Editor Barrel Name

    ReadMsg(1,1)Drum01Node
    ReadMsg(1,2)Drum01Node67
    ReadMsg(1,3)Drum01Node68
    ReadMsg(1,4)Drum01Node69
    ReadMsg(1,5)Drum01Node70
    ReadMsg(1,6)Drum01Node71
    ReadMsg(1,7)Drum01Node72
    ReadMsg(1,8)Drum01Node73

Use Simulation 3D Message Set Block to Control Traffic Signal Light

  1. Start the maneuver at 5 seconds. In the Lane Change Reference Generator block, set Maneuver start time to 5.

     See Code That Sets Parameters

  2. 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

  3. 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 TrafficLight1

    • Sample time to -1

    Simulation 3D Message Set block parameters dialog box

    This table provides the scene traffic signal light color that corresponds to the WriteMsg value in the Double Lane Change scene.

    Simulation 3D Message Set Block WriteMsg Value

    TrafficLight1 Color

    0Red
    1Yellow
    2Green

    Alternatively, at the MATLAB command prompt, enter this code.

     See Code That Sets Parameters

  4. 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 1

      Repeating Sequence Stair block mask

    • Output data type to int32

      Repeating Sequence Stair block mask

    Alternatively, at the MATLAB command prompt, enter this code. Apply the block changes and save the model.

     See Code That Sets Parameters

  5. Connect the blocks as shown. Confirm the block parameters and signal connections. Save the model.

    Simulink model.

  6. 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 Configuration0

    • Simulation 3D Message Set-1

    For more information about execution order, see Control and Display Execution Order.

  7. Run the maneuver. As the simulation runs, in the Simulation 3D Viewer, you can see the TrafficLight1 light change from red to yellow to green.

    3D image of traffic light showing yellow light.

    Time Range (s)

    WriteMsg Value

    TrafficLight1 Color

    0–3

    0Red

    3–5

    1Yellow

    5–30

    2Green

See Also

| | | |

Related Examples

More About