Línea#

Inicializando la clase de línea#

Un rastreador de línea se crea utilizando el siguiente constructor:

Line(port)

Este constructor utiliza un parámetro:

Parámetro

Descripción

port

El puerto de 3 cables al que está conectado el rastreador de línea, ya sea un puerto en el Cerebro o un Expandedor de 3 cables.

Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de la clase Line.

# Create the Brain.
brain = Brain()
# Construct a Line Tracker "line" with the Line class.
line = Line(brain.three_wire_port.a)

This line object will be used in all subsequent examples throughout this API documentation when referring to Line class methods.

Métodos de clase#

reflectivity()#

The reflectivity(units) method returns the reflectivity measured by the Line Tracker. The reflectivity of the Line Tracker is an estimation based on the raw value of the sensor. A reflectivity of 0% is a raw value of 3000 or greater. A reflectivity of 100% is a raw value of 0.

Parámetros

Descripción

unidades

Optional. The only valid unit for reflectivity is PERCENT.

Devuelve: La reflectividad medida por el Line Tracker como un valor en el rango 0 - 100%.

# Print the reflectivity of the Line Tracker to the
# Brain's screen.
brain.screen.print(line.reflectivity())

changed()#

The changed(callback, arg) method registers a callback function for when the value of the Line Tracker changes.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando cambie el valor del Rastreador de línea.

arg

Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada.

Devoluciones: Ninguna.

# Define a function line_changed().
def line_changed():
    # The Brain will print that the value detected by the
    # Line Tracker changed on the Brain's screen.
    brain.screen.print("Line Tracker changed")	
# Run line_changed when the value of the Line Tracker changes.
line.changed(line_changed)