Using Unreal Engine Visualization for Airplane Flight
This example shows how to add Unreal Engine® visualization using the Aerospace Simulation 3D library blocks. In this example, the Sky Hogg airplane flies over the prebuilt airport scene. To see the final model incorporating 3D visualization, open SkyHoggSim3DExampleModel
.
Note: This example is not supported in Simulink Online.
Start with Sky Hogg Example Model
Open the model used for the Lightweight Airplane Design example, asbSkyHogg
.
This model is set up for visualization using FlightGear in the Visualization subsystem. This example shows how to replace that implementation using Unreal Engine®.
Open the Visualization subsystem and delete everything except for In1 and Bus Selector1.
Adding Simulation 3D Animation Blocks
Use the library browser to go to Aerospace Blockset > Animation > Simulation 3D.
To the model:
Add the blocks Simulation 3D Scene Configuration, Simulation 3D Aircraft, and Simulation 3D Sky Hogg Pack.
Add a Scope block and attach it to the aircraft Altitude port.
Terminate the Simulation 3D Aircraft WoW port.
The WoW (Weight on Wheels) port returns a logical true if either the left or right main gear tire is on a surface (i.e. its altitude is zero) or false otherwise. Since this example has a flying aircraft, this port is not used.
Setting Up Simulation 3D Aircraft Block
Double-click to open the Simulation 3D Aircraft block to set up values on the Aircraft Parameters and Altitude Sensor tabs.
Aircraft Parameters tab
In the Aircraft Parameters tab:
Set the Type parameter to Sky Hogg
.
Select the desired color.
Leave the default name of
SimulinkVehicle1
.Leave the Sample time value of
-1
to allow the block to use the sample time in the Simulation 3D Scene Configuration block.
The initial conditions for the input ports are given in the Initial Values group. Each must be an 11-by-3 array. The aircraft component associated with each row for the Sky Hogg is as follows.
For this example, change the Initial translation value to [0 0 -2000; zeros(10, 3)]
and leave the Initial rotation value at zeros(11, 3)
. The -2000 meter Z value is the negative of the initial altitude (NED).
Altitude Sensor tab
The altitude sensor is optional and can be turned on and off by the Enable altitude and WoW sensors check box on this tab. The sensor works by sending ray traces vertically down from the aircraft body and each of its wheels. Altitude is only sensed if an object is hit by the rays, which are of the prescribed finite length. The Z offset values place the starting point of each ray at the given vertical (downward) distance from the aircraft body origin or wheel centers. For example, if the Z offset value entered for the Front tire radius (m) is the actual front tire radius for the aircraft mesh selected, then the returned second altitude value is zero when the aircraft front gear tire sits on the pavement.
Leave the default settings in place for now.
Setting Up Simulation 3D Scene Configuration Block
Check the configuration of the Simulation 3D Scene Configuration block. It should have Scene source set to Default Scenes
, with the Airport
scene selected. For the Scene view, use the name entered in the Simulation 3D Aircraft block, which by default is SimulinkVehicle1
. A Sample time of 1/60
or similar is fine; use a smaller value for a higher frame rate. To experiment with the weather, see the controls on the Weather tab. Note that weather in Unreal Engine® is currently just a visual sky effect; there are no actual wind vectors or forces, for example.
Connecting Simulation 3D Aircraft to Sky Hogg Translation and Rotation
The remaining step is to configure the Translation and Rotation port inputs to the Simulation 3D Aircraft block. These ports expect 11-by-3 array input at every time step when using Sky Hogg. See the Simulation 3D Aircraft block reference page for a full description. Since control surface motions are not provided by the model, change just the values of BODY.
Reconfigure the bus selector to output just Xe
and body
angles
.
Connect the Simulation 3D Sky Hogg Pack block output ports to the input ports of the Simulation 3D Aircraft block. Next connect the Xe
signal from the bus selector to the Body_T
input port of the pack block.
For rotation, the body angles
bus must be reassembled into a 1-by-3 vector. Create a subsystem to do this. Use a Bus Selector to obtain the three angles from the input and feed them into a Vector Concatenate block, then use a Reshape block to output a 2D row vector.
The Visualization subsystem should look like this:
Simulation
Model is ready to run.
After pressing the Run button, allow a few seconds for the 3D visualization window to initialize.
You should now see the airplane flying over the airport.
Once it is simulating, you can switch between camera views by first left-clicking inside the 3D window, then using the numbers keys 0 through 9 to choose between ten preconfigured camera positions. For more information on camera views, see the Run Simulation section in Customize Scenes Using Simulink and Unreal Editor.
Improving the Visualization to Simulation Interaction
Since the height change is so small (50 meters), it is difficult to see the altitude increase in the 3D window. For illustrative purposes, add a Gain block to increase the translation Z values.
Adding Propeller Rotation
This scene is not very realistic since the propeller is not turning. Propeller rotation is not typically calculated in the model, but you can choose a rotation rate for it. To rotate it at 1500 RPM, or 157 radians per second, add a Ramp block for the roll (phi) angle. The modified Sky Hogg Rotation subsystem should look like this.
Open the pack block mask and select the Propeller rotation check box, then click OK to close the mask. The Propeller_R port appears. Connect the Prop_R port from Sky Hogg Rotation to this port.
The final Visualization subsystem should look like this:
Altitude Sensor Rays
At first glance, the altitude sensor Scope block does not appear to be working (returning -1
values). This is because the altitude is greater than the length of the rays. Open the Simulation 3D Aircraft block mask and change the Length of rays (m) to 2500
. If you want to see the rays, select the Show sensor rays in viewer check box. Run the simulation again. The altitudes output in the two scopes validates that it is indeed at the prescribed location. If visible sensor rays are enabled, then they are colored red since they are hitting the ground. Without changing the ray length, the rays are colored green (if made visible) because they do not reach the ground.
Updated Simulation 3D Visualization Model
All of these steps have been completed for you in the following example model.
mdl = "SkyHoggSim3DExampleModel";
open_system(mdl);
See Also
Simulation 3D Aircraft | Simulation 3D Scene Configuration