Skip to main content

ServoMap

Struct ServoMap 

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

Maps a servo angle to its RC pulse width in microseconds, and back.

A hobby servo is positioned by the width of a pulse repeated about every 20 ms: the standard range is 1000 to 2000 microseconds spanning the full travel, with 1500 at centre. ServoMap::standard uses those defaults over 180 degrees; ServoMap::new covers servos with a different range or travel.

§Examples

use pamoja_kit::ServoMap;

let servo = ServoMap::standard();
assert_eq!(servo.pulse(0.0), 1000);
assert_eq!(servo.pulse(90.0), 1500); // centre
assert_eq!(servo.pulse(180.0), 2000);
assert!((servo.angle(1500) - 90.0).abs() < 1e-3);

Implementations§

Source§

impl ServoMap

Source

pub fn standard() -> Self

Returns the standard hobby-servo map: 1000 to 2000 microseconds over 180 degrees.

§Returns

The standard map.

Source

pub fn new(min_us: u16, max_us: u16, range_deg: f32) -> Self

Creates a map from explicit pulse and travel limits.

§Arguments
  • min_us - the pulse width at zero degrees.
  • max_us - the pulse width at full travel.
  • range_deg - the full travel in degrees; its magnitude is used.
§Returns

The map.

Source

pub fn pulse(&self, angle_deg: f32) -> u16

Returns the pulse width for an angle.

§Arguments
  • angle_deg - the desired angle in degrees, clamped to [0, range].
§Returns

The pulse width in microseconds.

Source

pub fn angle(&self, pulse_us: u16) -> f32

Returns the angle for a pulse width.

§Arguments
  • pulse_us - the pulse width in microseconds, clamped to the configured range.
§Returns

The angle in degrees, zero when the pulse range is empty.

Trait Implementations§

Source§

impl Clone for ServoMap

Source§

fn clone(&self) -> ServoMap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ServoMap

Source§

impl Debug for ServoMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.