pub struct DynpickSensor { /* private fields */ }Expand description
Dynpick 6-axis force-torque sensor.
Implementations§
Source§impl DynpickSensor
impl DynpickSensor
Sourcepub fn last_wrench(&self) -> Wrench
pub fn last_wrench(&self) -> Wrench
Returns the latest wrench that is stored in this instance without communicaing the sensor.
Use Self::update instead to obtain a new wrench from the sensor.
§Returns
Ok(sensor) if successfully connected, Err(reason) if failed.
Sourcepub fn sensitivity(&self) -> Sensitivity
pub fn sensitivity(&self) -> Sensitivity
Returns the sensitivity of this sensor.
Sourcepub fn update(&mut self) -> Result<Wrench, Error>
pub fn update(&mut self) -> Result<Wrench, Error>
Communicating to the sensor, updates the latest wrench.
§Returns
Ok(wrench) if succeeds, Err(reason) if failed.
Examples found in repository?
examples/demo.rs (line 79)
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}Sourcepub fn zeroed_next(&mut self) -> Result<(), Error>
pub fn zeroed_next(&mut self) -> Result<(), Error>
If this method succeeds, the next wrench acquired by Self::update will be zeroed.
This methos is useful for zero-point calibration.
§Examples
use dynpick_force_torque_sensor::{DynpickSensorBuilder, Triplet};
let mut sensor = DynpickSensorBuilder::open("/dev/ttyUSB0")
.and_then(|b| b.set_sensitivity_by_builtin_data())
.and_then(|b| b.build())
.unwrap();
sensor.zeroed_next().unwrap();
let wrench = sensor.update().unwrap();
assert_eq!(wrench.force, Triplet::new(0.0, 0.0, 0.0));
assert_eq!(wrench.torque, Triplet::new(0.0, 0.0, 0.0));Examples found in repository?
examples/demo.rs (line 66)
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}Sourcepub fn receive_product_info(&mut self) -> Result<String, Error>
pub fn receive_product_info(&mut self) -> Result<String, Error>
Reads the product info from the sensor.
§Returns
Ok(product_info) if succeeds, Err(reason) if failed.
Examples found in repository?
examples/demo.rs (line 86)
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}Sourcepub fn inner_port(&self) -> &Box<dyn SerialPort>
pub fn inner_port(&self) -> &Box<dyn SerialPort>
Returns the reference to the serial port for the sensor.
Examples found in repository?
examples/demo.rs (line 77)
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§
impl Freeze for DynpickSensor
impl !RefUnwindSafe for DynpickSensor
impl Send for DynpickSensor
impl !Sync for DynpickSensor
impl Unpin for DynpickSensor
impl UnsafeUnpin for DynpickSensor
impl !UnwindSafe for DynpickSensor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more