City Operations guide

A full shift over a working city block.

The graduation course. Sensors, camera and route planning at once, over a block with traffic, trees and a wash tunnel in it, and missions that grade several of those at the same time.

What you will learn

  • Sweep a street and log every contact the scanner returns.
  • Find a labelled target and photograph it from the right place.
  • Line up on a tunnel and fly it straight through.
  • Compose a long mission out of small, separately-testable functions.

Commands

Flight

await drone.moveTo(x, y, z)
Fly to an absolute point in the world, in one straight line.
await drone.moveForward(distance)
Fly `distance` meters along the drone's current heading, holding altitude.
await drone.turn(degrees)
Yaw in place, without moving.
drone.setSpeed(speed)
Set the cruise speed used by every move that follows.
await drone.setAltitude(altitude)
Climb or descend to an absolute height, holding position over the ground.
await drone.hover(seconds)
Hold station for a fixed time.
await drone.takeoff(altitude?)
Spool the motors and climb straight up from the pad.
await drone.land()
Descend straight down from wherever the drone currently is and settle on its landing gear.

Sensors

await drone.scan(range?)
Sweep the object-detection suite and list everything around the drone.
await drone.getPosition()
Where the drone is now, in world coordinates.

Camera

await drone.takePhoto(label?)
Hold steady for a beat and capture a frame from the drone camera.

Worked examples

Sweeping a street and logging it

A sweep is a lawnmower pattern with a scan at each pass. Collecting contacts into a Map keyed by label is what stops the same parked van being counted once per pass.

async function main(drone) {
    await drone.takeoff(6);
    drone.setSpeed(5);

    const found = new Map();

    for (let lane = 0; lane < 4; lane++) {
        await drone.moveTo(lane * 6, 6, -10);
        await drone.moveTo(lane * 6, 6, -28);

        for (const contact of await drone.scan(20)) {
            const key = contact.label ?? `${contact.kind}@${contact.x},${contact.z}`;

            if (!found.has(key)) {
                found.set(key, contact);
                console.log('new contact:', contact.kind, key);
            }
        }
    }

    console.log('swept', found.size, 'objects');
    await drone.land();
}

Photographing a named target

Photo objectives are graded on where the drone was standing when the shutter fired, so the job is to get to a sensible stand-off and point the nose at the subject. The 0.4 s stabilise happens inside `takePhoto()`. It does not need a hover before it.

async function main(drone) {
    await drone.takeoff(8);

    const contacts = await drone.scan(35);
    const subject = contacts.find((c) => c.label === 'clock-tower');

    if (!subject) {
        console.warn('clock-tower not in range');
        await drone.land();
        return;
    }

    // Stand off far enough to get the whole thing in frame.
    drone.setSpeed(3);
    await drone.turn(subject.bearingDeg);
    await drone.moveForward(subject.distance - 10);

    // Re-aim from the new position: the bearing changed on the way in.
    const closer = await drone.scan(20);
    const reacquired = closer.find((c) => c.label === 'clock-tower');

    if (reacquired) {
        await drone.turn(reacquired.bearingDeg);
    }

    await drone.takePhoto('clock-tower, north face');

    await drone.land();
}

Flying the wash tunnel

A tunnel is graded at both mouths, so it only counts if the drone goes in one end and out the other. Approaching on the tunnel's own axis, at the height scan gives for it (halfway up its walls and roof, a little above the middle of the opening) and committing to a single straight leg is what keeps it from clipping a wall halfway through.

async function main(drone) {
    await drone.takeoff(4);

    const [wash] = (await drone.scan(40)).filter((c) => c.kind === 'carwash');

    if (!wash) {
        console.warn('no wash tunnel in range');
        await drone.land();
        return;
    }

    // Line up well short of the mouth, on the tunnel's centreline.
    drone.setSpeed(2);
    await drone.moveTo(wash.x, wash.y, wash.z + 10);

    // Re-acquire from the new position and square up on it.
    const aligned = (await drone.scan(40)).find((c) => c.kind === 'carwash');

    if (aligned) {
        await drone.turn(aligned.bearingDeg);
    }

    await drone.hover(1);

    // One straight run, long enough to clear the far mouth.
    await drone.moveForward(20);

    await drone.land();
}

A shift, in pieces

A combined mission is long enough that debugging it as one block is painful. Splitting it into named phases lets you comment out three of them and fly the fourth until it works. That is how these get finished.

async function main(drone) {
    const CRUISE = 10;

    async function launch() {
        await drone.takeoff(CRUISE);
        drone.setSpeed(6);
    }

    async function survey() {
        for (const z of [-10, -20, -30]) {
            await drone.moveTo(0, CRUISE, z);
            await drone.takePhoto(`survey z=${z}`);
        }
    }

    async function inspect() {
        const contacts = await drone.scan(30);
        console.log('contacts on station:', contacts.length);
    }

    async function recover() {
        await drone.moveTo(0, CRUISE, 0);
        await drone.land();
    }

    await launch();
    await survey();
    await inspect();
    await recover();
}

Common mistakes

The bearing goes stale as you fly
`bearingDeg` is measured from where the drone was when it scanned. On a long approach, scan again near the target and re-aim.
Photos are graded on position, not on framing
A photo target checks where the drone was standing. Being close and pointed the wrong way still fails it, and so does a beautiful shot taken from outside the radius.
Scanning sees through walls
The scanner is geometric and reports everything within range regardless of what is between you and it. Something in the contact list is not necessarily something you can fly to in a straight line.

Fly the City Operations missions