These missions are not harder to plan. They are harder to fly. The margin for error is small enough that speed, settling time and the difference between absolute and relative altitude all start to matter.
Commands
Flight
await drone.setAltitude(altitude)
- Climb or descend to an absolute height, holding position over the ground.
drone.setSpeed(speed)
- Set the cruise speed used by every move that follows.
await drone.hover(seconds)
- Hold station for a fixed time.
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.
await drone.land()
- Descend straight down from wherever the drone currently is and settle on its landing gear.
Sensors
await drone.getAltitude()
- Current height above the field.
await drone.getPosition()
- Where the drone is now, in world coordinates.
Worked examples
Stepping up in fixed increments
`setAltitude()` is absolute, so a relative step means reading the current height and adding to it. Computing each rung from the base rather than from the last reading keeps a small hover drift from accumulating up the ladder.
async function main(drone) {
await drone.takeoff(2);
const base = await drone.getAltitude();
for (let step = 1; step <= 4; step++) {
await drone.setAltitude(base + step * 2);
// Let it settle before anything is measured at this rung.
await drone.hover(1);
console.log('rung', step, 'at', await drone.getAltitude());
}
await drone.land();
}
Slowing down for the tight part
Cruise speed is a setting, not an argument. It applies to every move that follows until it is changed. Cruising between the open stretches and slowing for the gates is usually faster overall than flying the whole route carefully.
async function main(drone) {
await drone.takeoff(3);
// Open ground: get it over with.
drone.setSpeed(8);
await drone.moveTo(10, 3, -10);
// Tight ground: buy accuracy with time.
drone.setSpeed(2);
await drone.moveTo(12, 2.4, -16);
await drone.moveTo(14, 2.4, -22);
await drone.land();
}
A slalom from a list of offsets
A weaving line is a straight run down one axis with an alternating offset on the other. Written this way the shape lives in two numbers, and widening the weave is a one-character edit.
async function main(drone) {
await drone.takeoff(3);
drone.setSpeed(4);
const gates = 6;
const spacing = 5; // meters between gates
const weave = 2.5; // how far off the centreline each way
for (let i = 0; i < gates; i++) {
const offset = i % 2 === 0 ? weave : -weave;
await drone.moveTo(offset, 3, -(i + 1) * spacing);
}
await drone.land();
}
Landing on a mark
Because `land()` drops straight down, a pinpoint landing is really a pinpoint hover: get the horizontal position right, let it stop moving, and only then descend.
async function main(drone) {
await drone.takeoff(4);
const pad = { x: 12, z: -18 };
// Arrive high and slow, directly over the pad.
drone.setSpeed(2);
await drone.moveTo(pad.x, 4, pad.z);
// Kill the drift before committing to the descent.
await drone.hover(1.5);
const here = await drone.getPosition();
console.log('offset', (here.x - pad.x).toFixed(2), (here.z - pad.z).toFixed(2));
await drone.land();
}