Smart delivery drone
Photo: Drone in flight / Hayden Soloviev · Wikimedia Commons · CC BY 4.0 (illustrative, not our aircraft)

Smart delivery drone

Shanghai University Students' Engineering Practice and Innovation Competition · delivery drone track

ResultGrand Prize (Shanghai) · 1st prize (university) Period2022.10 - 2022.12 My roleFlight control and mission flow · setpoint tuning

Repository ↗ Star

What the event actually was

The arena is 4 × 4 m, with the launch pad and three drop zones A, B and C in the corners. Zone A is a 500 mm target ring, scored by how far the payload lands from the centre; B and C carry different patterns that have to be recognised before releasing. A building stands between the start and zone A, and there are lamp posts on the B–C line — obstacles and pattern order are drawn on site, and the posts can shift by ±500 mm, precisely to defeat open-loop scripts that just follow a timer.

The payload is a cone with a spherical cap: 60 mm cap diameter, 50 mm base, 65 mm tall (70 mm limit). Compared with a cylinder it sits lower, tips less on landing and is less sensitive to rotor wash.

The flow is simple: load and secure → a single start command begins the clock → drop at A, B and C in order, one attempt each → B and C require crossing obstacles → after C, return and land to stop the clock.

Scoring details that shape the strategy: +5 per obstacle correctly crossed; +3 for returning inside the time limit; the payload must land upright or it does not count; a coefficient rewards autonomy; each team flies two rounds of five minutes, weighted 50% each with the best kept; a 20-second stop ends the round, and touching the safety net or an obstacle ends the run outright.

Arena and zones from the task statement: a 4000 × 4000 field, zone A as a 500 mm target ring, zones B and C identified by pattern, and a 600 × 600 launch pad at the bottom.
Arena and zones from the task statement: a 4000 × 4000 field, zone A as a 500 mm target ring, zones B and C identified by pattern, and a 600 × 600 launch pad at the bottom.

One stack in the air, one on the ground

The aircraft carries a PX4 flight controller and a Jetson Nano. The Nano does three jobs: MAVROS for talking to the flight controller, the RealSense T265 VIO pipeline (through vision_to_mavros into the EKF), and the downward CSI camera for pattern recognition. The ground station is a second Ubuntu machine running the mission program. The two talk over ROS networking, which means ROS_MASTER_URI, ROS_IP and /etc/hosts all have to agree before take-off — and when they do not, the symptom is “the aircraft flies but ignores commands”, which is why Chapter 1 of our operating manual is entirely about networking.

That is also how the work was split: flight control and mission flow, vision, and structure/release mechanism, four lines meeting in the same launch file.

Indoor test session: the mission node and status printouts on the ground station, the aircraft doing altitude and hover checks in an empty hall.
Indoor test session: the mission node and status printouts on the ground station, the aircraft doing altitude and hover checks in an empty hall.

One state machine, five actions

com_node is the mission program. Given a list of waypoints, it repeats the same block for each one:

for (int i = 0; i < num_fly + 1; i++) {
    fly_high(i, desire_z);   // from 0.3 m, step up to cruise altitude
    fly_to(i);               // approach the waypoint, arrived when all three axes are within 0.15 m
    landing();               // step down, landed when |vz| < 0.1 m/s and altitude < 0.1 m
    unload(i + 1);           // below 0.2 m: hold 3 s, send /servo, hold 2 s more
}

Four calls, but every one of them hides the same rule: setpoints have to be walked over, never jumped.

void add_target(int i) {
    for (int j = 0; j < 3; j++) {
        if (abs(next_point[j] - fly_point[i + 1][j]) > 0.3) {
            if (next_point[j] > fly_point[i + 1][j]) {
                next_point[j] -= change;
            } else {
                next_point[j] += change;
            }
        } else {
            next_point[j] = fly_point[i + 1][j];
        }
    }
}

With change between 0.02 and 0.05 m and the loop running at 20 Hz, the aircraft sees a smooth trajectory instead of a step input. Publishing the destination directly makes the controller fight the frame to catch up. This is the least glamorous line in the project and the one that decides whether the aircraft looks calm on video.

Three things only the field teaches

You have five seconds after arming to enter OFFBOARD. If PX4 does not receive external setpoints shortly after arming, it re-arms itself and the aircraft never leaves the ground. The on-site sequence was fixed accordingly: switch to OFFBOARD first, then arm — and never use AUTO.TAKEOFF.

send_info_node is a 20 Hz safety net. Whatever the mission is doing, if the aircraft is not yet in OFFBOARD or not armed, this node keeps publishing setpoints. Without it, the instant of switching modes manually is enough for the controller to decide it has no external command and drop out of the mode.

The landing target height is negative. landing() drives the setpoint z down to −0.5 m, below the floor. The aircraft cannot go there, so it keeps pushing down until speed and altitude fall under the thresholds. A hack, but a reliable one.

