-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_robotiq.py
69 lines (58 loc) · 2.09 KB
/
test_robotiq.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import signal
from RobotiqHand import RobotiqHand
#------------------------------------------------------------------------------
# test_robotiq.py
#------------------------------------------------------------------------------
HOST = "192.168.102.216"
PORT = 54321
cont = True
def handler(signal, frame):
global cont
cont = False
def test_robotiq():
print 'test_robotiq start'
hand = RobotiqHand()
hand.connect(HOST, PORT)
try:
print 'activate: start'
hand.reset()
hand.activate()
result = hand.wait_activate_complete()
print 'activate: result = 0x{:02x}'.format(result)
if result != 0x31:
hand.disconnect()
return
print 'adjust: start'
hand.adjust()
print 'adjust: finish'
while cont:
print 'close slow'
hand.move(255, 0, 1)
(status, position, force) = hand.wait_move_complete()
position_mm = hand.get_position_mm(position)
force_mA = hand.get_force_mA(force)
if status == 0:
print 'no object detected: position = {:.1f}mm, force = {:.1f}mA '.format(position_mm, force_mA)
elif status == 1:
print 'object detected closing: position = {:.1f}mm, force = {:.1f}mA '.format(position_mm, force_mA)
print 'keeping'
time.sleep(5)
elif status == 2:
print 'object detected opening: position = {:.1f}mm, force = {:.1f}mA '.format(position_mm, force_mA)
else:
print 'failed'
print 'open fast'
hand.move(0, 255, 0)
(status, position, force) = hand.wait_move_complete()
position_mm = hand.get_position_mm(position)
force_mA = hand.get_force_mA(force)
print 'position = {:.1f}mm, force = {:.1f}mA '.format(position_mm, force_mA)
except:
print 'Ctrl-c pressed'
hand.disconnect()
if __name__ == '__main__':
signal.signal(signal.SIGINT, handler)
test_robotiq()