-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLBRWrenchSineOverlay.py
139 lines (113 loc) · 3.78 KB
/
LBRWrenchSineOverlay.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
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
import argparse
import math
import sys
import numpy as np
import pyfri as fri
class LBRWrenchSineOverlayClient(fri.LBRClient):
def __init__(self, frequencyX, frequencyY, amplitudeX, amplitudeY):
super().__init__()
self.frequencyX = frequencyX
self.frequencyY = frequencyY
self.amplitudeX = amplitudeX
self.amplitudeY = amplitudeY
self.stepWidthX = 0.0
self.stepWidthY = 0.0
self.phiX = 0.0
self.phiY = 0.0
self.wrench = np.zeros(6, dtype=np.float32)
def monitor(self):
pass
def onStateChange(self, old_state, new_state):
if new_state == fri.ESessionState.MONITORING_READY:
self.phiX = 0.0
self.phiY = 0.0
self.stepWidthX = (
2.0 * math.pi * self.frequencyX * self.robotState().getSampleTime()
)
self.stepWidthY = (
2.0 * math.pi * self.frequencyY * self.robotState().getSampleTime()
)
def waitForCommand(self):
self.robotCommand().setJointPosition(self.robotState().getIpoJointPosition())
if self.robotState().getClientCommandMode() == fri.EClientCommandMode.WRENCH:
self.robotCommand().setWrench(self.wrench)
def command(self):
self.robotCommand().setJointPosition(self.robotState().getIpoJointPosition())
if self.robotState().getClientCommandMode() == fri.EClientCommandMode.WRENCH:
self.wrench[0] = self.amplitudeX * math.sin(self.phiX)
self.wrench[1] = self.amplitudeY * math.sin(self.phiY)
self.phiX += self.stepWidthX
self.phiY += self.stepWidthY
if self.phiX >= 2.0 * math.pi:
self.phiX -= 2.0 * math.pi
if self.phiY >= 2.0 * math.pi:
self.phiY -= 2.0 * math.pi
self.robotCommand().setWrench(self.wrench)
def args_factory():
parser = argparse.ArgumentParser(description="LRBJointSineOverlay example.")
parser.add_argument(
"--hostname",
dest="hostname",
default=None,
help="The hostname used to communicate with the KUKA Sunrise Controller.",
)
parser.add_argument(
"--port",
dest="port",
type=int,
default=30200,
help="The port number used to communicate with the KUKA Sunrise Controller.",
)
parser.add_argument(
"--frequencyx",
dest="frequencyX",
type=float,
default=0.25,
help="The frequency of sine wave in x-axis.",
)
parser.add_argument(
"--frequencyy",
dest="frequencyY",
type=float,
default=0.25,
help="The frequency of sine wave in y-axis.",
)
parser.add_argument(
"--amplitudex",
dest="amplitudeX",
type=float,
default=5.0,
help="The amplitude of sine wave in x-axis.",
)
parser.add_argument(
"--amplitudey",
dest="amplitudeY",
type=float,
default=5.0,
help="The amplitude of sine wave in y-axis.",
)
return parser.parse_args()
def main():
print("Running FRI Version:", fri.FRI_CLIENT_VERSION)
args = args_factory()
print(args)
client = LBRWrenchSineOverlayClient(
args.frequencyX, args.frequencyY, args.amplitudeX, args.amplitudeY
)
app = fri.ClientApplication(client)
success = app.connect(args.port, args.hostname)
if not success:
print("Connection to KUKA Sunrise controller failed.")
return 1
try:
while success:
success = app.step()
if client.robotState().getSessionState() == fri.ESessionState.IDLE:
break
except KeyboardInterrupt:
pass
finally:
app.disconnect()
return 0
if __name__ == "__main__":
sys.exit(main())