Skip to main content

Block Documentation

version 4.7.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()
up: drone.move_upward()
down: drone.move_downward()

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 first takeoff of the code execution.


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 m/s2∗10m/s^2*10.
Note: 1g = 9.8m/s29.8m/s^2

Parameters​

axis: x, y, z

Returns​

integer acceleration: positive or negative acceleration of the drone in the provided axis, in m/s2∗10m/s^2*10

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​

Code​

x: drone.get_pos_x()
y: drone.get_pos_y()
z: drone.get_pos_z()

Description​

Returns the current estimated position of the drone using the optical flow sensor. NOTE: The drone's position values are reset to 0 when drone takes off or battery is re-inserted.

Parameters​


axis: x, y, z
units: mm, cm, in, m


Returns​

float position: x, y, or z value in units selected

Example​

In this example, after takeoff, the console prints the x-y-z coordinates of the drone's position, in centimeters. Then, prints the x-y-z coordinates again after moving for 2 seconds.



In this example, after takeoff, the console prints the x-y-z coordinates of the drone's position, in inches. Prints x-coordinate of the drone after moving right. Prints y-coordinate of the drone after moving forward. Prints z-coordinate of the drone after flying higher.


Sensors (Color)​

get [type] color​

Block​

Code​

front: drone.get_front_color()
back: drone.get_back_color()

Description​

This functions reads the color data from either of the two bottom color sensors and returns one of the 8 pre-calibrated colors (provided in the color cards). The drone must be flat on a surface (not flying) for the color sensor to activate.

Parameters​

type: front, back

Returns​

color: detected color as a string (Red, Green, Yellow, Blue, Cyan, Magenta, Black, White, Unknown)

Example​

In this example, if the drone's front color detector detects the color green, the drone's LED will light up green; otherwise, the drone's LED will turn off.



In the example below, place the drone under two different colored surfaces, so that the back and front sensor detector aren't detecting the same surface. The program will output different colors for the back and front sensor.


get [type] [hsvl_rgb] value​

Block​

Code​

(front, hue): drone.get_front_color(kind="hsv")[0]
(front, saturation): drone.get_front_color(kind="hsv")[1]
(front, value): drone.get_front_color(kind="hsv")[2]
(front, lightness): drone.get_front_color(kind="hsl")[2]
(front, red): drone.get_front_color(kind="rgb")[0]
(front, green): drone.get_front_color(kind="rgb")[1]
(front, blue): drone.get_front_color(kind="rgb")[2]
(back, hue): drone.get_back_color(kind="hsv")[0]
(back, saturation): drone.get_back_color(kind="hsv")[1]
(back, value): drone.get_back_color(kind="hsv")[2]
(back, lightness): drone.get_back_color(kind="hsl")[2]
(back, red): drone.get_back_color(kind="rgb")[0]
(back, green): drone.get_back_color(kind="rgb")[1]
(back, blue): drone.get_back_color(kind="rgb")[2]

Description​

Returns the hue, saturation, value, lightness, red, green, or blue value from either of the drone's bottom color sensors. The drone must be flat on a surface (not flying) for the color sensor to activate.

Parameters​


type: color sensor to retrieve color data from: front or back.
hsvl_rgb: hue, saturation, value, lightness, red, green, or blue value to be retrieved.

Returns​

HSVL/RGB value: HSVL or RGB value retrieved from front or back sensor.

Example​


Sensors (Barometer)​

get pressure in [units]​

Block​

Code​

drone. get_pressure()

Description​

This function returns barometer data in either pascals or millibars.
Note: 1 mbar = 100 Pa

Parameters​

units: Pascal or millibar.

Returns​

float pressure: float value in either Pa or mbar

Example​


get elevation in [units]​

Block​

Code​

drone. get_elevation()

Description​

Returns the estimated elevation data from the drone's barometer.

Parameters​

units: m (meter), km (kilometer), ft (feet), mi (miles).

