Struct RobotiqGripper

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

Data Structure for interfacing with robotiq gripper with modbus rtu protocol.

Implementations§

Source§

impl RobotiqGripper

Source

pub const DEFAULT_SLAVE_ID: u8 = 9u8

The Default Modbus slave ID of robotiq gripper

Source

pub fn new(ctx: Context) -> Self

Constructer from a modbus context.

Source

pub fn from_path_slave_id( path: impl Into<String>, slave_id: u8, ) -> Result<Self, Error>

Constructer from USB port path, and slave id.

Source

pub fn from_path(path: impl Into<String>) -> Result<Self, Error>

Constructer form USB port path.

Examples found in repository?
examples/001_basic.rs (line 9)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn write_async( &mut self, cmd: GripperCommand, ) -> Result<(), RobotiqError>

Async function for writing a GripperCommand to the gripper

Examples found in repository?
examples/001_basic.rs (line 80)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn read_async(&mut self) -> Result<GripperStatus, RobotiqError>

Async function for reading GripperCommand from the gripper

Examples found in repository?
examples/001_basic.rs (line 82)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn reset(&mut self) -> Result<&mut Self, RobotiqError>

Turn off the activation bit rACT, to reset fault.

Examples found in repository?
examples/001_basic.rs (line 14)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn activate(&mut self) -> Result<&mut Self, RobotiqError>

Turn on the activation bit rACT to start initalization of the gripper

Examples found in repository?
examples/001_basic.rs (line 16)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn await_activate(&mut self) -> Result<&mut Self, RobotiqError>

Await for the initalization process to finish.

Examples found in repository?
examples/001_basic.rs (line 16)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn go_to( &mut self, pos_req: u8, speed: u8, force: u8, ) -> Result<&mut Self, RobotiqError>

Command the gripper to go to a certain set point with specified position, speed and force

§Parameter
§pos_req: u8

This register is used to set the target position for the gripper’s fingers. The position 0x00 and 0xFF correspond respectively to the fully opened and fully closed mechanical stops. For detail finger trajectory, please refer to the Specifications section of repective manual.

  • 0x00 - Open position
  • 0xFF - Close position
§Info

The activation will allow the gripper to adjust to any fingertips. No matter what is the size and/or shape of the fingertips, 0 will always be fully opened and 255 fully closed, with a quasi-linear relationship between the two values.

§speed: u8

This register is used to set the gripper closing and opening speed in real time, however, setting a speed will not initiate a motion.

  • 0x00 - Minimum speed
  • 0xFF - Maximum speed
§force: u8

The force setting defines the final gripper force for the gripper. The force will fix the maximum current sent to the motor. If the current limit is exceeded, the fingers stop and trigger an object detection notification. Please refer to the “Picking Features” section of respective manual.

  • 0x00- Minimum force
  • 0xFF- Maximum force
Examples found in repository?
examples/001_basic.rs (line 23)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn await_go_to(&mut self) -> Result<ObjDetectStatus, RobotiqError>

Await for the “Go To” command to finish.

§Return ObjDetectStatus

this function will return, when the gripper detected object at the end point, or reached target position.

Examples found in repository?
examples/001_basic.rs (line 25)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn automatic_release( &mut self, open: bool, ) -> Result<&mut Self, RobotiqError>

§Automatic release feature.

Automatic Release routine action slowly opens the gripper fingers until all motion axes reach their mechanical limits After all motion are completed, the gripper sends a fault signal and needed to be reinitalized before any other motion is performed. The atr(rATR) bit overrides all other commands excluding the activation bit act(rACT).

§Auto-release direction.

When auto-releasing, ard(rARD) commands the direction of the movement. The ard(rARD) bit should be set prior to or at the same time as the atr(rATR) bit. as the motion direction is set when the auto-release is initated.

