pub struct VisionCode(pub u8, pub u8, pub Option<u8>, pub Option<u8>, pub Option<u8>);
Expand description
A vision detection code.
Codes are a special type of detection signature that group multiple VisionSignature
s
together. A VisionCode
can associate 2-5 color signatures together, detecting the resulting object
when its color signatures are present close to each other.
These codes work very similarly to Pixy2 Color Codes.
Tuple Fields§
§0: u8
§1: u8
§2: Option<u8>
§3: Option<u8>
§4: Option<u8>
Implementations§
Source§impl VisionCode
impl VisionCode
Sourcepub const fn new(
sig_1: u8,
sig_2: u8,
sig_3: Option<u8>,
sig_4: Option<u8>,
sig_5: Option<u8>,
) -> Self
pub const fn new( sig_1: u8, sig_2: u8, sig_3: Option<u8>, sig_4: Option<u8>, sig_5: Option<u8>, ) -> Self
Creates a new vision code.
Two signatures are required to create a vision code, with an additional three optional signatures.
§Examples
use vexide::devices::smart::vision::VisionCode;
// Create a vision code associated with signatures 1, 2, and 3.
let code = VisionCode::new(1, 2, Some(3), None, None);
Sourcepub const fn from_id(id: u16) -> Self
pub const fn from_id(id: u16) -> Self
Creates a VisionCode
from a bit representation of its signature IDs.
§Examples
use vexide::devices::smart::vision::VisionCode;
let sig_1_id = 1;
let sig_2_id = 2;
let mut code_id: u16 = 0;
// Store the bits of IDs 1 and 2 in the code ID.
code_id = (code_id << 3) | u16::from(sig_1_id);
code_id = (code_id << 3) | u16::from(sig_2_id);
// Create a [`VisionCode`] from signatures 1 and 2.
let code = VisionCode::from_id(code_id);
Sourcepub const fn contains_signature(&self, id: u8) -> bool
pub const fn contains_signature(&self, id: u8) -> bool
Returns true
if a given signature ID is stored in this code.
§Examples
use vexide::devices::smart::vision::VisionCode;
// Create a vision code associated with signatures 1, 2, and 3.
let code = VisionCode::new(1, 2, Some(3), None, None);
assert!(code.contains_signature(1));
Sourcepub fn id(&self) -> u16
pub fn id(&self) -> u16
Returns the internal ID used by the sensor to determine which signatures belong to which code.
§Examples
use vexide::devices::smart::vision::VisionCode;
let sig_1_id = 1;
let sig_2_id = 2;
let mut code_id: u16 = 0;
// Store the bits of IDs 1 and 2 in the code ID.
code_id = (code_id << 3) | u16::from(sig_1_id);
code_id = (code_id << 3) | u16::from(sig_2_id);
// Create a [`VisionCode`] from signatures 1 and 2.
let code = VisionCode::from_id(code_id);
// The ID of the code we just created should be identical to the bit representation
// containing each signature ID we created it from.
assert_eq!(code.id(), code_id);
Trait Implementations§
Source§impl Clone for VisionCode
impl Clone for VisionCode
Source§fn clone(&self) -> VisionCode
fn clone(&self) -> VisionCode
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for VisionCode
impl Debug for VisionCode
Source§impl From<(u8, u8)> for VisionCode
impl From<(u8, u8)> for VisionCode
Source§fn from(signatures: (u8, u8)) -> Self
fn from(signatures: (u8, u8)) -> Self
Convert a tuple of two VisionSignature
s into a VisionCode
.
Source§impl From<(u8, u8, u8)> for VisionCode
impl From<(u8, u8, u8)> for VisionCode
Source§fn from(signatures: (u8, u8, u8)) -> Self
fn from(signatures: (u8, u8, u8)) -> Self
Convert a tuple of three VisionSignature
s into a VisionCode
.
Source§impl From<(u8, u8, u8, u8)> for VisionCode
impl From<(u8, u8, u8, u8)> for VisionCode
Source§fn from(signatures: (u8, u8, u8, u8)) -> Self
fn from(signatures: (u8, u8, u8, u8)) -> Self
Convert a tuple of four VisionSignature
s into a VisionCode
.
Source§impl From<(u8, u8, u8, u8, u8)> for VisionCode
impl From<(u8, u8, u8, u8, u8)> for VisionCode
Source§fn from(signatures: (u8, u8, u8, u8, u8)) -> Self
fn from(signatures: (u8, u8, u8, u8, u8)) -> Self
Convert a tuple of five VisionSignature
s into a VisionCode
.