Returns​

float elevation: float elevation value in units selected

Example​


Sensors (Temperature)​

get drone temperature in [units]​

Block​

Code​

drone. get_drone_temperature()

Description​

This block returns the current temperature of the drone in either Celsius or Fahrenheit.

Parameters​

units: Fahrenheit, Celsius, Kelvin

Returns​

float temperature: float value in degrees

Example​


Sensors (Battery)​

get battery​

Block​

Code​

drone. get_battery()

Description​

This function returns the current battery percentage of the drone battery.

Parameters​

None

Returns​

integer battery percentage: the battery percentage from 0 to 100

Example​

In this example, the program will check the drone's battery before takeoff and after landing.



In the example below, the program will check the drone's battery before takeoff and after the front flip. The difference of battery percentage will be larger in this example than the previous one.


Sensors (State)​

get [state] state​

Block​

Code​

modeFlight: drone.get_flight_state()
modeMovement: drone.get_movement_state()

Description​

Returns the current state of the drone.

Parameters​

state: type of state data to be retrieved: flight or movement.

Returns​

state: value of flight or movement state.

Example​


Colors​

load dataset​

Block​

Code​

drone. load_color_data()

Description​

Loads color data onto CoDrone EDU. The string inside the parameter is the name of your color set (name is set when creating the color set). predict_colors() block uses this color set to predict colors. To learn how to create a color set, visit our lesson on Color Sensors.

Parameters​

None

Returns​

None

Example​

To make this example work, your color set must be loaded into your Blockly workspace and code using the "load dataset" block. The "predict color" block will make a prediction of the color detected and return that color based on the color set that was loaded. Place the drone on different colored surfaces (red, yellow, or blue) to make the drone play a different note. Since this code runs on a "while True" loop, the loop will not stop running. To stop code from running, simply click the "Stop" button on the top-left side.


predict [type] color​

Block​

Code​

front: drone.predict_colors(drone.get_color_data())[0]

back: drone.predict_colors(drone.get_color_data())[1]

Description​

Predicts what color the color sensors are currently seeing (front or back).

Parameters​

sensor: the front or back sensor

Returns​

string predicted color: The color that's predicted based off of what the front or back sensor detects.

Example​

To make this example work, your color set must be loaded into your Blockly workspace and code using the "load dataset" block. The "predict color" block will make a prediction of the color detected and return that color based on the color set that was loaded. Place the drone on different colored surfaces (red, yellow, or blue) to make the drone play a different note. Since this code runs on a "while True" loop, the loop will not stop running. To stop code from running, simply click the "Stop" button on the top-left side.


Controller​

create new screen canvas​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_create_canvas()

Description​

Creates a canvas for drawing on the controller. This block is required for the other "draw" blocks to work and must be placed before the other "draw" blocks.

Parameters​

None

Returns​

None

Example​


draw line from x1: [x1], y1: [y1], x2: [x2], y2: [y2]​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_draw_line()

Description​

(x1,y1) \
\
\
\ (x2,y2)

Draws a line between points (x1, y1) and (x2, y2) on canvas created by "create new screen canvas".

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

Returns​

None

Example​


draw string [string] at x1: [x1], y1: [y1]​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_draw_string()

Description​

Draws a string from the given x1 and y1 positions on the canvas created by "create new screen canvas".

Parameters​

string: any string input
integer x1: starting x position

integer y1: starting y position

Returns​

None

Example​


draw rectangle from x1: [x1], y1: [y1], w: [w], h: [h], fill: [true/false]​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_draw_rectangle()

Description​

width
(x,y)|---------------|
| | height
|_______________|

Draws a rectangle on canvas created by "create new screen canvas", starting from point (x,y) and extends to a given height and width

Parameters​

integer x1: top left corner x coordinate
integer y1: top left corner y coordinate
integer w: width of rectangle
integer h: height of rectangle
boolean fill: optional parameter to fill in the rectangle or not. default value is False

