Main Content

uavScenario

Generate UAV simulation scenario

Since R2020b

    Description

    The uavScenario object generates a simulation scenario consisting of static meshes, UAV platforms, and sensors in a 3-D environment.

    Creation

    scene = uavScenario creates an empty UAV scenario with default property values. The default inertial frames are the north-east-down (NED) and the east-north-up (ENU) frames.

    scene = uavScenario(Name,Value) configures a uavScenario object with properties using one or more Name,Value pair arguments. Name is a property name and Value is the corresponding value. Name must appear inside quotes. You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN. Any unspecified properties take default values.

    Using this syntax, you can specify the UpdateRate, StopTime, HistoryBufferSize, ReferenceLocation, and MaxNumFrames properties. You cannot specify other properties of the uavScenario object, which are read-only.

    Properties

    expand all

    Simulation update rate, specified as a positive scalar in Hz. The step size of the scenario when using an advance object function is equal to the inverse of the update rate.

    Example: 2

    Data Types: double

    Stop time of the simulation, specified as a nonnegative scalar. A scenario stops advancing when it reaches the stop time.

    Example: 60.0

    Data Types: double

    Maximum number of steps stored in scenario, specified as a positive integer greater than 1. This property determines the maximum number of frames of platform poses stored in the scenario. If the number of simulated steps exceeds the value of this property, then the scenario stores only latest steps.

    Example: 60

    Data Types: double

    Scenario origin in geodetic coordinates, specified as a 3-element vector of scalars in the form [latitude longitude altitude]. latitude and longitude are geodetic coordinates in degrees. altitude is the height above the WGS84 reference ellipsoid in meters.

    Data Types: double

    Maximum number of frames in the scenario, specified as a positive integer. The combined number of inertial frames, platforms, and sensors added to the scenario must be less than or equal to the value of this property.

    Example: 15

    Data Types: double

    This property is read-only.

    Current simulation time, specified as a nonnegative scalar.

    Data Types: double

    This property is read-only.

    Indicate whether the scenario is running, specified as true or false. After a scenario simulation starts, it runs until it reaches the stop time.

    Data Types: logical

    This property is read-only.

    Transformation information between all the frames in the scenario, specified as a transformTree object. This property contains the transformation information between the inertial, platform, and sensor frames associated with the scenario.

    Data Types: object

    This property is read-only.

    Names of the inertial frames in the scenario, specified as a vector of strings.

    Data Types: string

    This property is read-only.

    UAV platforms in the scenario, specified as an array of uavPlatform objects.

    Static meshes in the scenario, specified as an array of extendedObjectMesh objects

    Object Functions

    setupPrepare UAV scenario for simulation
    addCustomTerrainAdd custom terrain data
    addMeshAdd new static mesh to UAV scenario
    addInertialFrameDefine new inertial frame in UAV scenario
    advanceAdvance UAV scenario simulation by one time step
    copyCopy UAV scenario
    updateSensorsUpdate sensor readings in UAV scenario
    removeCustomTerrainRemove custom terrain data
    restartReset simulation of UAV scenario
    showVisualize UAV scenario in 2-D
    show3DVisualize UAV scenario in 3-D
    terrainHeightReturns terrain height in UAV scenarios
    targetPosesFind positions, orientations, velocities, angular velocities, and accelerations of targets relative to ego UAV platform

    Examples

    collapse all

    Create a UAV scenario and set its local origin.

    scene = uavScenario("UpdateRate",200,"StopTime",2,"ReferenceLocation",[46, 42, 0]); 

    Add an inertial frame called MAP to the scenario.

    scene.addInertialFrame("ENU","MAP",trvec2tform([1 0 0])); 

    Add one ground mesh and two cylindrical obstacle meshes to the scenario.

    scene.addMesh("Polygon", {[-100 0; 100 0; 100 100; -100 100],[-5 0]},[0.3 0.3 0.3]);
    scene.addMesh("Cylinder", {[20 10 10],[0 30]}, [0 1 0]); 
    scene.addMesh("Cylinder", {[46 42 5],[0 20]}, [0 1 0], "UseLatLon", true); 

    Create a UAV platform with a specified waypoint trajectory in the scenario. Define the mesh for the UAV platform.

    traj = waypointTrajectory("Waypoints", [0 -20 -5; 20 -20 -5; 20 0 -5],"TimeOfArrival",[0 1 2]); 
    uavPlat = uavPlatform("UAV",scene,"Trajectory",traj); 
    updateMesh(uavPlat,"quadrotor", {4}, [1 0 0],eul2tform([0 0 pi])); 
    addGeoFence(uavPlat,"Polygon", {[-50 0; 50 0; 50 50; -50 50],[0 100]},true,"ReferenceFrame","ENU"); 

    Attach an INS sensor to the front of the UAV platform.

    insModel = insSensor(); 
    ins = uavSensor("INS",uavPlat,insModel,"MountingLocation",[4 0 0]); 

    Visualize the scenario in 3-D.

    ax = show3D(scene); 
    axis(ax,"equal"); 

    Simulate the scenario.

    setup(scene); 
    while advance(scene) 
        % Update sensor readings 
        updateSensors(scene); 
    
        % Visualize the scenario 
        show3D(scene,"Parent",ax,"FastUpdate",true); 
        drawnow limitrate 
    end 

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

    This example shows how to add terrain and custom building mesh to a UAV scenario.

    Add Terrain Surface

    Add terrain surface based on terrain elevation data from the n39_w106_3arc_v2.dt1 DTED file.

    addCustomTerrain("CustomTerrain","n39_w106_3arc_v2.dt1");
    scenario = uavScenario("ReferenceLocation", [39.5 -105.5 0]);
    addMesh(scenario,"terrain", {"CustomTerrain", [-200 200], [-200 200]}, [0.6 0.6 0.6]);
    show3D(scenario);

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

    Add Buildings

    Add a couple custom building meshes using vertices and polygon meshes into the scenario. Use the terrainHeight function to get ground height for each build base.

    buildingCenters = [-50, -50; 100 100];
    
    buildingHeights = [30 100];
    buildingBoundary = [-25 -25; -25 50; 50 50; 50 -25];
    for idx = 1:size(buildingCenters,1)
        buildingVertices = buildingBoundary+buildingCenters(idx,:);
        buildingBase = min(terrainHeight(scenario,buildingVertices(:,1),buildingVertices(:,2)));
        addMesh(scenario,"polygon", {buildingVertices, buildingBase+[0 buildingHeights(idx)]}, [0.3922 0.8314 0.0745]);
    end
    
    show3D(scenario);
    view([0 15])

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

    Remove Custom Terrain

    Remove the custom terrain that was imported.

    removeCustomTerrain("CustomTerrain")

    Version History

    Introduced in R2020b