VEX Optical Sensor C API module

Contents

Files

file optical.h

Classes

struct pros::c::optical_rgb_s
struct pros::c::optical_raw_s
struct pros::c::optical_gesture_s
struct optical_rgb_s_t
struct optical_raw_s_t
struct optical_gesture_s_t

Functions

double optical_get_hue(uint8_t port)
Get the detected color hue.
double optical_get_saturation(uint8_t port)
Get the detected color saturation.
double optical_get_brightness(uint8_t port)
Get the detected color brightness.
int32_t optical_get_proximity(uint8_t port)
Get the detected proximity value.
int32_t optical_set_led_pwm(uint8_t port, uint8_t value)
Set the pwm value of the White LED.
int32_t optical_get_led_pwm(uint8_t port)
Get the pwm value of the White LED.
optical_rgb_s_t optical_get_rgb(uint8_t port)
Get the processed RGBC data from the sensor.
optical_raw_s_t optical_get_raw(uint8_t port)
Get the raw, unprocessed RGBC data from the sensor.
optical_direction_e_t optical_get_gesture(uint8_t port)
Get the most recent gesture data from the sensor.
optical_gesture_s_t optical_get_gesture_raw(uint8_t port)
Get the most recent raw gesture data from the sensor.
int32_t optical_enable_gesture(uint8_t port)
Enable gesture detection on the sensor.
int32_t optical_disable_gesture(uint8_t port)
Disable gesture detection on the sensor.
int32_t vision_clear_led(uint8_t port)
Clears the vision sensor LED color, reseting it back to its default behavior, displaying the most prominent object signature color.
vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32_t u_min, const int32_t u_max, const int32_t u_mean, const int32_t v_min, const int32_t v_max, const int32_t v_mean, const float range, const int32_t type)
Creates a signature from the vision sensor utility.
vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id1, const uint32_t sig_id2, const uint32_t sig_id3, const uint32_t sig_id4, const uint32_t sig_id5)
Creates a color code that represents a combination of the given signature IDs.
vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id)
Gets the nth largest object according to size_id.
vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id)
Gets the nth largest object of the given signature according to size_id.
vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code)
Gets the nth largest object of the given color code according to size_id.
int32_t vision_get_exposure(uint8_t port)
Gets the exposure parameter of the Vision Sensor.
int32_t vision_get_object_count(uint8_t port)
Gets the number of objects currently detected by the Vision Sensor.
int32_t vision_get_white_balance(uint8_t port)
Get the white balance parameter of the Vision Sensor.
int32_t vision_print_signature(const vision_signature_s_t sig)
Prints the contents of the signature as an initializer list to the terminal.
int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t object_count, vision_object_s_t*const object_arr)
Reads up to object_count object descriptors into object_arr.
int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count, vision_object_s_t*const object_arr)
Reads up to object_count object descriptors into object_arr.
int32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code, const uint32_t object_count, vision_object_s_t*const object_arr)
Reads up to object_count object descriptors into object_arr.
vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_id)
Gets the object detection signature with the given id number.
int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t*const signature_ptr)
Stores the supplied object detection signature onto the vision sensor.
int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable)
Enables/disables auto white-balancing on the Vision Sensor.
int32_t vision_set_exposure(uint8_t port, const uint8_t exposure)
Sets the exposure parameter of the Vision Sensor.
int32_t vision_set_led(uint8_t port, const int32_t rgb)
Sets the vision sensor LED color, overriding the automatic behavior.
int32_t vision_set_white_balance(uint8_t port, const int32_t rgb)
Sets the white balance parameter of the Vision Sensor.
int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point)
Sets the (0,0) coordinate for the Field of View.
int32_t vision_set_wifi_mode(uint8_t port, const uint8_t enable)
Sets the Wi-Fi mode of the Vision sensor.

Enums

enum optical_direction_e { NO_GESTURE = 0, UP = 1, DOWN = 2, RIGHT = 3, LEFT = 4, ERROR = PROS_ERR }

Function documentation

double optical_get_hue(uint8_t port)

Get the detected color hue.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns hue value if the operation was successful or PROS_ERR_F if the operation failed, setting errno.

This is not available if gestures are being detected. Hue has a range of 0 to 359.999

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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    printf("Hue value: %lf \n", optical_get_hue(OPTICAL_PORT));
    delay(20);
  }
}

double optical_get_saturation(uint8_t port)

Get the detected color saturation.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns saturation value if the operation was successful or PROS_ERR_F if the operation failed, setting errno.

