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 how many cones 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 3D Visualization Engine Requirements.

Run a Double-Lane Change Maneuver That Hits Cones

With the 3D visualization environment enabled, run a double-lane change maneuver that hits the cones.

  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. In the top level of the model, set the Lane Change Reference Generator block parameters so that the vehicle does not successfully complete the maneuver. Set these block parameters, apply the changes, and save the model.

    • Maneuver start time to 5.

    • Longitudinal entrance velocity setpoint to 40.

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

     See Code That Sets Parameters

  4. Run the maneuver. As the simulation runs, in the AutoVrtlEnv window, you can see the vehicle hitting the cones.

Use Simulation 3D Message Get Block to Retrieve Cone Data

Use the Simulation 3D Message Get block to retrieve how many cones 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

    • Math Function

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

    • Signal name, SigName to NumOfConesHit

    • Data type, DataType to boolean

    • Message size, MsgSize to [2 15]

    • Sample time to -1

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

     See Code That Sets Parameters

  3. Set the Math Function block Output dimensionality parameter to transpose. When you run the simulation, the Math Function block outputs a [15 2] array.

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

     See Code That Sets Parameters

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

  5. 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 (Simulink).

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

    The results indicate that the vehicle hits SM_Cone20, SM_Cone29, and SM_Cone30 during the maneuver.

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

    Simulation 3D Message Get Block ReadMsg Value

    Unreal® Editor Cone Name

    Simulation 3D Message Get Block Array Element

    Unreal Editor Cone Name

    ReadMsg(1,1)SM_Cone5ReadMsg(2,1)SM_Cone10
    ReadMsg(1,2)SM_Cone4ReadMsg(2,2)SM_Cone09
    ReadMsg(1,3)SM_Cone3ReadMsg(2,3)SM_Cone08
    ReadMsg(1,4)SM_Cone2ReadMsg(2,4)SM_Cone07
    ReadMsg(1,5)SM_Cone01ReadMsg(2,5)SM_Cone06
    ReadMsg(1,6)SM_Cone15ReadMsg(2,6)SM_Cone20
    ReadMsg(1,7)SM_Cone14ReadMsg(2,7)SM_Cone19
    ReadMsg(1,8)SM_Cone13ReadMsg(2,8)SM_Cone18
    ReadMsg(1,9)SM_Cone12ReadMsg(2,9)SM_Cone17
    ReadMsg(1,10)SM_Cone11ReadMsg(2,10)SM_Cone16
    ReadMsg(1,11)SM_Cone25ReadMsg(2,11)SM_Cone30
    ReadMsg(1,12)SM_Cone24ReadMsg(2,12)SM_Cone29
    ReadMsg(1,13)SM_Cone23ReadMsg(2,13)SM_Cone28
    ReadMsg(1,14)SM_Cone22ReadMsg(2,14)SM_Cone27
    ReadMsg(1,15)SM_Cone21ReadMsg(2,15)SM_Cone26

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

  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 Set

    • Data Type Conversion

    • Stair Generator

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

    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

  3. Set the Data Type Conversion block parameters to convert data to int32. Set these block parameters, apply the changes, and save the model.

    • Output data type to int32

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

     See Code That Sets Parameters

  4. Set the Stair Generator 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.

    • Time to [0,2,3,5,8]

    • Amplitude to [0,0,1,2,2]

    • Sample time to 1

    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.

  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 (Simulink).

  7. Run the maneuver. As the simulation runs, in the AutoVrtlEnv window, you can see the TrafficLight1 light change from red to yellow to green.

    Time Range (s)

    WriteMsg Value

    TrafficLight1 Color

    0–3

    0Red

    3–5

    1Yellow

    5–8

    2Green

See Also

| | | |

Related Examples

More About