Returns​

None

Example​


draw square from x1: [x1], y1: [y1], w: [w], fill: [true/false]​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_draw_square()

Description​

width
(x,y)|------|
| | width
|______|

Draws a square on canvas created by "create new screen canvas", starting from point (x,y) and will extend to the given width

Parameters​

integer x1: top left corner x coordinate
integer y1: top left corner y coordinate
integer w: width of square
boolean fill: optional parameter to fill in the square or not. default value is False

Returns​

None

Example​


draw point at x: [x], y: [y]​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_draw_point()

Description​

Draws a point on canvas created by "create new screen canvas", at point (x, y).

Parameters​

integer x: x coordinate
integer y: y coordinate

Returns​

None

Example​


draw canvas on screen​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_draw_canvas()

Description​

Draws custom canvas onto the controller screen. This block is placed after placing the desired "draw" blocks for the canvas (created by "create new screen canvas" block).

Parameters​

None

Returns​

None

Example​


clear controller screen​

warning

This function is currently unavailable for CoDrone EDU (JROTC ed.).

Block​

Code​

drone. controller_clear_screen()

Description​

Clears the controller screen.

Parameters​

None

Returns​

None

Example​


get [button] button state​

Block​

Code​

L1: drone.l1_pressed()
L2: drone.l2_pressed()
L1: drone.r1_pressed()
L1: drone.r2_pressed()
h: drone.h_pressed()
power: drone.power_pressed()
up arrow: drone.up_arrow_pressed()
left arrow: drone.left_arrow_pressed()
right arrow: drone.right_arrow_pressed()
down arrow: drone.down_arrow_pressed()
s: drone.s_pressed()
p: drone.p_pressed()

Description​

This command determines if the controller's desired button has been pressed or held down.

Parameters​

button: The controller button to retrieve data from.

Returns​

Boolean is pressed: True if the button is pressed or held. Otherwise the function will return False.

Example​


get [type] joystick [axis] axis​

Block​

Code​

(left, x): drone.get_left_joystick_x()
(left, y): drone.get_left_joystick_y()
(right, x): drone.get_right_joystick_x()
(right, y): drone.get_right_joystick_y()

Description​

This command gets the position of the desired, left or right, joystick's x or y position.

Parameters​


type: The controller joystick to retrieve data from.
axis: The controller joystick's axis.

Returns​

integer position: The position of the desired joystick on the desired axis

Example​


Lists​

create empty list​

Block​

Description​

Creates an empty list (a list with no items).

Parameters​

None

Returns​

list: An empty list []

Example​


create list with​

Block​

Description​

Creates a list based on given values attached to the "create list with" block. The list could contain values with different data types: strings, integers, floats.

Parameters​

Clicking on the gear icon will give you the option to manually add or reduce the number of items.

Returns​

list: A list with values attached onto the "create list with" block

Example​

In this example, a list variable was created with a value of the same data type. The test_list variable is assigned the value of [2.5,3.5,1]


In this example, a list variable was created with a value of different data types. The test_list variable is assigned the value of [2,True,"Hello"]


create list with item [item] repeated [number] times​

Block​

Description​

Creates a list with a given value, repeated for a given number of times. The both parameters could contain an operation like "1+1", as long as it returns a value—integer or float. The first parameter can be a string value as well.

Parameters​

integer/float/string  value repeated: value that will be repeated in the list
integer  repeats: the number of times the given value will be in the list.

Returns​

list: A list containing the given value repeated a given number of times.

Example​

In this example, instead of simply putting a number block, the first parameter contains an operation block that will return a number, which is 2. The second parameter contains a number block of 3. Printing test_list will result in [2,2,2].


length of​

Block​

Description​

Returns the length of the list, which is the number of items that are inside the list.

Parameters​

None

Returns​

int length: The length (number of items in the list) of the list.

Example​

