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

The 3-Wire Port that the Line Tracker is connected to, whether it’s a port on the Brain, or a 3-Wire Expander.

A Brain or 3-Wire Expander must be created first before they can be used to create an object with the Line Class constructor.

# 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

units

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

callback

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)