vex_sdk/
ai_vision.rs

1//! V5 AI Vision Sensor
2
3use core::ffi::{c_double, c_float};
4
5use crate::V5_DeviceT;
6
7#[repr(C, packed)]
8#[derive(Default, Debug, Copy, Clone, PartialEq)]
9pub struct V5_DeviceAiVisionColor {
10    pub id: u8,
11    pub red: u8,
12    pub grn: u8,
13    pub blu: u8,
14    pub hangle: c_float,
15    pub hdsat: c_float,
16    pub reserved: u32,
17}
18
19#[repr(C, packed)]
20#[derive(Copy, Clone)]
21pub struct V5_DeviceAiVisionObject {
22    pub id: u8,
23    pub r#type: u8,
24    pub object: V5_DeviceAiVisionObjectData,
25}
26
27#[repr(C)]
28#[derive(Copy, Clone)]
29pub union V5_DeviceAiVisionObjectData {
30    pub color: V5_DeviceAiVisionColorData,
31    pub tag: V5_DeviceAiVisionTagData,
32    pub model: V5_DeviceAiVisionModelData,
33}
34
35/// Color Detection Data
36#[repr(C)]
37#[derive(Default, Debug, Copy, Clone, PartialEq)]
38pub struct V5_DeviceAiVisionColorData {
39    /// left side of object
40    pub xoffset: u16,
41    /// top of object
42    pub yoffset: u16,
43    /// width of object
44    pub width: u16,
45    /// height of object
46    pub height: u16,
47    /// angle of CC object in 0.1 deg units
48    pub angle: u16,
49}
50
51/// Apriltag coordinate data
52#[repr(C)]
53#[derive(Default, Debug, Copy, Clone, PartialEq)]
54pub struct V5_DeviceAiVisionTagData {
55    pub x0: i16,
56    pub y0: i16,
57    pub x1: i16,
58    pub y1: i16,
59    pub x2: i16,
60    pub y2: i16,
61    pub x3: i16,
62    pub y3: i16,
63}
64
65/// AI Model Data
66#[repr(C)]
67#[derive(Default, Debug, Copy, Clone, PartialEq)]
68pub struct V5_DeviceAiVisionModelData {
69    /// left side of object
70    pub xoffset: u16,
71    /// top of object
72    pub yoffset: u16,
73    /// width of object
74    pub width: u16,
75    /// height of object
76    pub height: u16,
77    /// confidence score
78    pub score: u16,
79}
80
81#[repr(C, packed)]
82#[derive(Default, Debug, Copy, Clone, PartialEq)]
83pub struct V5_DeviceAiVisionCode {
84    pub id: u8,
85    pub len: u8,
86    pub c1: i16,
87    pub c2: i16,
88    pub c3: i16,
89    pub c4: i16,
90    pub c5: i16,
91    pub c6: i16,
92    pub c7: i16,
93}
94
95unsafe extern "system" {
96    pub fn vexDeviceAiVisionClassNameGet(device: V5_DeviceT, id: i32, pName: *mut u8) -> i32;
97    pub fn vexDeviceAiVisionCodeGet(
98        device: V5_DeviceT,
99        id: u32,
100        pCode: *mut V5_DeviceAiVisionCode,
101    ) -> bool;
102    pub fn vexDeviceAiVisionCodeSet(device: V5_DeviceT, pCode: *mut V5_DeviceAiVisionCode);
103    pub fn vexDeviceAiVisionColorGet(
104        device: V5_DeviceT,
105        id: u32,
106        pColor: *mut V5_DeviceAiVisionColor,
107    ) -> bool;
108    pub fn vexDeviceAiVisionColorSet(device: V5_DeviceT, pColor: *mut V5_DeviceAiVisionColor);
109    pub fn vexDeviceAiVisionModeGet(device: V5_DeviceT) -> u32;
110    pub fn vexDeviceAiVisionModeSet(device: V5_DeviceT, mode: u32);
111    pub fn vexDeviceAiVisionObjectCountGet(device: V5_DeviceT) -> i32;
112    pub fn vexDeviceAiVisionObjectGet(
113        device: V5_DeviceT,
114        indexObj: u32,
115        pObject: *mut V5_DeviceAiVisionObject,
116    ) -> i32;
117    pub fn vexDeviceAiVisionSensorSet(device: V5_DeviceT, brightness: c_double, contrast: c_double);
118    pub fn vexDeviceAiVisionStatusGet(device: V5_DeviceT) -> u32;
119    pub fn vexDeviceAiVisionTemperatureGet(device: V5_DeviceT) -> c_double;
120}