Function Documentation
version 2.1 (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()
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()
Function Under Development
This function is currently in a development phase. We’re working to improve its stability and performance as we continue to develop more features for CoDrone EDU.
Description
Moves the drone forward for the given distance and unit for that distance.
Syntax
move_forward(distance)
move_forward(distance, unit, speed)
Parameters
integer distance: the numerical value of the value to move
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
integer speed: default 1 meter per second. Max is 2 meters/second
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_forward(distance=50, units="cm", speed=1)
time.sleep(3) # make sure to add a delay so the drone has enough time to fly
drone.land()
drone.close()
move_backward()
Function Under Development
This function is currently in a development phase. We’re working to improve its stability and performance as we continue to develop more features for CoDrone EDU.
Description
Moves the drone backward for the given distance and unit for that distance.
Syntax
move_backward(distance)
move_backward(distance, unit, speed)
Parameters
integer distance: the numerical value of the value to move
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
integer speed: default 1 meter per second. Max is 2 meters/second
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_backward(distance=50, units="cm", speed=1)
time.sleep(3) # make sure to add a delay so the drone has enough time to fly
drone.land()
drone.close()
move_left()
Function Under Development
This function is currently in a development phase. We’re working to improve its stability and performance as we continue to develop more features for CoDrone EDU.
Description
Moves the drone left for the given distance and unit for that distance.
Syntax
move_left(distance)
move_left(distance, unit, speed)
Parameters
integer distance: the numerical value of the value to move
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
integer speed: default 1 meter per second. Max is 2 meters/second
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_left(distance=50, units="cm", speed=1)
time.sleep(3) # make sure to add a delay so the drone has enough time to fly
drone.land()
drone.close()
move_right()
Function Under Development
This function is currently in a development phase. We’re working to improve its stability and performance as we continue to develop more features for CoDrone EDU.
Description
Moves the drone right for the given distance and unit for that distance.
Syntax
move_right(distance)
move_right(distance, unit, speed)
Parameters
integer distance: the numerical value of the value to move
string unit: The unit of measurement for the distance flown. Available units are "cm" (centimeter), "ft" (feet), "in" (inches), "m" (meter).
integer speed: default 1 meter per second. Max is 2 meters/second
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
drone.takeoff()
drone.move_right(distance=50, units="cm", speed=1)
time.sleep(3) # make sure to add a delay so the drone has enough time to fly
drone.land()
drone.close()
send_absolute_position()
Function Under Development
This function is currently in a development phase. We’re working to improve its stability and performance as we continue to develop more features for CoDrone EDU.
Description
Sends a movement command to the drone based on its absolute position from its takeoff location. Note: A sleep command for the length of the movement may be needed after using this movement command.
The 'x' position of the drone is forwards and reverse.
The 'y' position of the drone is left and right.
The 'z' position of the drone is up and down.
Syntax
send_absolute_position(positionX, positionY, positionZ, velocity, heading, rotationalVelocity)
Parameters
float positionX: The X position of the drone (-10 ~ 10). Forward is positive. Backwards is negative.
float positionY: The Y position of the drone (-10 ~ 10). Left is positive. Right is negative.
float positionZ: The Z position of the drone (-10 ~ 10). Up is positive. Down is negative.
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 (-360 - 360). Positive turns the drone left. Negative turns the drone right.
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
#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)
time.sleep(1) # Sleep command needed in order for this movement to execute.
# 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)
time.sleep(1)
drone.land()
drone.close()
turn()
Description
This function turns the drone to the left or right, based on the given power value (-100 - 100), for a given number of seconds.
Syntax
turn()
turn(power=50, seconds=None)
Parameters
int power: The number represents the direction and power of the turn. Negative power turns the drone to the right, and positive power turns the drone to the left.
float seconds: The duration of the turn
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.turn(50, 2) # drone will turn left at 50% power for 2 seconds
drone.turn(-20,5) # drone will turn right 20% power for 5 seconds
drone.land()
drone.close()
turn_degree()
Description
Turns right or left with absolute reference frame to drone's initial heading. Positive degrees turn to the left and negative degrees turn to the right.
Syntax
turn_degree(degree, timeout, p_value)
Parameters
integer degree: angle of turn in degrees (-180 - 180)
integer timeout: optional parameter that is duration in seconds that drone will try to turn. default value is 3.
integer p_value: optional parameter that is the gain of the proportional controller, if this increased CDE will turn quicker, the smaller the slower. default value is 10.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.turn_degree(90) # drone will turn left 90 degrees
drone.land()
drone.close()
turn_left()
Description
Turns the drone left using the built in gyroscope. The default degree is 90.
Syntax
turn_left()
turn_left(degree)
turn_left(timeout)
turn_left(degree, timeout)
Parameters
integer degree: optional parameter that turns the drone in the given degree. default value is 90.
integer timeout: optional parameter that is duration in seconds that drone will try to turn. default value is 3.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.turn_left() # make a 90 degree left turn.
drone.hover(1) # wait for 1 second in the air
drone.turn_left(30, 3) # make a 30 degree left turn with a 3 second timeout.
drone.land()
drone.close()
turn_right()
Description
Turns the drone right using the built in gyroscope. The default degree is 90.
Syntax
turn_right()
turn_right(degree)
turn_right(timeout)
turn_right(degree, timeout)
Parameters
integer degree: optional parameter that turns the drone in the given degree. default value is 90.
integer timeout: optional parameter that is duration in seconds that drone will try to turn. default value is 3.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.turn_right() # make a 90 degree right turn.
drone.hover(1) # wait for 1 second in the air
drone.turn_right(30, 3) # make a 30 degree right turn with a 3 second timeout.
drone.land()
drone.close()
Flight Sequences
circle()
Description
Flies the drone in the shape of a circle.
Syntax
circle()
circle(speed, direction)
Parameters
integer speed: optional parameter that is the speed the drone will move (0 - 100). default value is 75.
integer direction: optional parameter that determines the direction of the circle. 1 is right, -1 is left. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# default circle parameters (75, 1)
drone.circle()
drone.land()
drone.close()
flip()
Description
This functions makes the drone flip backward, forward, right, or left. Make sure your battery percentage is over 50% for the flip to execute.
Syntax
flip()
flip(direction)
Parameters
string direction: optional parameter that is the direction the drone will flip. default is "back"
Returns
None
Example Code
Add a hover or delay after the flip if you need to stabilize before your next command. The drone takes 3-4 seconds after a flip before it can do another flight command.
#Python code
import time
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.hover(3)
drone.flip("back") # send flip command
time.sleep(4) # wait for flip to complete
drone.set_pitch(30) # move forward for 1 second
drone.move(1)
drone.set_pitch(-30) # move backward for 1 second
drone.move(1)
drone.land()
drone.close()
spiral()
Description
Flies the drone in the shape of a downward spiral.
Syntax
spiral()
spiral(speed, seconds, direction)
Parameters
integer speed: optional parameter that is the speed the drone will move (0 - 100). default value is 50.
integer seconds: optional parameter that is the duration in seconds the drone flies in a downward spiral. default value is 5.
integer direction: optional parameter that determines the direction of the spiral. 1 is right, -1 is left. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# default spiral parameters (50, 5, 1)
drone.spiral()
drone.land()
drone.close()
square()
Description
Flies the drone in the shape of a square.
Syntax
square()
square(speed, seconds, direction)
Parameters
integer speed: optional parameter that is the speed the drone will move (0 - 100). default value is 50.
integer seconds: optional parameter that is the duration in seconds the drone flies for each side of the square. default value is 5.
integer direction: optional parameter that determines the direction of the square. 1 is right, -1 is left. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# default square parameters (60, 1, 1)
drone.square()
drone.land()
drone.close()
sway()
Description
Flies the drone in a swaying motion.
Syntax
sway()
sway(speed, seconds, direction)
Parameters
integer speed: optional parameter that is the speed the drone will move (0 - 100). default value is 30.
integer seconds: optional parameter that is the duration in seconds the drone will fly in each "sway" motion. default value is 2.
integer direction: optional parameter that determines the direction of the sway. 1 is right, -1 is left. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# default sway parameters (30, 2, 1)
drone.sway()
drone.land()
drone.close()
triangle()
Description
Flies the drone in the shape of a triangle.
Syntax
triangle()
triangle(speed, seconds, direction)
Parameters
integer speed: optional parameter that is the speed the drone will move (0 - 100). default value is 60.
integer seconds: optional parameter that is the duration in seconds the drone flies for each side of the triangle. default value is 1.
integer direction: optional parameter that determines the direction of the triangle. 1 is right, -1 is left. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# default triangle parameters (60, 1, 1)
drone.triangle()
drone.land()
drone.close()
Flight Variables
get_move_values()
Description
Previously named print_move_values()
. Returns the current values of roll, pitch, yaw, and throttle flight variables.
Syntax
get_move_values()
Parameters
None
Returns
None
Example Code
# Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.set_roll(30)
drone.set_pitch(40)
drone.set_yaw(50)
drone.set_throttle(60)
move_list = drone.get_move_values() # get_move_values() returns list of flight variables
print("roll:", move_list[0])
print("pitch:", move_list[1])
print("yaw:", move_list[2])
print("throttle:", move_list[3])
drone.close()
move()
Description
The move command will move the drone based on the set flight variables (set_pitch, set_roll, etc). If given a parameter the move command will execute the movement for the given amount of seconds. If given no parameter then the drone will execute the move command indefinitley. You must takeoff()
first to use a move()
function.
Syntax
move(duration)
Parameters
integer duration: Duration of the movement in seconds
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# Drone goes up for 1 second with 50 power
drone.set_pitch(50)
drone.move(1) # move command executes the movement for 1 second
drone.land()
drone.close()
print_move_values()
This function has been deprecated and will be removed in a future release. Please use get_move_values()
instead, which returns move values (roll, pitch, yaw, throttle) that can be printed as needed.
Description
Prints the current values of roll, pitch, yaw, and throttle flight variables.
Syntax
print_move_values()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.set_pitch(50)
drone.set_roll(50)
drone.print_move_values() # will print pitch and roll at 50 and throttle and yaw at 0
drone.land()
drone.close()
reset_move()
This function has been deprecated and will be removed in a future release. Please use reset_move_values()
instead.
Description
The reset_move command will reset the values of roll, pitch, yaw, and throttle to 0.
Syntax
reset_move()
reset_move(attempts)
Parameters
integer attempts: Optional parameter that sends the reset_move command multiple times.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.set_pitch(50)
drone.set_roll(50)
drone.move(2)
drone.reset_move() # reset the pitch and roll to 0.
drone.move(2) # after resetting flight variables, move(2) won't move the drone
drone.land()
drone.close()
reset_move_values()
Description
The reset_move_values command will reset the values of roll, pitch, yaw, and throttle to 0.
Syntax
reset_move_values()
reset_move_values(attempts)
Parameters
integer attempts: Optional parameter that sends the reset_move_values command multiple times.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.set_pitch(50)
drone.set_roll(50)
drone.move(2)
drone.reset_move_values() # reset the pitch and roll to 0.
drone.move(2) # after resetting flight variables, move(2) won't move the drone
drone.land()
drone.close()
set_pitch()
Description
This is a setter function that allows you to set the pitch variable. Once you set pitch, you have to use move() to actually execute the movement. The pitch variable will remain what you last set it until the end of the flight sequence, so you will have to set it back to 0 if you don't want the drone to pitch again.
Syntax
set_pitch(power)
Parameters
integer power: Sets the pitch variable (-100 - 100). The number represents the direction and power of the output for that flight motion variable. Negative pitch is backwards, positive pitch is forwards.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# Drone goes forward for 1 second with 50 power
drone.set_pitch(50)
drone.move(1) # move command executes the movement for 1 second
drone.land()
drone.close()
set_roll()
Description
This is a setter function that allows you to set the roll variable. Once you set roll, you have to use move()
to actually execute the movement. The roll variable will remain what you last set it until the end of the flight sequence, so you will have to set it back to 0 if you don't want the drone to roll again.
Syntax
set_roll(power)
Parameters
integer power: Sets the roll variable (-100 - 100). The number represents the direction and power of the output for that flight motion variable. Negative roll is left, positive roll is right.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# Drone goes right for 1 second with 50 power
drone.set_roll(50)
drone.move(1) # move command executes the movement for 1 second
drone.land()
drone.close()
set_throttle()
Description
This is a setter function that allows you to set the throttle variable. Once you set throttle, you have to use move() to actually execute the movement. The throttle variable will remain what you last set it until the end of the flight sequence, so you will have to set it back to 0 if you don't want the drone to throttle again.
Syntax
set_throttle(power)
Parameters
integer power: Sets the pitch variable (-100 - 100). The number represents the direction and power of the output for that flight motion variable. Negative throttle is down, positive throttle is up.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# Drone goes up for 1 second with 50 power
drone.set_throttle(50)
drone.move(1) # move command executes the movement for 1 second
drone.land()
drone.close()
set_yaw()
Description
This is a setter function that allows you to set the yaw variable. Once you set yaw, you have to use move()
to actually execute the movement. The yaw variable will remain what you last set it until the end of the flight sequence, so you will have to set it back to 0 if you don't want the drone to yaw again.
Syntax
set_yaw(power)
Parameters
integer power: Sets the pitch variable (-100 - 100). The number represents the direction and power of the output for that flight motion variable. Negative yaw is right, positive yaw is left.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# Drone turns left for 1 second with 50 power
drone.set_yaw(50)
drone.move(1) # move command executes the movement for 1 second
drone.land()
drone.close()
LED
controller_LED_off()
Description
Turns off the controller LEDs.
Syntax
controller_LED_off()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_LED_off()
drone.close()
drone_LED_off()
Description
Turns off the drone LED.
Syntax
drone_LED_off()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.drone_LED_off()
drone.close()
set_controller_LED()
Description
This function sets the LED color and brightness of the CoDrone EDU controller's LEDs. This is done by setting RGB values (0 - 255) and brightness level (0 - 100).
Syntax
set_controller_LED(red, green, blue, brightness)
Parameters
integer red: pixel value for the color red (0 - 255)
integer green: pixel value for the color green (0 - 255)
integer blue: pixel value for the color blue (0 - 255)
integer brightness: brightness of the controller LED (0 - 100)
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.set_controller_LED(0, 0, 255, 100)
drone.close()
set_drone_LED()
Description
This function sets the LED color and brightness of the CoDrone EDU's LED. This is done by setting RGB values (0 - 255) and brightness level (0 - 100).
Syntax
set_drone_LED(red, green, blue, brightness)
Parameters
integer red: pixel value for the color red (0 - 255)
integer green: pixel value for the color green (0 - 255)
integer blue: pixel value for the color blue (0 - 255)
integer brightness: brightness of the drone LED (0 - 100)
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.set_drone_LED(0, 0, 255, 100)
drone.close()
Sounds
controller_buzzer()
Description
Plays a note using the controller's buzzer.
Syntax
controller_buzzer(note, duration)
Parameters
integer/Note note: frequency of the note, in Hertz or a Note object
integer duration: Duration of the note in milliseconds
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_buzzer(400, 300)
drone.controller_buzzer(600, 300)
drone.close()
drone_buzzer()
Description
Plays a note using the drone's buzzer.
Syntax
drone_buzzer(note, duration)
Parameters
integer/Note note: frequency of the note, in Hertz or a Note object
integer duration: Duration of the note in milliseconds
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.drone_buzzer(400, 300)
drone.drone_buzzer(600, 300)
drone.close()
start_drone_buzzer()
Description
This function allows the drone buzzer to be played in the background while other commands are given to the drone.
Syntax
start_drone_buzzer(note)
Parameters
integer/Note note: the frequency of the note, in Hertz or a Note object
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.start_drone_buzzer(500) # starting the buzzer
# these commands run while the buzzer runs in the background
for i in range(5):
drone.set_drone_LED(255, 0, 0, 100)
time.sleep(0.5)
drone.set_drone_LED(0, 255, 0, 100)
time.sleep(0.5)
drone.stop_drone_buzzer() # stops the buzzer
drone.close()
stop_drone_buzzer()
Description
Stops the drone buzzer if started in the background.
Syntax
stop_drone_buzzer()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.start_drone_buzzer(500) # starting the buzzer
# these commands run while the buzzer runs in the background
for i in range(5):
drone.set_drone_LED(255, 0, 0, 100)
time.sleep(0.5)
drone.set_drone_LED(0, 255, 0, 100)
time.sleep(0.5)
drone.stop_drone_buzzer() # stops the buzzer
drone.close()
start_controller_buzzer()
Description
This function allows the controller buzzer to be played in the background while other commands are given to the drone.
Syntax
start_controller_buzzer(note)
Parameters
integer/Note note: the frequency of the note, in Hertz or a Note object
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.start_controller_buzzer(Note.A4) # starting the buzzer
# these commands run while the buzzer runs in the background
for i in range(3):
drone.set_controller_LED(255, 0, 0, 100)
time.sleep(0.5)
drone.set_controller_LED(0, 255, 0, 100)
time.sleep(0.5)
drone.stop_controller_buzzer() # stops the buzzer
drone.close()
stop_controller_buzzer()
Description
Stops the controller buzzer if started in the background.
Syntax
stop_controller_buzzer()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.start_controller_buzzer(440) # starting the buzzer
# these commands run while the buzzer runs in the background
for i in range(3):
drone.set_controller_LED(255, 0, 0, 100)
time.sleep(0.5)
drone.set_controller_LED(0, 255, 0, 100)
time.sleep(0.5)
drone.stop_controller_buzzer() # stops the buzzer
drone.close()
Sensors (Position)
get_pos_x()
Description
Getter function that gets the x position of the drone. (x is forwards and backwards)
Syntax
get_pos_x()
get_pos_x(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
string unit: The unit of measurement that is chosen for the position distance. Available units are "m" (meter), "cm" (centimeter), "mm" (millimeter), or "in" (inch). If a parameter is not specified cm is chosen by default.
Returns
integer x-position: The current x position of the drone.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
print(drone.get_pos_x())
drone.land()
drone.close()
get_pos_y()
Description
Getter function that gets the y position of the drone. (y is left and right)
Syntax
get_pos_y()
get_pos_y(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
string unit: The unit of measurement that is chosen for the position distance. Available units are "m" (meter), "cm" (centimeter), "mm" (millimeter), or "in" (inch). If a parameter is not specified cm is chosen by default.
Returns
integer y-position: The current y position of the drone.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
print(drone.get_pos_y())
drone.land()
drone.close()
get_pos_z()
Description
Getter function that gets the z position of the drone. (z is up and down)
Syntax
get_pos_z()
get_pos_z(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
string unit: The unit of measurement that is chosen for the position distance. Available units are "m" (meter), "cm" (centimeter), "mm" (millimeter), or "in" (inch). If a parameter is not specified cm is chosen by default.
Returns
integer z-position: The current z position of the drone.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
print(drone.get_pos_z())
drone.land()
drone.close()
get_position_data()
Description
get_position_data is a getter function that retuns a list of position data for the drone. The 'x' position of the drone is forwards and reverse. The 'y' position of the drone is left and right. The 'z' position of the drone is up and down.
Syntax
get_position_data()
get_position_data(delay)
Parameters
float delay: the delay in seconds before the position data is returned. default value is 0.01.
Returns
list position data: A list of position data for the drone. The list contains the current time of the running program [0], x position data [1], y position data [2], z position data [3].
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
data = drone.get_position_data()
print(data)
drone.land()
drone.close()