Servo

Struct Servo 

Source
pub struct Servo<'a, S: TimerSpeed> {
    pub duty_range: Range<f32>,
    /* private fields */
}

Fields§

§duty_range: Range<f32>

Valid duty cycle range in absolute values (e.g., 102..491 for SG90 with 12-bit). This corresponds to the pulse width range of the servo.

Implementations§

Source§

impl<'d, S: TimerSpeed> Servo<'d, S>

Source

pub fn new<'a>( name: &'static str, config: ServoConfig, ledc: &mut Ledc<'a>, timer: &'a Timer<'a, S>, channel_num: Number, pin: impl OutputPin + 'a, ) -> Result<Servo<'a, S>, Error>
where Timer<'a, S>: TimerHW<S>,

Creates new servo driver instance for LEDC channel.

§Arguments
  • name - Name identifier for the servo (for logging)
  • config - Servo configuration
  • ledc - LEDC peripheral instance
  • timer - Configured timer instance (use ServoConfig::configure_timer to create it)
  • channel_num - Channel number (e.g., channel::Number::Channel0)
  • pin - GPIO pin to use for PWM output
Source

pub fn step(&mut self, step_size: f32) -> Result<bool, Error>

Makes step in absolute duty units should be lesser than duty_range(). Return false if servo reaches min or max position. See also step_pct() for percentage-based stepping. Note: Step takes some time depending on servo speed.

Source

pub fn step_pct(&mut self, step_pct: u8) -> Result<bool, Error>

Makes step in percentage of total range. Returns false if servo reaches min or max position. See also step() for absolute duty-based stepping. Note: Step takes some time depending on servo speed.

Source

pub fn set_dir(&mut self, dir: Dir) -> Option<Dir>

Set servo to move new direction. Returns old direction if direction was actually changes.

Source

pub fn get_dir(&self) -> Dir

Returns current direction value.

Source

pub fn get_angle(&self) -> f32

Returns current angle value in degrees.

Source

pub fn set_angle(&mut self, angle: f32) -> bool

Sets servo to specified angle in degrees. Note: turn to angle takes some time depending on servo speed.

Source

pub fn duty_range(&self) -> f32

Returns the size of the duty range (difference between max and min duty values). This is not the number of steps, but the range size in duty units.

Auto Trait Implementations§

§

impl<'a, S> Freeze for Servo<'a, S>

§

impl<'a, S> !RefUnwindSafe for Servo<'a, S>

§

impl<'a, S> !Send for Servo<'a, S>

§

impl<'a, S> !Sync for Servo<'a, S>

§

impl<'a, S> Unpin for Servo<'a, S>

§

impl<'a, S> !UnwindSafe for Servo<'a, S>

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> Same for T

Source§

type Output = T

Should always be Self
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.