ServoConfig

Struct ServoConfig 

Source
pub struct ServoConfig {
    pub max_angle: f32,
    pub frequency: Rate,
    pub pulse_width_ns: Range<u32>,
    pub duty: Duty,
}

Fields§

§max_angle: f32

Max angle that servo can be turned, mostly 180, 360.

§frequency: Rate

What frequency expect servo (ex. 50Hz for SG90).

§pulse_width_ns: Range<u32>

What pulse width in nanos servo supports (ex. 500000-2400000ns for SG90).

§duty: Duty

PWM resolution in bits. Higher bits means more precise control.

Implementations§

Source§

impl ServoConfig

Source

pub fn default_servo(duty: Duty, max_angle: f32) -> Self

Default servo configuration with 50Hz frequency and pulse width range of 500000-2500000 ns (0.5-2.5ms).

Source

pub fn sg90(duty: Duty) -> Self

Config for SG90. Can be used for SG90s as well.

Source

pub fn mg995(duty: Duty) -> Self

Config for MG995. High-torque servo motor with metal gears. Can be used for MG996, MG996R as well.

Source

pub fn configure_timer<'a, S: TimerSpeed>( &self, ledc: &mut Ledc<'a>, timer_num: Number, clock_source: S::ClockSourceType, ) -> Result<Timer<'a, S>, Error>
where Timer<'a, S>: TimerHW<S>,

Helper function to configure a timer with this servo’s configuration.

Source

pub fn calc_duty_range(&self, max_duty: f32) -> Range<f32>

Calculates duty range in absolute values for this servo configuration. Returns absolute duty values (0..max_duty), not percentages.

Source

pub fn duty_to_angle( &self, duty: f32, max_duty: f32, duty_range: &Range<f32>, ) -> f32

Transforms absolute duty value to angle in degrees. Returns angle in degrees (0.0..max_angle).

Source

pub fn angle_to_duty(&self, angle: f32, duty_range: &Range<f32>) -> f32

Transforms angle in degrees to absolute duty value.

Trait Implementations§

Source§

impl Clone for ServoConfig

Source§

fn clone(&self) -> ServoConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ServoConfig

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> 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.