← MPI Scholar Academy

Fly a Drone with Python Code

Watch the drone fly a program, then write that program yourself from a blank page. This is real Python — a real library, imported the ordinary way, running in your browser.

Mission

—

1 WatchSee the program and what each line does to the drone.
2 Your turnBlank page. Write it yourself and fly the same mission.
← Academy
The program

        
1 Next line

Starting Python...
Flight deck
Waiting
Drag to turn · right-drag or shift-drag to pan · scroll to zoom
POWER off X 0 Y 0 HEIGHT 0 FACING N BATTERY — WATER 0 CARGO empty
The library — mpi.drone

Every program starts the same way. You import the class, then you build a drone from it. Drone is a class; drone is the one you made.

from mpi.drone import Drone

drone = Drone()
drone.power_on()
drone.takeoff()
drone.forward(3)
drone.land()
drone.shutdown()
Power drone.power_on() — boot it up; nothing works before this drone.shutdown() — switch off, on the ground drone.charge() — refill the battery on a green pad Flying drone.takeoff() / drone.land() drone.forward(n) / drone.back(n) drone.left(n) / drone.right(n) drone.up(n) / drone.down(n) drone.turn_left(90) / drone.turn_right(90) Working drone.pickup() / drone.release() drone.fill() — draw water from the pond drone.spray() — dump water below drone.water() — water the garden below drone.pick() — take the fruit from a grown bed Going somewhere drone.fly_to(x, y) — across, then along PLACES["pond"] — the map of named squares drone.fly_to(*PLACES["pond"]) Asking drone.scan() → "open" or "blocked" drone.fire_here() → True / False drone.garden_here() → a dry bed below drone.fruit_here() → fruit ready to pick drone.gardens_left() → beds still dry drone.water_left() → loads left drone.energy_left() → battery left drone.carrying() → True / False drone.position() → (x, y, height) print(drone) — the drone describes itself