This is not available if gestures are being detected. Saturation has a range of 0 to 1.0

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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    printf("Saturation value: %lf \n", optical_get_saturation(OPTICAL_PORT));
    delay(20);
  }
}

double optical_get_brightness(uint8_t port)

Get the detected color brightness.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns brightness value if the operation was successful or PROS_ERR_F if the operation failed, setting errno.

This is not available if gestures are being detected. Brightness has a range of 0 to 1.0

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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    printf("Brightness value: %lf \n", optical_get_brightness(OPTICAL_PORT));
    delay(20);
  }
}

int32_t optical_get_proximity(uint8_t port)

Get the detected proximity value.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns poximity value if the operation was successful or PROS_ERR if the operation failed, setting errno.

This is not available if gestures are being detected. proximity has a range of 0 to 255.

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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    printf("Proximity value: %d \n", optical_get_proximity(OPTICAL_PORT));
    delay(20);
  }
}

int32_t optical_set_led_pwm(uint8_t port, uint8_t value)

Set the pwm value of the White LED.

Parameters
port The V5 Optical Sensor port number from 1-21
value
Returns 1 if the operation is successful or PROS_ERR if the operation failed, setting errno.

value that ranges from 0 to 100

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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    optical_set_led_pwm(OPTICAL_PORT, 50);
    delay(20);
  }
}

int32_t optical_get_led_pwm(uint8_t port)

Get the pwm value of the White LED.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns LED pwm value that ranges from 0 to 100 if the operation was successful 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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    printf("PWM Value: %d \n", optical_get_led_pwm(OPTICAL_PORT));
    delay(20);
  }
}

optical_rgb_s_t optical_get_rgb(uint8_t port)

Get the processed RGBC data from the sensor.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns rgb value if the operation was successful or an optical_rgb_s_t with all fields set to 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 Optical Sensor

Example

#define OPTICAL_PORT 1

optical_rgb_s_t RGB_values;
void opcontrol() {
  while (true) {
    RGB_values = optical_get_rgb(OPTICAL_PORT);
    printf("Red value: %lf \n", RGB_values.red);
    printf("Green value: %lf \n", RGB_values.green);
    printf("Blue value: %lf \n", RGB_values.blue);
    printf("Brightness value: %lf \n", RGB_values.brightness);
    delay(20);
  }
}

optical_raw_s_t optical_get_raw(uint8_t port)

Get the raw, unprocessed RGBC data from the sensor.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns raw rgb value if the operation was successful or an optical_raw_s_t with all fields set to 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 Optical Sensor

Example

#define OPTICAL_PORT 1

optical_raw_s_t raw_values;
void opcontrol() {
while (true) {
  raw_values = optical_get_raw(OPTICAL_PORT);
  printf("Red value: %ld \n", raw_values.red);
  printf("Green value: %ld \n", raw_values.green);
  printf("Blue value: %ld \n", raw_values.blue);
  printf("Clear value: %ld \n", raw_values.clear);
  delay(20);
  }
}

optical_direction_e_t optical_get_gesture(uint8_t port)

Get the most recent gesture data from the sensor.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns gesture value if the operation was successful or PROS_ERR if the operation failed, setting errno.

Gestures will be cleared after 500mS

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 Optical Sensor

Example

#define OPTICAL_PORT 1

optical_direction_e_t gesture;
void opcontrol() {
  while (true) {
    gesture = optical_get_gesture(OPTICAL_PORT);
    printf("Gesture value: %d \n", gesture);
    delay(20);
  }
}

optical_gesture_s_t optical_get_gesture_raw(uint8_t port)

Get the most recent raw gesture data from the sensor.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns gesture value if the operation was successful or an optical_gesture_s_t with all fields set to 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 Optical Sensor

Example

#define OPTICAL_PORT 1

optical_gesture_s_t raw_gesture;
void opcontrol() {
  while (true) {
    raw_gesture = optical_get_gesture_raw(OPTICAL_PORT);
    printf("Up data: %u \n", raw_gesture.udata);
    printf("Down data: %u \n", raw_gesture.ddata);
    printf("Left data: %u \n", raw_gesture.ldata);
    printf("Right data: %u \n", raw_gesture.rdata);
    printf("Type: %u \n", raw_gesture.type);
    printf("Count: %u \n", raw_gesture.count);
    printf("Time: %lu \n", raw_gesture.time);
    delay(20);
  }
}

int32_t optical_enable_gesture(uint8_t port)

Enable gesture detection on the sensor.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns 1 if the operation is successful 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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    optical_enable_gesture(OPTICAL_PORT);
    delay(20);
  }
}

