/
example_build_time_analysis.py
142 lines (113 loc) · 4.76 KB
/
example_build_time_analysis.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
"""
A simple example showing how to use PySLM for calculating the build time estimate.
This example takes advantage of the multi-processing module to run across more threads.
"""
import pyslm
import shapely
from pyslm import hatching as hatching
import numpy as np
import time
from multiprocessing import Manager
from multiprocessing.pool import Pool
from multiprocessing import set_start_method
"""
Constants
"""
layerThickness = 0.03 # [mm]
rotation = [60, 0.0, 45]
layerRecoatTime = 30.0 # [s]
contourLaserScanSpeed = 250.0 # [mm/s]
hatchLaserScanSpeed = 1000.0 # [mm/s]
eos_m280_alsi10mg_brate = 4.8*3600/1000 # [cm3/hr]
hatchDistance = 0.16
numCountourOffsets = 1
def calculateLayer(input):
# Typically the hatch angle is globally rotated per layer by usually 66.7 degrees per layer
d = input[0]
zid= input[1]
layerThickness = d['layerThickness']
solidPart = d['part']
# Slice the boundary
geomSlice = solidPart.getVectorSlice(zid*layerThickness, returnCoordPaths=False)
if len(geomSlice) > 0:
return geomSlice
else:
return [shapely.geometry.Polygon()]
def main():
set_start_method("spawn")
# Imports the part and sets the geometry to an STL file (frameGuide.stl)
solidPart = pyslm.Part('FrameGuide')
solidPart.setGeometry('../models/frameGuide.stl')
solidPart.origin[0] = 5.0
solidPart.origin[1] = 2.5
solidPart.scaleFactor = 1.0
solidPart.rotation = rotation
solidPart.dropToPlatform()
# Create the multi-threaded map function using the Python multiprocessing library
layers = []
p = Pool(processes=8)
d = Manager().dict()
d['part'] = solidPart
d['layerThickness'] = layerThickness
# Rather than give the z position, we give a z index to calculate the z from.
numLayers = int(solidPart.boundingBox[5] / layerThickness)
z = np.arange(0, numLayers).tolist()
# The layer id and manager shared dict are zipped into a list of tuple pairs
processList = list(zip([d] * len(z), z))
startTime = time.time()
print('Beginning Slicing')
# uncomment to test the time processing in single process
#for pc in processList:
# calculateLayer(pc)
layers = p.map(calculateLayer, processList)
p.close()
print('\t Multiprocessing time {:.1f}'.format(time.time() - startTime))
print('Slicing Finished')
polys = []
for layer in layers:
for poly in layer:
polys.append(poly)
layers = polys
"""
Calculate total layer statistics:
"""
totalHeight = solidPart.boundingBox[5]
totalVolume = solidPart.volume
totalPerimeter = np.sum([layer.length for layer in layers]) * numCountourOffsets
totalArea = np.sum([layer.area for layer in layers])
print('\nStatistics:')
print('\tDiscretised volume {:.2f} cm3'.format(totalArea * layerThickness / 1e3))
print("\tNum Layers {:d} Height: {:.2f}".format(numLayers, totalHeight))
print("\tVolume: {:.2f} cm3, Area: {:.2f} mm2, Contour Perimeter: {:.2f} mm".format(totalVolume/1000, totalArea,totalPerimeter))
"""
Calculate the time estimates:
This calculates the total scan time using the layer slice approach
"""
hatchTimeEstimate = totalArea / hatchDistance / hatchLaserScanSpeed
boundaryTimeEstimate = totalPerimeter / contourLaserScanSpeed
scanTime = hatchTimeEstimate + boundaryTimeEstimate
recoaterTimeEstimate = numLayers * layerRecoatTime
totalTime = hatchTimeEstimate + boundaryTimeEstimate + recoaterTimeEstimate
print('\nLayer Approach:')
print("\tScan Time: {:.2f} hr, Recoat Time: {:.2f} hr, Total time: {:.3f} hr".format(scanTime / 3600, recoaterTimeEstimate/3600, totalTime/3600))
"""
Calculate using a simplified approach
Projected Area:
Calculates the projected vertical area of the part
"""
print('\nApproximate Build Time Estimate:')
# Calculate the vertical face angles
v0 = np.array([[0., 0., 1.0]])
v1 = solidPart.geometry.face_normals
sin_theta = np.sqrt((1-np.dot(v0, v1.T)**2))
triAreas = solidPart.geometry.area_faces * sin_theta
projectedArea = np.sum(triAreas)
print('\tProjected surface area: {:.3f}'.format(projectedArea))
print('\tSurface area: {:.3f}'.format(solidPart.surfaceArea))
approxScanTime = solidPart.volume/(hatchDistance * hatchLaserScanSpeed * layerThickness) + solidPart.surfaceArea / (contourLaserScanSpeed*layerThickness)
approxProjectedScanTime = solidPart.volume / (hatchDistance * hatchLaserScanSpeed * layerThickness) + projectedArea / (
contourLaserScanSpeed * layerThickness)
print('\tApprox scan time (surface) {:.2f} hr'.format(approxScanTime/3600))
print('\tApprox scan time (using projected area): {:.2f} hr'.format(approxProjectedScanTime/3600))
if __name__ == '__main__':
main()