-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicro_test.py
64 lines (60 loc) · 1.62 KB
/
micro_test.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
import numpy as np
import matplotlib.pyplot as plt
import time
import gcode_analyser as gan
import machining as m
"""
tg = m._connect()
for i in range(10):
m._setGcodeValue(tg, "M3 S1000")
print("Spindle on")
time.sleep(5)
m._setGcodeValue(tg, "M5")
print("Spindle off")
time.sleep(5)
m._disconnect(tg)
"""
def get_gcode_points(filename):
with open(filename, 'r') as f:
lines = f.readlines()
points = []
for line in lines:
x = float(line.split(' ')[1][1:])
y = float(line.split(' ')[2][1:])
z = float(line.split(' ')[3][1:])
points.append([x,y,z])
return np.array(points)
def write_points_to_file(filename, points):
with open(filename, 'w') as f:
for i in range(len(points[:,0])):
x = str(points[i, 0])
y = str(points[i, 1])
z = str(points[i, 2])
f.write(x+' '+y+' '+z+'\n')
#--- MAIN ---#
data = get_gcode_points('cam/deck_surface.gc')
data[:, 1] = data[:, 1] - 801.95
write_points_to_file('out/deck.asc', data)
data = get_gcode_points('cam/bottom_surface.gc')
data[:, 1] = data[:, 1] - 801.95
data[:, 2] = -data[:, 2]
write_points_to_file('out/bottom.asc', data)
print('done')
"""
p, f = gan.data_from_gcode('cam/bottom.gc')
d = gan.p2p_distance(p)
t = gan.milling_time_segment(p, f)
index = []
for i in range(len(t)):
if t[i] < 3.0*0.001:
index.append(i)
print('done..')
p, f = gan.data_from_gcode('cam/deck.gc')
d = gan.p2p_distance(p)
t = gan.milling_time_segment(p, f)
index = []
for i in range(len(t)):
if t[i] < 3.0*0.001:
index.append(i)
print('done..')
"""