-
Notifications
You must be signed in to change notification settings - Fork 2
/
robotiq_gripper_example.cpp
110 lines (93 loc) · 3.61 KB
/
robotiq_gripper_example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <ur_rtde/robotiq_gripper.h>
#include <chrono>
#include <iostream>
#include <thread>
using namespace std;
using namespace ur_rtde;
/**
* Print object detection status of gripper
*/
void printStatus(int Status)
{
switch (Status)
{
case RobotiqGripper::MOVING:
std::cout << "moving";
break;
case RobotiqGripper::STOPPED_OUTER_OBJECT:
std::cout << "outer object detected";
break;
case RobotiqGripper::STOPPED_INNER_OBJECT:
std::cout << "inner object detected";
break;
case RobotiqGripper::AT_DEST:
std::cout << "at destination";
break;
}
std::cout << std::endl;
}
int main(int argc, char* argv[])
{
std::cout << "Gripper test" << std::endl;
ur_rtde::RobotiqGripper gripper("127.0.0.1", 63352, true);
gripper.connect();
// Test emergency release functionality
if (!gripper.isActive())
{
gripper.emergencyRelease(RobotiqGripper::OPEN);
}
std::cout << "Fault status: 0x" << std::hex << gripper.faultStatus() << std::dec << std::endl;
std::cout << "activating gripper" << std::endl;
gripper.activate();
// Test setting of position units and conversion of position values
gripper.setUnit(RobotiqGripper::POSITION, RobotiqGripper::UNIT_DEVICE);
std::cout << "OpenPosition: " << gripper.getOpenPosition() << " ClosedPosition: " << gripper.getClosedPosition()
<< std::endl;
gripper.setUnit(RobotiqGripper::POSITION, RobotiqGripper::UNIT_NORMALIZED);
std::cout << "OpenPosition: " << gripper.getOpenPosition() << " ClosedPosition: " << gripper.getClosedPosition()
<< std::endl;
// Test of move functionality with normalized values (0.0 - 1.0)
int status = gripper.move(1, 1, 0, RobotiqGripper::WAIT_FINISHED);
printStatus(status);
status = gripper.move(0, 1, 0, RobotiqGripper::WAIT_FINISHED);
printStatus(status);
// We preset force and and speed so we don't need to pass it to the following move functions
gripper.setForce(0.0);
gripper.setSpeed(0.5);
// We switch the position unit the mm and define the position range of our gripper
gripper.setUnit(RobotiqGripper::POSITION, RobotiqGripper::UNIT_MM);
gripper.setPositionRange_mm(50);
std::cout << "OpenPosition: " << gripper.getOpenPosition() << " ClosedPosition: " << gripper.getClosedPosition()
<< std::endl;
gripper.move(50);
status = gripper.waitForMotionComplete();
printStatus(status);
gripper.move(10);
status = gripper.waitForMotionComplete();
printStatus(status);
std::cout << "moving to open position" << std::endl;
status = gripper.open();
status = gripper.waitForMotionComplete();
printStatus(status);
// Test async move - start move and then wait for completion
gripper.close(0.02, 0, RobotiqGripper::START_MOVE);
status = gripper.waitForMotionComplete();
printStatus(status);
status = gripper.open(1.0, 0.0, RobotiqGripper::WAIT_FINISHED);
printStatus(status);
gripper.setUnit(RobotiqGripper::POSITION, RobotiqGripper::UNIT_DEVICE);
gripper.setUnit(RobotiqGripper::SPEED, RobotiqGripper::UNIT_DEVICE);
gripper.setUnit(RobotiqGripper::FORCE, RobotiqGripper::UNIT_DEVICE);
std::cout << "OpenPosition: " << gripper.getOpenPosition() << " ClosedPosition: " << gripper.getClosedPosition()
<< std::endl;
gripper.move(255, 5, 0);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
while (RobotiqGripper::MOVING == gripper.objectDetectionStatus())
{
std::cout << "waiting..." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
printStatus(gripper.objectDetectionStatus());
std::cout << "disconnecting" << std::endl;
gripper.disconnect();
}