Distance#

Introduction#

The VEX IQ (2nd Gen) Distance Sensor offers methods for interacting with the VEX IQ (2nd Gen) sensors. These include tracking distances and velocities.

For the examples below, the configured Distance Sensors will be named Distance1, and will be used in all subsequent examples throughout this API documentation when referring to distance class methods.

Below is a list of all available methods:

Getters – Return object data from the Distance Sensor.

  • foundObject – (1st Gen) Returns whether an object is within range.

  • distance – (1st Gen) Returns the distance to the nearest object.

  • objectDistance – (2nd Gen) Returns the distance to the nearest object.

  • objectVelocity – (2nd Gen) Returns the speed of a detected object.

  • objectSize – (2nd Gen) Returns the estimated size of the detected object (small, medium, large).

  • isObjectDetected – (2nd Gen) Returns whether an object is within range (approx. 406 mm or 16 inches).

  • installed – Returns whether the Distance Sensor is connected to the Brain.

Constructors – Manually initialize the Distance Sensors.

  • sonar – Create a (1st Gen) Distance Sensor.

  • distance – Create a (2nd Gen) Distance Sensor.

Getters#

foundObject#

foundObject returns a Boolean indicating whether or not the Distance Sensor detects an object.

  • 1 – The Distance Sensor detects an object.

  • 0 – The Distance Sensor does not detect an object.

Note: This is a (1st Gen) Distance Sensor method.

Usage:
Distance1.foundObject()

Parameters

Description

This method has no parameters.

// Example coming soon

distance#

distance returns the current distance from the Distance Sensor and a detected object as a double.

Note: This is a (1st Gen) Distance Sensor method.

Usage:
Distance1.distance(units)

Parameters

Description

units

The unit that represents the distance:

  • mm – millimeters
  • inches
  • distanceUnits::cm – centimeters
// Example coming soon

objectDistance#

objectDistance returns the distance between the Distance Sensor and the nearest object as a double.

Note: This is a (2nd Gen) Distance Sensor method.

Usage:
Distance1.objectDistance(units)

Parameters

Description

units

The unit that represents the distance:

  • mm – millimeters
  • inches
  • distanceUnits::cm – centimeters
// Example coming soon

objectVelocity#

objectVelocity returns the velocity of a detected object measured in meters per second as a double. A positive value indicates the object is moving toward the Distance Sensor, while a negative value indicates it is moving away.

Note: This is a (2nd Gen) Distance Sensor method.

Usage:
Distance1.objectVelocity()

Parameters

Description

This method has no parameters.

// Example coming soon

objectSize#

objectSize returns an enumerated value (enum) representing the estimated size of the detected object based on how much of the Distance Sensor (2nd gen)’s field of view it occupies:

When printed directly, it shows the numeric value associated with that size:

Size

Numeric Value

none

0

small

1

medium

2

large

3

Note: This is a (2nd Gen) Distance Sensor method.

Usage:
Distance1.objectSize()

Parameters

Description

This method has no parameters.

// Example coming soon

isObjectDetected#

isObjectDetected returns a Boolean indicating whether the Distance Sensor detects an object.

  • 1 – The Distance Sensor detects an object.

  • 0 – The Distance Sensor does not detect an object.

Note: This is a (2nd Gen) Distance Sensor method.

Usage:
Distance1.isObjectDetected()

Parameters

Description

This method has no parameters.

// Example coming soon

installed#

installed returns if the Distance Sensor is connected.

  • 1 – The Distance Sensor is connected to the Brain.

  • 0 – The Distance Sensor is not connected to the Brain.

Usage:
Distance1.installed()

Parameters

Description

This method has no parameters.

// Example coming soon

Constructors#

sonar#

sonar creates an object of the sonar Class in the specified port.

Usage:
sonar Distance1 = sonar(port);

Parameter

Description

port

Which Smart Port that the Distance Sensor (1st Gen) is connected to as PORT followed by the port number, ranging from 1 to 12.

// Example coming soon

distance#

distance creates an object of the distance Class in the specified port.

Usage:
distance Distance1 = distance(port);

Parameter

Description

port

Which Smart Port that the Distance Sensor is connected to as PORT followed by the port number, ranging from 1 to 12.

// Example coming soon