Distance Sensor#

Introduction#

The V5 Distance Sensor measures the distance to an object, its approximate size, and its approach speed. It operates over a range of 20 mm to 2,000 mm.

Below 200 mm, accuracy is approximately ±15 mm, and above 200 mm, accuracy improves to about 5%.

The Distance Sensor uses a Class 1 laser, ensuring detection is always directed straight ahead and is classroom-safe.

The VEX V5 Distance Sensor.

Below is a list of available Distance Sensor measurements:

object distance#

The object distance block returns the distance from the sensor to the nearest object.

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

Parameters

Description

device

Which Distance Sensor to use, configured in the Devices window.

units

The unit of measurement:

  • mm – millimeters, from 20 to 2000.
  • inches – 0.78 to 78.74

Example

Drive forward until an object is detected within 200 mm#
  when started
  [Drive forward until the object is within 50 mm away.]
  drive [forward v]
  wait until <([Distance1 v] object distance in [mm v]) [math_less_than v] [50]>
  stop driving

object velocity#

The object velocity block returns the relative speed of an object traveling toward or away from the Distance Sensor in m/s (meters per second).

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

Parameters

Description

device

Which Distance Sensor to use, configured in the Devices window.

object size is?#

The object size is? block returns whether the detected object is of a certain size. The size is determined by how much of the Distance Sensor’s view is taken up by the detected object.

  • True – The Distance Sensor is detecting an object of the specified size.

  • False – The Distance Sensor is not detecting an object of the specified size.

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

Parameters

Description

device

Which Distance Sensor to use, configured in the Devices window.

size

The size of the object to look for:

  • small
  • medium
  • large

Distance Sensor found object?#

The Distance Sensor found object? block returns whether the Distance Sensor is detecting an object.

  • True – The Distance Sensor is detecting an object.

  • False – The Distance Sensor is not detecting an object.

  <[Distance1 v] found an object?>

Parameters

Description

device

Which Distance Sensor to use, configured in the Devices window.

Example

Drive forward until an object is detected within 50 mm#
  when started
  [Drive forward until the object is within 50 mm away.]
  forever
  drive [forward v]
  if <[Distance1 v] found an object?> then
    if <([Distance1 v] object distance in [mm v]) [math_less_than v] [50]> then
    stop driving
    break