int32_t optical_disable_gesture(uint8_t port)

Disable gesture detection on the sensor.

Parameters
port The V5 Optical Sensor port number from 1-21
Returns 1 if the operation is successful 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 Optical Sensor

Example

#define OPTICAL_PORT 1

void opcontrol() {
  while (true) {
    optical_disable_gesture(OPTICAL_PORT);
    delay(20);
  }
}

int32_t vision_clear_led(uint8_t port)

Clears the vision sensor LED color, reseting it back to its default behavior, displaying the most prominent object signature color.

Parameters
port The V5 port number from 1-21
Returns 1 if the operation was successful 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 a vision sensor

Example

#define VISION_PORT 1
void initialize() {
  vision_clear_led(VISION_PORT);
}

vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32_t u_min, const int32_t u_max, const int32_t u_mean, const int32_t v_min, const int32_t v_max, const int32_t v_mean, const float range, const int32_t type)

Creates a signature from the vision sensor utility.

Parameters
id The signature ID
u_min Minimum value on U axis
u_max Maximum value on U axis
u_mean Mean value on U axis
v_min Minimum value on V axis
v_max Maximum value on V axis
v_mean Mean value on V axis
range Scale factor
type Signature type
Returns A vision_signature_s_t that can be set using vision_set_signature

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1

void opcontrol() {
// values acquired from the vision utility
vision_signature_s_t RED_SIG =
  vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0);
vision_set_signature(VISION_PORT, EXAMPLE_SIG, &RED_SIG);
while (true) {
  vision_signature_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);
  // Gets the largest object of the EXAMPLE_SIG signature
  printf("sig: %d", rtn.signature);
  // Prints "sig: 1"
  delay(2);
  }
}

vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id1, const uint32_t sig_id2, const uint32_t sig_id3, const uint32_t sig_id4, const uint32_t sig_id5)

Creates a color code that represents a combination of the given signature IDs.

Parameters
port The V5 port number from 1-21
sig_id1 The first signature id [1-7] to add to the color code
sig_id2 The second signature id [1-7] to add to the color code
sig_id3 The third signature id [1-7] to add to the color code
sig_id4 The fourth signature id [1-7] to add to the color code
sig_id5 The fifth signature id [1-7] to add to the color code
Returns A vision_color_code_t object containing the color code information.

If fewer than 5 signatures are to be a part of the color code, pass 0 for the additional function parameters.

This function uses the following values of errno when an error state is reached: EINVAL - Fewer than two signatures have been provided or one of the signatures is out of its [1-7] range (or 0 when omitted).

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1
#define OTHER_SIG 2

void opcontrol() {
  vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG);
}

vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id)

Gets the nth largest object according to size_id.

Parameters
port The V5 port number from 1-21
size_id The object to read from a list roughly ordered by object size (0 is the largest item, 1 is the second largest, etc.)
Returns The vision_object_s_t object corresponding to the given size id, or PROS_ERR if an error occurred.

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 vision sensor EDOM - size_id is greater than the number of available objects. EHOSTDOWN - Reading the vision sensor failed for an unknown reason.

Example

#define VISION_PORT 1

void opcontrol() {
while (true) {
  vision_object_s_t rtn = vision_get_by_size(VISION_PORT, 0);
  // Gets the largest object
  printf("sig: %d", rtn.signature);
  delay(2);
  }
}

vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id)

Gets the nth largest object of the given signature according to size_id.

Parameters
port The V5 port number from 1-21
size_id The object to read from a list roughly ordered by object size (0 is the largest item, 1 is the second largest, etc.)
sig_id
Returns The vision_object_s_t object corresponding to the given signature and size_id, or PROS_ERR if an error occurred.

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 vision sensor EINVAL - sig_id is outside the range [1-8] EDOM - size_id is greater than the number of available objects. EAGAIN - Reading the vision sensor failed for an unknown reason.

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1

void opcontrol() {
while (true) {
  vision_object_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);
  // Gets the largest object of the EXAMPLE_SIG signature
  printf("sig: %d", rtn.signature);
  // Prints "sig: 1"
  delay(2);
  }
}

vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code)

Gets the nth largest object of the given color code according to size_id.

Parameters
port The V5 port number from 1-21
size_id The object to read from a list roughly ordered by object size (0 is the largest item, 1 is the second largest, etc.)
color_code The vision_color_code_t for which an object will be returned
Returns The vision_object_s_t object corresponding to the given color code and size_id, or PROS_ERR if an error occurred.

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 vision sensor EAGAIN - Reading the vision sensor failed for an unknown reason.

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1
#define OTHER_SIG 2

