Vision#
The Vision Sensor must be connected to your V5 Brain and configured in VEXcode V5 before it can be used.
Refer to these articles for more information about using the Vision Sensor.
Initializing the Vision Class#
A Vision Sensor is created by using the following constructor:
Vision(port, brightness, sigs)
This constructor uses three parameter:
Parameter |
Description |
---|---|
|
A valid Smart Port that the Vision Sensor is connected to. |
|
Optional. The brightness value for the Vision Sensor, from 1 - 100. |
|
Optional. The name of one or more Signature objects. |
# Create a new Signature "dark_blue" with the Colordesc class.
dark_blue = Signature(1, -3911, -3435, -3673,10879, 11421, 11150,2.5, 0)
# Create a new Vision Sensor "vision_1" with the Vision
# class, with the "dark_blue" Signature.
vision_1 = Vision(Ports.PORT1, 100, dark_blue)
This vision_1
AiVision object and dark_blue
Signature object will be used in all subsequent examples throughout this API documentation when referring to Vision class methods.
Class Methods#
take_snapshot()#
The take_snapshot(index, count)
method takes the current snapshot visible to the Vision Sensor and detects the objects of a given Signature or Code.
Before taking a snapshot you must configure signatures for the Vision Sensor to look for.
Parameters |
Description |
---|---|
index |
|
count |
Optional. The maximum number of objects to obtain. The default is 8. |
Returns: A tuple of detected objects or an empty tuple if nothing is available.
while True:
# Create a tuple named "darkblue_objects" of detected objects
# matching the "dark_blue" Signature.
darkblue_objects = vision_1.take_snapshot(dark_blue)
# Clear the screen/reset so that we can display
# new information.
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
# Print the amount of objects detected that matched
# the "dark_blue" Signature using the len command.
brain.screen.print("object count:", len(vision_objects))
# Wait 0.5 seconds before repeating the loop and
# taking a new snapshot.
wait(0.5, SECONDS)
largest_object()#
The largest_object()
method retrieves the largest object detected by the Vision Sensor in the latest snapshot.
Vision Object Properties |
Description |
---|---|
|
The unique ID of the object. |
|
The top left x position of the object. |
|
The top left y position of the object. |
|
The center x position of the object. |
|
The center y position 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. |
Returns: A Vision object or None if it does not exist.
while True:
# Create a tuple named "darkblue_objects" of detected objects
# matching the "dark_blue" Signature.
darkblue_objects = vision_1.take_snapshot(dark_blue)
# Clear the screen/reset so that we can display
# new information.
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
# Print the largest detected object's CenterX
# coordinate to the Brain's screen.
brain.screen.print("Center X: ", vision_1.largest_object.centerX)
# Wait 0.5 seconds before repeating the loop and
# taking a new snapshot.
wait(0.5, SECONDS)
installed()#
The installed()
method checks if the Vision Sensor is connected.
Returns: True
if the Vision Sensor is connected. False
if it is not.
timestamp()#
The timestamp()
method returns the timestamp of the last status packet received from the sensor.
Returns: The timestamp of the last status packet received from the sensor in milliseconds.