Function Documentation
version 1.9 (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()
Flight Commands (Start / Stop)
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()
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()
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()
reset_sensor()
Description
This function will reset the gyro angles back to zero for roll, pitch, and yaw. NOTE: If you're resetting right before a takeoff, make sure to add a time.sleep(1)
before the takeoff()
, otherwise the take off might be skipped.
Syntax
reset_sensor()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
print("Before")
print("X angle:", drone.get_x_angle())
print("Y angle:", drone.get_y_angle())
print("Z angle:", drone.get_z_angle())
drone.takeoff()
drone.set_yaw(50)
drone.move(1)
drone.land()
print("After")
print("X angle:", drone.get_x_angle())
print("Y angle:", drone.get_y_angle())
print("Z angle:", drone.get_z_angle())
drone.reset_sensor()
print("Reset")
print("X angle:", drone.get_x_angle())
print("Y angle:", drone.get_y_angle())
print("Z angle:", drone.get_z_angle())
drone.close()
Flight Commands (Movement)
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()
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()
detect_wall()
Description
Returns True when a distance below the threshold is reached. The sensor range is up to 1.5 meters (150cm)
Syntax
detect_wall()
detect_wall(distance)
Parameters
integer distance: An optional parameter that is the threshold in centimeters that will return True. The default value is 50
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
# if a wall is detected in less than 500mm true will be returned.
if drone.detect_wall():
print("wall detected!")
else:
print("no wall detected!")
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
Sound
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
get_battery()
Description
This function returns the current battery level percentage of the drone.
Syntax
get_battery()
Parameters
None
Returns
integer battery percentage: The current battery percentage of the drone's battery.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
battery = drone.get_battery()
print(battery)
drone.close()
get_bottom_range()
Description
This is a getter function which returns the current bottom range of the drone. The default unit of measurement is centimeters. This function uses the bottom range sensor to measure distance from the drone to the surface below the drone.
Syntax
get_bottom_range()
get_bottom_range(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
string unit: The unit of measurement that is chosen for the height 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 bottom range: The current bottom range calculated by the bottom range sensor (cm default). -100 or 0 when the sensor returns an error. 999.9 when the detected object is out of range (1.5 meters) or the sensor timed out.
Example Code
#Python code
import time
from codrone_edu.drone import *
drone = Drone()
drone.pair()
max_bottom_range = 100
drone.takeoff()
drone.set_throttle(20)
current_bottom_range = drone.get_bottom_range("cm")
while current_bottom_range <= max_bottom_range:
drone.move()
current_bottom_range = drone.get_bottom_range("cm")
print(current_bottom_range)
drone.land()
drone.close()
get_temperature()
Description
This is a getter function gets the drone's temperature from the barometer. The sensor reads the drone’s temperature, not the air around it. Default unit is Celcius.
Syntax
get_temperature()
get_temperature(unit)
Parameters
string unit: A string for the unit of temperature of the drone. Available units are "C" (Celcius), "F" (Fahrenheit), and "K" (Kelvin).
Returns
integer temperature: The temperature of the drone in the given unit as a float. Default unit is Celcius.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
temperature = drone.get_temperature()
print(temperature)
drone.close()
get_flight_state()
Description
get_flight_state()
is a getter function that gets the current flight state of the drone.
Syntax
get_flight_state()
Parameters
None
Returns
string state: The current flight state of the drone.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
print(drone.get_flight_state())
drone.close()
get_flow_x()
Description
This getter function gets the relative position value calculated by the optical flow sensor from the x direction (forward and reverse).
Syntax
get_flow_x()
get_flow_x(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
string unit: The unit of measurement that is chosen for the 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 relative x-position: The relative position value calculated by the optical flow sensor from the x direction. (cm default).
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.set_pitch(50)
drone.move(1)
print(drone.get_flow_x())
drone.land()
drone.close()
get_flow_y()
Description
This getter function gets the relative position value calculated by the optical flow sensor from the y direction (left and right).
Syntax
get_flow_y()
get_flow_y(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
integer unit: The unit of measurement that is chosen for the 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 relative y-positionThe relative position value calculated by the optical flow sensor from the y direction. (cm default).
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.set_roll(50)
drone.move(1)
print(drone.get_flow_y())
drone.land()
drone.close()
get_front_range()
Description
This is a getter function which returns the current Range from the front range sensor. The default unit of measurement is centimeters. This function uses the front range sensor to measure distance from the drone to the surface in front of the drone.
Syntax
get_front_range()
get_front_range(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
string unit: A string for the unit of measurement that is chosen for the range 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 front range: The current range calculated by the front range sensor (cm by default). -10 or 0 when the sensor returns an error value. 999 when the detected object is out of range (1.5 meters) or the sensor timed out.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
drone.hover(3)
distance = drone.get_front_range()
print(distance)
drone.land()
drone.close()
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()
get_pressure()
Description
This is a getter function that returns the data from the barometer. The function returns a value in the unit Pascals. Note: 1atm = 101325 Pa
Syntax
get_pressure()
Parameters
None
Returns
float pressure: air pressure measured by barometer in Pascals.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
# print the pressure
pressure = drone.get_pressure()
print(pressure)
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()
get_x_accel()
Description
Getter function that gets the x acceleration of the drone. (x is forwards and backwards)
Syntax
get_x_accel()
Parameters
None
Returns
integer x-acceleration: The current x acceleration of the drone.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
print(drone.get_x_accel())
drone.land()
drone.close()
get_x_angle()
Description
This is a getter function which returns the current X angle from the gyroscope in the drone. This angle is on the "roll" axis.
Syntax
get_x_angle()
Parameters
None
Returns
integer roll angle: The current angle in regards to the X direction in degrees.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
print(drone.get_x_angle())
drone.close()
get_y_accel()
Description
Getter function that gets the y acceleration of the drone. (y is left and right)
Syntax
get_y_accel()
Parameters
None
Returns
integer y-acceleration: The current y acceleration of the drone.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
print(drone.get_y_accel())
drone.land()
drone.close()
get_y_angle()
Description
This is a getter function which returns the current Y angle from the gyroscope in the drone. This angle is on the "pitch" axis.
Syntax
get_y_angle()
Parameters
None
Returns
integer pitch angle: The current angle in regards to the Y direction, in degrees.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
print(drone.get_y_angle())
drone.close()
get_z_accel()
Description
Getter function that gets the z acceleration of the drone (z is up and down). When the CoDrone EDU is at rest on a flat surface, the gyroscope sensor should be reading a value of 9.8 * 10 meters per second squared (m/s2) due to gravity.
Syntax
get_z_accel()
Parameters
None
Returns
integer z-acceleration: The current z acceleration of the drone.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.takeoff()
print(drone.get_z_accel())
drone.land()
drone.close()
get_z_angle()
Description
This is a getter function which returns the current Z angle from the drone. This is angle is the "yaw" direction.
Syntax
get_z_angle()
Parameters
None
Returns
integer yaw angle: The current angle in regards to the Z direction.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
print(drone.get_z_angle())
drone.close()
get_height()
Description
This is a getter function which returns the current height of the drone. The default unit of measurement is centimeters. This function uses the bottom range sensor to measure distance from the drone to the surface below the drone.
Syntax
get_height()
get_height(unit="cm")
— "m"
, "mm"
, and "in"
are other options for unit
Parameters
string unit: The unit of measurement that is chosen for the height 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 height: The current range calculated by the bottom range sensor (cm default). -100 or 0 when the sensor returns an error. 999.9 when the detected object is out of range (1.5 meters) or the sensor timed out.
Example Code
#Python code
import time
from codrone_edu.drone import *
drone = Drone()
drone.pair()
max_height = 100
drone.takeoff()
drone.set_throttle(20)
current_height = drone.get_height("cm")
while current_height <= max_height:
drone.move()
current_height = drone.get_height("cm")
print(current_height)
drone.land()
drone.close()
get_back_color()
Description
get_back_color()
is a getter function that calls get_color_data()
but only returns the data for the back color sensor.
Syntax
get_back_color()
Parameters
None
Returns
back color data: Returns the back color sensor data.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
color_data = drone.get_back_color()
print(color_data)
drone.close()
get_color_data()
Description
Getter function that gets a list of color data from the drone.
Syntax
get_color_data()
Parameters
None
Returns
list color data: Returns a list of color data.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
color_data = drone.get_color_data()
drone.close()
get_front_color()
Description
get_front_color()
is a getter function that calls get_color_data()
but only returns the data for the front color sensor.
Syntax
get_front_color()
Parameters
None
Returns
front color data: Returns the back color sensor data.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
color_data = drone.get_front_color()
print(color_data)
drone.close()
load_classifier()
This function is currently unavailable for Python for Robolink.
Description
load_classifier()
is a function that can load a custom color set onto the CoDrone EDU. If no custom color set is given then the default color set is loaded. There is also an option to show the color set as a graph.
Syntax
load_classifier()
load_classifier(dataset, show_graph)
Parameters
string dataset: An optional parameter to load a custom color set. If no color set is given then the default color set will be used.
boolean show_graph: An optional boolean parameter that will show a graph of the color set data. The default value is False.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
# This example assumes the "custom_color_data" directory exists
drone.load_classifier("custom_color_data")
color_data = drone.get_color_data()
color = drone.predict_colors(color_data)
print(color)
drone.close()
predict_colors()
This function is currently unavailable for Python for Robolink.
Description
Predicts what color the color sensors are currently seeing.
Syntax
predict_colors(color_data)
Parameters
list color_data: loaded from drone.get_color_data()
Returns
list predictions: A prediction of which color the front and back color sensors are currently seeing, as a list.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.load_classifier("color_data_file")
color_data = drone.get_color_data()
color = drone.predict_colors(color_data)
print(color)
drone.close()
get_colors()
Description
get_colors()
is a getter function that returns one of the 8 pre-calibrated colors (provided in the color cards).
Syntax
get_colors()
Parameters
None
Returns
list predictions: Returns a list containing the front and back color sensor predictions as strings (Red, Green, Yellow, Blue, Cyan, Magenta, Black, White, Unknown)
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
colors = drone.get_colors()
print(colors)
drone.close()
new_color_data()
This function is currently unavailable for Python for Robolink.
Description
new_color_data()
is a function that creates a new dataset of custom color prediction data.
Syntax
new_color_data(label, data, dataset)
Parameters
string label: label name that will be used for the filename.
list data: HSV data samples
string dataset: Folder name where the text file will be stored.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
dataset = "color_data"
colors = ["green", "purple", "red", "lightblue", "blue", "yellow", "black", "white"]
for color in colors:
data = []
samples = 500
for i in range(1):
print("Sample: ", i+1)
next = input("Press enter to calibrate " + color)
print("0% ", end="")
for j in range(samples):
color_data = drone.get_color_data()[0:9]
data.append(color_data)
time.sleep(0.005)
if j % 10 == 0:
print("-", end="")
print(" 100%")
drone.new_color_data(color, data, dataset)
print("Done calibrating.")
drone.close()
append_color_data()
This function is currently unavailable for Python for Robolink.
Description
append_color_data()
is a function that adds onto an existing dataset of custom color prediction data. the dataset parameter must already exist in order to use this function.
Syntax
append_color_data(label, data, dataset)
Parameters
string label: label name that will be used for the filename.
list data: HSV data samples
string dataset: Folder name where the text file will be stored.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
dataset = "color_data"
colors = ["green", "purple", "red", "lightblue", "blue", "yellow", "black", "white"]
for color in colors:
data = []
samples = 500
for i in range(1):
print("Sample: ", i+1)
next = input("Press enter to calibrate " + color)
print("0% ", end="")
for j in range(samples):
color_data = drone.get_color_data()[0:9]
data.append(color_data)
time.sleep(0.005)
if j % 10 == 0:
print("-", end="")
print(" 100%")
drone.append_color_data(color, data, dataset)
print("Done calibrating.")
drone.close()
height_from_pressure()
Description
This function gets the drone's current height in centimeters based on the initial pressure sensor reading. You must call set_initial_pressure() to establish a reference point.
Syntax
height_from_pressure()
height_from_pressure(b, m)
Parameters
float b: slope intercept in pascals (default is set to 0)
float m: slope in centimeters/pascals (default is set to 9.34)
Returns
float height: Estimated height in centimeters relative to starting position.
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.set_initial_pressure() # Take an initial pressure reading as a reference
for i in range(300):
print(drone.height_from_pressure(), " centimeters")
time.sleep(0.2)
drone.close()
set_initial_pressure()
Description
This function saves an initial pressure reading to the drone. This function is used in combination with other functions such as height_from_pressure()
Syntax
set_initial_pressure()
Parameters
None
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
# Here is where we save our initial pressure. Now the 'height_from_pressure()' function has a reference for height
drone.set_initial_pressure()
# The drone will not take off in this example but by moving it up and down manually the resulting height will print
for i in range(300):
print(drone.height_from_pressure(), " millimeters")
time.sleep(0.2)
drone.close()
get_angular_speed_x()
Description
This function returns the current angular speed in degrees per second around the x-axis ("roll" axis).
Syntax
get_angular_speed_x()
Parameters
None
Returns
integer angular speed: positive or negative angle speed in degrees per second
Example Code
Tilt the drone left and right while the program runs to see the angular speed change. Then, hold the drone as still as possible and watch angular speed drop.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
for i in range(100):
print(drone.get_angular_speed_x())
time.sleep(0.05)
drone.close()
get_angular_speed_y()
Description
This function returns the current angular speed in degrees per second around the y-axis ("pitch" axis).
Syntax
get_angular_speed_y()
Parameters
None
Returns
integer angular speed: positive or negative angle speed in degrees per second
Example Code
Tilt the drone forward and backward while the program runs to see the angular speed change. Then, hold the drone as still as possible and watch angular speed drop.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
for i in range(100):
print(drone.get_angular_speed_y())
time.sleep(0.05)
drone.close()
get_angular_speed_z()
Description
This function returns the current angular speed in degrees per second around the z-axis ("yaw" axis).
Syntax
get_angular_speed_z()
Parameters
None
Returns
integer angular speed: positive or negative angle speed in degrees per second
Example Code
Turn the drone left and right on a flat surface while the program runs to see the angular speed change. Then, hold the drone as still as possible and watch angular speed drop.
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
for i in range(100):
print(drone.get_angular_speed_z())
time.sleep(0.05)
drone.close()
get_sensor_data()
Description
This functions returns a list of 31 values including time stamps and sensor values. It requests 5 distinct lists of data and compiles them into one list. This function returns data more quickly than individual sensor requests.
Syntax
get_sensor_data()
get_sensor_data(delay)
Parameters
integer delay: The delay in seconds for each sensor request (out of 5). The total delay will be 5x this delay value. The default value is 0.1 seconds.
Returns
list sensor data: A list of length 31 consisted of sensor data.
- data[0] Altitude time stamp
- data[1] Temperature in Celsius
- data[2] Pressure (Pascals)
- data[3] Elevation output from barometer (meters)
- data[4] Height value output from bottom range sensor (meters)
- data[5] Motion data time stamp
- data[6] acceleration X Int16 2 Byte -1568 ~ 1568 (-156.8 ~ 156.8) m/s2 x 10 X
- data[7] acceleration Y Int16 2 Byte -1568 ~ 1568 (-156.8 ~ 156.8) m/s2 x 10 Y
- data[8] acceleration Z Int16 2 Byte -1568 ~ 1568 (-156.8 ~ 156.8) m/s2 x 10 Z
- data[9] gyroRoll: Int16 2 Byte -2000 ~ 2000 degree/second Roll
- data[10] gyroPitch Int16 2 Byte -2000 ~ 2000 degree/second Pitch
- data[11] gyroYaw Int16 2 Byte -2000 ~ 2000 degree/second Yaw
- data[12] angleRoll Int16 2 Byte -180 ~ 180 degree Roll
- data[13] anglePitch Int16 2 Byte -180 ~ 180 degree Pitch
- data[14] angleYaw Int16 2 Byte -180 ~ 180 degree Yaw
- data[15] Position data time stamp
- data[16] x Float32 4 Byte - X axis in meters
- data[17] y Float32 4 Byte - Y axis in meters
- data[18] z Float32 4 Byte - z axis in meters
- data[19] Range sensor data time stamp
- data[20] Front range sensor (millimeters)
- data[21] Bottom range sensor (millimeters)
- data[22] Drone state time stamp
- data[23] modeSystem (system operating mode)
- data[24] modeFlight (flight controller operating mode)
- data[25] modeControlFlight (flight control mode)
- data[26] modeMovement (moving state)
- data[27] headless (headless setting status)
- data[28] sensorOrientation (sensor orientation)
- data[29] battery parcentage level
- data[30] current speed setting
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
# collect multiple data points
data = drone.get_sensor_data()
for i in range(len(data)):
print(i, data[i]) # print out each data point
drone.close()
get_error_data()
Description
This command requests if the drone is in an error state. One or more of the following error states can be printed to console.
- Motion_Calibrating: Drone is calibrating.
- Motion_NoAnswer: Gyroscope Accelerometer is unresponsive and may be damaged.
- Motion_WrongValue: Gyroscope Accelerometer is giving erroneous data.
- Motion_NotCalibrated: Gyroscope Accelerometer is not calibrated.
- Pressure_NoAnswer: Barometer is unresponsive.
- Pressure_WrongValue: Barometer is giving erroneous data.
- RangeGround_NoAnswer: Bottom Range sensor is unresponsive.
- RangeGround_WrongValue: Bottom range sensor has given an incorrect value.
- Flow_NoAnswer: Optical flow sensor is unresponsive.
- Flow_CannotRecognizeGroundImage: Optical flow sensor is giving erroneous data due to the image.
Syntax
get_error_data()
get_error_data(delay)
Parameters
float delay: The delay in seconds that the command will wait for a response. The default value is 0.1.
Returns
string error state: text consisting of one or more error messages
Example Code
Turn the drone left and right on a flat surface while the program runs to see the angular speed change. Then, hold the drone as still as possible and watch angular speed drop.
#Python code
from time import sleep
from codrone_edu.drone import *
from codrone_edu.protocol import *
drone = Drone()
drone.pair()
# For demonstration purposes, activate motion calibration
drone.sendCommand(CommandType.ClearBias)
sleep(0.1)
for i in range(10):
drone.get_error_data() # see motion error state during calibration
time.sleep(0.5)
drone.close()
Controller
down_arrow_pressed()
Description
A function that determines if the controller's down arrow button has been pressed.
Syntax
down_arrow_pressed()
Parameters
None
Returns
boolean pressed down: True if the down arrow button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.down_arrow_pressed():
print("down arrow button has been pressed!")
drone.close()
get_button_data()
Description
get_button_data()
is a function that will return a list of information about the most recent button pressed.
Syntax
get_button_data()
Parameters
None
Returns
list button data: A list of data that includes the time of the current program, the number associated with the most recent button pressed, and finally the state of the most recent button pressed. (Down, Pressed, Up)
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
print(drone.get_button_data())
drone.close()
h_pressed()
Description
A function that determines if the controller's H button has been pressed.
Syntax
h_pressed()
Parameters
None
Returns
boolean pressed H: True if the H button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.h_pressed():
print("H button has been pressed!")
drone.close()
l1_pressed()
Description
A function that determines if the controller's L1 button has been pressed.
Syntax
l1_pressed()
Parameters
None
Returns
boolean pressed L1: True if the L1 button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.l1_pressed():
print("L1 button has been pressed!")
drone.close()
l2_pressed()
Description
A function that determines if the controller's L2 button has been pressed.
Syntax
l2_pressed()
Parameters
None
Returns
boolean pressed L2: True if the L2 button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.l2_pressed():
print("L2 button has been pressed!")
drone.close()
left_arrow_pressed()
Description
A function that determines if the controller's left arrow button has been pressed.
Syntax
left_arrow_pressed()
Parameters
None
Returns
boolean pressed left: True if the left arrow button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.left_arrow_pressed():
print("left arrow button has been pressed!")
drone.close()
p_pressed()
Description
A function that determines if the controller's P button has been pressed.
Syntax
p_pressed()
Parameters
None
Returns
boolean pressed P: True if the P button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.p_pressed():
print("P button has been pressed!")
drone.close()
power_pressed()
Description
A function that determines if the controller's power button has been pressed. Since pressing the power button also switches the drone to flight mode, this function only detects alternate button presses. In other words, the function can only detect a power button press when in LINK state.
Syntax
power_pressed()
Parameters
None
Returns
boolean pressed power: True if the power button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.power_pressed():
print("power button has been pressed!")
drone.close()
r1_pressed()
Description
A function that determines if the controller's R1 button has been pressed.
Syntax
r1_pressed()
Parameters
None
Returns
boolean pressed R1: True if the R1 button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.r1_pressed():
print("R1 button has been pressed!")
drone.close()
r2_pressed()
Description
A function that determines if the controller's R2 button has been pressed.
Syntax
r2_pressed()
Parameters
None
Returns
boolean pressed R2: True if the R2 button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.r2_pressed():
print("R2 button has been pressed!")
drone.close()
right_arrow_pressed()
Description
A function that determines if the controller's right arrow button has been pressed.
Syntax
right_arrow_pressed()
Parameters
None
Returns
boolean pressed right: True if the right arrow button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.right_arrow_pressed():
print("right arrow button has been pressed!")
drone.close()
s_pressed()
Description
A function that determines if the controller's S button has been pressed.
Syntax
s_pressed()
Parameters
None
Returns
boolean pressed S: True if the S button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.s_pressed():
print("S button has been pressed!")
drone.close()
up_arrow_pressed()
Description
A function that determines if the controller's up arrow button has been pressed.
Syntax
up_arrow_pressed()
Parameters
None
Returns
boolean pressed up: True if the up arrow button is pressed or held. Otherwise the function will return false.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
if drone.up_arrow_pressed():
print("up arrow button has been pressed!")
drone.close()
get_joystick_data()
Description
get_joystick_data()
is a getter function that gets a list of data about the state of both joysticks on the controller.
Syntax
get_joystick_data()
Parameters
None
Returns
list joystick data: A list of data that includes the time of the current program, and information about the left and right joysticks.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
print(drone.get_joystick_data())
drone.close()
get_left_joystick_x()
Description
get_left_joystick_x()
is a getter function that gets the position of the left joystick's x position.
Syntax
get_left_joystick_x()
Parameters
None
Returns
integer left joystick x-value: A value between -100 and 100 depending on the x position of the left joystick.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
print(drone.get_left_joystick_x())
drone.close()
get_left_joystick_y()
Description
get_left_joystick_y()
is a getter function that gets the position of the left joystick's y position.
Syntax
get_left_joystick_y()
Parameters
None
Returns
integer left joystick y-value: A value between -100 and 100 depending on the y position of the left joystick.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
print(drone.get_left_joystick_y())
drone.close()
get_right_joystick_x()
Description
get_right_joystick_x()
is a getter function that gets the position of the right joystick's x position.
Syntax
get_right_joystick_x()
Parameters
None
Returns
integer right joystick x-value: A value between -100 and 100 depending on the x position of the right joystick.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
print(drone.get_right_joystick_x())
drone.close()
get_right_joystick_y()
Description
get_right_joystick_y()
is a getter function that gets the position of the right joystick's y position.
Syntax
get_right_joystick_y()
Parameters
None
Returns
integer right joystick y-value: A value between -100 and 100 depending on the y position of the right joystick.
Example Code
#Python code
from codrone_edu.drone import *
import time
drone = Drone()
drone.pair()
while True:
time.sleep(0.1)
print(drone.get_right_joystick_y())
drone.close()
Screen
controller_clear_screen()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Clears all drawings from the controller screen
Syntax
controller_clear_screen()
controller_clear_screen(pixel)
Parameters
string pixel: optional parameter that assigns all pixels to either white or black. white is the default value.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
drone.close()
controller_create_canvas()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Creates a new image object for drawing
Syntax
controller_create_canvas()
Parameters
None
Returns
Image image: Returns a new image object that is 127 x 63 pixels
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
image = drone.controller_create_canvas() # see controller_draw_canvas for how to draw on this new image object
drone.close()
controller_draw_arc()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws an arc (a portion of a circle outline) between the start and end angles, inside the given bounding box.
Syntax
controller_draw_arc(arc_list, start_angle, end_angle, image, pixel_width)
Parameters
list arc_list: Two points to define the bounding box. Sequence of [(x0, y0), (x1, y1)], where x1 >= x0 and y1 >= y0.
integer start_angle: Starting angle, in degrees. Angles are measured from 3 o’clock, increasing clockwise.
integer end_angle: Ending angle, in degrees.
Image image: image object created from create_image_canvas()
.
integer pixel_width: optional parameter that is the line width, in pixels. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
image = drone.controller_create_canvas() # create image object
arc_list = [(20, 40), (50, 50)]
drone.controller_draw_arc(arc_list, 0, 180, image) # set arc onto image object
drone.controller_draw_canvas(image) # draw image onto controller screen
drone.close()
controller_draw_canvas()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws custom image canvas onto the controller screen
Syntax
controller_draw_canvas(image)
Parameters
Image image: image object to be drawn onto the controller screen
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
image = drone.controller_create_canvas() # create image object
arc_list = [(20, 40), (50, 50)]
ellipse_list = [(10, 10), (40, 40)]
chord_list = [(60, 20), (100, 50)]
drone.controller_draw_ellipse(ellipse_list, image) # draw onto image object
drone.controller_draw_arc(arc_list, 0, 180, image)
drone.controller_draw_chord(chord_list, 0, 180, image)
drone.controller_draw_canvas(image) # draw image onto controller screen
drone.close()
controller_draw_chord()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Same as controller_draw_arc(), but connects the end points with a straight line.
Syntax
controller_draw_chord(arc_list, start_angle, end_angle, image, pixel_width)
Parameters
list chord_list: Two points to define the bounding box. Sequence of [(x0, y0), (x1, y1)], where x1 >= x0 and y1 >= y0.
integer start_angle: Starting angle, in degrees. Angles are measured from 3 o’clock, increasing clockwise.
integer end_angle: Ending angle, in degrees.
Image image: image object created from create_image_canvas()
.
integer pixel_width: optional parameter that is the line width, in pixels. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
image = drone.controller_create_canvas() # create image object
chord_list = [(20, 40), (50, 50)]
drone.controller_draw_chord(chord_list, 0, 180, image) # set chord onto image object
drone.controller_draw_canvas(image) # draw image onto controller screen
drone.close()
controller_draw_ellipse()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws an ellipse inside the given bounding box.
Syntax
controller_draw_ellipse(ellipse_list, image, fill_in, pixel_width)
Parameters
list ellipse_list: Two points to define the bounding box. Sequence of [(x0, y0), (x1, y1)] where x1 >= x0 and y1 >= y0.
Image image: image object created from create_image_canvas()
.
integer fill_in: optional parameter. None by default. 0 will fill with black.
integer pixel_width: optional parameter that is the line width, in pixels. default value is 1.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
image = drone.controller_create_canvas() # create image object
ellipse_list = [(10, 10), (40, 40)]
drone.controller_draw_ellipse(ellipse_list, image) # set ellipse onto image object
drone.controller_draw_canvas(image) # draw image onto controller screen
drone.close()
controller_draw_image()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
This function is currently unavailable for Python for Robolink.
Description
Draws image when given a pixel_list of image data
Syntax
controller_draw_image(pixel_list)
Parameters
list pixel_list: the list of image data. can be obtained using get_image_data()
function.
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
image = get_image_data("example.png") # where example.png is an image in the same directory as the program
drone.controller_draw_image(image) # draws the image onto the controller's screen
drone.close()
controller_draw_line()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws a line between points (x1, y1) and (x2, y2)
(x1,y1) \
\
\
\ (x2,y2)
Syntax
controller_draw_line(x1, y1, x2, y2, pixel, line_type)
Parameters
integer x1: point 1 x coordinate
integer y1: point 1 y coordinate
integer x2: point 2 x coordinate
integer y2: point 2 y coordinate
string pixel: optional parameter that changes the pixel color of the line. default value is Black
string line_type: optional parameter that is the type of line drawn. default is Solid
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
drone.controller_draw_line(0,0, 60, 60)
drone.close()
controller_draw_point()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws a single pixel at the point (x,y)
Syntax
controller_draw_point(x, y, pixel)
Parameters
integer x: x coordinate
integer y: y coordinate
string pixel: optional parameter that changes the pixel color of the line. default value is Black
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
drone.controller_draw_point(10, 10) # place a pixel at the (10,10) coordinate
drone.close()
controller_draw_polygon()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
The polygon outline consists of straight lines between the given coordinates, plus a straight line between the last and the first coordinate.
Syntax
controller_draw_polygon(point_list)
Parameters
list point_list: the list of coordinates
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
point_list_square = ((10, 10), (30, 10), (30, 30), (10, 30)) # creating a list of coordinates
drone.controller_draw_polygon(point_list_square)
drone.close()
controller_draw_rectangle()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws a rectangle onto the controller screen starting from point (x,y) and extends to given height and width
width
(x,y)|---------------|
| | height
|_______________|
Syntax
controller_draw_rectangle(x, y, width, height, pixel, fill, line_type)
Parameters
integer x: top left corner x coordinate
integer y: top left corner y coordinate
integer width: width of rectangle
integer height: height of rectangle
string pixel: optional parameter that changes the pixel color of the line. default value is Black
boolean fill: optional parameter to fill in the rectangle or not. default value is False
string line_type: optional parameter that is the type of line drawn. default is Solid
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
drone.controller_draw_rectangle(30, 15, 50, 30)
drone.close()
controller_draw_square()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws a square on the controller screen starting from point (x,y) and will extend to the given width
width
(x,y)|------|
| | width
|______|
Syntax
controller_draw_square(x, y, width, pixel, fill, line_type)
Parameters
integer x: top left corner x coordinate
integer y: top left corner y coordinate
integer width: width of square
string pixel: optional parameter that changes the pixel color of the line. default value is Black
boolean fill: optional parameter to fill in the square or not. default value is False
string line_type: optional parameter that is the type of line drawn. default is Solid
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
drone.controller_draw_square(10, 10, 25)
drone.close()
controller_draw_string_align()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws a string from the given x_start, x_end and y positions. The string can be aligned along the x_start and x_end positions
Syntax
controller_draw_string_align(x_start, x_end, y, string, alignment, string_font, pixel_color)
Parameters
integer x_start: starting x position
integer x_end: ending x position
integer y: y position
string string: the string to write
string alignment: optional parameter that is the alignment between x_start and x_end. can align Left, Right, or Center. default value is Center
integer string_font: optional parameter that is the font of the string to be written. default value is LiberationMono5x8
integer pixel_color: optional parameter that is the pixel color of the written string. default value is Black
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
drone.controller_draw_string_align(0, 70, 0, "Hello, world!")
drone.close()
controller_draw_string()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
Description
Draws a string from the given x_start, x_end and y positions. The string can be aligned along the x_start and x_end positions
Syntax
controller_draw_string(x, y, string, string_font, pixel_color)
Parameters
integer x: starting x position
integer y: starting y position
string string: the string to write
integer string_font: optional parameter that is the font of the string to be written. default value is LiberationMono5x8
string pixel_color: optional parameter that is the pixel color of the written string. default value is Black
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
drone.controller_draw_string(0, 0, "Hello, world!")
drone.close()
controller_preview_canvas()
This function is currently unavailable for CoDrone EDU (JROTC ed.).
This function is currently unavailable for Python for Robolink.
Description
Creates a pop up window to preview your current image object on your computer screen.
Syntax
controller_preview_canvas(image)
Parameters
Image image: image object to be previewed
Returns
None
Example Code
#Python code
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen() # clear screen for drawing
image = drone.controller_create_canvas() # create image object
arc_list = [(20, 40), (50, 50)]
ellipse_list = [(10, 10), (40, 40)]
chord_list = [(60, 20), (100, 50)]
drone.controller_draw_ellipse(ellipse_list, image) # draw onto image object
drone.controller_draw_arc(arc_list, 0, 180, image)
drone.controller_draw_chord(chord_list, 0, 180, image)
drone.controller_preview_canvas(image) # draw image onto controller screen
drone.close()