After creating the list [1,2,3] and assigning it to the variable test_list, the console will print the length of test_list, which is 3 (three items in the list).


[list] is empty​

Block​

Description​

Returns a boolean value indicating if the list is empty or not (if the list has no items or not).

Parameters​

list list variable: a variable that's a list

Returns​

boolean  is empty: True if there are items in the list. Otherwise, returns False

Example​

In this example, test_list block is attached to the "create empty list" block. The console prints test_list, which is []. Then, the console prints the length of test_list, which is 0. Finally, the console prints whether or not test_list is empty, which is True. These 3 printing statements are ways to verify if the list is indeed empty or not. "is empty" is useful when applying if-statements to it.


In this example, the console prints whether or not test_list is empty, which is False. test_list indeed is not empty since there are items in it.


in list [list] find [occurrence] occurrence of item [item]​

Block​

Description​

Returns the position number (index) of the first/last occurrence of the given item in the given list variable.

Parameters​

list list variable: a variable that is a list
occurrence: the first or last occurrence of the item
integer/float/string  item: value of the item

Returns​

integer index: The position number of the item in the list

Example​

In this example, the test_list variable is assigned the value of [1,2,3]. The console prints 1 as the first occurrence of the item "2" in test_list since it is the second item in test_list.


in list [list] get/remove [occurrence]​

Block​

Description​

If choosing the "get" option, it returns the value of the item in a given index of the list. If choosing the "remove" option, it removes the item in a given index of the list. If choosing the "get and remove" option, it returns the value of the item and removes the item in a given index of the list.

Parameters​


list  list variable: A variable that is a list
command: option to whether to get, get and remove, or remove an item from the list
index: The position number of the item. (Some options require an integer input like the "#" and "# from end").

Returns​

integer/float/string  item: If choosing "get" or "get and remove", the value of the item is returned. If choosing "remove", returns None

Example​

In this example, the list variable test_list is created with a value of [100,5,2,3]. The list blocks use 0-based indexing, which means that the first item in a list is index 0, the second item in a list is index 1, and so on. If an index is negative, the last item of the list is index -1, the second-to-last item of the list is index -2, and so on. The first print statement outputs 100 since #0 indicates the first item of the list. The second print statement outputs 2 since #2 indicates the 3rd item of the list. The third print statement outputs 3 because, in Python, index #-1 indicates the last item of the list. The fourth print statement outputs 3 because #3 indicates 4th item of the list.



In the example below, the list variable test_list is created with a value of [100,5,2,3]. Then, in order, the items at index 3, index 2, and index 1 are removed from test_list. The console prints test_list, which outputs [100].



In the example below, the list variable test_list is created with a value of [100,5,2,3]. Then, in order, the items at index 3, index 2, and index 1 are printed on the console and removed from test_list. The console prints test_list, which outputs [100]. NOTE: "get and removed" option makes the block capable to be attached to a variable block as well.


in list [list] set/insert [occurence] as [value]​

Block​

Description​

If choosing the "set" option, the block will set an existing item at a given index to a given value. If choosing the "insert at" option, the block insert/add a new item a given value into a given index in the list.

Parameters​


list: list variable: a variable that is a list that you'll be modifying
command: option to whether set an existing item to a value or insert a new item into the list.
index: The position number of the item. (Some options require an integer input like the "#" and "# from end").
integer/float/string value: The value that the updated or new item will be.

Returns​

None

Example​

In this example, the list variable test_list is created with a value of [100,5,2,3]. On the next block, the item at index 0 (100) will be a set with a new value given by the value parameter. The new value is equal to the current value of the item at index 0 (represented by the "get" block inside) subtracted by 1 (99). Finally, printing test_list will result this output: [99,5,2,3].



In this example, the list variable test_list is created with a value of [100,5,2,3]. On the next block, a new item will be inserted/at index 4 with a value given by the value parameter. The new item's value is equal to the value of the item at index 0 (represented by the "get" block inside) subtracted by 1 (99). Finally, printing test_list will result this output: [100,5,2,3,99].


