Drone Function Documentation
version 2.3 (Changelog)
Connection
pair()
Description
This function connects your controller with the program. You can also set the specific USB port name.
Syntax
pair()
pair(portname)
Parameters
string portname: A string containing the port name or number.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair() # pair automatically, may not always work
# drone.pair(port_name = 'COM3') # pair with a specific port
drone.takeoff()
drone.hover(1)
drone.land()
drone.close()
close()
Description
This function closes the connection of your controller with the program.
Syntax
close()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.hover(1)
drone.land()
drone.close() # closes connection between controller and program
Flight Commands
takeoff()
Description
This function makes the drone takeoff at an average height of 80 centimeters and hover. The drone will always hover for 1 second in order to stabilize before it executes the next command. NOTE: The takeoff parameters or height cannot be modified.
Syntax
takeoff()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.hover(3)
drone.land()
drone.close()
land()
Description
This function makes the drone stop all commands, hover, and make a soft landing where it is. The function will also reset the flight motion variables to 0. NOTE: If you want to take off and immediately land, it is recommended to run a hover()
or time.sleep()
in between the takeoff()
and land()
, because the CoDrone EDU may miss the land command otherwise.
Syntax
land()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.hover(3) # include a hover() or time.sleep() to prevent land() from skipping
drone.land()
drone.close()
emergency_stop()
Description
This function immediately stops all commands and motors, so the drone will stop flying immediately. The function will also reset the flight motion variables to 0. NOTE: If you want to take off and emergency stop, it is recommended to run a hover()
or time.sleep()
in between the takeoff()
and emergency_stop()
, because the CoDrone EDU might miss the emergency_stop() command.
Syntax
emergency_stop()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.hover(3) #Recommended to have a hover() or time.sleep(1) before landing
drone.emergency_stop()
drone.close()
hover()
Description
This function makes the drone hover for a given amount of time. If given no parameters, it will hover indefinitely until given a another command.
Syntax
hover(duration)
Parameters
integer duration: Duration of the hovering in seconds
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.hover(3)
drone.land()
drone.close()
go()
Description
A beginner-friendly function that allows the drone to move the drone at a given direction, power, and duration.
Syntax
go(direction, power=50, duration=1)
Parameters
string direction: The direction of the movement
int power: The power at which the drone flies (0-100). Defaults to 50% if not defined.
float duration: The duration of the movement. Defaults to 1 second if not defined.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.go("forward", 30, 1) # move forward at 30% power for 1 second
drone.go("backward", 30, 1) # move backward at 30% power for 1 second
drone.go("right", 30, 1) # move right at 30% power for 1 second
drone.go("left", 30, 1) # move left at 30% power for 1 second
drone.land()
drone.close()
avoid_wall()
Description
A looped method that makes the drone fly forward until it reaches a desired distance based on the front range sensor. The range of front sensor is from 0cm-100cm
Syntax
avoid_wall()
avoid_wall(timeout)
avoid_wall(distance)
avoid_wall(timeout, distance)
Parameters
integer timeout: timeout is an optional parameter that is the duration in seconds that the function will run. the default value is 2
integer distance: distance is an optional parameter that is the distance in centimeters the drone will stop at in front of an object. the default value is 70
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# fly forward until a wall is found 50 cm away. run this loop for 10 seconds.
drone.avoid_wall(10, 50)
drone.land()
drone.close()
keep_distance()
Description
A looped method that makes the drone fly forward until it reaches a desired distance. Once the desired distance in reached the drone will maintain that distance. The sensor range is up to 150 cm.
Syntax
keep_distance()
keep_distance(timeout)
keep_distance(distance)
keep_distance(timeout, distance)
Parameters
integer timeout: the duration in seconds that the function will execute. The default value is 2 seconds.
integer distance: the distance in centimeters the drone will stop and maintain distance in front of an object. The default value is 50 centimeters.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# maintain a distance of 60cm from an object once detected for 10 seconds
drone.keep_distance(10, 60)
drone.land()
drone.close()
get_trim()
Description
This function gets the current trim values of the drone.
Syntax
get_trim()
Parameters
None
Returns
list trim data: A list of trim data — [0] for roll trim and [1] for pitch trim
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
# print the trim values
trim = drone.get_trim()
print(trim)
print(trim[0])
print(trim[1])
drone.close()
reset_trim()
Description
You can reset the roll and pitch trim of the drone in case your drone is drifting. This function will reset the roll and pitch trim values back to zero.
Syntax
reset_trim()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.set_trim(5,0)
print(drone.get_trim())
drone.takeoff()
drone.hover(3)
drone.land()
drone.reset_trim()
print(drone.get_trim())
drone.close()
set_trim()
Description
You can set the roll and pitch trim of the drone in case your drone is drifting. For example, if the drone is drifting to its right, you may want to set the roll to a small negative value. This trim will remain saved, even after powering off until you've changed the trim either programmatically, or done a reset with the remote. NOTE: If you're setting the trim right before a takeoff, make sure to add a time.sleep(1)
before the takeoff()
, otherwise the takeoff commmand might be skipped.
Syntax
set_trim(roll, pitch)
Parameters
integer roll: the power of the roll (-100 - 100)
integer pitch: the power of the pitch (-100 - 100)
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.set_trim(-5, 0) # example: drone is drifting right, so trim to roll left a little bit
time.sleep(1) # Add a time.sleep(1) before takeoff if you're planning to set the trim before takeoff
drone.takeoff()
drone.hover(3)
drone.land()
drone.close()
move_forward()
Description
Moves the drone forward for a given distance. For the best performance, please make sure your drone is flying over a well-lit, patterned surface.
Syntax
move_forward(distance)
move_forward(distance, unit, speed)
Parameters
float distance: the distance to travel.
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
float speed: The drone's speed, in meters per second. The default speed is 1.0 meter per second. Max is 2.0 meters per second.
Returns
None
Example Code
The drone will take off, move forward 50cm at 1m/s, and land.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_forward(distance=50, units="cm", speed=1)
drone.land()
drone.close()
move_backward()
Description
Moves the drone backward for a given distance. For the best performance, please make sure your drone is flying over a well-lit, patterned surface.
Syntax
move_backward(distance)
move_backward(distance, unit, speed)
Parameters
float distance: the distance to travel.
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
float speed: The drone's speed, in meters per second. The default speed is 1.0 meter per second. Max is 2.0 meters per second.
Returns
None
Example Code
The drone will take off, move backward 50cm at 1m/s, and land.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_backward(distance=50, units="cm", speed=1)
drone.land()
drone.close()
move_left()
Description
Moves the drone left for a given distance. For the best performance, please make sure your drone is flying over a well-lit, patterned surface.
Syntax
move_left(distance)
move_left(distance, unit, speed)
Parameters
float distance: the distance to travel.
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
float speed: The drone's speed, in meters per second. The default speed is 1.0 meter per second. Max is 2.0 meters per second.
Returns
None
Example Code
The drone will take off, move left 50cm at 1m/s, and land.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_left(distance=50, units="cm", speed=1)
drone.land()
drone.close()
move_right()
Description
Moves the drone right for a given distance. For the best performance, please make sure your drone is flying over a well-lit, patterned surface.
Syntax
move_right(distance)
move_right(distance, unit, speed)
Parameters
float distance: the distance to travel.
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
float speed: The drone's speed, in meters per second. The default speed is 1.0 meter per second. Max is 2.0 meters per second.
Returns
None
Example Code
The drone will take off, move right 50cm at 1m/s, and land.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_right(distance=50, units="cm", speed=1)
drone.land()
drone.close()
move_distance()
Description
Moves the drone by the specified distances along the x, y, and z axes, relative to its current position and heading. If two or more distances have non-zero values, the function will move the drone by these distances simultaneously. For the best performance, please make sure your drone is flying over a well-lit, patterned surface.

