Main Content

Simulate UAV Scenario Trajectory in Unreal Engine Environment

This example shows how to design a flight trajectory in a UAV scenario, and use the generated trajectory for 3D simulation in the Unreal Engine® simulation environment.

To access the Simulink® model in this example, open the example live script by either clicking Open Live Script in the documentation or entering this command at the MATLAB® command line.

openExample("uav/SimulateUAVScenarioTrajectoryInUnrealEngineEnvironmentExample")

Design Flight Trajectory in UAV Scenario

Create a UAV scenario with default properties.

scene = uavScenario;

Import the US City Block scene into the UAV scenario as mesh.

addMesh(scene,"unreal scene",{"urban",[0 0 0],0},[1 1 1])

Visualize the scenario.

% Show the scenario
ax = show3D(scene);

% Disable data tip snapping
ax.Interactions = dataTipInteraction("SnapToDataVertex","off");

Figure contains an axes object. The axes object with xlabel East (m), ylabel North (m) contains an object of type patch.

In the scenario visualization, select the waypoints that you want to use for the trajectory. Selecting a point in the visualization will display a data tip that shows its coordinate. Store the waypoints that you have chosen in the north-east-down (NED) coordinate frame.

waypoints_selection_revised.png

wpts = ...
    [0.15 -191 -30; ...
     0.15 -112 -30; ...
     -110 -112 -30; ...
     -110 -20  -30; ...
     -7   -20  -30];

To create a UAV mission to parse for a multirotor trajectory, first calculate the UAV starting location in geodetic coordinates. Assume that the UAV starts at the first waypoint.

StartPos = ned2lla(wpts(1,:),scene.ReferenceLocation,"ellipsoid");

Create the UAV mission, and add all of the waypoints to the mission in the local north-east-down (NED) reference frame.

mission = uavMission(Frame="LocalNED",Speed=5,HomeLocation=StartPos);

for idx = 1:5
    addWaypoint(mission,wpts(idx,:)-wpts(1,:));
end

Create a multirotor mission parser, and parse the mission into a multirotor trajectory.

MissionParser = multirotorMissionParser;
trajectory = parse(MissionParser,mission,scene.ReferenceLocation);

Plot the trajectory.

show(trajectory)
axis equal

Figure contains an axes object. The axes object contains 411 objects of type patch, line.

Simulate Flight Trajectory in Unreal Engine

Open the ScenarioTrajectoryinUE.slx simulink model

open_system("ScenarioTrajectoryinUE.slx")

The Simulink model contains a Read UAV Trajectory block, which generates translation and rotation samples for the Simulation 3D UAV Vehicle block from the trajectory that you have created.

Open the block parameters of the Read UAV Trajectory block and specify the Trajectory source parameter as From trajectory object in workspace. Specify the Trajectory object parameter as trajectory.

Run the Simulink model. The UAV flies along the trajectory from the UAV scenario in the Unreal Engine environment..

sim("ScenarioTrajectoryinUE.slx");

See Also

| | |

Related Topics