DistanceSensor

Struct DistanceSensor 

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

A struct which represents a V5 smart port configured as a distance sensor.

Implementations§

Source§

impl DistanceSensor

Source

pub unsafe fn new(port: u8) -> DistanceSensor

Constructs a new distance sensor.

§Safety

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

Source

pub fn get_distance(&self) -> Result<i32, DistanceSensorError>

Gets the currently measured distance from the sensor in millimetres.

Source

pub fn get_confidence(&self) -> Result<i32, DistanceSensorError>

Gets the confidence in the distance reading.

This is a value that has a range of 0 to 63. 63 means high confidence, lower values imply less confidence. Confidence is only available when distance is > 200mm (the value 10 is returned in this scenario).

Source

pub fn get_object_size(&self) -> Result<i32, DistanceSensorError>

Gets the current estimated relative object size.

This is a value that has a range of 0 to 400. A 18” x 30” grey card will return a value of approximately 75 in typical room lighting.

Source

pub fn get_object_velocity(&self) -> Result<f64, DistanceSensorError>

Gets the object velocity in metres per second.

Trait Implementations§

Source§

impl DataSource for DistanceSensor

Source§

type Data = DistanceData

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

type Error = DistanceSensorError

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 From<SmartPort> for DistanceSensor

Source§

fn from(port: SmartPort) -> Self

Converts to this type from the input type.

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.