Design Real-World Trajectory in UAV Scenario and Visualize with Cesium
This example shows how to design and visualize a real-world UAV trajectory by using the Read UAV Trajectoy block and OpenStreetMap® (OSM) data from Manhattan, New York.
Design Flight Trajectory in UAV Scenario
Create a UAV scenario with the reference location set to 1 Wall Street at [40.707088 -74.012146 0].
scene = uavScenario(ReferenceLocation=[40.707088 -74.012146 0]);
Set the x-, and y-limits and colors for the terrain and building data. Import the terrain elevation data and the OSM building data by using the addMesh function.
% Add terrain mesh xTerrainLimits = [-200 200]; yTerrainLimits = [-200 200]; color = [0.6 0.6 0.6]; addMesh(scene,"terrain",{"gmted2010",xTerrainLimits,yTerrainLimits},color) % Add building mesh xBuildingLimits = [-150 150]; yBuildingLimits = [-150 150]; color = [0.6431 0.8706 0.6275]; addMesh(scene,"buildings",{"manhattan.osm",xBuildingLimits,yBuildingLimits,"auto"},color)
Visualize the scenario.
show3D(scene);
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.
wpts = ... [-130 -90 -50; ... -30 -24 -50; ... 70 30 -50; ... 0 120 -50];
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:4 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
Visualize Flight Trajectory in Cesium
Open the ScenarioTrajectoryinCesium.slx
simulink model
open_system("ScenarioTrajectoryinCesium.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
.
To visualize the trajectory in Cesium, first complete the steps in Visualize with Cesium if you have not already done so. The initial setup includes creating a Cesium Ion account and access token, and creating a new token in the Simulink Authentication Manager to hold your Cesium Ion token.
Specify these parameters for the Simulation 3D Scene Configuration Block:
In the Scene tab, set Scene source to Default Scenes.
In the Geospatial tab, select Enable geospatial configuration.
For the Access token ID parameter, enter your Cesium Ion token name.
Specify the Origin height (m), Origin latitude, and Origin longitude using the corresponding values from the scenario reference location coordinates.
To enable the OSM buildings in the visualization, populate the Additional asset ID parameter with the Cesium OSM Building ID.
Select Use advanced Sun sky.
To start the simulation, from the Simulink Toolstrip, select Run, then allow a few seconds for the 3D visualization window to initialize. After a few additional seconds, Cesium Ion loads the 3D imagery. The UAV flies along the trajectory defined by your UAV scenario.
See Also
Read UAV Trajectory | uavScenario
| multirotorFlightTrajectory
| uavMission