Control#

Esperar#

The wait(time, units) command is used to wait for a specific amount of time before moving to the next command.

Este es un comando en espera y no permitirá que se ejecute ningún comando posterior hasta que el comando finalice.

Parámetros

Descripción

tiempo

Un entero positivo que representa la cantidad de segundos o milisegundos a esperar antes del próximo comando.

unidades

The units that the time will use: SECONDS or MSEC(Milliseconds).

Devoluciones: Ninguna.

def main():
    # Drive forward.
    drivetrain.drive(FORWARD)
    # Wait 2 seconds.
    wait(2, SECONDS)
    # Stop the Drivetrain.
    drivetrain.stop()

Para#

for value in expression_list:

for value in expression_list: is a loop that repeatedly executes commands for a number of iterations.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

valor

Cualquier entero o variable previamente establecida que informa un valor.

lista_de_expresiones

The range() function, list, or function that returns a list.

Devoluciones: Ninguna.

def main():
    # Do the following commands 5 times.
    for repeat_count in range(5):
        # Drive forward for 5 inches.
        drivetrain.drive_for(FORWARD, 5, INCHES)
        # Wait 1 second before repeating.
        wait(1, SECONDS)

Si#

if condition:
    # What happens if the condition is True.

The if condition statement is used to execute a block of commands if the condition evaluates as True.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

condición

La condición es cualquier declaración, expresión o variable booleana que se evalúa como verdadera o falsa.

Devoluciones: Ninguna.

def main():
    # Drive forward continuously.
    drivetrain.drive(FORWARD)

    # Continuously check the if statement every 5 Milliseconds.
    while True:
        wait(5, MSEC)

        # If the left bumper is pressed, turn right for 90 degrees.
        if left_bumper.pressed():
            brain.print("Bumper pressed!")

Si/Si no#

if condition:
    # What happens if the condition is True.
else:
    # What happens if the condition is False.

if/else es una declaración de control que ejecuta un bloque de comandos si la condición se evalúa como Verdadero, u otro bloque de comandos si una condición se evalúa como Falso.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

condición

La condición es cualquier declaración, expresión o variable booleana que se evalúa como verdadera o falsa.

Devoluciones: Ninguna.

def main():
    # Continuously check the if statement every 5 Milliseconds.
    while True:
        wait(5,MSEC)

        # If the distance sensor has found an object, drive forward.
        if distance.found_object(): 
            drivetrain.drive(FORWARD)

        # If the distance sensor hasn't found an object, turn to the right.    
        else:
            drivetrain.turn(RIGHT)

Si/Si/Si no#

if condition:
    # What happens if condition 1 is True, otherwise, check condition 2.
elif condition2:
    # What happens if condition 2 is True.
else
    # What happens if neither conditions are True.

The elif statement is a conditional that will check if its condition evaluates to True or False. It is possible to combine many conditions with the use of logical operators such as and, or, and not.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

condición

La condición es cualquier declaración, expresión o variable booleana que se evalúa como verdadera o falsa.

Devoluciones: Ninguna.

You can include as many elif statements in succession as necessary.

def main():
    # Continuously check the if statement every 5 Milliseconds.
    while True:
        wait(5,MSEC)

        # If the Down Eye Sensor detects the color green,
        # turn right for 90 degrees.
        if down_eye.detect(GREEN): 
            drivetrain.turn_for(RIGHT, 90, DEGREES)
        
        # If the Down Eye Sensor detects the color blue,
        # turn left for 90 degrees.
        elif down_eye.detect(BLUE):
            drivetrain.turn_for(LEFT, 90, DEGREES)

        # If the Down Eye Sensor doesn't detect green or blue,
        # drive forward.    
        else:
            drivetrain.drive(FORWARD)

Esperar hasta#

while not condition:

while not is a loop that repeatedly executes commands as long as the condition evaluates as True.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

condición

La condición es cualquier declaración, expresión o variable booleana que se evalúa como verdadera o falsa.

Devoluciones: Ninguna.

def main():
    # Continuously check if the VR Robot isn't within 50 MM
    # of an object in front of it every 5 Milliseconds.
    while not front_distance.get_distance(MM) < 50:
        wait(5, MSEC)

        # While the VR Robot is farther than 50 MM of an object,
        # drive forward.
        drivetrain.drive(FORWARD)

    # While the VR Robot is closer than 50 MM of an object, stop driving.
    drivetrain.stop()

Mientras#

while condition:

while is a loop that repeatedly executes commands as long as the condition evaluates as True.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

condición

La condición es cualquier declaración, expresión o variable booleana que se evalúa como verdadera o falsa.

Devoluciones: Ninguna.

def main():
    # Continuously check if the VR Robot is within 50 MM of an object
    # in front of it every 5 Milliseconds.
    while front_distance.get_distance(MM) > 50:
        wait(5, MSEC)

        # While the VR Robot is farther than 50 MM of an object,
        # drive forward.
        drivetrain.drive(FORWARD)

    # While the VR Robot is closer than 50 MM of an object, stop driving.
    drivetrain.stop()

Salir de un bucle#

The break command is used to exit a repeating loop immediately.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Devoluciones: Ninguna.

def main():
    # Drive forward.
    drivetrain.drive(FORWARD)

    # Continuously check the if statement every 5 Milliseconds.
    while True:
        wait(5,MSEC)

        # If the Front Eye Sensor detects a close object,
        # break out of the while loop.
        if front_eye.near_object():
            break

    # Stop driving if out of the while loop.    
    drivetrain.stop()

Detener el proyecto#

The stop_project() command is used to stop a running project.

Este es un comando en espera y evita que se ejecuten comandos posteriores.

Devoluciones: Ninguna.

def main():
    # Continuously check the if statement every 5 Milliseconds.
    while True:
        wait(5,MSEC)

        # Stop the project if the left bumper is pressed.
        if left_bumper.pressed(): 
            stop_project()
        
        # If the left bumper hasn't been pressed, drive forward.
        else:
            drivetrain.drive(FORWARD)