Set Up Top-Down Simulink Visualization for Unreal Engine Simulation
Scenes run in the Unreal Engine® simulation environment can be complex and contain multiple moving actors, so it can be useful to view part of a complex simulation from a simpler top-down perspective. You can create a top-down view of an area of interest, to use during simulation, by setting up a Simulink Simulation 3D Camera. Use this example to learn how to set up and configure a camera to capture a 2-D, top-down view of an area of interest.
Model Overview
The model consists of these main components:
Scene — A Simulation 3D Scene Configuration block configures the scene in which you simulate.
Vehicles — Many Simulation 3D Vehicle with Ground Following blocks configure the vehicles within the scene and specify their trajectories.
Camera — A Simulation 3D Camera block is configured to view an area of interest from a top-down perspective. A Video Viewer block visualizes the simulation output of this sensor.
open_system("topDownUnrealEngineCamera.slx")
This model captures a top-down video showing a 70-by-45 meter area of interest in the Large Parking Lot scene.
The area of interest is offset by –40 meters in the X-axis and 15 meters in the Y-axis, corresponding to the blue outlined area in this image.
Calculate Camera Focal Lengths
Calculate focal length values of the camera by changing the parameters below. First, specify your desired video resolution, the intended height of the camera above the scene, and the size of the area of interest you want to capture. Your output resolution aspect ratio should match the aspect ratio of the area you are capturing.
xOutputResolution = 1555; % pixels yOutputResolution = 1000; % pixels cameraHeight = 500; % meters areaImageWidth = 70; % meters areaImageHeight = 45; % meters xFocalLength = xOutputResolution*cameraHeight/areaImageWidth
xFocalLength = 1.1107e+04
yFocalLength = yOutputResolution*cameraHeight/areaImageHeight
yFocalLength = 1.1111e+04
Inspect Camera Parameters
In the Simulink Simulation 3D Camera block, the parameters are modified to provide the top-down view using the desired resolution parameters and calculated focal lengths.
Mounting
Parent name —
Scene Origin
Mounting location —
Origin
Specify offset —
on
Relative translation [X, Y, Z] (m) —
[20 15 cameraHeight]
Relative rotation [Roll, Pitch, Yaw] (deg) —
[-90 90 0]
These parameters ensure that the camera is above the center of the area of interest, does not follow any vehicles in the scene, is high enough above the scene to provide a more orthographic perspective, and is pointed directly down at the scene.
Parameters
Focal length (pixels) —
[xFocalLength yFocalLength]
Optical center (pixels) —
[xOutputResolution yOutputResolution] / 2
Image size (pixels) —
[yOutputResolution xOutputResolution]
Simulate Model
Run the model. The Video Viewer block displays a top-down, orthographic view of the area of interest from the Unreal Engine simulation.
sim("topDownUnrealEngineCamera.slx");