Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88862343
fem_scan_strategy.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Oct 21, 01:30
Size
5 KB
Mime Type
text/x-python
Expires
Wed, Oct 23, 01:30 (2 d)
Engine
blob
Format
Raw Data
Handle
21828995
Attached To
R11910 Additive Manufacturing Work
fem_scan_strategy.py
View Options
"""
A simple example showing how to use PySLM for generating slices across a 3D model
"""
import
pyslm
from
pyslm
import
hatching
as
hatching
import
numpy
as
np
from
helpers
import
*
import
pyslm.visualise
import
pyslm.geometry
import
pyslm.analysis
def
fem_scan_strategy
(
dt
,
layer_no
):
# Imports the part and sets the geometry to an STL file (frameGuide.stl)
solidPart
=
pyslm
.
Part
(
'inversePyramid'
)
stl_dir
=
'../Part_geometry/layer/'
stl_name
=
stl_dir
+
'layer_{}.stl'
.
format
(
str
(
layer_no
)
.
zfill
(
3
))
solidPart
.
setGeometry
(
stl_name
)
#solidPart.origin[0] = 0
#solidPart.origin[1] = 0
#solidPart.scaleFactor = 1.0
#solidPart.rotation = [0, 0, 0]
#solidPart.dropToPlatform()
# Create a StripeHatcher object for performing any hatching operations
myHatcher
=
hatching
.
Hatcher
()
# Set the base hatching parameters which are generated within Hatcher
if
layer_no
%
2
==
0
:
myHatcher
.
hatchAngle
=
90
else
:
myHatcher
.
hatchAngle
=
0
myHatcher
.
spotCompensation
=
0.05
myHatcher
.
numInnerContours
=
0
myHatcher
.
numOuterContours
=
1
myHatcher
.
scanContourFirst
=
True
myHatcher
.
hatchDistance
=
0.1
myHatcher
.
hatchSortMethod
=
hatching
.
AlternateSort
()
# Set the layer thickness
#layerThickness = 0.04 # [mm]
#infill_velocity_mag = 0.8
#contour_velocity_mag = 0.9
#alpha = 8e-6
#contour_infill_delay = get_interpolation_limits(0.00377/2, infill_velocity_mag, alpha)
#contour_scan_limits = get_interpolation_limits(0.00377/2, contour_velocity_mag, alpha)
#Perform the hatching operations
print
(
'Hatching Started'
)
layers
=
[]
contour_coordinates
=
[]
infill_coordinates
=
[]
geomSlice
=
solidPart
.
getVectorSlice
(
solidPart
.
boundingBox
[
5
]
-
1e-7
)
# Hatch the boundary using myHatcher
layer
=
myHatcher
.
hatch
(
geomSlice
)
# Plot the layer geometries using matplotlib
#pyslm.visualise.plot(layer, plot3D=False, plotArrows=False, plotOrderLine=False, plotColorbar=False)
#plt.show()
#plt.xlim([0, 20])
model1
=
pyslm
.
geometry
.
Model
()
model1
.
mid
=
1
model1
.
name
=
"Contour"
model2
=
pyslm
.
geometry
.
Model
()
model2
.
mid
=
2
model2
.
name
=
"Infill"
bstyle1
=
pyslm
.
geometry
.
BuildStyle
()
bstyle2
=
pyslm
.
geometry
.
BuildStyle
()
bstyle1
.
setStyle
(
bid
=
1
,
focus
=
0
,
pointExposureTime
=
0
,
pointExposureDistance
=
0
,
power
=
180
,
laserSpeed
=
800
)
bstyle2
.
setStyle
(
bid
=
2
,
focus
=
0
,
pointExposureTime
=
0
,
pointExposureDistance
=
0
,
power
=
200
,
laserSpeed
=
900
)
model1
.
buildStyles
.
append
(
bstyle1
)
model2
.
buildStyles
.
append
(
bstyle2
)
#layer.geometry[0].mid = 1
#layer.geometry[0].bid = 1
#layer.geometry[1].mid = 1
#layer.geometry[1].bid = 2
for
i
in
range
(
len
(
layer
.
geometry
[
0
:
-
1
])):
layer
.
geometry
[
i
]
.
mid
=
1
layer
.
geometry
[
i
]
.
bid
=
1
layer
.
geometry
[
-
1
]
.
mid
=
2
layer
.
geometry
[
-
1
]
.
bid
=
2
scanIter
=
pyslm
.
analysis
.
ScanIterator
([
model1
,
model2
],
[
layer
])
scanIter
.
timestep
=
dt
# Generate a list of point exposures - note the 3rd column is the current time
ab
=
np
.
array
([
point
for
point
in
scanIter
])
if
layer_no
%
2
==
0
:
contourtime
=
scanIter
.
getLayerTime
(
0
)
-
scanIter
.
getLayerGeomTime
(
0
,
-
1
)
contourstep
=
int
(
np
.
ceil
(
contourtime
/
dt
))
infill_scan
=
ab
[
contourstep
:]
y0
=
infill_scan
[
0
,
1
]
k
=
0
counter
=
0
for
i
,
j
in
enumerate
(
infill_scan
):
y
=
j
[
1
]
if
y0
!=
y
:
if
counter
%
2
==
0
:
infill_scan
[
k
:
i
,
0
]
=
np
.
sort
(
infill_scan
[
k
:
i
,
0
])
else
:
infill_scan
[
k
:
i
,
0
]
=
np
.
flip
(
np
.
sort
(
infill_scan
[
k
:
i
,
0
]))
#print((infill_scan[k:i]))
k
=
i
y0
=
y
counter
+=
1
ab
[
contourstep
:]
=
infill_scan
# t = 0
# for i in range(len(ab)):
# t += dt
# scanIter.seek(time=t)
# print(scanIter.getCurrentLaserPosition(), scanIter.isLaserOn())
#store = np.zeros((len(ab),4))
#scanIter.seekByLayer(0)
#scanIter._layerGeomTime = 0
"""
scanIter.seekByLayerGeometry(0, 0)
#np.array([point for point in scanIter])
print(scanIter.getLayerGeomTime(0,0), scanIter.getLayerGeomTime(0,1))
t = np.arange(1e-14, scanIter.getLayerGeomTime(0,0), scanIter.timestep)
for i,pff in enumerate(t):
# Seek based on the time
scanIter.seek(time=pff+1e-14)
# Get the current laser state (position, laser parameters, firing)
laserX, laserY = scanIter.getCurrentLaserPosition()
laserOn = scanIter.isLaserOn()
bstyle = scanIter.getCurrentBuildStyle()
print("1", scanIter._layerGeomTime, pff, laserX, laserY, laserOn, scanIter.time, bstyle.laserPower)
store[i] = laserX/1000, laserY/1000, bstyle.laserPower, scanIter.time
scanIter.seekByLayerGeometry(0, -1)
#np.array([point for point in scanIter])
t = np.arange(1e-14, scanIter.getLayerGeomTime(0,-1), scanIter.timestep)
for j,pff in enumerate(t):
# Seek based on the time
scanIter.seek(time=pff+1e-14+scanIter.getLayerGeomTime(0,0))
# Get the current laser state (position, laser parameters, firing)
laserX, laserY = scanIter.getCurrentLaserPosition()
laserOn = scanIter.isLaserOn()
bstyle = scanIter.getCurrentBuildStyle()
print("2", scanIter._layerGeomTime, pff, laserX, laserY, laserOn, pff, bstyle.laserPower)
store[i+j] = laserX/1000, laserY/1000, bstyle.laserPower, pff
print(scanIter.getLayerGeomTime(0,0), scanIter.getLayerGeomTime(0,1))
"""
print
(
'Completed Hatching'
)
#store = store[~np.all(store == 0, axis=1)]
ab
[:,
0
]
=
ab
[:,
0
]
/
1000
ab
[:,
1
]
=
ab
[:,
1
]
/
1000
return
ab
Event Timeline
Log In to Comment