线#
初始化线类#
使用以下构造函数创建线跟踪器:
Line(port)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用 Line Class 构造函数创建对象。
# 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.
类方法#
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.
参数 |
描述 |
---|---|
单位 |
Optional. The only valid unit for reflectivity is |
**返回:**线跟踪器测量的反射率,范围为 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.
参数 |
描述 |
---|---|
打回来 |
当线跟踪器的值改变时调用的回调函数。 |
arg |
**可选。**传递给回调函数的参数元组。 |
**返回:**无。
# 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)