线#
初始化线类#
使用以下构造函数创建线跟踪器:
The line
constructor uses one parameter:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用线路类构造函数创建对象。
// Create the Brain.
brain Brain;
// Construct a Line Tracker "Line" with the line class.
line Line = line(Brain.ThreeWirePort.A);
This Line
object will be used in all subsequent examples throughout this API documentation when referring to line class methods.
类方法#
reflectivity()#
The reflectivity(percentUnits units)
command 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.
参数 |
描述 |
---|---|
单位 |
The only valid unit for reflectivity is |
返回: 一个双精度值,表示线跟踪器测量的反射率,范围为 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()#
The changed(callback)
command registers a callback function for when the value of the Line Tracker changes.
参数 |
描述 |
---|---|
打回来 |
当线跟踪器的值发生变化时调用的回调函数。 |
**返回:**无。
// 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);
}