距离#
介绍#
VEX IQ(第二代)距离传感器提供了与 VEX IQ(第二代)传感器交互的方法。这些方法包括跟踪距离和速度。
For the examples below, the configured Distance Sensors will be named Distance1
, and will be used in all subsequent examples throughout this API documentation when referring to distance
class methods.
以下是所有可用方法的列表:
Getters – 从距离传感器返回对象数据。
foundObject
– (1st Gen) Returns whether an object is within range.distance
– (1st Gen) Returns the distance to the nearest object.objectDistance
– (2nd Gen) Returns the distance to the nearest object.objectVelocity
– (2nd Gen) Returns the speed of a detected object.objectSize
– (2nd Gen) Returns the estimated size of the detected object (small, medium, large).isObjectDetected
– (2nd Gen) Returns whether an object is within range (approx. 406 mm or 16 inches).installed
– Returns whether the Distance Sensor is connected to the Brain.
构造函数——手动初始化距离传感器。
吸气剂#
foundObject#
foundObject
returns a Boolean indicating whether or not the Distance Sensor detects an object.
1
– The Distance Sensor detects an object.0
– The Distance Sensor does not detect an object.
**注意:**这是一种(第一代)距离传感器方法。
Usage:
Distance1.foundObject()
参数 |
描述 |
---|---|
该方法没有参数。 |
// Example coming soon
distance#
distance
returns the current distance from the Distance Sensor and a detected object as a double.
**注意:**这是一种(第一代)距离传感器方法。
Usage:
Distance1.distance(units)
参数 |
描述 |
---|---|
|
The unit that represents the distance:
|
// Example coming soon
objectDistance#
objectDistance
returns the distance between the Distance Sensor and the nearest object as a double.
**注意:**这是一种(第二代)距离传感器方法。
Usage:
Distance1.objectDistance(units)
参数 |
描述 |
---|---|
|
The unit that represents the distance:
|
// Example coming soon
objectVelocity#
objectVelocity
returns the velocity of a detected object measured in meters per second as a double. A positive value indicates the object is moving toward the Distance Sensor, while a negative value indicates it is moving away.
**注意:**这是一种(第二代)距离传感器方法。
Usage:
Distance1.objectVelocity()
参数 |
描述 |
---|---|
该方法没有参数。 |
// Example coming soon
objectSize#
objectSize
returns an enumerated value (enum) representing the estimated size of the detected object based on how much of the Distance Sensor (2nd gen)’s field of view it occupies:
直接打印时,它会显示与该尺寸相关的数值:
尺寸 |
数值 |
---|---|
|
0 |
|
1 |
|
2 |
|
3 |
**注意:**这是一种(第二代)距离传感器方法。
Usage:
Distance1.objectSize()
参数 |
描述 |
---|---|
该方法没有参数。 |
// Example coming soon
isObjectDetected#
isObjectDetected
returns a Boolean indicating whether the Distance Sensor detects an object.
1
– The Distance Sensor detects an object.0
– The Distance Sensor does not detect an object.
**注意:**这是一种(第二代)距离传感器方法。
Usage:
Distance1.isObjectDetected()
参数 |
描述 |
---|---|
该方法没有参数。 |
// Example coming soon
installed#
installed
returns if the Distance Sensor is connected.
1
– The Distance Sensor is connected to the Brain.0
– The Distance Sensor is not connected to the Brain.
Usage:
Distance1.installed()
参数 |
描述 |
---|---|
该方法没有参数。 |
// Example coming soon
构造函数#
sonar#
sonar
creates an object of the sonar Class in the specified port.
Usage:
sonar Distance1 = sonar(port);
范围 |
描述 |
---|---|
|
Which Smart Port that the Distance Sensor (1st Gen) is connected to as |
// Example coming soon
distance#
distance
creates an object of the distance Class in the specified port.
Usage:
distance Distance1 = distance(port);
范围 |
描述 |
---|---|
|
Which Smart Port that the Distance Sensor is connected to as |
// Example coming soon