How 3D Simulation in Unreal Engine Environment Works
Simulink® 3D Animation™ allows you to co-simulate MATLAB® and Simulink with the 3D simulation engine from Unreal Engine® from Epic Games®. This co-simulation framework allows Simulink 3D Animation to send data between the Unreal Engine and MATLAB or Simulink. Understanding how communication with the 3D simulation engine works can help you troubleshoot performance issues and customize your models.
Communication with 3D Simulation Engine
When you run your algorithms using Simulink 3D Animation, MATLAB and Simulink co-simulate the algorithms with the 3D simulation engine through, lock-step mechanism. The lock-step mechanism is a synchronization approach where the simulation progresses in fixed time steps, and the two simulation engines, either MATLAB or Simulink and the 3D simulation engine, run sequentially. One simulation engine waits while the other simulation engine proceeds, so each simulation produces consistent results.
During each simulation step:
MATLAB or Simulink configures the initial settings of the 3D environment, including actor transformations and properties and the custom scene viewpoint. MATLAB or Simulink also determines the configuration parameters of the 3D environment and the actors using the 3D simulation engine feedback.
The co-simulation framework sends data from MATLAB or Simulink to the 3D simulation engine.
The co-simulation framework sends a command signal to the 3D simulation engine indicating the end of data transfer.
The 3D simulation engine executes the simulation. The 3D simulation engine configures the 3D environment and the actors based on the data from MATLAB or Simulink, then provides updated information about the 3D environment and the actors.
The co-simulation framework sends data from the 3D simulation engine to MATLAB or Simulink.
The co-simulation framework sends an acknowledge signal to MATLAB or Simulink, indicating the end of data transfer from the 3D simulation engine.
To communicate with the 3D simulation engine, MATLAB uses the sim3d.World
class and Simulink uses the Simulation 3D Scene
Configuration block.
Simulation Speed
Simulation speed depends on the stop time and the sample time of the simulation. The
stop time is the duration of the simulation. The sample time is the time interval at
which the output is updated during the simulation. The simulation step is the ratio of
stop time to sample time. A smaller step enables more detailed and accurate simulation
but can increase computational load and simulation time. It determines how often the
state of the simulation is updated, including the positions, velocities, and other
properties of objects within the simulation. To set the stop time and the sample time in
MATLAB, set the StopTime
and SampleTime
arguments, respectively, in the sim3d.World
object. To set the sample time in Simulink, use the Sample time parameter in the
Simulation 3D Scene
Configuration block. If you decrease the sample time, the software takes
more samples per second, so simulation speed decreases. For more information on sample
time, see SampleTime.
If you want to slow down a 3D simulation to investigate system behavior, you can use
simulation pacing. The pacing rate determines how fast the simulation runs relative to
real time. The pacing rate adjusts the speed at which the simulation progresses. A
pacing rate of 1 means the simulation runs in real time, a rate greater than 1 increases
the simulation beyond real-time speed, and a rate less than 1 slows down the simulation.
You can configure simulation pacing in MATLAB using the EnablePacing and PacingRate
properties of the sim3d.World
object. In Simulink, configure simulation pacing using the Simulation Pacing Options (Simulink).
Simulation speed also depends on model complexity, computational speed, and the speed
at which the system can render a scene, which depends on the system configuration. You
can use the profile
function in MATLAB or the Simulink Profiler (Simulink) in Simulink to analyze the distribution of simulation execution time among the
simulation components and see the computational time of each component in the
simulation. For more information on profiling, see Profile Your Code to Improve Performance.
See Also
sim3d.World
| sim3d.Actor
| sim3d.sensors.IdealCamera
| Simulation 3D Scene
Configuration | Simulation 3D
Actor | Simulation 3D Camera
Get