Block Documentation
version 4.3.0 (Changelog)
Flight Commands
takeoff
Block
Code
drone. takeoff()Description
This functions makes the drone take off. CoDrone EDU takes off at an average height of 80 centimeters off the ground. A takeoff block must be used before any other flight command or flight movement. NOTE: The takeoff height cannot be modified.
Parameters
None
Returns
None
Example
land
Block
Code
drone. land()Description
This function makes the drone land by throttling down safely.
Parameters
None
Returns
None
Example
hover
Block
Code
drone. hover()Description
This function makes the drone hover in place for a duration in seconds.
Parameters
integer duration: the duration of the hover in seconds
Returns
None
Example
go [direction] for [seconds] seconds at [power] % power
Block
Code
drone. go()Description
This function flies the drone in a direction for a given duration and a power percentage.
Parameters
direction: forward, backward, up, down, left, right
integer duration: the duration of movement, in seconds
integer power: the power/speed of drone between 0 and 100
Returns
None
Example
go [direction] [distance] [units]
Block
Code
forward: drone.move_forward()
backward: drone.move_backward()
left: drone.move_left()
right: drone.move_right()
Description
This function flies the drone in a direction for a given distance. The units of the distance can be modified. NOTE: This block may require a "wait" block to prevent skipping the movement command.
Parameters
direction: forward, backward, up, down, left, right
float distance: the distance traveled
units: the units of the distance traveled
Returns
None
Example
go to coordinate (x, y, z) = ([x], [y], [z]) m
Block
Code
drone. send_absolute_position()Description
This function flies the drone to a given coordinate/position relative to its position before its most recent takeoff.
Parameters
float x position: The desired x-position that the drone will fly to
float y position: The desired y-position that the drone will fly to
float z position: The desired z-position that the drone will fly to
Returns
None
Example
turn [direction] [degrees] degrees
Block
Code
left: drone.turn_left()
right: drone.turn_right()
Description
Turns right or left relative to the drone's current heading.
Parameters
integer degrees: angle of the turn between 0 and 180
Returns
None
Example
turn [direction] for [seconds] seconds at [power]% power
Block
Code
left:
drone.drone.set_roll(0)
drone.drone.set_pitch(0)
drone.drone.set_yaw(power)
drone.drone.set_throttle(0)
drone.drone.move(duration)
right:
drone.drone.set_roll(0)
drone.drone.set_pitch(0)
drone.drone.set_yaw(power)
drone.drone.set_throttle(0)
drone.drone.move(duration)
Description
Turns CoDrone EDU to the left or to the right for a duration in seconds at a percentange of power.
Parameters
direction: left, right
integer duration: the duration of the movement, in seconds
integer power: the power/speed of the drone between 0 and 100
Returns
None
Example
turn to heading [degrees]°
Block
Code
drone. turn_degree()Description
Turns right or left to a specified heading, in degrees, with respect to drone's initial heading. The initial heading is defined by the heading right after takeoff. The function will calculate the shortest path to the specified heading and turn in that direction.
Parameters
integer degree: angle of turn, in degrees. This function allows values more than 360, but the drone will not do more than a full rotation. To go to degree=450, it will not calculate the difference from starting heading (0) and turn for 1.25 revolutions. It will calculate the equivalent angle (90) and take the shortest rotation.
Returns
None
Example
set_[RPYT] to [power]%
Block
Code
drone. set_roll()drone. set_pitch()
drone. set_yaw()
drone. set_throttle()
Description
This function sets the power for the given motion (roll, pitch, yaw or throttle) but will not send a move command. This function is most of the time paired with a "move" block, so that the "move" block can send a move command.
roll: positive roll power will move the drone right and negative roll power will move the drone left.
pitch: positive pitch power will move the drone forward and negative pitch power will move the drone backward.
throttle: positive throttle power will move the drone upward and negative throttle power will move the drone downward.
yaw: positive yaw power will rotate the drone left and negative yaw power will rotate the drone right.
Parameters
integer power: the power/speed of the drone between -100 and 100
Returns
None
Example
In this example, after taking off, the drone sets its roll, pitch, yaw, and throttle power to 20%, but this will not make the drone move yet. Finally, the drone lands.
In this example, after taking off, the drone sets its roll and pitch power to 25% and move for 1 second at those powers/speeds.
In this example, after taking off, the drone sets its yaw variable at 25% for left turns and moves for 1 second. Then, the drone sets its yaw variable at -25% for right turns and moves for 1 second.
move [duration] seconds
Block
Code
drone. move()Description
Moves CoDrone EDU for a duration in seconds in the direction set by the roll, pitch, yaw, and throttle values.
Parameters
integer duration: the duration of the movement in seconds
Returns
None
Example
move()
Block
Code
drone. move()Description
Moves CoDrone EDU in the direction set by the flight variables with the smallest duration possible (about 0.01 seconds). Since it has no specified duration, it is often used inside of a loop to check sensors simultaneously.
Parameters
None
Returns
None
Example
Flight Sequences
flip
Block
Code
drone. flip()Description
This function makes the drone flip back, front, right, or left. Make sure your battery percentage is over 50% for the flip to execute.
Parameters
direction: back, front, right, left
Returns
None
Example
Add a hover or delay block 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. Not adding a delay after a flip can cause following blocks to not be performed.
In this example below, after take off, the drone should flip forward and backward (flips might not be executed since a flip needs a wait block).
circle
Block
Code
drone. circle()Description
This command flies the drone in a circle, clockwise (right) or counter-clockwise (left).
Parameters
direction: The direction that drone will start flying in a circle.
Returns
None
Example
triangle
Block
Code
drone. triangle()Description
This command flies the drone in a triangle, clockwise (right) or counter-clockwise (left).
Parameters
direction: The direction that drone will start flying in a triangle.
Returns
None
Example
square
Block
Code
drone. square()Description
This command flies the drone in a square, clockwise (right) or counter-clockwise (left).
Parameters
direction: The direction that drone will start flying in a square.
Returns
None
Example
sway
Block
Code
drone. sway()Description
This command sways the drone side-to-side.
Parameters
None
Returns
None
Example
avoid wall at [distance] cm for [timeout] seconds
Block
Code
drone. avoid_wall()Description
CoDrone EDU will fly forward and stop when an obstacle is detected a given distance away (in centimeters). The block will run until the timeout (in seconds) is finished or the obstacle is found, whichever comes first. The default timeout is 10 seconds for an obstacle detected 20cm away.
Parameters
integer distance: the distance, in centimeters, at which the CoDrone EDU will stop to avoid obstacle
integer timeout: the timeout duration in seconds
Returns
None
Example
Place the drone on the floor a few feet away from a wall. When you run the code, the drone will fly forward until the wall is detected 20 centimeters away. The next block will immediately execute. In this case, the drone will land.
keep distance [distance] cm for [timeout] seconds
Block
Code
drone. keep_distance()Description
CoDrone EDU will fly forward and stop when an obstacle is detected a given distance away (in centimeters). The block will run until the timeout (in seconds) is finished or the obstacle is found, whichever comes first. The default timeout is 10 seconds for an obstacle detected 20cm away.
Parameters
integer distance: the distance, in centimeters, at which the CoDrone EDU will stop to avoid obstacle
integer timeout: the timeout duration in seconds
Returns
None
Example
Place the drone on the floor a few feet away from a wall. When you run the code, the drone will fly forward until the wall is detected 20 centimeters away. The next block will immediately execute. In this case, the drone will land.
Lights
set [device] LED color to [color], with a brightness of [brightness]
Block
Code
drone:
drone.set_drone_LED()
controller:
drone.set_controller_LED()
Description
This command sets the color of drone's or controller's LED with a given brightness.
Parameters
device: The device that will receive the light command.
color: The color of the LED.
brightness: The brightness of the LED, between 0-255.
Returns
None
Example
In this example, the program is switching between three colors (red, yellow, and green) every half second for 10 times.
In this example, a list variable test_list is created ["Red", "Blue", "White"]. For 25 iterations, the color is set to a random color (a string) from test_list, and the drone's LED color lights up with that color.
set [device] LED R=[R], G=[G], B=[B], [brightness]
Block
Code
drone:
drone.set_drone_LED()
controller:
drone.set_controller_LED()
Description
Sets the color of drone's or controller's LED. Colors are set by using its RGB (red, green, blue) equivalent values.
Parameters
device: The device that will receive the light command.
integer red: pixel value for the color red between 0 and 255.
integer green: pixel value for the color green between 0 and 255.
integer blue: pixel value for the color blue between 0 and 255.
integer brightness: brightness of the LED between 0 and 255.
Returns
None
Example
set [device] LED sequence [sequence] with color R=[R], G=[G], B=[B], and speed [speed]
Block
Code
drone:
drone.set_drone_LED_mode()
controller:
drone.set_controller_LED_mode()
Description
This command sets the color and light sequence of drone's or controller's LED. Colors are set by using its RGB (red, green, blue) equivalent values.
Parameters
device: The device that will receive the light command.
sequence: The light sequence or pattern of the LED: dimming, fade in, fade out, blink, double blink, and rainbow. The rainbow light sequence is not affected by the RGB values.
integer red: pixel value for the color red between 0 and 255.
integer green: pixel value for the color green between 0 and 255.
integer blue: pixel value for the color blue between 0 and 255.
speed: speed of the LED mode between 0 and 255.
Returns
None
Example
turn [device] LED off
Block
Code
drone. drone_LED_off()Description
Turns off the drone's or controller's LED.
Parameters
None
Returns
None
Example
Sounds
play this note [note] for [duration] seconds on [device]
Block
Description
Plays a note for a duration in seconds using the drone or controller buzzer.
Parameters
note: note range from C3 to B7, Mute, Fin.
integer duration: the duration of the note played, in seconds.
device: The device that will receive buzzer (sound) command.
Returns
None
Example
In this example, a different note is being played for half a second on the drone.
play frequency [frequency] hertz for [duration] ms on [device]
Block
Description
Plays a frequency for a duration in seconds using the drone or controller buzzer.
Parameters
frequency: frequency of the buzzer sound.
integer duration: the duration of the buzzer sound, in seconds.
device: The device that will receive buzzer (sound) command.
Returns
None
Example
In this example, a different frequency is being played for half a second on the drone.
In the example below, a list variable test_list is created [450,500,650,800,700]. The loop iterates through the list using the "length of" block as the stop parameter of the loop block. The frequency variable is set a value from test_list at index i (the loop's index variable). Depending on which conditional statement frequency satisfies, the drone will buzz a specific frequency.
play [sequence] sound on [device]
Block
Description
Plays a sound sequence or melody using the drone or controller buzzer.
Parameters
sequence: the sound sequence or melody.
device: The device that will receive buzzer (sound) command.
Returns
None
Example
In this example, the drone should be on a color card before running the program. If the color is green, the drone will play a "success" melody. If the color card is yellow, the drone will play a "warning" melody. If the color card is any other color, the drone will play an "error" melody.
Sensors (Motion)
get angle [axis]
Block
Code
x: drone.get_angle_x()
y: drone.get_angle_y()
z: drone.get_angle_z()
Description
This function returns the current gyroscope angle measurement for either the x (roll),y (pitch), or z (yaw) axis. NOTE: The drone's angle values are reset to 0 when drone takes off or battery is re-inserted.
Parameters
axis: x, y, z
Returns
integer angle: gyroscope angle measurement for the given axis, in degrees
Example
get angular speed [axis]
Block
Code
x: drone.get_angular_speed_x()
y: drone.get_angular_speed_y()
z: drone.get_angular_speed_z()
Description
This function returns the current angular velocity in degrees per second for either the x (roll), y (pitch), or z (yaw) axis.
Parameters
axis: x, y, z
Returns
integer angular velocity: the angular velocity of the drone in the provided axis, in degrees per second
Example
get acceleration [axis]
Block
Code
x: drone.get_accel_x()
y: drone.get_accel_y()
z: drone.get_accel_z()
Description
This function returns the current acceleration on either the x, y, or z axis in units of .
Note: 1g =
Parameters
axis: x, y, z
Returns
integer acceleration: positive or negative acceleration of the drone in the provided axis, in
Example
reset gyro
Block
Code
drone. reset_gyro()Description
Resets the gyroscope angles to 0. Make sure the drone is on a flat surface when running this block.
Parameters
None
Returns
None
Example
To use this example file turn the drone manually with your hand and watch the Z angle change. Then, place the drone on a flat surface before the reset. You will see that the Z angle is reset to 0.
Sensors (Range)
get [type] range in [units]
Block
Code
front: drone.get_front_range()
bottom: drone.get_bottom_range()
Description
Returns the calculated distance from either the front or bottom infrared (IR) range sensor to the surface. The sensor range is up to 1.5m.
NOTE: The front range sensor will not be able to get an exact reading of 0 due to light scattering and interference. The lowest value you may see is approximately 9mm (0.9cm) by covering the sensor.
NOTE: The bottom range sensor will be able to get an exact reading of 0 if the drone is sitting on a surface. If the drone is sitting on a surface, the bottom range sensor turns off (causing a reading of 0), so that the color sensor can turn on and detect color without any interference. It is safe to assume that if the drone is sitting on a surface, the bottom range or height is 0.
Parameters
type: front, bottom
units: cm, mm, in, m
Returns
float distance: float value in the units selected
Example
In this example, after takeoff, the drone has its throttle set at 55% power, moving upward. Before entering the loop, it checks if the drone has already reached the maximum bottom range (set as 100), measured in centimeters. If not, it will continuously fly upward until the current bottom range is more than the max bottom range.
In this example below, run the program, manually point the drone to a wall, and then move it aroun until the drone is less than 70 cm away from a wall. Click the Stop button if you want to stop running the program.
get height in [units]
Block
Code
drone. get_height()Description
Returns the calculated distance from the bottom infrared (IR) range sensor to the surface. The sensor range is up to 1.5m. This is another name for the "get range" block with the "bottom" option selected.
NOTE: The bottom range sensor will be able to get an exact reading of 0 if the drone is sitting on a surface. If the drone is sitting on a surface, the bottom range sensor turns off (causing a reading of 0), so that the color sensor can turn on and detect color without any interference. It is safe to assume that if the drone is sitting on a surface, the bottom range or height is 0.
Parameters
units: cm, in, mm, m
Returns
float height: float height value in the units selected
Example
Sensors (Position)
get position [axis] in [units]
Block