The release itself is even cruder: wait until altitude is below 0.2 m, hold position for 3 seconds so the airframe and payload settle, send one byte to the Arduino, then hold 2 seconds more so the aircraft does not climb away and drag the payload with it.

The release mechanism

The cargo bay is fully enclosed: four acrylic rods and two outer rings, heavily perforated to save weight. Each bay has its own servo whose arm presses the payload against the frame so it stays still in flight; on command the arm rotates, the payload drops vertically, and the bay keeps flying and can be reused.

CAD model of the cargo bay and servo release: one servo arm per bay holds the payload until the drop command arrives.
CAD model of the cargo bay and servo release: one servo arm per bay holds the payload until the drop command arrives.

The Nano-to-Arduino link is a single-byte serial protocol: 1 / 2 / 3 open the corresponding bay, 6 resets all of them, anything else is ignored, at 9600 baud. The device is pinned to /dev/arduino through a udev alias, otherwise every replug moves it between ttyACM0 and ttyACM1 — a reconfiguration you only want to do once.

The vision half

The downward camera runs at 960 × 540 and the detector is pure contour geometry, not template matching. The test is a single dimensionless ratio, perimeter² over area:

  • circle: perimeter² ÷ (4 × area) ≈ π, tolerance 0.4;
  • square: perimeter² ÷ area ≈ 16, tolerance 2.

Pre-processing is bilateral filtering → Canny(24, 144) → a 9 × 9 closing to bridge broken edges → a 3 × 3 opening to kill highlights, then findContours filtered by the test above. The centroid comes from the contour moments, the pixel offset (480 − x, 270 − y) is converted into metres with a pinhole model, and that offset nudges the drop point.

The advantage is weight: it runs on a Nano and needs no training. The disadvantage is recorded in the known issues below.

Results

First prize at the university qualifier (October 2022) and the Grand Prize at the municipal final (December 2022).

What decided the run was not how steadily the aircraft flew but how many of the three drops landed upright. The final version flew blind to the waypoint, applied one visual correction, then landed and settled before releasing — so the residual error came mostly from T265 drift rather than from recognition accuracy.

In the same semester we used the system as the group project of a French-taught project management course: Gantt chart, four decks on risk, resources, scheduling and communication, a survey, a promo video and a full set of weekly plans. Sharing one set of material between the technical and the PM project was the best value decision of that year.

Known issues

The archived code is left exactly as it ran; the problems are documented rather than fixed:

  • the vision test is single-frame with no multi-frame consistency check: one spurious contour that satisfies the test immediately sends its offset to the flight controller;
  • the focal lengths fx = 4.476, fy = 5.96 and the sensor size were calibrated for that one CSI camera — changing the camera requires recalibration;
  • desire_z (cruise altitude) takes five different values across the launch files — 0.5 / 1.0 / 1.4 / 2.0 / 5.0 m — and you must check which one is live before flying;
  • landing_quadrotor.cpp, take_off_test.cpp and fly.cpp are half-finished: they depend on a message type that does not exist, or do not compile. Do not roslaunch them.

Material

The rules, the task statement, the operating manual, the complete ROS workspace and 14 debugging recordings (seven of them public in the release) are in the repository:

https://github.com/yicongl1/Drone-Delivery-2022

The archive was reorganised into six levels — competition material, technical documents, code, recordings, project management course, miscellany — compressing 630 files and 4.7 GB down to 391 files and 4.5 GB. Git tracks only 312 files (about 295 MB); the recordings live in the release. Teammate names were replaced with neutral placeholders throughout.

Technical notes

01 Drone debugging: ROS networking between the Jetson Nano and the ground station From VMware bridging and ifconfig to bashrc/hosts, the full debugging sequence and field screenshots that bring the Nano and ground station onto the same ROS network. 02 Setpoints at 20 Hz: keeping PX4 where it thinks it should be Five OFFBOARD lessons — why setpoints must keep flowing, why they must not jump, and why the landing target height is negative. 03 Recognising a target ring by shape: the C²/(4A) ≈ π test Bilateral filtering, Canny, closing and opening, then one dimensionless ratio to pick out circles and squares — and why a single-frame test is dangerous on site. 04 17 tasks, 8 people, 5 weekly plans: project management behind the drone The other deliverable of that semester: WBS, Gantt and PERT, RACI, five weekly plans, a project dashboard, and 211 survey responses that shaped the product positioning.

Certificates

11th Shanghai University Engineering Training Competition · 1st prize (Oct 2022)
11th Shanghai University Engineering Training Competition · 1st prize (Oct 2022)
12th Shanghai Engineering Practice and Innovation Competition · Grand Prize, delivery drone track (Dec 2022)
12th Shanghai Engineering Practice and Innovation Competition · Grand Prize, delivery drone track (Dec 2022)

Related skills

  • ROS
  • OpenCV
  • C++
  • Project management