Page MenuHomec4science

fem_scan_strategy.py
No OneTemporary

File Metadata

Created
Fri, Sep 13, 14:25

fem_scan_strategy.py

"""
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):
# Imports the part and sets the geometry to an STL file (frameGuide.stl)
solidPart = pyslm.Part('inversePyramid')
solidPart.setGeometry('/home/ekinkubilay/Documents/AM/Part_geometry/layer/layer_001.stl')
#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
myHatcher.hatchAngle = 0
myHatcher.spotCompensation = 0.05
myHatcher.numInnerContours = 0
myHatcher.numOuterContours = 1
myHatcher.scanContourFirst = True
myHatcher.hatchDistance = 0.05
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)
print('Completed Hatching')
# Plot the layer geometries using matplotlib
pyslm.visualise.plot(layer, plot3D=False, plotArrows=False, plotOrderLine=False, plotColorbar=False)
plt.show()
#plt.xlim([-10, -5])
model = pyslm.geometry.Model()
model.mid = 1
model.name = "Infill"
bstyle1 = pyslm.geometry.BuildStyle()
bstyle2 = pyslm.geometry.BuildStyle()
bstyle1.setStyle(bid=1, focus=1, pointExposureTime=0, pointExposureDistance=0 ,power=180, laserSpeed = 800, laserMode=pyslm.geometry.LaserMode.CW)
bstyle2.setStyle(bid=2, focus=1, pointExposureTime=0, pointExposureDistance=0 ,power=200, laserSpeed = 900, laserMode=pyslm.geometry.LaserMode.CW)
model.buildStyles.append(bstyle1)
model.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 = 1
layer.geometry[-1].bid = 2
scanIter = pyslm.analysis.ScanIterator([model], [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])
#print(ab)
store = np.zeros((len(ab),4))
#scanIter.seekByLayer(0)
#scanIter._layerGeomTime = 0
"""
scanIter.seekByLayerGeometry(0, 0)
#np.array([point for point in scanIter])
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
"""
#store = store[~np.all(store == 0, axis=1)]
ab[:,0] = ab[:,0]/1000
ab[:,1] = ab[:,1]/1000
return ab
#d = fem_scan_strategy(4e-4)

Event Timeline