-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTXT2LS_Kjellberg_Laser.py
156 lines (140 loc) · 6.39 KB
/
TXT2LS_Kjellberg_Laser.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
class Kjellberg_Laser(object):
def __init__(self):
# self.last_x, self.last_y, self.last_z, self.last_weld_state, self.last_nr = state_list
self.last_x = None
self.last_y = None
self.last_z = None
self.last_rx = None
self.last_ry = None
self.last_rz = None
# self.last_A = None
# self.last_B = None
# self.last_v = None
# self.last_cnt = None
# self.path_control_style = None
self.last_weld_state = None
self.last_nr = 0
self.output = None
self.tail = None
def get_main_header(self):
utool_number = 3
template = [f" CALL HOME_ALL",
"",
f" UFRAME_NUM = 1",
f" UTOOL_NUM = {utool_number}",
f" COL GUARD ADJUST 150",
f" !Teach Startpoint in PR90",
f" !----",
# f" !Hoehenzusatz R99 in mm",
f" !Weld speed R100 in mm/sec",
f" !Retraction +Z in R101 in mm",
f" !Retraction speed in R102 in %",
f" !END_PUB Time Before in R103 in s",
f" !Wartezeit nach Schweissstop R104 in s",
f" !Drahtvorschubzeit R105",
f" !----",
f""]
return template
def parse_line(self, dataset, flag, output):
self.output = output
# print(dataset)
nr, x, y, z, rx, ry, rz, weld_state = dataset.replace(
" ", "").replace("\n", "").split(",")
assert_border_xyz = 300
assert_border_rxryrz = 45
# assert_border_AB = 80 # fuers erste # TODO
nr = int(nr)
assert nr >= 0
x = float(x)
assert x <= assert_border_xyz and x >= -assert_border_xyz
y = float(y)
assert y <= assert_border_xyz and y >= -assert_border_xyz
z = float(z)
assert z <= assert_border_xyz and z >= 0
# rotations
rx = float(rx)
assert rx <= assert_border_rxryrz and rx >= -assert_border_rxryrz
ry = float(ry)
assert ry <= assert_border_rxryrz and ry >= -assert_border_rxryrz
rz = float(rz)
assert rz <= 180 and rz >= -180
weld_state = int(weld_state)
assert weld_state == 1 or weld_state == 0
if self.last_weld_state is not None:
# print("not None")
if weld_state != self.last_weld_state:
# print("not equal")
if weld_state == 1:
# end of retraction and start welding
# remove last drive command, antroduce safety point,
# drive there, and reinsert drivecommand
self.output[-1] = f" PR[92] = PR[91]"
self.output.append(f" PR[92,3] = PR[92,3] + R[101]")
self.output.append(f"J PR[92] R[102]% CNT100")
self.output.append(
f"L PR[91] 100mm/sec FINE RampTo R[100]")
self.output.append(f" WAIT 2.00(sec)")
self.output.append(f" CALL LASER_DRAHT_START")
elif weld_state == 0:
# print("0")
# end of welding and start of retraction
# add weldstop to last drive command, add retractio and drive there
self.output[-1] += "TB R[103]sec,CALL END_PUD"
self.output.append(f" WAIT .50(sec)")
self.output.append(f" DO[117:Laser Start]=OFF")
self.output.append(f" WAIT R[104]")
self.output.append(f" R[4] = 1.2")
self.output.append(f" DO[123]=ON")
self.output.append(f" WAIT R[105]")
self.output.append(f" DO[123]=OFF")
self.output.append(f" WAIT 10.00(sec)")
self.last_weld_state = weld_state
# if layer changes, then actualise from teached point
# to enable corrections in process
if nr != self.last_nr:
self.last_nr = nr
self.output.append(f" !-- Layer/Ebene {nr} --")
self.output.append(f" PR[91] = PR[90]")
self.output.append(f" PR[91,1] = PR[90,1] + {x:4.3f}")
self.output.append(f" PR[91,2] = PR[90,2] + {y:4.3f}")
self.output.append(f" PR[91,3] = PR[90,3] + {z:4.3f}")
# self.output.append(f" PR[91,4] = PR[90,4] - {rx:4.3f}")
# self.output.append(f" PR[91,5] = PR[90,5] + {ry:4.3f}")
# self.output.append(f" PR[91,6] = PR[90,6] + {rz:4.3f}")
self.last_x, self.last_y, self.last_z = x, y, z
self.last_rx, self.last_ry, self.last_rz = rx, ry, rx
else:
if x != self.last_x:
self.last_x = x
self.output.append(f" PR[91,1] = PR[90,1] + {x:4.3f}")
if y != self.last_y:
self.last_y = y
self.output.append(f" PR[91,2] = PR[90,2] + {y:4.3f}")
if z != self.last_z:
self.last_z = z
self.output.append(f" PR[91,3] = PR[90,3] + {z:4.3f}")
if rx != self.last_rx:
self.last_rx = rx
self.output.append(f" PR[91,4] = PR[90,4] - {rx:4.3f}")
if ry != self.last_ry:
self.last_ry = ry
self.output.append(f" PR[91,5] = PR[90,5] + {ry:4.3f}")
# if rz != self.last_rz:
# self.last_rz = rz
# self.output.append(f" PR[91,6] = PR[90,6] + {rz:4.3f}")
if flag == "start":
self.output.append(f"L PR[91] R[100]mm/sec CNT100")
elif flag == "welding":
self.output.append(f"L PR[91] R[100]mm/sec CNT100")
elif flag == "stop":
self.output.append(f"L PR[91] R[100]mm/sec CNT100")
self.output[-1] += " TB R[103]sec,CALL END_PUD"
self.output.append(f" DO[117:Laser Start]=OFF")
self.output.append(f" !Sicherheitspunkt!")
self.output.append(f" PR[92] = PR[91]")
self.output.append(f" PR[92,3] = PR[92,3] + R[101]")
self.output.append(f"J PR[92] R[102]% CNT100")
self.output.append(f" WAIT 10.00(sec)")
self.output.append(f" DO[119:Gas]=OFF")
else:
print(f"something is wrong with dataset: {dataset}")