Main Content

Create and Use an Oval Track

You can create a oval track withRoadRunnerand use it in a Vehicle Dynamics Blockset™ simulation that co-simulates with Unreal®. This example provides the workflow for creating the oval track that is used in theFollow Waypoints Around Oval Trackexample.

Before you start, make sure that you have the products required to follow the workflow.

Step Required Products

1

Step 1: Create Track in RoadRunner

RoadRunner

2

Step 2: Export Track From RoadRunner

RoadRunner

Unreal Engine®4.26

RoadRunnerplugin

Visual Studio®2019

3

Step 3: Import Track to Unreal Engine

4

Step 4: Co-Simulate in Vehicle Dynamics Blockset

Unreal Engine 4.26

Vehicle Dynamics Blockset

Vehicle Dynamics Blockset Interface for Unreal Engine 4 Projects

Step 1: Create Track inRoadRunner

In this example, you create the oval track specified in the following figure. The locations and reference poses are in theRoadRunnercoordinate system, (X,Y,θ). The locations,XandY, are in m. The reference poses,θ, are in deg.

Plot of X, Y, and reference poses showing an oval track.

Legend

Green

Locations of patch boundaries,X,Y

Red

Intersection points of straight-line segments,X,Y

Black

Track locations and reference poses,X,Y,θ

UseRoadRunnerto create the oval track. For more information about creating tracks, see

Create Straight Line Segments

  1. Open theRoad Plan Tool.

  2. Navigate toLibrary Browser>RoadStyles. SelectResidential.

  3. Right-click to place the start and endpoints of a straight-line road.

  4. After each straight segment, left-click and repeat the preceding step.

  5. Selecting the road control points. Use the preceding figure to the enter coordinate information.

Create Circular Arc

  1. Open theRoad Plan Tool. If you are continuing from creating the straight-line segments, theResidentialroad is the default road.

  2. Right-click to place the start and endpoints of the arc. If you use this method to connect straight lines, there might be multiple control points. Delete all but one control point.

  3. To create a control point, right-click anywhere in the road. To position it as specified in red in the preceding figure, left-click in each arc control point.

  4. 要创建圆弧,编辑的位置the control points. If the start of a road marks the end of another,RoadRunnerconnects them.

Adjust Road Width

  1. Open theLane Width Tool.

  2. Select the road that needs the width adjustment.

  3. To adjust the road width, select any purple or red segment.

  4. Modify the lines so that the entire width of the road is 14 m, or 7 m from the road centerline to each edge.

Create Patch

  1. Open theSurface Tool.

  2. Right-click to create four nodes.

  3. Right-click the first node to close the loop. By default, the surface is green.

Add Trees

To provide visual cues that indicate how fast the vehicle is traveling, you can add trees.

  1. Open theProp Curve Tool.

  2. Select an asset to place in the scene. For example, selectProps\Trees\Eucalyptus_Sm01.

  3. Right-click to select the inner boundary of the trajectory. To limit the trees in the green areas, adjust the tangents at the control points.

  4. To facilitate faster import into Unreal Engine, choose an appropriate spacing that limits the number of trees in the scene. The import time is proportional to the number of scene assets.

Step 2: Export Track FromRoadRunner

  1. InRoadRunner, open the scene.

  2. SelectFile>Export>Unreal (.fbx + .xml)

  3. In the Export Unreal dialog box, selectSplit by Segmentationand export folder. ClickExport.

Step 3: Import Track toUnreal Engine

After exporting fromRoadRunner, you import the data into Unreal Engine.

Create Empty Project

Create an empty project by following the steps listed inCreate Empty Project in Unreal Engine.

Acquire and RebuildRoadRunnerPlugins

  1. Download theRoadRunnerplugin. For more information, seeDownloading Plugins(RoadRunner).

  2. Extract theRoadRunnerplugin.zipfile. Locate theRoadRunnerImporterandRoadRunnerMaterialsfolders under the Unreal Engine plugins.

    Note

    The Unreal Engine plugin folder also contains aRoadRunnerCarlaintegration plugin. If you are not using CARLA, do not copy this folder.

  3. Copy theRoadRunnerImporterandRoadRunnerMaterialsfolders into thePluginsfolder under the project folder. If a Plugins folder does not exist, create one.

    Image of Plugins folder.

  4. Use a or b to rebuild the plugin.

    1. Generate the project files.

      • Windows®– Right-click the .uprojectfile and selectGenerate Visual Studio project files.

      • Linux®– Set environment variableUE4_ROOTto your Unreal Engine installation folder. At the command line, run this code:

        $UE4_ROOT/GenerateProjectFiles.sh -project="" -game -engine

    2. Open the project. SelectYesto build the plugins.

    If both a and b fail, try using Visual Studio to build the binaries.

  5. Verify that theRoadRunnerand MathWorks Interface plugins are enabled. SelectEdit>Plugins. Confirm thatEnabled被选中。

Import toUnreal Engine

  1. In the Unreal Editor, clickImport. Select the.fbxfile from Step 2.

    Note

    SelectingFile>Import Into Leveldoes not use the exportedRoadRunnerxml. Instead, it uses the Unreal importer.

  2. Use the default options in theRoadRunnerImport Options Dialog Box. ClickImport.

  3. Under theScenetab, selectImport as Dynamic. This enables translation of the whole scene.

  4. UnderStatic Meshes, clearRemove Degenerates. SetNormal Input MethodasInput Normals. ClickImport. The import can take up to 1 hour to complete.

  5. In theWorld Outliner, select the scene that you imported, for exampleFbxScene_OvalTrack1. To align theRoadRunnerand Unreal coordinate systems, enter a 90° rotation about theZ-axis.

    Unreal Engine World Outliner tab

  6. Optionally, consider using the editor to add terrain and foliage in the scene.

  7. Save the project (.uproject) file. Close the Unreal Editor.

Step 4: Co-Simulate inVehicle Dynamics Blockset

  1. Open the Simulink®model. Do not open the Unreal Editor.

  2. At the command-line, run these commands:

    sim3d.Engine.stop sim3d.Engine.start

  3. Open theSimulation 3D Scene Configurationblock.

    1. SetScene sourcetoUnreal Editor.

    2. SetProjectto the project (.uproject) file that you saved inStep 3: Import Track to Unreal Engine.

    3. ClickApply.

    4. ClickOpen Unreal Editor.

    The project opens in the Unreal Editor.

  4. SelectBlueprints>Open Level Blueprint.

  5. In the level blueprint:

    1. SelectFile>Reparent Blueprint.

    2. SelectSim3dLevelScriptActor.

    3. ClickSave.

    4. Close the level blueprint.

    5. In the editor, clickSave Current.

    This ensures that the vehicle identifies the ground properly during co-simulation.

  6. Run the simulation.

    1. In the Simulink model, clickRun.

      Because the source of the scenes is the project opened in the Unreal Editor, the simulation does not start.

    2. Verify that the Diagnostic Viewer window in Simulink displays this message:

      In the Simulation 3D Scene Configuration block, you set the scene source to 'Unreal Editor'. In Unreal Editor, select 'Play' to view the scene.

      This message confirms that Simulink has instantiated the vehicles and other assets in the Unreal Engine 3D environment.

    3. In the Unreal Editor, clickPlay. The simulation runs in the scene currently open in the Unreal Editor.

See Also

Related Examples

More About