想象#
初始化视觉类#
使用以下构造函数创建视觉传感器:
The vision
constructor creates a vision object in the specified port.
范围 |
描述 |
---|---|
|
视觉传感器连接到的有效 智能端口。 |
|
视觉传感器的亮度设置,范围从 0 到 255。 |
|
一个或多个 签名 对象的名称。 |
// Create a new Signature "darkBlue" with the signature class.
vision::signature darkBlue = vision::signature(1, -3911, -3435, -3673,10879, 11421, 11150,2.5, 0);
// Create a new Vision Sensor "Vision1" with the vision class.
vision Vision1 = vision(PORT1, 50, darkBlue);
This Vision1
vision object and darkBlue
signature object will be used in all subsequent examples throughout this API documentation when referring to vision class methods.
类方法#
拍摄快照()#
The takeSnapshot(index, count)
method takes the current snapshot visible to the Vision sensor and detects the objects of a given signature, code, or signature id.
在拍摄快照之前,您必须配置视觉传感器要查找的签名。
参数 |
描述 |
---|---|
指数 |
签名、代码或签名 ID。 |
数数 |
**可选。**要获取的对象的最大数量。默认值为 8。 |
**返回:**无。
while (true) {
// Take a snapshot to check for detected objects.
Vision1.takeSnapshot(darkBlue);
// Clear the screen/reset so that we can display
// new information.
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
// If objects were found, print the location.
if (Vision1.objects[0].exists) {
Brain.Screen.print("Center X: %d", Vision1.largestObject.centerX);
} else {
Brain.Screen.print("no object");
}
wait(0.5, seconds);
}
最大对象#
The largestObject
property holds the largest object detected by the Vision sensor.
然后,您可以访问视觉对象的以下属性。
视觉对象属性 |
描述 |
---|---|
|
对象的唯一 ID。 |
|
对象左上角的 x 坐标。 |
|
对象左上角的 y 坐标。 |
|
对象的中心 x 坐标。 |
|
对象的中心 y 坐标。 |
|
物体的宽度。 |
|
物体的高度。 |
|
物体的角度。 |
|
视觉相机是否检测到物体。 |
**返回:**一个视觉对象。
while (true) {
// Take a snapshot to check for detected objects.
Vision1.takeSnapshot(darkBlue);
// Clear the screen/reset so that we can display
// new information.
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
// If objects were found, print the location.
if (Vision1.objects[0].exists) {
Brain.Screen.print("Center X: %d", Vision1.largestObject.centerX);
} else {
Brain.Screen.print("no object");
}
wait(0.5, seconds);
}
对象数量#
The objectCount
property holds the number of objects detected in the latest snapshot taken by the Vision sensor.
**返回:**视觉传感器检测到的物体数量。
while (true) {
// Take a snapshot to check for detected objects.
Vision1.takeSnapshot(darkBlue);
// Clear the screen/reset so that we can display
// new information.
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
// Print how many objects were detected.
Brain.Screen.print("object count: %d", Vision1.objectCount);
wait(0.5, seconds);
}
设置LED模式()#
The setLedMode(mode)
method changes the mode of the LED on the Vision Sensor.
参数 |
描述 |
---|---|
模式 |
LED 模式。自动模式下,LED 颜色由视觉传感器固件控制。手动模式下,LED 颜色由用户程序控制。 |
返回: 如果设置保存成功,则返回 True。如果设置保存失败,则返回 False。
获取 LED 模式 ()#
The getLedMode()
method returns the mode of the LED from the Vision Sensor.
Returns: An ledMode
that represents the current mode of the Vision Sensor LED.
设置LED亮度()#
The setLedBrightness(percent)
method changes the brightness of the LED on the Vision Sensor when LED is set to manual mode.
参数 |
描述 |
---|---|
百分比 |
手动模式下视觉传感器 LED 总亮度的百分比。取值范围为 0 至 100。0 = LED 熄灭。 |
Returns: true
if the setting was successfully saved. false
if it was not.
获取LED亮度()#
The getLedBrightnesstLedMode()
method returns the brightness of the LED from the Vision Sensor.
返回: 一个介于 0 到 100 之间的值,表示视觉传感器 LED 的当前亮度。
设置LED颜色()#
The setLedColor(red, green, blue)
method changes the color of the LED on the Vision Sensor when LED is set to manual mode.
参数 |
描述 |
---|---|
红色的 |
0 - 255 之间的值,表示 LED 红色的强度。 |
绿色的 |
0 - 255 之间的值,表示 LED 绿色的强度。 |
蓝色的 |
0 - 255 之间的值,表示 LED 蓝色的强度。 |
Returns: true
if the setting was successfully saved.
获取 LED 颜色 ()#
The getLedColor(red, green, blue)
method returns the color of the LED from the Vision Sensor.
参数 |
描述 |
---|---|
红色的 |
用于存储 LED 红色强度的值的引用。 |
绿色的 |
用于存储 LED 绿色强度的值的引用。 |
蓝色的 |
用于存储 LED 蓝色强度的值的引用。 |
Returns: true
if the values were successfully received. false
if they were not.
时间戳()#
The timestamp()
method requests the timestamp of the last received status packet from the Vision Sensor.
**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。
安装()#
The installed()
method checks if the Vision Sensor is connected.
Returns: true
if the Vision Sensor is connected. false
if it is not.