pub struct Linkbot { /* private fields */ }
Expand description
An object representing a Linkbot.
Implementations§
Source§impl Linkbot
impl Linkbot
Sourcepub fn new(serial_id: &str) -> Option<Linkbot>
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.
Sourcepub fn get_joint_angles(&mut self) -> Result<(f64, f64, f64, u32), i32>
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.
Sourcepub fn move_motors(
&mut self,
mask: u8,
j1: f64,
j2: f64,
j3: f64,
) -> Result<(), i32>
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.
Sourcepub fn move_motors_to(
&mut self,
mask: u8,
j1: f64,
j2: f64,
j3: f64,
) -> Result<(), i32>
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.
Sourcepub fn move_wait(&mut self, mask: u8) -> Result<(), i32>
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).
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.
});
}
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.