Main Content

Using Simulation 3D Visualization with Aerospace Blockset

This example shows how to add 3D visualization to a Simulink® model using the Aerospace Simulation 3D library blocks. To see the final model incorporating 3D visualization, open SkyHoggSim3DExampleModel.

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:

  1. Add the blocks Simulation 3D Scene Configuration and Simulation 3D Aircraft.

  2. Add a Scope block and attach it to the aircraft Altitude port.

  3. 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, Inital Values, and Altitude Sensor tabs.

Aircraft Parameters tab

In the Aircraft Parameters tab:

  • Set the Type parameter to SkyHogg.

  • 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.

Initial Values tab

The initial conditions for the input ports are given in the Initial Values tab. If it is an airliner, each must be a 12-by-3 array. For the Sky Hogg, each must be an 11-by-3 array because the Sky Hogg has only one powerplant. 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; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0] 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 sensor 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 gear tire radius (in meters) 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 the BODY. Set all other values to zero.

Reconfigure the bus selector to output just Xe and body angles.

Next, create a subsystem to take the Xe values as input and return the Translation array that the aircraft block needs. Connect the Xe input to a Reshape block with row vector (2-D) output. Add a Constant block for the rest of the translations (zeros(10,3)), and feed both into another Vector Concatenate block. Set this block to Multidimensional array mode with a Concatenate dimension of 1.

Create a similar subsystem for rotation, which returns the 11-by-3 array of rotations for the aircraft. Use a Bus Selector to obtain the three angles from the input and feed those into a Vector Concatenate. The remainder of the subsystem is identical to the translation subsystem.

The final 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, you can add a Gain block to increase the translation Z values.

Adding Propeller Rotation

This scene is not very realistic since the propeller isn't turning. Propeller rotation is not something that is 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 of the second row of the Rotations array. The modified Sky Hogg Rotation subsystem should look something like this.

Altitude Sensor Rays

At first glance, the altitude sensor Scope 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 (in meters) to 2500. If you want to see the rays, select the Enable visible sensor rays 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

|