void opcontrol() {
  vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG);
  while (true) {
    vision_object_s_t rtn = vision_get_by_code(VISION_PORT, 0, code1);
    // Gets the largest object
    printf("sig: %d", rtn.signature);
    delay(2);
  }
}

int32_t vision_get_exposure(uint8_t port)

Gets the exposure parameter of the Vision Sensor.

Parameters
port The V5 port number from 1-21
Returns The current exposure setting from [0,150], PROS_ERR if an error occurred

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 vision sensor

Example

#define VISION_PORT 1

void initialize() {
  if (vision_get_exposure(VISION_PORT) < 50)
  vision_set_exposure(VISION_PORT, 50);
}

int32_t vision_get_object_count(uint8_t port)

Gets the number of objects currently detected by the Vision Sensor.

Parameters
port The V5 port number from 1-21
Returns The number of objects detected on the specified vision sensor. Returns PROS_ERR if the port was invalid or an error occurred.

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 vision sensor

Example

#define VISION_PORT 1

void opcontrol() {
  while (true) {
    printf("Number of Objects Detected: %d\n", vision_get_object_count(VISION_PORT));
    delay(2);
  }
}

int32_t vision_get_white_balance(uint8_t port)

Get the white balance parameter of the Vision Sensor.

Parameters
port The V5 port number from 1-21
Returns The current RGB white balance setting of the sensor

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 vision sensor

Example

#define VISION_PORT 1
#define VISION_WHITE 0xff

void initialize() {
  if (vision_get_white_balance(VISION_PORT) != VISION_WHITE)
  vision_set_white_balance(VISION_PORT, VISION_WHITE);
}

int32_t vision_print_signature(const vision_signature_s_t sig)

Prints the contents of the signature as an initializer list to the terminal.

Parameters
sig The signature for which the contents will be printed
Returns 1 if no errors occured, PROS_ERR otherwise

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1

void opcontrol() {
  vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);
  vision_print_signature(sig);
}

int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t object_count, vision_object_s_t*const object_arr)

Reads up to object_count object descriptors into object_arr.

Parameters
port The V5 port number from 1-21
size_id The object to read from a list roughly ordered by object size (0 is the largest item, 1 is the second largest, etc.)
object_count The number of objects to read
object_arr out A pointer to copy the objects into
Returns The number of object signatures copied. This number will be less than object_count if there are fewer objects detected by the vision sensor. Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects than size_id were found. All objects in object_arr that were not found are given VISION_OBJECT_ERR_SIG as their signature.

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), or fewer than object_count number of objects were found. ENODEV - The port cannot be configured as a vision sensor EDOM - size_id is greater than the number of available objects.

Example

#define VISION_PORT 1
#define NUM_VISION_OBJECTS 4

void opcontrol() {
  vision_object_s_t object_arr[NUM_VISION_OBJECTS];
  while (true) {
    vision_read_by_size(VISION_PORT, 0, NUM_VISION_OBJECTS, object_arr);
    printf("sig: %d", object_arr[0].signature);
    // Prints the signature of the largest object found
    delay(2);
  }
}

int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count, vision_object_s_t*const object_arr)

Reads up to object_count object descriptors into object_arr.

Parameters
port The V5 port number from 1-21
size_id The object to read from a list roughly ordered by object size (0 is the largest item, 1 is the second largest, etc.)
sig_id
object_count The number of objects to read
object_arr out A pointer to copy the objects into
Returns The number of object signatures copied. This number will be less than object_count if there are fewer objects detected by the vision sensor. Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects than size_id were found. All objects in object_arr that were not found are given VISION_OBJECT_ERR_SIG as their signature.

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), or fewer than object_count number of objects were found. ENODEV - The port cannot be configured as a vision sensor EDOM - size_id is greater than the number of available objects.

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1
#define NUM_VISION_OBJECTS 4

void opcontrol() {
  vision_object_s_t object_arr[NUM_VISION_OBJECTS];
  while (true) {
    vision_read_by_sig(VISION_PORT, 0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr);
    printf("sig: %d", object_arr[0].signature);
    // Prints "sig: 1"
    delay(2);
  }
}

int32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code, const uint32_t object_count, vision_object_s_t*const object_arr)

Reads up to object_count object descriptors into object_arr.

