Main Content

Design Obstacle Avoidance Package Delivery Scenario Using UAV Scenario Designer

This example shows how to rapidly design and customize a UAV scenario to validate an obstacle avoidance algorithm.

The UAV Package Delivery example uses a specific scenario modelling a few city blocks to validate the obstacle avoidance algorithm. However, you must verify that the UAV can fly safely and consistently with an obstacle avoidance algorithm by simulating over different scenarios. For example, you may want to evaluate the algorithm over a denser urban setting with closely spaced buildings. These scenarios are difficult to setup without a visual reference. In this example, start with a simple scenario and gradually add layers of complexity to it by importing a terrain, more obstacles, and moving actors to the scene by using UAV Scenario Designer. After validating the obstacle avoidance algorithm in UAV Scenario Designer, export and simulate in a scenario in Simulink.

Launch App

To start the app, click Apps > UAV Scenario Designer, or execute the uavScenarioDesigner function.

To view the final state of the scenario designed in the example, load it from the stored scenario data to workspace. To see the scenario within the app, click Import Scenario under the Import Section and import the scenario into the app. Otherwise, following along with the example.

load customizedScenario;

Import Terrain

Click Import Terrain > Import DTED terrain to import a Digital Terrain Elevation Data (DTED) terrain into the app. The app shows a list of pre-registered terrains. To register a custom terrain in MATLAB®, use the addCustomTerrain function.

Import terrain dialog

Select gmted2010 from the Import terrain from MATLAB session dialog box.

Keep the reference location Latitude, Longitude, and Altitude to the deafult zero values. In the Property Panel, set the Latitude Limits, and Longitude Limits to [-0.003 0.002] and [-0.0015 0.0015] respectively. Click Import Terrain in the Property Panel to finish importing the terrain with these properties.

Add Obstacles to Scenario

Add simple buildings to the scene by importing 2-D polygons into the app. The 2-D polygons are represented by N-by-2 vertices that denote the X and Y corner points of the polygon. This polygon is imported as a 3-D polyhedron into the app where its depth can be adjusted. Some templates are provided in 'buildingTemplates.mat'.

load('buildingTemplates.mat')

Click Scene Objects > Polygon in the toolstrip and import any building. After placing them in the Scenario Canvas, you can adjust the Height, Color, and Position of this polygon. Adding an object on top of the terrain automatically adjusts its base to match ground elevation. If you move the object or adjust its dimensions, you can use the quick access button 'Snap To Ground Elevation' to quickly adjust building elevation.

Import building8 and place it in the UAV Scenario Canvas. Try adjusting the position of the building by clicking and dragging the object marker in UAV Scenario Canvas.

In the Property Panel, set the height to 30 meters and set the color of the building to green.

Click Snap To Ground Elevation to place the modified building back onto the terrain. Add more buildings to the scene following this step.

Leverage Toolbar Controls to Navigate 3-D Scenario

The UAV Scenario View offers helpful controls to ease scenario design.

toolbarcontrols.png

  1. Hide Object Markers: Object markers are useful to quickly find an object in a large 3-D Scene but can cause clutter in a compact and dense urban scenario. Use this button to hide or reveal object markers.

  2. Visualization controls: Fine tune visualization such as pan/zoom/rotate.

  3. Zoom to Last Selected: Zooms onto the selected object/platform. You can change your selection by selecting the relevant object in the UAV Scenario Canvas or through the Scene Browser.

  4. Restore View: Restore default view of the scenario.

Click Hide Object Markers in both the UAV Scenario Canvas (2-D) and UAV Scenario View (3-D) view to remove markers. Click Zoom To Last Selected in 2-D and 3-D while placing objects or platforms onto scene to snap focus to a specific scenario object/platform.

Add UAV Platform to Scenario

Next add a UAV platform to the scene. This platform will serve as a foundation to validate the obstacle avoidance algorithm in later steps. Scroll within the overhead UAV Scenario Canvas to zoom into a location. Now select a Quadrotor from the Platform section in App toolstrip and place it into the Scenario Canvas. In the Property Panel, set the name of the platform to UAV. This makes it easier to identify the platform scenario element in the Simulink model later.

To ensure the UAV starts sufficiently away from obstacles, select the platform UAV and click Zoom to Last Selected in either the 2-D or 3-D view to zoom to the platform. Once focused on the UAV, zoom out slowly to gain a sense of the UAV's sorroundings.

