Main Content

UAV Package Delivery

This example shows through incremental design iterations how to implement a small multicopter simulation to takeoff, fly, and land at a different location in a city environment.

Open the Project

To get started, open the example live script and access the supporting files by either clickingOpen Live Scriptin the documentation or using theopenExamplefunction.

openExample('uav/UAVPackageDeliveryExample');

Then, open the Simulink™ project file.

prj = openProject('uavPackageDelivery.prj');

Model Architecture and Conventions

The top model consists of the following subsystems and model references:

  1. Ground Control Station:Used to control and monitor the aircraft while in-flight.

  2. External Sensors - Lidar & Camera:Used to connect to previously-designed scenario or a Photorealistic simulation environment. These produce Lidar readings from the environment as the aircraft flies through it.

  3. On Board Computer:Used to implement algorithms meant to run in an on-board computer independent from the Autopilot.

  4. Multirotor:Includes a low-fidelity and mid-fidelity multicopter mode, a flight controller including its guidance logic.

The model's design data is contained in a Simulink™ data dictionary in thedatafolder (uavPackageDeliveryDataDict.sldd). Additionally, the model usesVariant Subsystems(Simulink)to manage different configurations of the model. Variables placed in the base workspace configure these variants without the need to modify the data dictionary.

Following Example Steps

Use theProject Shortcutsto step through the example. Each shortcut sets up the required variables for the project.

1. Getting Started

Click the通用电气tting Startedproject shortcut, which sets up the model for a four-waypoint mission using a low-fidelity multirotor plant model.RuntheuavPackageDeliverymodel, which shows the multirotor takeoff, fly, and land in a 3-D plot.

The model usesUAV Path Managerblock to determine which is the active waypoint throughout the flight. The active waypoint is passed into theGuidance Mode SelectorStateflow™ chart to generate the necessary inner loop control commands.

2. Connecting to a GCS

Once you are able to fly a basic mission, you are ready to integrate your simulation with a Ground Station Software so you can better control the aircraft's mission. For this, you need to download and installQGroundControlGround Control Station software.

The model uses the UAV Toolbox™mavlinkioto establish a connection between Simulink and QGroundControl. The connection is implemented as a MATLAB® System Block located inuavPackageDelivery /地面控制站/ Flight Mission/QGC/MAVLink Interface.

To test the connectivity between Simulink and QGroundControl follow these steps:

  1. Click theConnecting to a GCSproject shortcut.

  2. Launch QGroundControl.

  3. In QGroundControl, load the mission plan namedshortMission.planlocated in/utilities/qgc.

  4. Runthe simulation.

  5. When QGroundControl indicates that it is connected to the system, upload the mission.

Once the aircraft takes off, you should see the UAV fly its mission as sent by QGC as shown below.

You can modify the mission by adding waypoints or moving those that are already in the mission. Upload the mission and the aircraft should respond to these changes.

3. Setting a Cuboid Scenario

Now that aircraft's model can be flow from a ground control station, consider the environment the aircraft flies in. For this example, a few city blocks are modelled in a cuboid scenario using theuavScenarioobject.The scenario is based on the city block shown in the left figure below.

To safely fly the aircraft in this type of scenario, you need a sensor that provides information about the environment such as a lidar sensor to the model. This example uses auavLidarPointCloudGeneratorobject added to the UAV scenario with auavSensorobject. The lidar sensor model generates readings based on the pose of the sensor and the obstacles in the environment.

Click the设置一个长方体的场景shortcut andRunthe model. As the model runs, a lidar point cloud image is displayed as the aircraft flies through the cuboid environment:

4.避障

To avoid obstacles in the environment, the model must use the available sensor data as the UAV flies the mission in the environment. To modify the model configuration, click the避障or3D Obstacle Avoidanceshortcut. A scope appears that shows the closest point to a buildling in the cuboid environment.避障shortcut configures the model to use planar lidar information andVector Field Histogram(Navigation Toolbox)to avoid obstacles by changing UAV's direction in its current x-y plane.3D Obstacle Avoidanceshortcut configures the model to use 3D lidar points and避障to avoid obstacles by changing UAV's direction in 3D space.

Runthe model. In避障mode, as the model runs, the aircraft attempts to fly in a straight path between buildings to a drop site but deviates to avoid obstacles along the way. Observe the change in distance to obstacles over time and observe a similar behavior in3D Obstacle Avoidancemode, with the UAV now also able to adjust altitude to fly over obstacles.

5. Photorealistic Simulation

Up to this point, the environment has been a simple cuboid scenario. To increase the fidelity of the environment, click thePhotorealistic Simulationshortcut, which places the aircraft in a more realistic world to fly through. The PhotorealisticQuadrotor variant located atuavPackageDelivery/photorealisticSimulationEngi/SimulationEnvironmentVariantbecomes active. This variant contains the necessary blocks to configure the simulation environment and the sensors mounted on the aircraft:

Runthe model. The aircraft is set up to fly the same mission from steps 1 and 2. Notice as the aircraft flies the mission the lidar point clouds update and an image from the front-facing camera is shown.

6. Fly Full Mission in a Photorealistic Simulation Environment

Next, click theFly full mission设置连接到QGroun快捷方式dControl from step 2 for uploading the mission inside the photorealistic environment. Follow these steps to run the simulation:

  1. Launch QGroundControl.

  2. In QGroundControl, load the mission plan namedshortMission.planlocated in/utilities/qgc.

  3. Runthe Simulation.

  4. When QGroundControl indicates that it is connected to a system, upload the mission.

As the aircraft starts to fly, you can modify the mission in QGroundControl by adding waypoints or moving those that are already in the mission. Upload the mission and the aircraft should respond to these changes. Throughout the flight you'll see the aircraft flying in the scenario.

7. Flying Obstacle Avoidance in a Photorealistic Simulation Environment

Next, the goal is to fly a mission by specifying a takeoff and landing point in QGroundControl and using the obstacle avoidance to navigate around the obstacles along the path. Click theFly full Obstacle AvoidanceorFly full 3D Obstacle Avoidanceshortcut and follow these steps to run the simulation:

  1. Launch QGroundControl.

  2. In QGroundControl, load the mission plan namedoaMission.planlocated in/utilities/qgc.

  3. Runthe Simulation.

  4. When QGroundControl indicates that it is connected to a system, upload the mission.

Throughout the flight, watch the aircraft try to follow the commanded path in QGroundControl, while at the same time attempting to avoid colliding with the buildings in the environment. IfFly full 3D Obstacle Avoidanceis used, you can observe that UAV flies over the lower buildings rather than around it.

At some point during the flight, you will see the UAV pass through a narrow pass between two buildings.

8. Adding a 6DOF Plant Model for Higher-Fidelity Simulation

As a final step, click theAdding a High Fidelity Plantshortcut, which activates the high-fidelity variant of the UAV model located atuavPackageDelivery/MultirotorModel/Inner Loop and Plant Model/High-FidelityModel. This variant contains an inner-loop controller and a high-fidelity plant model.

Runthe model. There are minor changes in behavior due to the high-fidelity model, but the UAV flies the same mission.

When you are done exploring the models, close the project file.

close(prj);