Parameters
port The V5 port number from 1-21
size_id The object to read from a list roughly ordered by object size (0 is the largest item, 1 is the second largest, etc.)
color_code The vision_color_code_t for which objects will be returned
object_count The number of objects to read
object_arr out A pointer to copy the objects into
Returns The number of object signatures copied. This number will be less than object_count if there are fewer objects detected by the vision sensor. Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects than size_id were found. All objects in object_arr that were not found are given VISION_OBJECT_ERR_SIG as their signature.

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), or fewer than object_count number of objects were found. ENODEV - The port cannot be configured as a vision sensor

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1
#define OTHER_SIG 2
#define NUM_VISION_OBJECTS 4

void opcontrol() {
  vision_object_s_t object_arr[NUM_VISION_OBJECTS];
  vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG, 0, 0, 0);
  while (true) {
    vision_read_by_code(VISION_PORT, 0, code1, NUM_VISION_OBJECTS, object_arr);
    printf("sig: %d", object_arr[0].signature);
    // Prints the signature of the largest object found
    delay(2);
  }
}

vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_id)

Gets the object detection signature with the given id number.

Parameters
port The V5 port number from 1-21
signature_id The signature id to read
Returns A vision_signature_s_t containing information about the signature.

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1

void opcontrol() {
  vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);
  vision_print_signature(sig);
}

int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t*const signature_ptr)

Stores the supplied object detection signature onto the vision sensor.

Parameters
port The V5 port number from 1-21
signature_id The signature id to store into
signature_ptr in A pointer to the signature to save
Returns 1 if no errors occured, PROS_ERR otherwise

Example

#define VISION_PORT 1
#define EXAMPLE_SIG 1

void opcontrol() {
  vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);
  sig.range = 10.0;
  vision_set_signature(VISION_PORT, EXAMPLE_SIG, &sig);
}

int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable)

Enables/disables auto white-balancing on the Vision Sensor.

Parameters
port The V5 port number from 1-21
enable
Returns 1 if the operation was successful 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 a vision sensor EINVAL - enable was not 0 or 1

Example

#define VISION_PORT 1

void initialize() {
  vision_set_auto_white_balance(VISION_PORT, true);
}

int32_t vision_set_exposure(uint8_t port, const uint8_t exposure)

Sets the exposure parameter of the Vision Sensor.

Parameters
port The V5 port number from 1-21
exposure
Returns 1 if the operation was successful 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 a vision sensor

Example

#define VISION_PORT 1

void initialize() {
  if (vision_get_exposure(VISION_PORT) < 50)
  vision_set_exposure(VISION_PORT, 50);
}

int32_t vision_set_led(uint8_t port, const int32_t rgb)

Sets the vision sensor LED color, overriding the automatic behavior.

Parameters
port The V5 port number from 1-21
rgb An RGB code to set the LED to
Returns 1 if the operation was successful 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 a vision sensor

Example

#define VISION_PORT 1

void initialize() {
  vision_set_led(VISION_PORT, COLOR_BLANCHED_ALMOND);
}

int32_t vision_set_white_balance(uint8_t port, const int32_t rgb)

Sets the white balance parameter of the Vision Sensor.

Parameters
port The V5 port number from 1-21
rgb The new RGB white balance setting of the sensor
Returns 1 if the operation was successful 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 a vision sensor

Example

#define VISION_PORT 1
#define VISION_WHITE 0xff

void initialize() {
  vision_set_white_balance(VISION_PORT, VISION_WHITE);
}

int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point)

Sets the (0,0) coordinate for the Field of View.

Parameters
port The V5 port number from 1-21
zero_point One of vision_zero_e_t to set the (0,0) coordinate for the FOV
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This will affect the coordinates returned for each request for a vision_object_s_t from the sensor, so it is recommended that this function only be used to configure the sensor at the beginning of its use.

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 vision sensor

Example

#define VISION_PORT 1

void initialize() {
  vision_set_zero_point(VISION_PORT, E_VISION_ZERO_CENTER);
}

int32_t vision_set_wifi_mode(uint8_t port, const uint8_t enable)

Sets the Wi-Fi mode of the Vision sensor.

Parameters
port The V5 port number from 1-21
enable Disable Wi-Fi on the Vision sensor if 0, enable otherwise (e.g. 1)
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This functions uses the following values of errno when an error state is reached: ENXIO - The given port is not within the range of V5 ports (1-21) EACCESS - Anothe resources is currently trying to access the port

Example

#define VISION_PORT 1

void initialize() {
  vision_set_wifi_mode(VISION_PORT, 0);
}

Enum documentation

enum optical_direction_e

Enumerators
NO_GESTURE

UP

The direction indicating an upward gesture.

DOWN

The direction indicating a downward gesture.

RIGHT

The direction indicating a rightward gesture.

LEFT

The direction indicating a leftward gesture.

ERROR