Distance Sensing#

To make Distance Sensor blocks appear in VEXcode V5, a Distance Sensor must be configured in the Devices window.

For more information, refer to these articles:

Object Distance#

The Object Distance block is used to report the distance of the nearest object from the Distance Sensor.

  ([Distance10 v] object distance in [mm v])

The Object Distance block reports a range from 20mm to 2000mm.

Choose which Distance Sensor to use.

Image of a device used for measuring object distance with a display showing distance readings and settings.

Choose what units to report in: millimeters (mm) or inches.

Diagram illustrating various object distance units used in sensing applications with V5 Brain.

In this example, the Distance Sensor will report the current distance between it and the closest object.

  when started :: hat events
  print ([Distance10 v] object distance in [mm v]) on [Brain v] ◀ and set cursor to next row

Object Velocity#

The Object Velocity block is used to report the current velocity of an object in meters per second (m/s).

  ([Distance10 v] object velocity in m/s)

Choose which Distance Sensor to use.

Diagram of an object velocity device used for measuring object speed in robotics applications.

In this example, the Distance Sensor will report the current velocity of an object moving in front of it.

  when started :: hat events
  print ([Distance10 v] object velocity in m/s) on [Brain v] ◀ and set cursor to next row

Object Size Is#

The Object Size Is block is used to report if the Distance Sensor detects the specified object size.

  <[Distance10 v] object size is [small v] ?>

The Distance Sensor determines the size of the object detected (none, small, medium, large) based on the amount of light reflected and returned to the sensor.

The Object Size Is block reports True when the Distance Sensor detects the specified size.

The Object Size Is block reports False when the Distance Sensor doesn’t detect the specified size.

Choose which Distance Sensor to use.

Diagram illustrating the relationship between object size and distance as detected by a distance sensor.

Choose which size of the object you want the Object Sensor to check for.

  • small

  • medium

  • large

Diagram illustrating the various sizes of objects detected by a distance sensor in a robotics context.

In this example, if the Distance Sensor detects a small object, it will drive forward until the object is large.

  when started :: hat events
  [Check if the Distance Sensor sees a small object .]
  if <[Distance10 v] object size is [small v] ?> then
  [If a small object is detected, drive forward.]
  drive [forward v]
  [Wait until the small detected object is large.]
  wait until <[Distance10 v] object size is [large v] ? >
  [When the object size is large, stop driving.]
  stop driving
  end

Distance Sensor Found Object#

The Distance Sensor Found Object block is used to report if the Distance Sensor sees an object within its field of view.

  <[Distance10 v] found an object?>

The Distance Sensor Found Object block reports True when the Distance Sensor sees an object or surface within its field of view.

The Distance Sensor Found Object block reports False when the Distance Sensor does not detect an object or surface.

Choose which Distance Sensor to use.

Image showing a distance detection device with a range finder detecting an object's distance and size.

In this example, when the Distance Sensor detects an object, it will print a message to the Brain.

  when started :: hat events
  [Don't print the message until the Distance Sensor finds an object.]
  wait until <[Distance10 v] found an object?>
  print [Distance Sensor has detected an object.] on [Brain v] ◀ and set cursor to next row