Struct RotationSensor

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

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

Implementations§

Source§

impl RotationSensor

Source

pub unsafe fn new(port: u8, reversed: bool) -> Result<Self, RotationSensorError>

Constructs a new rotation sensor.

§Safety

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

Source

pub fn reset(&mut self) -> Result<(), RotationSensorError>

Reset the current absolute position to be the same as the Rotation Sensor angle.

Source

pub fn set_position(&mut self, rotation: u32) -> Result<(), RotationSensorError>

Set the Rotation sensor to a desired rotation value in centidegrees.

Source

pub fn reset_position(&mut self) -> Result<(), RotationSensorError>

Reset the current absolute position to be the same as the Rotation Sensor angle.

Source

pub fn get_position(&self) -> Result<i32, RotationSensorError>

Get the Rotation Sensor’s current position in centidegrees.

Source

pub fn get_velocity(&self) -> Result<i32, RotationSensorError>

Get the Rotation Sensor’s current velocity in centidegrees per second.

Source

pub fn get_angle(&self) -> Result<i32, RotationSensorError>

Get the Rotation Sensor’s current angle in centidegrees (0-36000).

Source

pub fn set_reversed(&mut self, reverse: bool) -> Result<(), RotationSensorError>

Set the rotation direction of the sensor.

Source

pub fn reverse(&mut self) -> Result<(), RotationSensorError>

Reverses the rotational sensor’s direction.

Source

pub fn get_reversed(&self) -> Result<bool, RotationSensorError>

Get the Rotation Sensor’s reversed flag.

Trait Implementations§

Source§

impl DataSource for RotationSensor

Source§

type Data = RotationSensorData

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

type Error = RotationSensorError

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<(SmartPort, bool)> for RotationSensor

Source§

type Error = RotationSensorError

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

fn try_from((port, reversed): (SmartPort, bool)) -> Result<Self, Self::Error>

Performs the conversion.

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.