Using Pre-built Scenes | Using Unreal Engine with Simulink, Part 1
From the series: Using Unreal Engine with Simulink
Part 1 of this tutorial series uses a Double Lane Change reference application to demonstrate how to enable and initialize one of the Unreal Engine® scenes that ships with Vehicle Dynamics Blockset™.
Published: 13 Oct 2021
Hi, and welcome to our video series on Using Unreal Engine with Simulink. I'm Mike Sasena and I'll be walking you through a series of video tutorials designed to help you make the most out of Simulink's Unreal Engine interface. Now most of the details I'll be covering here today are explained in our documentation. We'll post some links to help you find those as well.
In these videos, I'll show you how this interface works using the Vehicle Dynamics Blockset. But you can follow similar steps with other MathWorks products that support Unreal Engine, such as automated driving toolbox, aerospace blockset, or UAV toolbox. The series assumes that you've already installed the MathWorks products of interest and the Unreal Engine from Epic Games.
Over the course of the series, I'll walk you through the following steps. In this video, I'll show you how to enable the Unreal Engine with one of our pre-built scenes. In the next video, I'll help you install and configure the tools you need to create your own custom scenes. After that, I'll connect some custom scenes to Simulink by co-simulating with the Unreal editor for quick iterations on the scene.
In the last video, I'll explain how to compile your scene into an executable that you can share with colleagues to run directly from Simulink. Let's start by using the Unreal Engine features that come prebuilt with vehicle dynamics blockset. I'll show you how to turn on the Unreal Engine, select the scene of interest, and initialize the vehicle in your scene.
The location of these options may differ slightly depending on which example you're using and which version of MATLAB. First off, be aware that you do not need to install the Unreal Engine for these examples. The scenes used here are standalone executables. All you need is the proper MathWorks products installed.
To start, I'll open an example called The Double Lane Change Maneuver in vehicle dynamics blockset. You can run the command shown here or use the examples tab in the Simulink start page. Once the project is loaded, you'll see the Simulink model shown here. Notice that as subsystems for the maneuver, driver, controller, plant, sensors, in environment. There's also a visualization subsystem where we specify information about the connection to the Unreal Engine.
When I run this model, you'll see a 2D plot of the vehicle pop up but no one Unreal Engine window. That's because we have the Unreal Engine disabled by default. Not all users have GPUs needed for this work on their computer. So a game engine would run pretty slowly in that case. To turn on Unreal, I can open the green block within the visualization subsystem and select the radio button to enable Unreal Engine. This will then run the example in the scene selected from the pull down menu.
If I want to run the same simulation in a different scene, I can just select the different option from that menu. Of course, if your model isn't designed for that particular environment in mind, you might get some unexpected results. I don't think you'd want to run a constant radius test in a city block for example.
Along with the scene selection, you can specify the initial position of the vehicle you're controlling from Simulink. Note that there are actually two aspects of initializing vehicle position. The Unreal Engine visualization and the Simulink physics model. The Unreal Engine needs to know where to instantiate the actors when first generating the scene, and that value is set from the same 3D vehicle block.
Depending on which example you're using, those parameters may be within the same 3D block in the visualization subsystem or it may be set by a helper function in the maneuver subsystem. For this example, I'll set the parameters in the same 3D vehicle block. Make sure that you use the correct sign convention as described in the Help.
The Simulink plant model also contains parameters for the initial position. These are used to set the position of your vehicle at the first time step of your simulation. If you don't use the same values for the unreal and plant model initialization, you'll see the vehicle jump locations at that first time step. Once I've set my initial conditions, I can run the simulation and view the results.
In this video, I showed you an example that includes the Unreal Engine and how to select different pre-built scenes and starting points for your vehicle. You can also create your own custom scenes and connect those to Simulink. In the next video, we'll show you how to install and configure the tools necessary to do that.