Skip to main content

DynpickSensorBuilder

Struct DynpickSensorBuilder 

Source
pub struct DynpickSensorBuilder<C> { /* private fields */ }
Expand description

Builder of a connection to a dynpick sensor.

§Examples

use dynpick_force_torque_sensor::DynpickSensorBuilder;

let sensor = DynpickSensorBuilder::open("/dev/ttyUSB0")
    .and_then(|b| b.set_sensitivity_by_builtin_data())
    .and_then(|b| b.build())
    .unwrap();

Implementations§

Source§

impl DynpickSensorBuilder<SensitivityNotSetYet>

Source

pub fn open<'a>( path: impl Into<Cow<'a, str>>, ) -> Result<DynpickSensorBuilder<SensitivityNotSetYet>, Error>

Connects to the dynpick force torque sensor.

§Params
  1. path The sensor’s path.
§Returns

Ok(builder) if successfully connected, Err(reason) if failed.
Before you use the sensor, you need to calibrate the sensor by calling Self::set_sensitivity_by_builtin_data or Self::set_sensitivity_manually.

§Examples

See the example here.

Examples found in repository?
examples/demo.rs (line 53)
26fn main() {
27    println!("dynpick-force-torque-sensor demo started.");
28    println!("Make sure that the sensor is connected to the computer.");
29    println!("Make sure setting udev rule. See examples/setup_udev_rule.sh in detail.");
30
31    // Search USB-connected dynpick sensor.
32    let path = match search_usb_sensor_path() {
33        Ok(Some(path)) => path,
34        Ok(None) => {
35            println!("No dynpick sensor is connected.");
36            return;
37        }
38        Err(e) => {
39            println!("{}", e);
40            return;
41        }
42    };
43    println!("Found a sensor. Path: {}", path);
44
45    // Specify the sensitivity manually.
46    let sensitivity = {
47        let force = Triplet::new(24.9, 24.6, 24.5);
48        let torque = Triplet::new(1664.7, 1639.7, 1638.0);
49        Sensitivity::new(force, torque)
50    };
51
52    // Connect the found sensor.
53    let sensor = DynpickSensorBuilder::open(path)
54        .map(|b| b.set_sensitivity_manually(sensitivity))
55        .and_then(|b| b.build());
56    let mut sensor = match sensor {
57        Ok(s) => s,
58        Err(e) => {
59            println!("{}", e);
60            return;
61        }
62    };
63    println!("Successfully opened the sensor.");
64
65    // Correct zero-point
66    match sensor.zeroed_next() {
67        Ok(_) => println!("Offset the sensor."),
68        Err(e) => {
69            println!("An error occurred during offset: {}", e);
70            return;
71        }
72    }
73
74    // Repeatedly receive wrenches from the sensor.
75    let measurement_count = 1000;
76    for i in 0..measurement_count {
77        std::thread::sleep(sensor.inner_port().timeout());
78
79        match sensor.update() {
80            Ok(w) => println!("[{}/{}] {:?}", i + 1, measurement_count, w),
81            Err(e) => println!("[{}/{}] {}", i + 1, measurement_count, e),
82        }
83    }
84
85    // Info
86    println!("Product info: {:?}", sensor.receive_product_info());
87
88    println!("dynpick-force-torque-sensor demo finished.");
89}
Source

pub fn set_sensitivity_manually( self, sensitivity: Sensitivity, ) -> DynpickSensorBuilder<Ready>

Set the Sensitivity of the connected sensor by using the specified sensitivity.

§Examples
use dynpick_force_torque_sensor::{DynpickSensorBuilder, Sensitivity, Triplet};

let sensitivity = {
    let force = Triplet::new(24.9, 24.6, 24.5);
    let torque = Triplet::new(1664.7, 1639.7, 1638.0);
    Sensitivity::new(force, torque)
};

let sensor = DynpickSensorBuilder::open("/dev/ttyUSB0")
    .map(|b| b.set_sensitivity_manually(sensitivity))
    .and_then(|b| b.build())
    .unwrap();
