Skip to main content

Servo

Struct Servo 

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

Represents a Servo controlled by a PWM pin.

Implementations§

Source§

impl Servo

Source

pub fn new(board: &dyn Hardware, pin: u8, default: u16) -> Result<Self, Error>

Creates an instance of a Servo attached to a given board.

§Errors
  • UnknownPin: this function will bail an error if the pin does not exist for this board.
  • IncompatiblePin: this function will bail an error if the pin does not support SERVO mode.
Source

pub fn new_inverted( board: &dyn Hardware, pin: u8, default: u16, ) -> Result<Self, Error>

Creates an instance of an inverted Servo attached to a given board (see Self::set_inverted`).

§Errors
  • UnknownPin: this function will bail an error if the pin does not exist for this board.
  • IncompatiblePin: this function will bail an error if the pin does not support SERVO mode.
Source

pub fn to(&mut self, to: u16) -> Result<&Self, Error>

Moves the servo to the requested position at max speed.

Source

pub fn sweep(&mut self, ms: u64) -> &Self

Sweeps the servo in phases of ms (milliseconds) duration. This is an animation and can be stopped by calling Self::stop().

§Parameters
  • ms: the blink duration in milliseconds
Source

pub fn get_pin(&self) -> u8

Returns the pin (id) used by the device.

Source

pub fn get_pin_info(&self) -> Result<Pin, Error>

Returns Pin information.

Source

pub fn get_type(&self) -> ServoType

Returns the servo type.

Source

pub fn set_type(self, servo_type: ServoType) -> Self

Sets the servo type.

Source

pub fn get_range(&self) -> Range<u16>

Returns the servo motion range limitation in degree.

A servo has a physical range (cf Self::set_degree_range) corresponding to a command range limitation (cf Self::set_pwn_range). Those are intrinsic top the servo itself. On the contrary, the motion range limitation here is a limitation you want to set for your servo because of how it is used in your robot: for example an arm that can turn only 20-40° in motion range.

Source

pub fn set_range<R: Into<Range<u16>>>(self, range: R) -> Self

Sets the Servo motion range limitation in degree. This guarantee the servo to stays in the given range at any time.

  • No matter the order given, the range will always have min <= max
  • No matter the values given, the range will always stay within the Servo degree_range.
Source

pub fn get_degree_range(&self) -> Range<u16>

Returns the theoretical range of degrees of movement for the servo (some servos can range from 0 to 90°, 180°, 270°, 360°, etc.).

Source

pub fn set_degree_range<R: Into<Range<u16>>>(self, degree_range: R) -> Self

Sets the theoretical range of degrees of movement for the servo (some servos can range from 0 to 90°, 180°, 270°, 360°, etc.).

  • No matter the order given, the range will always have min <= max
  • This may impact the range since it will always stay within the given degree_range.
Source

pub fn get_pwn_range(&self) -> Range<u16>

Returns the theoretical range of pwm controls the servo response to.

Source

pub fn set_pwn_range<R: Into<Range<u16>>>( self, pwm_range: R, ) -> Result<Self, Error>

Sets the theoretical range of pwm controls the servo response to.

§Parameters
  • pwm_range: the range limitation
Source

pub fn is_inverted(&self) -> bool

Returns if the servo command is set to be inverted.

Source

pub fn set_inverted(self, inverted: bool) -> Self

Sets the servo command inversion mode.

Source

pub fn is_auto_detach(&self) -> bool

Returns if the servo command is set to be auto_detach itself.

Source

pub fn set_auto_detach(self, auto_detach: bool) -> Self

Sets the servo to auto-detach itself after a given delay.

Source

pub fn get_detach_delay(&self) -> usize

Returns the delay (in ms) before the servo is auto-detach (if enabled).

Source

pub fn set_detach_delay(self, detach_delay: usize) -> Self

Sets the delay (in ms) before the servo is auto-detach (if enabled).

Trait Implementations§

Source§

impl Clone for Servo

Source§

fn clone(&self) -> Servo

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 Debug for Servo

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Device for Servo

Source§

impl Display for Servo

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Output for Servo

Source§

fn set_state(&mut self, state: State) -> Result<State, Error>

Internal only: you should rather use Self::to() function.

Source§

fn get_state(&self) -> State

Returns the actuator current state.
Source§

fn get_default(&self) -> State

Returns the actuator default (or neutral) state.
Source§

fn animate<S: Into<State>>( &mut self, state: S, duration: u64, transition: Easing, )

Animates the output of the device. In other word: the state of the device will be animated from current step to targeted step through an interpolation of in-between states. The function will last for the required duration and the interpolation will follow an easing transition function. Read more
Source§

fn is_busy(&self) -> bool

Indicates the busy status, ie if the device is running an animation.
Source§

fn stop(&mut self)

Stops the current animation, if any.
Source§

fn reset(&mut self) -> Result<State, Error>

Resets the actuator to default (or neutral) state.
Source§

fn scale_state( &mut self, previous: State, target: State, progress: f32, ) -> State

Internal only.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Servo

§

impl !UnwindSafe for Servo

§

impl Freeze for Servo

§

impl Send for Servo

§

impl Sync for Servo

§

impl Unpin for Servo

§

impl UnsafeUnpin for Servo

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.