Examples found in repository?
examples/001_basic.rs (line 41)
4async fn main() -> Result<(), RobotiqError> {
5    // The serial port path
6    let path = "COM17";
7
8    // create a connection to serial RS485 modbus
9    let mut gripper = RobotiqGripper::from_path(path)?;
10
11    // Reset and Activation of Gripper
12    //
13    // reset gripper, recommended
14    gripper.reset().await?;
15    // activate the gripper, it will try to open and close.
16    gripper.activate().await?.await_activate().await?;
17    println!("finished activation.");
18    std::thread::sleep(std::time::Duration::from_millis(1000));
19
20    // Basic Gripper Command
21    //
22    // set gripper with position, speed and force
23    gripper.go_to(0x08, 0x00, 0x00).await?;
24    // the result of the setting command, return whether or not it have clamp an object
25    let obj_detect_status = gripper.await_go_to().await?;
26    println!("Object Detect Status : {:?}", obj_detect_status);
27    std::thread::sleep(std::time::Duration::from_millis(1000));
28
29    // Chained command
30    //
31    // chained command with builder pattern
32    let obj_detect_status = gripper.go_to(0xFF, 0xFF, 0xFF).await?.await_go_to().await?;
33    println!("Object Detect Status : {:?}", obj_detect_status);
34    std::thread::sleep(std::time::Duration::from_millis(1000));
35
36    // Automatic Release Routine
37    //
38    // set the gripper into motion
39    gripper.go_to(0x08, 0x00, 0x00).await?;
40    std::thread::sleep(std::time::Duration::from_millis(100));
41    gripper.automatic_release(false).await?;
42    // you will need to reset and reactivate the gripper after automatic release routine
43    gripper
44        .reset()
45        .await?
46        .activate()
47        .await?
48        .await_activate()
49        .await?;
50    std::thread::sleep(std::time::Duration::from_millis(1000));
51    gripper.go_to(0x08, 0x00, 0x00).await?;
52    std::thread::sleep(std::time::Duration::from_millis(1000));
53
54    // Gripper Command
55    //
56    // Construct GripperCommand to command gripper
57    //
58    // a null command, all zero, will deactivate and reset the gripper
59    let cmd_null = GripperCommand::new();
60    // command to activate the gripper
61    let cmd_act = GripperCommand::new().act(true);
62    // commands to set the gripper with position requested, speed, and force
63    let cmd_goto_1 = GripperCommand::new()
64        .act(true)
65        .gto(true)
66        .pos_req(0x08)
67        .speed(0x00)
68        .force(0x00);
69    let cmd_goto_2 = GripperCommand::new()
70        .act(true)
71        .gto(true)
72        .pos_req(0xFF)
73        .speed(0xFF)
74        .force(0xFF);
75    // command to perform automatic release routine
76    let cmd_atr = GripperCommand::new().act(true).atr(true).ard(true);
77
78    //
79    //
80    gripper.write_async(cmd_null).await?;
81    gripper.write_async(cmd_act).await?;
82    while gripper.read_async().await?.sta != ActivationStatus::Completed {
83        std::thread::sleep(std::time::Duration::from_millis(100));
84    }
85    std::thread::sleep(std::time::Duration::from_millis(1000));
86
87    //
88    //
89    gripper.write_async(cmd_goto_1).await?;
90    while gripper.read_async().await?.obj == ObjDetectStatus::InMotion {
91        std::thread::sleep(std::time::Duration::from_millis(100));
92    }
93    std::thread::sleep(std::time::Duration::from_millis(1000));
94
95    //
96    //
97    gripper.write_async(cmd_goto_2).await?;
98    std::thread::sleep(std::time::Duration::from_millis(100));
99    gripper.write_async(cmd_atr).await?;
100    while gripper.read_async().await?.fault != GripperFault::AutomaticReleaseCompleted {
101        std::thread::sleep(std::time::Duration::from_millis(100));
102    }
103    std::thread::sleep(std::time::Duration::from_millis(1000));
104
105    gripper
106        .reset()
107        .await?
108        .activate()
109        .await?
110        .await_activate()
111        .await?
112        .go_to(0x00, 0xFF, 0xFF)
113        .await?
114        .await_go_to()
115        .await?;
116
117    Ok(())
118}
Source

pub async fn await_automatic_release( &mut self, ) -> Result<&mut Self, RobotiqError>

Await for the automatic release routine to finish.

Trait Implementations§

Source§

impl Drop for RobotiqGripper

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.