Examples found in repository?
examples/demo.rs (line 54)
26fn main() {
27    println!("dynpick-force-torque-sensor demo started.");
28    println!("Make sure that the sensor is connected to the computer.");
29    println!("Make sure setting udev rule. See examples/setup_udev_rule.sh in detail.");
30
31    // Search USB-connected dynpick sensor.
32    let path = match search_usb_sensor_path() {
33        Ok(Some(path)) => path,
34        Ok(None) => {
35            println!("No dynpick sensor is connected.");
36            return;
37        }
38        Err(e) => {
39            println!("{}", e);
40            return;
41        }
42    };
43    println!("Found a sensor. Path: {}", path);
44
45    // Specify the sensitivity manually.
46    let sensitivity = {
47        let force = Triplet::new(24.9, 24.6, 24.5);
48        let torque = Triplet::new(1664.7, 1639.7, 1638.0);
49        Sensitivity::new(force, torque)
50    };
51
52    // Connect the found sensor.
53    let sensor = DynpickSensorBuilder::open(path)
54        .map(|b| b.set_sensitivity_manually(sensitivity))
55        .and_then(|b| b.build());
56    let mut sensor = match sensor {
57        Ok(s) => s,
58        Err(e) => {
59            println!("{}", e);
60            return;
61        }
62    };
63    println!("Successfully opened the sensor.");
64
65    // Correct zero-point
66    match sensor.zeroed_next() {
67        Ok(_) => println!("Offset the sensor."),
68        Err(e) => {
69            println!("An error occurred during offset: {}", e);
70            return;
71        }
72    }
73
74    // Repeatedly receive wrenches from the sensor.
75    let measurement_count = 1000;
76    for i in 0..measurement_count {
77        std::thread::sleep(sensor.inner_port().timeout());
78
79        match sensor.update() {
80            Ok(w) => println!("[{}/{}] {:?}", i + 1, measurement_count, w),
81            Err(e) => println!("[{}/{}] {}", i + 1, measurement_count, e),
82        }
83    }
84
85    // Info
86    println!("Product info: {:?}", sensor.receive_product_info());
87
88    println!("dynpick-force-torque-sensor demo finished.");
89}
Source

pub fn set_sensitivity_by_builtin_data( self, ) -> Result<DynpickSensorBuilder<Ready>, Error>

Set the Sensitivity of the connected sensor, reading its sensitivity from it.
Some sensors may not support this functionality (Err(_) will be returned under this situation).

§Examples

See the example here

§Note

This method has not been tested yet because my sensor (WDF-6M200-3) does not support this functionality.

Source§

impl DynpickSensorBuilder<Ready>

Source

pub fn build(self) -> Result<DynpickSensor, Error>

Consuming this builder, attempts to construct a sensor instance.

Examples found in repository?
examples/demo.rs (line 55)
26fn main() {
27    println!("dynpick-force-torque-sensor demo started.");
28    println!("Make sure that the sensor is connected to the computer.");
29    println!("Make sure setting udev rule. See examples/setup_udev_rule.sh in detail.");
30
31    // Search USB-connected dynpick sensor.
32    let path = match search_usb_sensor_path() {
33        Ok(Some(path)) => path,
34        Ok(None) => {
35            println!("No dynpick sensor is connected.");
36            return;
37        }
38        Err(e) => {
39            println!("{}", e);
40            return;
41        }
42    };
43    println!("Found a sensor. Path: {}", path);
44
45    // Specify the sensitivity manually.
46    let sensitivity = {
47        let force = Triplet::new(24.9, 24.6, 24.5);
48        let torque = Triplet::new(1664.7, 1639.7, 1638.0);
49        Sensitivity::new(force, torque)
50    };
51
52    // Connect the found sensor.
53    let sensor = DynpickSensorBuilder::open(path)
54        .map(|b| b.set_sensitivity_manually(sensitivity))
55        .and_then(|b| b.build());
56    let mut sensor = match sensor {
57        Ok(s) => s,
58        Err(e) => {
59            println!("{}", e);
60            return;
61        }
62    };
63    println!("Successfully opened the sensor.");
64
65    // Correct zero-point
66    match sensor.zeroed_next() {
67        Ok(_) => println!("Offset the sensor."),
68        Err(e) => {
69            println!("An error occurred during offset: {}", e);
70            return;
71        }
72    }
73
74    // Repeatedly receive wrenches from the sensor.
75    let measurement_count = 1000;
76    for i in 0..measurement_count {
77        std::thread::sleep(sensor.inner_port().timeout());
78
79        match sensor.update() {
80            Ok(w) => println!("[{}/{}] {:?}", i + 1, measurement_count, w),
81            Err(e) => println!("[{}/{}] {}", i + 1, measurement_count, e),
82        }
83    }
84
85    // Info
86    println!("Product info: {:?}", sensor.receive_product_info());
87
88    println!("dynpick-force-torque-sensor demo finished.");
89}

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