Skip to main content

The Vision Sensor's Sensing Blocks

VEXcode IQ has Sensing blocks for the Vision Sensor. The first two you already used in the Play section to take a snapshot and to check if the object exists.

In the figure below, you see that the (Snapshot) block captured the GREENBOX snapshot. The object, GREENBOX, was identified in the snapshot and so the answer of whether it exists is TRUE.

Let's look at these other Sensing blocks and what their values tell us.

To the left a Take snapshot block set to GREENBOX is shown with an image of the snapshot shown below. To the right each of the Vision Sensor blocks is shown with the value it would report based on this snapshot. In order they read Object exists? True, Object count 1, Object center x 154, object center y 105, object width 140, object height 142.

  • The (Object count) block tells us how many GREENBOX objects are in the snapshot. Here, there is only 1 detected.
  • The center X value tells us whether the GREENBOX object is to the left or right of the robot's center point. Remember, the Vision Sensor is mounted in the middle of the front of the robot and so the snapshot's view is the robot's view.
    • If center X is greater than 157.5, the object is to the right of the robot's center point.
    • If center X is less than 157.5, the object is to the left of the robot's center point.
  • The center Y value tells us whether the GREENBOX is higher or lower than the robot's center point.
    • If center Y is greater than 105.5, the object is lower than the robot's center point.
    • If center Y is less than 105.5, the object is higher than the robot's center point.
  • The width and height values tell us how close the GREENBOX is to the robot.
    • The same-sized object will be larger in width and height as it gets closer to the robot.

How are the center X and center Y values calculated?

The values are calculated based on the coordinates within the snapshot. The width and height of the object are already calculated.

The Vision Sensor tracks the X and Y values of the upper left corner of the object. Below, those coordinates are (84, 34).

Snapshot from the Vision Sensor configuration showing a hand holding a green side of a cube, with an overlay on top. Above the overlay it reads Greenbox, and, in a red callout box, X 84, Y 34, W 140 and H 142.

The center X and center Y values can be calculated based off of the coordinates of the upper left corner (84, 34), and the width (W 140) and height (H 142) values provided.

The VEXcode Vision Sensor blocks are shown with the values they report based on the snapshot above. In order they read Object center x 154, Object center y 105, object width 140, and object height 142.

  • centerX = 140/2 + 84 = 154
    • centerX = half the width of the object added to its leftmost X coordinate
  • centerY = 142/2 + 34 = 105
    • centerY = half the height of the object added to its topmost Y coordinate