pub struct Servo { /* private fields */ }Expand description
Represents a Servo controlled by a PWM pin.
Implementations§
Source§impl Servo
impl Servo
Sourcepub fn new(board: &dyn Hardware, pin: u8, default: u16) -> Result<Self, Error>
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.
Sourcepub fn new_inverted(
board: &dyn Hardware,
pin: u8,
default: u16,
) -> Result<Self, Error>
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.
Sourcepub fn to(&mut self, to: u16) -> Result<&Self, Error>
pub fn to(&mut self, to: u16) -> Result<&Self, Error>
Moves the servo to the requested position at max speed.
Sourcepub fn sweep(&mut self, ms: u64) -> &Self
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
Sourcepub fn get_range(&self) -> Range<u16>
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.
Sourcepub fn set_range<R: Into<Range<u16>>>(self, range: R) -> Self
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.
Sourcepub fn get_degree_range(&self) -> Range<u16>
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.).
Sourcepub fn set_degree_range<R: Into<Range<u16>>>(self, degree_range: R) -> Self
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
rangesince it will always stay within the givendegree_range.
Sourcepub fn get_pwn_range(&self) -> Range<u16>
pub fn get_pwn_range(&self) -> Range<u16>
Returns the theoretical range of pwm controls the servo response to.
Sourcepub fn set_pwn_range<R: Into<Range<u16>>>(
self,
pwm_range: R,
) -> Result<Self, Error>
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
Sourcepub fn is_inverted(&self) -> bool
pub fn is_inverted(&self) -> bool
Returns if the servo command is set to be inverted.
Sourcepub fn set_inverted(self, inverted: bool) -> Self
pub fn set_inverted(self, inverted: bool) -> Self
Sets the servo command inversion mode.
Sourcepub fn is_auto_detach(&self) -> bool
pub fn is_auto_detach(&self) -> bool
Returns if the servo command is set to be auto_detach itself.
Sourcepub fn set_auto_detach(self, auto_detach: bool) -> Self
pub fn set_auto_detach(self, auto_detach: bool) -> Self
Sets the servo to auto-detach itself after a given delay.
Sourcepub fn get_detach_delay(&self) -> usize
pub fn get_detach_delay(&self) -> usize
Returns the delay (in ms) before the servo is auto-detach (if enabled).
Sourcepub fn set_detach_delay(self, detach_delay: usize) -> Self
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§
impl Device for Servo
Source§impl Output for Servo
impl Output for Servo
Source§fn set_state(&mut self, state: State) -> Result<State, Error>
fn set_state(&mut self, state: State) -> Result<State, Error>
Internal only: you should rather use Self::to() function.