in list [list] get sub-list from [index1] to [index2]​

Block​

Description​

Returns a list that is a sub-list of a given list from a given starting index (inclusive) to a given ending index (non-inclusive). It does not modify the given list.

Parameters​

list list: a list block or a variable that is a list
starting index: The index on the list where the sub-list will start at. (Some options require an integer input like the "#" and "# from end").
ending index: The index on the list where the sub-list will end at, which is not included into the sub-list. (Some options require an integer input like the "#" and "# from end").

Returns​

list sub-list: The sub-list from the given list

Example​

In this example, the list variable test_list is created with a value of [23,2,100,5,4,3]. The list variable new_list is created with a value of [23,2,100]. This is because the "get sub-list" block gets a portion of test_list from index 0 (23) to index 3 (5), which is not included into the sub-list.


sort numeric/alphabetic ascending/descending​

Block​

Description​

Returns sorted list based on numerical/alphaetical order and ascending/descending order. This could be attached to a "print" block or a "set variable" block.

NOTE: alphabetical ordering, in programming, is done using the strings' letters' ASCII codes. The uppercase alphabet (A-Z) has ASCII values between 65 and 90, and the lowercase alphabet (a-z) has ASCII values between 97 and 122. This means lowercase alphabet has higher ASCII values than the uppercase alphabet.

Parameters​


order type: The way the list is sorted, by alphabetical or numerical order
order: ascending (A-z or smallest to biggest) or descending (z-A or biggest to smallest)

Returns​

list sorted list: a sorted list

Example​

In this example, a list variable test_list is created with a value of [5,2,3]. The console prints the output of the sorted list from test_list in ascending, numerical order [2,3,5].



In the example below, a list variable test_list is created with a value of ["Zebra","apple","Mouse"]. The console prints the sorted list from test_list in descending alphabetical order, which is ["apple", "Zebra", "Mouse"].



In the example below, a list variable test_list is created with a value of ["Zebra","apple","Mouse"]. The console prints the sorted list from test_list in descending alphabetical order (ignoring case), which is ["Zebra", "Mouse", "apple"]. Ignoring case essentially reads the uppercase letters as lowercase letters, so a lowercase "z" has a greater ASCII value than a lowercase "m" (and lowercase "m" greater than lowercase "a").


make [list from text/text from list] [text/list] with delimiter [value]​

Block​

Description​

If choosing the "list from text" option, the block internally splits the given text into parts based on the given delimiter and returns a list. For example, the string "12!23!5!" with a delimiter of "!" will be converted to [12,23,5]. If choosing the "text from list" option, the block internally joins the given list's items based on the given delimiter and returns a string. For example, the list [12,3,5] with a delimiter of "--" will be converted to "12--3--5".

Parameters​

string/list string/list variable: the variable, which is a list or text, that will be converted into a string or list.
string delimiter: a string of characters that will join a list's items or split the text's contents.

Returns​

string/list converted string or list: a list (or string) that is the result of the conversion of the given string (or list) with the given delimiter.

Example​

In this example, the string "14,2,1" will be converted into a list with the "," delimiter. The list variable test_list will be set to this conversion. The console will print test_list, which is [14,2,1].

In this example, the list variable test_list will have value of ["Hello","Hi","Greetings"]. The string variable test_string will have the value of "Hello--Hi--Greetings" since it's set to the value of the converted list of test_list with the -- delimiter.


reverse [list]​

Block​

Description​

Returns a list with the reversed order of the given list.

Parameters​

list list variable: the list variable that will its order reversed

Returns​

list reversed list: a reversed list of the given list

Example​

In this example, the list variable test_list has a value of [23,2,100,5,4,3]. Then, the list variable new_list is set to the value of a reversed list of test_list. The console will print [3,4,5,100,2,23].