AI Vision Sensor C API module
Classes
- struct aivision_color_s_t
- This structure contains the parameters used by the AI Vision Sensor to define a color.
- struct aivision_code_s_t
- This structure contains the parameters used by the AI Vision sensor to define a code.
- struct aivision_object_color_s_t
- This structure contains a detected color.
- struct aivision_object_tag_s_t
- This structure contains a detected tag.
- struct aivision_object_s_t
- This structure contains one of aivision_detected_type_e_t, stored in type.
Functions
- struct __attribute__((packed)) aivision_object_color_s
Functions
- int32_t aivision_reset(uint8_t port)
- Resets the AI Vision sensor to the initial state.
- int32_t aivision_get_enabled_detection_types(uint8_t port)
- Returns a bitfield of the types of objects the AI vision sensor is currently searching for, as per aivision_mode_type_e_t.
- int32_t aivision_set_enabled_detection_types(uint8_t port, uint8_t bits, uint8_t bitmask)
- Modifies the types of objects the AI vision sensor is currently searching for, as per aivision_mode_type_e_t.
- int32_t aivision_enable_detection_types(uint8_t port, uint8_t types_mask)
- Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
- int32_t aivision_disable_detection_types(uint8_t port, uint8_t types_mask)
- Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
- int32_t aivision_set_tag_family_override(uint8_t port, aivision_tag_family_e_t family)
- Sets the april tag family to detect.
- int32_t aivision_set_tag_family(uint8_t port, aivision_tag_family_e_t family)
- Sets the april tag family to detect.
-
int32_t aivision_set_color(uint8_t port,
const aivision_
color_ s_ t* color) - Set a color configuration that the AI vision sensor will detect.
-
aivision_
color_ s_ t aivision_get_color(uint8_t port, uint32_t id) - Get a color configuration that the AI vision sensor has stored.
- int32_t aivision_get_class_name(uint8_t port, int32_t id, uint8_t* class_name)
- Get a class name that the AI vision sensor has stored.
- int32_t aivision_set_usb_bounding_box_overlay(uint8_t port, bool enabled)
- Enable or disable the bounding box overlay the AI Vision sensor outputs on the USB port.
- int32_t aivision_start_awb(uint8_t port)
- Runs auto white balance to adjust to different lighting conditions.
-
aivision_
code_ s_ t aivision_get_code(uint8_t port, uint32_t id) - Get a code that the AI vision sensor has stored.
-
int32_t aivision_set_code(uint8_t port,
const aivision_
code_ s_ t* wcode) - Set a code that the AI vision sensor will detect for.
- int32_t aivision_get_object_count(uint8_t port)
- Get the current number of objects detected by the AI vision sensor.
-
aivision_
object_ s_ t aivision_get_object(uint8_t port, uint32_t object_index) - Get the detected object at a given object index; there are aivision_get_object_count objects and the index starts from 0.
- double aivision_get_temperature(uint8_t port)
- Get the current reported temperature of the AI Vision sensor in degrees Celsius.
- 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.
- double optical_get_integration_time(uint8_t port)
- Get integration time (update rate) of the optical sensor in milliseconds, with minimum time being.
- int32_t optical_set_integration_time(uint8_t port, double time)
- Set integration time (update rate) of the optical sensor in milliseconds.
- 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.
Macros
Parameters given by VEX
- #define AIVISION_MAX_OBJECT_COUNT
- #define AIVISION_MAX_CLASSNAME_COUNT
- #define AIVISION_MODE_TAG_SET_BIT
Enums
- enum aivision_detected_type_e_t { E_AIVISION_DETECTED_COLOR = (1 << 0), E_AIVISION_DETECTED_CODE = (1 << 1), E_AIVISION_DETECTED_OBJECT = (1 << 2), E_AIVISION_DETECTED_TAG = (1 << 3) }
- This enumeration defines what kind of object is stored inside the union in aivision_object_s.
- enum aivision_mode_type_e_t { E_AIVISION_MODE_TAGS = (1 << 0), E_AIVISION_MODE_COLORS = (1 << 1), E_AIVISION_MODE_OBJECTS = (1 << 2), E_AIVISION_MODE_COLOR_MERGE = (1 << 4), E_AIVISION_MODE_ALL = (1 << 0) | (1 << 1) | (1 << 2) }
- This enumeration defines what kinds of objects the ai vision sensor will scan for: tags (april tags), colors (user defined colors), and objects (game elements), and all (all objects)
- enum aivision_tag_family_e_t { TAG_CIRCLE_21H7 = 0, TAG_16H5 = 1, TAG_25H9 = 2, TAG_61H11 = 3 }
- This enumeration corresponds to a family of AprilTags.
Variables
Function documentation
struct __attribute__((packed)) aivision_object_color_s
#include <pros/ai_vision.h>
int32_t aivision_reset(uint8_t port)
#include <pros/ai_vision.h>
Resets the AI Vision sensor to the initial state.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
Returns | PROS_SUCCESS 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 AIVISION_PORT 1 void initialize() { aivision_reset(AIVISION_PORT); }
int32_t aivision_get_enabled_detection_types(uint8_t port)
#include <pros/ai_vision.h>
Returns a bitfield of the types of objects the AI vision sensor is currently searching for, as per aivision_mode_type_e_t.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
Returns | the bitfield 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 AIVISION_PORT 1 void initialize() { aivision_get_enabled_detection_types(AIVISION_PORT); }
int32_t aivision_set_enabled_detection_types(uint8_t port,
uint8_t bits,
uint8_t bitmask)
#include <pros/ai_vision.h>
Modifies the types of objects the AI vision sensor is currently searching for, as per aivision_mode_type_e_t.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
bits | the bits to set |
bitmask | the bitmask to apply |
Returns | PROS_SUCCESS 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 aivision_set_enabled_detection_types(1, 0b010, 0b101) would disable the detection of tags and objects, and leave the setting of colors alone.
int32_t aivision_enable_detection_types(uint8_t port,
uint8_t types_mask)
#include <pros/ai_vision.h>
Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
types_mask | The types to enable |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Enabling any given type of object will not disable the detection of other objects. This must be done explicitly.
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 AIVISION_PORT 1 void initialize() { // start or continue looking for AI model objects aivision_enable_detection_types(AIVISION_PORT, aivision_mode_type_e_t::E_AIVISION_MODE_OBJECTS); }
int32_t aivision_disable_detection_types(uint8_t port,
uint8_t types_mask)
#include <pros/ai_vision.h>
Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
types_mask | The types to enable |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Disabling any given type of object will not affect the detection of other objects.
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 AIVISION_PORT 1 void initialize() { // stop looking for AI model objects (competition elements, for example) aivision_disable_detection_types(AIVISION_PORT, aivision_mode_type_e_t::E_AIVISION_MODE_OBJECTS); }
int32_t aivision_set_tag_family_override(uint8_t port,
aivision_tag_family_e_t family)
#include <pros/ai_vision.h>
Sets the april tag family to detect.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
family | the tag family to configure the AI Vision sensor to detect |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Use this function will override the enabled apriltag detection family.
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
int32_t aivision_set_tag_family(uint8_t port,
aivision_tag_family_e_t family)
#include <pros/ai_vision.h>
Sets the april tag family to detect.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
family | the tag family to configure the AI Vision sensor to detect |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Use this function will allow multiple apriltags to be detected.
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
int32_t aivision_set_color(uint8_t port,
const aivision_ color_ s_ t* color)
#include <pros/ai_vision.h>
Set a color configuration that the AI vision sensor will detect.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
color | the color to configure the AI Vision sensor to detect |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno |
The color detection type must be separately enabled. If a color with the same ID already is stored in the sensor, it will be overwritten.
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
aivision_ color_ s_ t aivision_get_color(uint8_t port,
uint32_t id)
#include <pros/ai_vision.h>
Get a color configuration that the AI vision sensor has stored.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
id | the id of color from 1-7 |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno |
If you attempt to get a color configuration that has not been previously used, the behavior is not defined.
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
int32_t aivision_get_class_name(uint8_t port,
int32_t id,
uint8_t* class_name)
#include <pros/ai_vision.h>
Get a class name that the AI vision sensor has stored.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
id | the id of the class name from 0-(AIVISION_MAX_CLASSNAME_COUNT - 1) |
class_name | a string of length >=20 to store the classname. |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno |
The AI Vision sensor may not correctly report classnames for the first several hundred milliseconds of being plugged in. By passing in -1 for the id, the function will return the number of class names the AI vision sensor reports. For other values of id, the function return value is undefined
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
int32_t aivision_set_usb_bounding_box_overlay(uint8_t port,
bool enabled)
#include <pros/ai_vision.h>
Enable or disable the bounding box overlay the AI Vision sensor outputs on the USB port.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
enabled | if the overlay is enabled or disabled |
Returns | PROS_SUCCESS 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
int32_t aivision_start_awb(uint8_t port)
#include <pros/ai_vision.h>
Runs auto white balance to adjust to different lighting conditions.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
Returns | PROS_SUCCESS 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
aivision_ code_ s_ t aivision_get_code(uint8_t port,
uint32_t id)
#include <pros/ai_vision.h>
Get a code that the AI vision sensor has stored.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
id | The id from 1-5 |
Returns | the code, or a struct with an invalid ID 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
int32_t aivision_set_code(uint8_t port,
const aivision_ code_ s_ t* wcode)
#include <pros/ai_vision.h>
Set a code that the AI vision sensor will detect for.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
wcode | |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno |
The id of the code is stored in the aivision_
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
int32_t aivision_get_object_count(uint8_t port)
#include <pros/ai_vision.h>
Get the current number of objects detected by the AI vision sensor.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
Returns | the number of objects 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
aivision_ object_ s_ t aivision_get_object(uint8_t port,
uint32_t object_index)
#include <pros/ai_vision.h>
Get the detected object at a given object index; there are aivision_get_object_count objects and the index starts from 0.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
object_index | the object index |
Returns | the detected object if the operation was successful or an invalid object type 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
double aivision_get_temperature(uint8_t port)
#include <pros/ai_vision.h>
Get the current reported temperature of the AI Vision sensor in degrees Celsius.
Parameters | |
---|---|
port | The V5 port number from 1-21 |
Returns | the temperature if the operation was successful or PROS_ERR_F 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
double optical_get_hue(uint8_t port)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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_ |
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)
#include <pros/optical.h>
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_ |
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)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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_ |
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)
#include <pros/optical.h>
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)
#include <pros/optical.h>
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); } }
double optical_get_integration_time(uint8_t port)
#include <pros/optical.h>
Get integration time (update rate) of the optical sensor in milliseconds, with minimum time being.
Parameters | |
---|---|
port | The V5 Optical Sensor port number from 1-21 |
Returns | Integration time in milliseconds if the operation is successful or PROS_ERR_F 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
int32_t optical_set_integration_time(uint8_t port,
double time)
#include <pros/optical.h>
Set integration time (update rate) of the optical sensor in milliseconds.
Parameters | |
---|---|
port | The V5 Optical Sensor port number from 1-21 |
time | The desired integration time in milliseconds |
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
int32_t vision_clear_led(uint8_t port)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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_ |
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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_ |
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)
#include <pros/vision.h>
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_ |
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)
#include <pros/vision.h>
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_ |
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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_ |
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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)
#include <pros/vision.h>
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_
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)
#include <pros/vision.h>
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 aivision_detected_type_e_t
#include <pros/ai_vision.h>
This enumeration defines what kind of object is stored inside the union in aivision_object_s.
enum aivision_mode_type_e_t
#include <pros/ai_vision.h>
This enumeration defines what kinds of objects the ai vision sensor will scan for: tags (april tags), colors (user defined colors), and objects (game elements), and all (all objects)
enum aivision_tag_family_e_t
#include <pros/ai_vision.h>
This enumeration corresponds to a family of AprilTags.
Variable documentation
aivision_object_s_t
#include <pros/ai_vision.h>
Define documentation
#define AIVISION_MAX_OBJECT_COUNT
#include <pros/ai_vision.h>
#define AIVISION_MAX_CLASSNAME_COUNT
#include <pros/ai_vision.h>
#define AIVISION_MODE_TAG_SET_BIT
#include <pros/ai_vision.h>