线#

初始化线类#

使用以下构造函数创建线跟踪器:

line 构造函数使用一个参数:

范围

描述

端口

线路跟踪器连接到的 3 线端口,无论它是 大脑 上的端口,还是 3 线扩展器 上的端口。

必须先创建 Brain3-Wire Expander,然后才能使用线路类构造函数创建对象。

// Create the Brain.
brain Brain;
// Construct a Line Tracker "Line" with the line class.
line Line = line(Brain.ThreeWirePort.A);

当引用线类方法时,此“Line”对象将在整个 API 文档的所有后续示例中使用。

类方法#

反射率()#

reflectivity(percentUnits 单位) 命令返回线追踪器测量的反射率。线追踪器的反射率是根据传感器原始值估算的。反射率为 0% 表示原始值大于或等于 3000。反射率为 100% 表示原始值为 0。

参数

描述

单位

反射率的唯一有效单位是“百分比”。

返回: 一个双精度值,表示线跟踪器测量的反射率,范围为 0 - 100%。

// Get Line Tracker reflectivity in range of 0 - 100%.
double value = Line.reflectivity();

// Print the reflectivity of the Line Tracker to the
// Brain's screen.
Brain.Screen.print(value);

已更改()#

changed(callback) 命令注册一个回调函数,用于当线跟踪器的值发生变化时。

参数

描述

打回来

当线跟踪器的值发生变化时调用的回调函数。

**返回:**无。

// Define the lineChanged function with a void return type,
// showing it doesn't return a value.
void lineChanged() {
  // The Brain will print that the value of the Line Tracker
  // changed on the brain screen.
  Brain.Screen.print("Line Tracker value changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run lineChanged when the value of the Line Tracker changes.
  Line.changed(lineChanged);
}