Syntax
move_distance(positionX, positionY, positionZ, velocity)
Parameters
float positionX: The distance to travel in the x-direction, in meters. This corresponds to forward/backward movement.
float positionY: The distance to travel in the y-direction, in meters. This corresponds to left/right movement.
float positionZ: The distance to travel in the z-direction, in meters. This corresponds to vertical movement.
float velocity: The drone's velocity, in meters per second. The default velocity is 1.0 meter per second. Max is 2.0 meters per second.
Returns
None
Example Code 1
The drone will take off, simultaneously move forward 0.5m, left 0.5m, and upward 0.25m at 1m/s (relative to its current position and heading), move back 0.75cm at 0.75m/s (relative to its current position and heading), and land.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_distance(0.5, 0.5, 0.25, 1) # move forward 0.5m, left 0.5m, and upward 0.25m simultaneously at 1m/s
drone.move_distance(-0.75, 0, 0, 0.75) # move back 0.75m at 0.75m/s
drone.land()
drone.close()
Example Code 2
The drone will take off, move upward 0.50m at 0.50m/s, move right 0.50m at 0.50m/s, move downward 0.50m at 0.50m/s, move left 0.50m at 0.50m/s, and land.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_distance(0, 0, 0.5, 0.50) # move up 0.50m at 0.50m/s
drone.move_distance(0, -0.5, 0, 0.50) # move right 0.50m at 0.50m/s
drone.move_distance(0, 0, -0.5, 0.50) # move down 0.50m at 0.50m/s
drone.move_distance(0, 0.5, 0, 0.50) # move left 0.50m at 0.50m/s
drone.land()
drone.close()
send_absolute_position()
Description
Sends a movement command to the drone based on its absolute position from its first takeoff location. For the best performance, please make sure your drone is flying over a well-lit, patterned surface.


Syntax
send_absolute_position(positionX, positionY, positionZ, velocity, heading, rotationalVelocity)
Parameters
float positionX: The X position of the drone (-10m ~ 10m).
float positionY: The Y position of the drone (-10m ~ 10m).
float positionZ: The Z position of the drone (0m ~ 1.5m).
float velocity: The velocity of the drone in meters per second (0.5 ~ 2). The movement speed of the drone.
integer heading: Heading value in degrees. The heading is the z-angle of the drone.
integer rotationalVelocity: The rotational velocity of the drone in degrees per second (0 - 360). Left and right rotation speed of the drone.
Returns
None
Example Code 1
The drone takes off, moves to (0.5m, 0, 1m) at 0.5m/s, hovers at (0.5m, 0, 1m) since the drone is already in that position, and then lands.
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# Sending the drone forward from its takeoff location 0.5 meters moving at 0.5 m/s
drone.send_absolute_position(0.5, 0, 1, 0.5, 0, 0)
# Sending the same command will cause the drone to hover around
# the same area since this command uses absolute positioning from the takeoff location
drone.send_absolute_position(0.5, 0, 1, 0.5, 0, 0)
drone.land()
drone.close()