VEX Distance Sensor C++ API module

Contents

Files

file distance.hpp

Classes

class pros::v5::Distance

Functions

Distance(const std::uint8_t port)
Creates a Distance Sensor object for the given port.
Distance(const Device& device)
std::int32_t get() virtual
Get the currently measured distance from the sensor in mm.
std::int32_t get_distance() virtual
Get the currently measured distance from the sensor in mm.
static std::vector<Distance> get_all_devices()
Gets all distance sensors.
std::int32_t get_confidence() virtual
Get the confidence in the distance reading.
std::int32_t get_object_size() virtual
Get the current guess at relative object size.
double get_object_velocity() virtual
Get the object velocity in m/s.

Function documentation

Distance(const std::uint8_t port)

Creates a Distance Sensor object for the given port.

Parameters
port The V5 port number from 1-21

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a Distance Sensor

Example

#define DISTANCE_PORT 1

void opcontrol() {
  Distance distance(DISTANCE_PORT);
}

Distance(const Device& device)

std::int32_t get() virtual

Get the currently measured distance from the sensor in mm.

Returns The distance value or PROS_ERR if the operation failed, setting errno. Will return 9999 if the sensor can not detect an object.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Distance Sensor

Example

 #define DISTANCE_PORT 1

 void opcontrol() {
Distance distance(DISTANCE_PORT);
   while (true) {
     printf("Distance confidence: %d\n", distance.get());
     delay(20);
   }
 }

std::int32_t get_distance() virtual

Get the currently measured distance from the sensor in mm.

Returns The distance value or PROS_ERR if the operation failed, setting errno. Will return 9999 if the sensor can not detect an object.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Distance Sensor

Example

 #define DISTANCE_PORT 1

 void opcontrol() {
Distance distance(DISTANCE_PORT);
   while (true) {
     printf("Distance confidence: %d\n", distance.get_distance());
     delay(20);
   }
 }

static std::vector<Distance> get_all_devices()

Gets all distance sensors.

Returns A vector of Distance sensor objects.

Example

void opcontrol() {
  std::vector<Distance> distance_all = pros::Distance::get_all_devices();  // All distance sensors that are
connected
}

std::int32_t get_confidence() virtual

Get the confidence in the distance reading.

Returns The confidence value or PROS_ERR if the operation failed, setting errno.

This is a value that has a range of 0 to 63. 63 means high confidence, lower values imply less confidence. Confidence is only available when distance is > 200mm.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Distance Sensor

Example

 #define DISTANCE_PORT 1

 void opcontrol() {
Distance distance(DISTANCE_PORT);
   while (true) {
     printf("Distance confidence: %d\n", distance.get_confidence());
     delay(20);
   }
 }

std::int32_t get_object_size() virtual

Get the current guess at relative object size.

Returns The size value or PROS_ERR if the operation failed, setting errno. Will return -1 if the sensor is not able to determine object size.

This is a value that has a range of 0 to 400. A 18" x 30" grey card will return a value of approximately 75 in typical room lighting.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Distance Sensor

Example

 #define DISTANCE_PORT 1

 void opcontrol() {
Distance distance(DISTANCE_PORT);
   while (true) {
     printf("Distance confidence: %d\n", distance.get_object_size());
     delay(20);
   }
 }

double get_object_velocity() virtual

Get the object velocity in m/s.

Returns The velocity value or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Distance Sensor

Example

void opcontrol() {
 Distance distance(DISTANCE_PORT);
  while (true) {
    printf("Distance Object velocity: %f\n", distance.get_object_velocity());
    delay(20);
  }
}