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, launch the project from the command line.

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 the data folder (uavPackageDeliveryDataDict.sldd). Additionally, the model uses Variant Subsystems (Simulink) to manage different configurations of the model. Variables placed in the base workspace configure these variants without the need to modifiy the data dictionary.

Following Example Steps

Use the Project Shortcuts to step through the example. Each shortcut sets up the required variables for the project.

1. Getting Started

Click the Getting Started project shortcut, which sets up the model for a four-waypoint mission using a low-fidelity multirotor plant model. Run the uavPackageDelivery model, which shows the multirotor takeoff, fly, and land in a 3-D plot.

The model uses UAV Path Manager block to determine which waypoint is active throughout the flight. The active waypoint is passed into the Guidance Mode Selector Stateflow™ 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 install QGroundControl Ground Control Station software.

The model uses the UAV Toolbox™ mavlinkio to establish a connection between Simulink and QGroundControl. The connection is implemented as a MATLAB System Block located in uavPackageDelivery/Ground Control Station/Get Flight Mission/QGC/MAVLink Interface.

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

  1. Click the Connecting to a GCS project shortcut.

  2. Launch QGroundControl.

  3. In QGroundControl, load the mission plan named shortMission.plan located in /utilities/qgc.

  4. Run the 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 the uavScenario object. 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 a uavLidarPointCloudGenerator object added to the UAV scenario with a uavSensor object. The lidar sensor model generates readings based on the pose of the sensor and the obstacles in the environment.

Click the Setting a Cuboid Scenario shortcut and Run the model. As the model runs, a lidar point cloud image is displayed as the aircraft flies through the cuboid environment:

4. Obstacle Avoidance

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 Obstacle Avoidance shortcut. A scope appears that shows the closest point to a buidling in the cuboid environment.

Run the model. As the model runs, the aircraft attempts to fly in a straight path between buildings to a drop site and avoids obstacles along the way. Notice the change in distance to obstacles over time.

5. Photorealistic Simulation

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

Run the 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 the Fly full mission shortcut, which sets up the connectivity to QGroundControl 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 named shortMission.plan located in /utilities/qgc.

  3. Run the 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 the Fly full Obstacle Avoidance shortcut and follow these steps to run the simulation:

  1. Launch QGroundControl.

  2. In QGroundControl, load the mission plan named oaMission.plan located in /utilities/qgc.

  3. Run the 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.

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 High Fidelity Simulation

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

Run the 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);