AI Vision Sensor C++ API module
Classes
- class pros::v5::AIVision
Functions
- AIVision(const std::uint8_t port) explicit
- Create a AI Vision Sensor object on the given port.
- AIVision(const Device& device)
- static std::vector<AIVision> get_all_devices()
- Gets all vision sensors.
- static bool is_type(const Object& object, AivisionDetectType type)
- Check if the dected type is the same as the given type.
- int32_t reset()
- Resets the AI Vision sensor to the initial state.
- int32_t get_enabled_detection_types()
- Returns a bitfield of the types of objects the AI vision sensor is currently searching for, as per AivisionModeType.
- int32_t enable_detection_types(AivisionModeType types_mask)
- Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
-
template<class... Flags>int32_t enable_detection_types(Flags... flags)
- Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
- int32_t disable_detection_types(AivisionModeType types_mask)
- Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
-
template<class... Flags>int32_t disable_detection_types(Flags... flags)
- Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
- int32_t set_tag_family(AivisionTagFamily family, bool override = false)
- Sets the april tag family to detect.
- int32_t set_color(const Color& color)
- Set a color configuration that the AI vision sensor will detect.
- AIVision::Color get_color(uint32_t id)
- Get a color configuration that the AI vision sensor has stored.
- uint32_t set_code(const Code& code)
- Set a code that the AI vision sensor will detect for.
- AIVision::Code get_code(uint32_t id)
- Get a code that the AI vision sensor has stored.
- int32_t start_awb()
- Runs auto white balance to adjust to different lighting conditions.
- int32_t get_class_name(int32_t id, char* class_name)
- Get a class name that the AI vision sensor has stored.
- std::optional<std::string> get_class_name(int32_t id)
- Get a class name that the AI vision sensor has stored.
- int32_t get_object_count()
- Get the current number of objects detected by the AI vision sensor.
- Object get_object(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.
- std::vector<Object> get_all_objects()
- Get all detected objects in a vector.
Enums
- enum class AivisionDetectType: uint8_t { color = (1 << 0), code = (1 << 1), object = (1 << 2), tag = (1 << 3) }
- Enum class for describing detection type of objects detected by the AI Vision Sensor.
- enum class AivisionModeType: uint8_t { tags = (1 << 0), colors = (1 << 1), objects = (1 << 2), color_merge = (1 << 4), all = (1 << 0) | (1 << 1) | (1 << 2) }
- Enum class for enabling/disabling detection types of AI Vision Sensor.
- enum class AivisionTagFamily { tag_21H7 = 0, tag_16H5 = 1, tag_25H9 = 2, tag_61H11 = 3 }
- Enum class for describing family of apriltags to detect.
Typedefs
-
using Color = aivision_
color_ s_ t -
using Code = aivision_
code_ s_ t -
using Object = aivision_
object_ s_ t
Function documentation
AIVision(const std::uint8_t port) explicit
#include <pros/ai_vision.hpp>
Create a AI Vision Sensor object on 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 an AI vision sensor
Example
void opcontrol() { pros::AIVision ai_sensor(2); // Creates a vision sensor on port two }
AIVision(const Device& device)
#include <pros/ai_vision.hpp>
static std::vector<AIVision> get_all_devices()
#include <pros/ai_vision.hpp>
Gets all vision sensors.
Returns | A vector of AIVision sensor objects. |
---|
Example
void opcontrol() { std::vector<AIVision> aivision_all = pros::AIVision::get_all_devices(); // All AI vision sensors that are connected }
static bool is_type(const Object& object,
AivisionDetectType type)
#include <pros/ai_vision.hpp>
Check if the dected type is the same as the given type.
Returns | true if the type is the same, false otherwise |
---|
Example
void opcontrol() { pros::AIVision aivision(1); pros::AIVision::Object object = aivision.get_object(0); if (AIVision::is_type(AivisionDetectType::color, object)) { printf("is color\n"); } else if (AIVision::is_type(AivisionDetectType::object, object)) { printf("is object\n"); } else if (AIVision::is_type(AivisionDetectType::code, object)) { printf("is code\n"); } else if (AIVision::is_type(AivisionDetectType::tag, object)) { printf("is tag\n"); } else { printf("unknown\n"); } }
int32_t reset()
#include <pros/ai_vision.hpp>
Resets the AI Vision sensor to the initial state.
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() { pros::AIVision aivision(AIVISION_PORT); aivision.reset(); }
int32_t get_enabled_detection_types()
#include <pros/ai_vision.hpp>
Returns a bitfield of the types of objects the AI vision sensor is currently searching for, as per AivisionModeType.
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() { pros::AIVision aivision(AIVISION_PORT); int32_t enabled_types = aivision.get_enabled_detection_types(); printf("is tag: %d\n", enabled_types | AivisionModeType::tags); }
int32_t enable_detection_types(AivisionModeType types_mask)
#include <pros/ai_vision.hpp>
Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
Parameters | |
---|---|
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.
For this function you must use bitwise or to combine the types you want to enable.
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() { pros::AIVision aivision(AIVISION_PORT); // start or continue looking for AI model objects // enable aivision to look for tags and objects aivision.enable_detection_types(AivisionModeType::tags | AivisionModeType::objects); }
#include <pros/ai_vision.hpp>
template<class... Flags>
int32_t enable_detection_types(Flags... flags)
Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
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.
For this function you can use comma separated values to combine the types you want to enable.
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() { pros::AIVision aivision(AIVISION_PORT); // start or continue looking for AI model objects // enable aivision to look for tags and objects aivision.enable_detection_types(AivisionModeType::tags, AivisionModeType::objects); }
int32_t disable_detection_types(AivisionModeType types_mask)
#include <pros/ai_vision.hpp>
Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
Parameters | |
---|---|
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.
For this function you must use bitwise or to combine the types you want to disable.
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() { pros::AIVision aivision(AIVISION_PORT); // stop looking for AI model objects (competition elements, for example) // disable aivision to look for tags and objects aivision.disable_detection_types(AivisionModeType::tags | AivisionModeType::objects); }
#include <pros/ai_vision.hpp>
template<class... Flags>
int32_t disable_detection_types(Flags... flags)
Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.
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.
For this function you can use comma separated values to combine the types you want to disable.
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() { pros::AIVision aivision(AIVISION_PORT); // stop looking for AI model objects (competition elements, for example) // disable aivision to look for tags and objects aivision.disable_detection_types(AivisionModeType::tags | AivisionModeType::objects); }
int32_t set_tag_family(AivisionTagFamily family,
bool override = false)
#include <pros/ai_vision.hpp>
Sets the april tag family to detect.
Parameters | |
---|---|
family | the tag family to configure the AI Vision sensor to detect |
override | if true, the given family will be set as the only enabled tag family. |
Returns | PROS_SUCCESS if the operation was successful or PROS_ERR if the operation failed, setting errno. |
If override is true, the AI vision sensor will only look for the given family. Otherwise, it will add the given tag to the list of enabled tags.
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
#define AIVISION_PORT 1 void initialize() { pros::AIVision aivision(AIVISION_PORT); // set the only tag family to look for to 21H7 aivision.set_tag_family(AivisionTagFamily::tag_21H7); // add 16H5 to the list of enabled tag families aivision.set_tag_family(AivisionTagFamily::tag_16H5); // set the only tag family to look for to 25H9 aivision.set_tag_family(AivisionTagFamily::tag_25H9, true); }
int32_t set_color(const Color& color)
#include <pros/ai_vision.hpp>
Set a color configuration that the AI vision sensor will detect.
Parameters | |
---|---|
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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); AIVision::Color color = {1, 207, 19, 25, 10.00, 0.20}; aivision.set_color(color); }
AIVision::Color get_color(uint32_t id)
#include <pros/ai_vision.hpp>
Get a color configuration that the AI vision sensor has stored.
Parameters | |
---|---|
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
#define AIVISION_PORT 1 void opcontrol() { pros::
uint32_t set_code(const Code& code)
#include <pros/ai_vision.hpp>
Set a code that the AI vision sensor will detect for.
Parameters | |
---|---|
code | The code to set |
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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); AIVision::Code code = {1, 207, 19, 25, 10.00, 0.20}; aivision.set_code(code); }
AIVision::Code get_code(uint32_t id)
#include <pros/ai_vision.hpp>
Get a code that the AI vision sensor has stored.
Parameters | |
---|---|
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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); AIVision::Code code = aivision.get_code(0); printf("id: %d, length: %d, c1: %d, c2: %d, c3: %d, c4: %d, c5: %d\n", code.id, code.length, code.c1, code.c2, code.c3, code.c4, code.c5); ) }
int32_t start_awb()
#include <pros/ai_vision.hpp>
Runs auto white balance to adjust to different lighting conditions.
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 get_class_name(int32_t id,
char* class_name)
#include <pros/ai_vision.hpp>
Get a class name that the AI vision sensor has stored.
Parameters | |
---|---|
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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); char* class_name = new char[21]; aivision.get_class_name(0, class_name); printf("%s\n", class_name); delete[] class_name; }
std::optional<std::string> get_class_name(int32_t id)
#include <pros/ai_vision.hpp>
Get a class name that the AI vision sensor has stored.
Parameters | |
---|---|
id | the id of the class name from 0-(AIVISION_MAX_CLASSNAME_COUNT - 1) |
Returns | the class name string in std::optional if the operation was successful or an empty optional 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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); auto name = aivision.get_class_name(1); if(name.has_value()) { printf("Class name: %s\n", name.value().c_str()); } else { printf("Error: %ld\n", errno); } }
int32_t get_object_count()
#include <pros/ai_vision.hpp>
Get the current number of objects detected by the AI vision sensor.
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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); int32_t object_count = aivision.get_object_count(); printf("%d\n", object_count); }
Object get_object(uint32_t object_index)
#include <pros/ai_vision.hpp>
Get the detected object at a given object index; there are aivision_get_object_count objects and the index starts from 0.
Parameters | |
---|---|
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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); int32_t object_count = aivision.get_object_count(); for (int i = 0; i < object_count; i++) { pros::AIVision::Object object = aivision.get_object(i); printf("Object %d: %d\n", i, object.type); } }
std::vector<Object> get_all_objects()
#include <pros/ai_vision.hpp>
Get all detected objects in a vector.
Returns | a vector of all detected 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
#define AIVISION_PORT 1 void opcontrol() { pros::AIVision aivision(AIVISION_PORT); auto objects = aivision.get_all_objects(); for (const auto& object : objects) { printf("Object %d: %d\n", object.id, object.type); } }
Enum documentation
enum class AivisionDetectType: uint8_t
#include <pros/ai_vision.hpp>
Enum class for describing detection type of objects detected by the AI Vision Sensor.
Enumerators | |
---|---|
color |
object was detected based on color descriptor |
code |
object was detected based on code descriptor |
object |
object was detected using AI model |
tag |
object was detected as an AprilTag |
enum class AivisionModeType: uint8_t
#include <pros/ai_vision.hpp>
Enum class for enabling/disabling detection types of AI Vision Sensor.
Enumerators | |
---|---|
tags |
AprilTag detection. |
colors |
color and code detection |
objects |
AI model object detection. |
color_merge |
merge adjacent color detections |
all |
|
enum class AivisionTagFamily
#include <pros/ai_vision.hpp>
Enum class for describing family of apriltags to detect.
Typedef documentation
using Color = aivision_ color_ s_ t
#include <pros/ai_vision.hpp>
using Code = aivision_ code_ s_ t
#include <pros/ai_vision.hpp>
using Object = aivision_ object_ s_ t
#include <pros/ai_vision.hpp>