The default Z position of the UAV is the terrain height at the selected X and Y position. Adjust its height interactively with the time-altitude plot. Click the Time-Altitude Button in the Trajectory tab. Drag the altitude line vertically to interactively change the height of the platform.

Add Lidar to Platform

Click Sensors > Lidar to add a lidar sensor to the platform so that it can sense the obstacles to avoid. Select the location of the lidar on the platform in the Sensor Canvas. Set the Update Rate of the sensor to 2 Hz. Set the sensor name to Lidar in the Property Panel.

Use the Y-Z and Z-X views to place the sensor on your UAV interactively. The first scene to validate the obstacle avoidance is ready.

Export Scenario Object to MATLAB

Export the scenario to the MATLAB workspace.

Navigate to the main toolstrip tab UAV Scenario and first set Update Rate of the scenario to 2 Hz. Click Export Scenario to open the Export Scenario to Workspace dialog box, and rename the scenario to scene. Click Export to export the UAV scenario to the workspace.

The uavScenario object named scene should now exist in MATLAB workspace.

Simulate Obstacle Avoidance Algorithm

Use the basic scenario, scene, to simulate an obstacle avoidance algorithm. Open the attached Simulink model customScenarioPipeline and configure this model to read the scenario parameters directly from the scenario object in workspace. Run initializeScenarioParams to read the scenario object and populate the workspace with parameters needed by the model. This model uses the obstacle avoidance algorithm provided in UAV Package Delivery. Observe that the UAV platform avoids the obstacles in the path by flying over them.

plantDataDictionary = Simulink.data.dictionary.open('customPackageDelivery.sldd');

%Use a predefined 'scene' designed by following previous steps provided by the example.
load BasicScenario

%Initialize Scenario Parameters for Simulink.
initializeScenarioParams;

%Open and simulate Obstacle-Avoidance Algorithm.
simModel='customScenarioPipeline.slx';
open_system(simModel);
sim(simModel);

The UAV platform successfully flies over the obstacles and arrives at the landing area succesfully. It may not always be possible to carry out such an altitude-gain manuever in a timely fashion to avoid obstacles. Customize the scenario in the next steps, to simulate other manuevers with the obstacle avoidance algorithm.

Customize Package Delivery Scenario

To evaluate algorithm robustness, modify the scenario by:

  • Increasing the height of buildings and building density

  • Adding more obstacles to your scenario

  • Adding moving actors to the scene.

By modifying the scenario in this way, the algorithm should fly around the buildings and should not react eratically to detected moving entities.

Move the buildings such that they are closer together as shown in the graphic below. Then adjust each building height to be 60 meters in the Property Panel. The height of the buildings changes from the base so click Snap To Ground Elevation to position the objects on terrain again.

closerPolygons.png

Click Scene Object > Cylinder to add a cylinders to the UAV Scenario Canvas. Add one cylinder at [-103 -73.4] and set Radius to 10 meters. Add another cylinder at [3 -29] and set Radius to 5 meters.

Add two quadrotors to the scene and assign trajectories such that they move towards the obstacling avoiding platform, UAV. The second platform is red by default, and the third platform is orange by default. From the Trajectory tab, add waypoints to the trajectory of the yellow quadrotor so that it circules around the cylinder at [-103 -73.4] as shown in the figure below. Design the red and yellow quadrotor trajectories to move in the general direction towards the blue platform using the figure below as reference. To enable the lidar to detect these moving actors , adjust their trajectories using the Time-Altitude plot to match the altitude of the blue ego platform.

The finished scene should look similar to the figure shown below. The static objects modified are highlighted. The red and yellow markers represent moving actors added to the scene.

Simulate Obstacle Avoidance in Customized Scenario

Simulate the efficiency of the algorithm over the customized scenario.

%Load predefined scenario developed in this example. 
load customizedScenario;
%Initialize Scenario Parameters for Simulink.
initializeScenarioParams;
%Open and simulate Obstacle-Avoidance Algorithm.
open_system(simModel);
sim(simModel);

The UAV platform successfully uses the obstacle avoidance algorithm to reach its destination. Further customize the scenario as needed by repeating the last step to fine-tune and simulate your obstacle avoidance algorithm.

discardChanges(plantDataDictionary);
close_system(simModel);