Repository navigation
Expand file tree
/
Copy pathkeycontrol.py
More file actions
158 lines (121 loc) · 3.42 KB
/
Copy pathkeycontrol.py
File metadata and controls
158 lines (121 loc) · 3.42 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# keycontrol.py
# Charlie DeLorey
# 08/01/2019
# purpose: control arm with keyboard keys
# **program takes the current gripper state ("open" or "close") as commandline argument**
# Currently no support for end effector orientation (rx, ry, rz)
"""
KEY MAPPING
Open gripper: Close gripper:
| | ||
/ \ / \
| | | |
h g
In the horizontal plane:
/ \
w
< a d >
s
\ /
In the vertical plane:
/ \
i
< j l >
k
\ /
"""
import time
import urx
import logging
import sys
import math
from urx.robotiq_two_finger_gripper import Robotiq_Two_Finger_Gripper
from signal import signal, SIGINT
from sys import exit
def handler(signal_received, frame):
exit(0)
#function for getting character input from keyboard
class _Getch:
"""Gets a single character from standard input. Does not echo to the
screen."""
def __init__(self):
try:
self.impl = _GetchWindows()
except ImportError:
self.impl = _GetchUnix()
def __call__(self): return self.impl()
class _GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class _GetchWindows:
def __init__(self):
import msvcrt
def __call__(self):
import msvcrt
return msvcrt.getch()
getch = _Getch()
#function for calculating axis adjustment
def calc_dist(l):
return (l / math.sqrt(2))
if __name__ == "__main__":
rob = urx.Robot("172.22.22.2")
signal(SIGINT, handler)
robotiqgrip = Robotiq_Two_Finger_Gripper(rob, 1.2)
gripstate = sys.argv[1]
l = 0.05
v = 0.03
a = 0.1
pose = rob.getl()
counter = 1
while counter == 1 :
#THE COMMANDS MOVE THE END EFFECTOR RELATIVE TO THE VIEWER (i.e. "forward" means toward the viewer)
inp = getch()
if inp == "s":
pose[0] += l
rob.movep(pose, acc=a, vel=v, wait=False) #forward x
if inp == 'a':
pose[1] += calc_dist(l) #change y
pose[2] -= calc_dist(l) #change z; combined, they will move the ee correctly
rob.movep(pose, acc=a, vel=v, wait=False) #left
if inp == "w":
pose[0] -= l
rob.movep(pose, acc=a, vel=v, wait=False) #back x
if inp == 'd':
pose[1] -= calc_dist(l)
pose[2] += calc_dist(l)
rob.movep(pose, acc=a, vel=v, wait=False) #right
if inp == 'i':
pose[1] -= calc_dist(l)
pose[2] -= calc_dist(l)
rob.movep(pose, acc=a, vel=v, wait=False)
if inp == 'j':
pose[1] += calc_dist(l)
pose[2] -= calc_dist(l)
rob.movep(pose, acc=a, vel=v, wait=False)
if inp == 'k':
pose[1] += calc_dist(l)
pose[2] += calc_dist(l)
rob.movep(pose, acc=a, vel=v, wait=False)
if inp == 'l':
pose[1] -= calc_dist(l)
pose[2] += calc_dist(l)
rob.movep(pose, acc=a, vel=v, wait=False)
if inp == "h": #open gripper (if not already open)
if gripstate == "close":
robotiqgrip.open_gripper()
gripstate = "open"
if inp == "g": #close gripper (if not already closed)
if gripstate == "open":
robotiqgrip.close_gripper()
gripstate = "close"
rob.close()