vision#
Initializing the vision Class#
A Vision Sensor is created by using the following constuctors:
The vision
constructor creates a vision object in the specified port.
Parameter |
Description |
---|---|
|
A valid Smart Port that the Vision Sensor is connected to. |
|
The brightness setting for the Vision Sensor, from 0 - 255. |
|
The name of one or more signature objects. |
// 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.
Class Methods#
takeSnapshot()#
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.
Before taking a snapshot you must configure signatures for the Vision sensor to look for.
Parameters |
Description |
---|---|
index |
A signature, code, or signature id. |
count |
Optional. The maximum number of objects to obtain. The default is 8. |
Returns: None.
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);
}
largestObject#
The largestObject
property holds the largest object detected by the Vision sensor.
You can then access the following properties of a Vision Object.
Vision Object Properties |
Description |
---|---|
|
The unique ID of the object. |
|
The top left x coordinate of the object. |
|
The top left y coordinate of the object. |
|
The center x coordinate of the object. |
|
The center y coordinate of the object. |
|
The width of the object. |
|
The height of the object. |
|
The angle of the object. |
|
If the Vision camera detects the object or not. |
Returns: A Vision Object.
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);
}
objectCount#
The objectCount
property holds the number of objects detected in the latest snapshot taken by the Vision sensor.
Returns: The number of objects detected 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);
}
setLedMode()#
The setLedMode(mode)
method changes the mode of the LED on the Vision Sensor.
Parameters |
Description |
---|---|
mode |
The LED mode. Automatic mode will cause the LED color to be controlled by the Vision Sensor firmware. Manual mode allows the LED color to be controlled by the user program. |
Returns: True if the setting was successfully saved. False if it was not.
getLedMode()#
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.
setLedBrightness()#
The setLedBrightness(percent)
method changes the brightness of the LED on the Vision Sensor when LED is set to manual mode.
Parameters |
Description |
---|---|
percent |
A percentage of total brightness of the Vision Sensor LED when in manual mode. Values are 0 to 100. 0 = LED off. |
Returns: true
if the setting was successfully saved. false
if it was not.
getLedBrightness()#
The getLedBrightnesstLedMode()
method returns the brightness of the LED from the Vision Sensor.
Returns: A value between 0 and 100 that represents the current brightness of the Vision Sensor LED.
setLedColor()#
The setLedColor(red, green, blue)
method changes the color of the LED on the Vision Sensor when LED is set to manual mode.
Parameters |
Description |
---|---|
red |
A value from 0 - 255 that represents the intensity of the red color of the LED. |
green |
A value from 0 - 255 that represents the intensity of the green color of the LED. |
blue |
A value from 0 - 255 that represents the intensity of the blue color of the LED. |
Returns: true
if the setting was successfully saved.
getLedColor()#
The getLedColor(red, green, blue)
method returns the color of the LED from the Vision Sensor.
Parameters |
Description |
---|---|
red |
A reference to a value to store the intensity of the red color of the LED. |
green |
A reference to a value to store the intensity of the green color of the LED. |
blue |
A reference to a value to store the intensity of the blue color of the LED. |
Returns: true
if the values were successfully received. false
if they were not.
timestamp()#
The timestamp()
method requests the timestamp of the last received status packet from the Vision Sensor.
Returns: Timestamp of the last status packet as an unsigned 32-bit integer in milliseconds.
installed()#
The installed()
method checks if the Vision Sensor is connected.
Returns: true
if the Vision Sensor is connected. false
if it is not.