AdiAnalog

Struct AdiAnalog 

Source
pub struct AdiAnalog { /* private fields */ }
Expand description

A struct which represents a V5 ADI port configured as an ADI analog input.

Implementations§

Source§

impl AdiAnalog

Source

pub unsafe fn new(port: u8, expander_port: u8) -> Result<Self, AdiAnalogError>

Initializes an ADI analog reader on an ADI port.

§Safety

This function is unsafe because it allows the user to create multiple mutable references to the same ADI analog reader. You likely want to implement Robot::new() instead.

Source

pub fn calibrate(&mut self) -> Result<i32, AdiAnalogError>

Calibrates the analog sensor on the specified channel. This method assumes that the true sensor value is not actively changing at this time and computes an average from approximately 500 samples, 1 ms apart, for a 0.5 s period of calibration. The average value thus calculated is returned and stored for later calls to the ext_adi_analog_read_calibrated and ext_adi_analog_read_calibrated_HR functions. These functions will return the difference between this value and the current sensor value when called. Do not use this function when the sensor value might be unstable (gyro rotation, accelerometer movement). Returns: The average sensor value computed by this function.

Source

pub fn read(&self) -> Result<i32, AdiAnalogError>

Reads an analog input channel and returns the 12-bit value. The value returned is undefined if the analog pin has been switched to a different mode. The meaning of the returned value varies depending on the sensor attached. Returns: The analog sensor value, where a value of 0 reflects an input voltage of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V

Source

pub fn read_calibrated(&self) -> Result<i32, AdiAnalogError>

Reads the calibrated value of an analog input channel. The AdiAnalog::read_calibrated()(crate::adi::analog::AdiAnalog:: read_calibrated()) function must be run first on that channel. This function is inappropriate for sensor values intended for integration, as round-off error can accumulate causing drift over time. Use AdiAnalog::read_calibrated_hr()(crate::adi::analog::AdiAnalog:: read_calibrated_hr()) instead. Returns: The difference of the sensor value from its calibrated default from -4095 to 4095.

Source

pub fn read_calibrated_hr(&self) -> Result<i32, AdiAnalogError>

Reads the calibrated value of an analog input channel 1-8 with enhanced precision. The AdiAnalog::read_calibrated()(crate::adi::analog::AdiAnalog:: read_calibrated()) function must be run first. This is intended for integrated sensor values such as gyros and accelerometers to reduce drift due to round-off, and should not be used on a sensor such as a line tracker or potentiometer. The value returned actually has 16 bits of “precision”, even though the ADC only reads 12 bits, so that errors induced by the average value being between two values come out in the wash when integrated over time. Think of the value as the true value times 16. Returns: The difference of the sensor value from its calibrated default from -16384 to 16384.

Trait Implementations§

Source§

impl DataSource for AdiAnalog

Source§

type Data = i32

The type of data produced by the data source.
Source§

type Error = AdiAnalogError

The type of errors which could occur while reading data.
Source§

fn read(&self) -> Result<Self::Data, Self::Error>

Tries to read a new value form the data source.
Source§

impl TryFrom<AdiPort> for AdiAnalog

Source§

fn try_from(port: AdiPort) -> Result<Self, Self::Error>

Converts a AdiPort into a AdiAnalog.

Source§

type Error = AdiAnalogError

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoBroadcast for T
where T: DataSource,

Source§

fn into_broadcast( self, ) -> Result<BroadcastWrapper<T>, (<T as DataSource>::Error, T)>

Converts the data source into a BroadcastWrapper. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.