Struct Linkbot

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

An object representing a Linkbot.

Implementations§

Source§

impl Linkbot

Source

pub fn new(serial_id: &str) -> Option<Linkbot>

Try to connect to a Linkbot.

If there is an error, None is returned and an error message is printed to stderr.

Source

pub fn get_joint_angles(&mut self) -> Result<(f64, f64, f64, u32), i32>

Get a Linkbot’s current joint angles.

Returns a tuple containing the three joint angles in degrees and a timestamp representing the number of milliseconds the robot has been powered on.

Source

pub fn move_motors( &mut self, mask: u8, j1: f64, j2: f64, j3: f64, ) -> Result<(), i32>

Move a Linkbot’s motors. The mask specifies which motors to move. For instance, a mask value of 5 (0b101) indicates that motors 1 and 3 should be moved. A mask of 4 (0b100) indicates that only motor 3 should be moved.

The units of movement are in degrees.

Source

pub fn move_motors_to( &mut self, mask: u8, j1: f64, j2: f64, j3: f64, ) -> Result<(), i32>

Move a Linkbot’s motors to absolute positions.

See move_motors for a description of the mask argument.

Source

pub fn move_wait(&mut self, mask: u8) -> Result<(), i32>

Wait until a Linkbot’s motors have stopped moving.

This function blocks execution in the current thread until the Linkbot’s motors have stopped moving. The motors to wait for are specified by the mask argument. For instance, to wait for all motors, specify a mask of 0x07 (0b111). Or, to only wait for motor 3, specify a mask of 0x04 (0b100).

Source

pub fn set_button_handler<F>(&mut self, callback: F) -> Result<(), i32>
where F: FnMut(Button, ButtonState, u32) + 'static,

Set a callback for when a Linkbot button is pressed

The callback will be called whenever a button is depressed or released. The third argument of the callback function is a timestamp indicating the number of milleseconds the robot has been powered on.

§Examples
extern crate linkbot;
use linkbot::Linkbot;

fn main() {
    let mut l = Linkbot::new("ZRG6").unwrap();
    l.set_button_handler( |button, state, timestamp| {
        // Do something. This closure will be called when any button is depressed or
        // released.
    });
}
Source

pub fn unset_button_handler(&mut self) -> Result<(), i32>

Remove the Linkbot button handler

If there was a button handler previously set with set_button_handler(), this function removes it and restores the default Linkbot button functionality.

Source

pub fn set_buzzer_frequency(&mut self, frequency: f32) -> Result<(), i32>

Set the buzzer frequency

Set the buzzer frequency to a value specified in Hertz (Hz). Set the buzzer frequency to 0 to stop the buzzer.

Auto Trait Implementations§

§

impl Freeze for Linkbot

§

impl !RefUnwindSafe for Linkbot

§

impl !Send for Linkbot

§

impl !Sync for Linkbot

§

impl Unpin for Linkbot

§

impl !UnwindSafe for Linkbot

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