femto.pgmcompiler module#
- class PGMCompiler(filename: 'str', n_glass: 'float' = 1.5, n_environment: 'float' = 1.33, export_dir: 'str' = '', samplesize: 'tuple[float, float]' = (100, 50), laser: 'str' = 'PHAROS', home: 'bool' = False, new_origin: 'tuple[float, float]' = (0.0, 0.0), warp_flag: 'bool' = False, rotation_angle: 'float' = 0.0, aerotech_angle: 'float' = 0.0, long_pause: 'float' = 0.5, short_pause: 'float' = 0.05, output_digits: 'int' = 6, speed_pos: 'float' = 5.0, flip_x: 'bool' = False, flip_y: 'bool' = False, _total_dwell_time: 'float' = 0.0, _shutter_on: 'bool' = False, _mode_abs: 'bool' = True)#
Bases:
object
- filename: str#
- n_glass: float = 1.5#
- n_environment: float = 1.33#
- export_dir: str = ''#
- samplesize: tuple[float, float] = (100, 50)#
- laser: str = 'PHAROS'#
- home: bool = False#
- new_origin: tuple[float, float] = (0.0, 0.0)#
- warp_flag: bool = False#
- rotation_angle: float = 0.0#
- aerotech_angle: float = 0.0#
- long_pause: float = 0.5#
- short_pause: float = 0.05#
- output_digits: int = 6#
- speed_pos: float = 5.0#
- flip_x: bool = False#
- flip_y: bool = False#
- classmethod from_dict(param)#
Create an instance of the class from a dictionary.
It takes a class and a dictionary, and returns an instance of the class with the dictionary’s keys as the instance’s attributes.
- Parameters:
param (dict[str, Any]) – Dictionary mapping values to class attributes.
dict() – Dictionary mapping values to class attributes.
- Return type:
Instance of class
- property xsample: float#
x-dimension of the sample
- Return type:
The absolute value of the x element of the samplesize array.
- property ysample: float#
y-dimension of the sample
- Return type:
The absolute value of the y element of the samplesize array.
- property neff: float#
Effective refractive index.
- Return type:
Effective refractive index of the waveguide.
- property pso_label: str#
PSO command lable.
If the laser is ANT, return Z, otherwise return X.
- Return type:
Lable for the PSO commands.
- property tshutter: float#
Shuttering delay.
Function that gives the shuttering delay time given the fabrication laboratory.
- Return type:
Delay time [s].
- property dwell_time: float#
Total DWELL time.
- Return type:
Total pausing times in the G-code script.
- header()#
Add header instructions.
It reads the header file for the laser cutter and adds it to the instructions list. The user can specify the fabrication line to work in
ANT
,CARBIDE
,PHAROS
orUWE
laser when the G-Code Compiler obj is instantiated.- Return type:
None
- dvar(variables)#
Add declared variable instructions.
Adds the declaration of variables in a G-Code file.
- Parameters:
variables (list(str)) – List of G-Code variables.
- Return type:
None
- mode(mode='abs')#
Movements mode.
The function appends the mode string to the list of instructions. If the string is not ‘abs’ or ‘inc’, it will raise a ValueError.
- Parameters:
mode (str, optional) – Operation mode of the movements commands. It can be ABSOLUTE or INCREMENTAL. The default value is ABSOLUTE.
- Return type:
None
- comment(comstring)#
Add a comment.
Adds a comment to a G-Code file.
- Parameters:
comstring (str) – Comment string.
- Return type:
None
- shutter(state)#
Open and close shutter.
Adds the instruction to open (or close) the shutter to a G-Code file. The user specifies the state and the function compare it to the current state of the shutter (which is tracked internally during the compilation of the .pgm file).
- Parameters:
state (str) – State of the shutter (ON or OFF).
- Return type:
None
- dwell(pause)#
Add pause.
- Parameters:
pause (float) – Pause duration [s].
- Return type:
None
- set_home(home_pos)#
Set coordinates of present position.
The user can set the current Aerotech postition to a particular set of coordinates, given as an input list. A variable can be excluded if set to
None
. The function can be used to set a user-defined home position.- Parameters:
home_pos (list(float)) – List of coordinates (x, y, z) of the new value for the current point [mm].
- Return type:
None
- move_to(position, speed_pos=None)#
Move to target.
Utility function to move to a given position with the shutter
OFF
. The user can specify the target position and the positioning speed.- Parameters:
position (list(float, optional)) – List of target coordinates (x, y, z) [mm].
speed_pos (float, optional) – Translation speed. The default value is
self.speed_pos
.
- Return type:
None
- go_origin()#
Return to origin.
Utility function, returns to the origin (0,0,0) with shutter
OFF
.- Return type:
None
- go_init()#
Return to initial point.
Utility function to return to the initial point of fabrication (-2,0,0) with shutter
OFF
.- Return type:
None
- axis_rotation(angle=None)#
Aerotech axis rotation (G84).
Context manager for the G84 command. The user can specify the angle (in degree) of the axis rotation.
- Parameters:
angle (float) – Value [deg] of the rotation angle
- Yields:
Current PGMCompiler instance
- Return type:
Generator[PGMCompiler, None, None]
- for_loop(var, num)#
Foor loop instruction.
Context manager that manages a
FOR
loops in a G-Code file.- Parameters:
var (str) – Iterating variable.
num (int) – Number of iterations.
- Yields:
Current PGMCompiler instance
- Return type:
Generator[PGMCompiler, None, None]
- repeat(num)#
Repeat loop instruction.
Context manager that manages a
REPEAT
loops in a G-Code file.- Parameters:
num (int) – Number of iterations.
- Yields:
Current PGMCompiler instance
- Return type:
Generator[PGMCompiler, None, None]
- tic()#
Start time measure.
Print the current time (hh:mm:ss) in message panel. The function is intended to be used before the execution of an operation or script to measure its time performances.
- Return type:
None
- toc()#
Stop time measure.
Print the current time (hh:mm:ss) in message panel. The function is intended to be used after the execution of an operation or script to measure its time performances.
- Return type:
None
- instruction(instr)#
Add G-Code instruction.
Adds a G-Code instruction passed as parameter to the PGM file.
- Parameters:
instr (str) – G-Code instruction to add.
- Return type:
None
- load_program(filename, task_id=2)#
Load G-code script.
Adds the instruction to LOAD an external G-Code script in the driver memory. The function is used for FARCALL programs.
- Parameters:
filename (str) – Filename of the G-code script.
task_id (int, optional) – Task ID number onto which the program will be loaded (and executed). The default value is 2.
- Return type:
None
- remove_program(filename, task_id=2)#
Remove program from memory buffer.
Adds the instruction to REMOVE a program from memory buffer in a G-Code file.
- Parameters:
filename (str) – Filename of the G-code script.
task_id (int, optional) – Task ID number onto which the program will be loaded (and executed). The default value is 2.
- Return type:
None
- programstop(task_id=2)#
Program stop.
Add the instruction to stop the execution of an external G-Code script and empty the Task in which the program was running.
- Parameters:
task_id (int, optional) – Task ID number onto which the program will be loaded (and executed). The default value is 2.
- Return type:
None
- farcall(filename)#
FARCALL instruction.
Adds the instruction to call and execute an external G-Code script in the current G-Code file.
- Parameters:
filename (str) – Filename of the G-code script.
- Return type:
None
- bufferedcall(filename, task_id=2)#
BUFFEREDCALL instruction.
Adds the instruction to run an external G-Code script in queue mode.
- Parameters:
filename (str) – Filename of the G-code script.
task_id (int, optional) – Task ID number onto which the program will be loaded (and executed). The default value is 2.
- Return type:
None
- farcall_list(filenames, task_id=2)#
Chiamatutto.
Load and execute sequentially a list of G-Code scripts.
- Parameters:
filenames (list(str)) – List of filenames of the G-code scripts to be executed.
task_id (list(int), optional) – Task ID number onto which the program will be loaded (and executed). The default value is 2 for all the scripts in the filename list.
- Return type:
None
- write(points)#
The function convert the quintuple (X,Y,Z,F,S) to G-Code instructions. The (X,Y,Z) coordinates are transformed using the transformation matrix that takes into account the rotation of a given rotation_angle and the homothety to compensate the (effective) refractive index different from 1. Moreover, if the warp_flag is True the points are compensated along the z-direction.
The transformed points are then parsed together with the feed rate and shutter state coordinate to produce the LINEAR (G1) movements.
- Parameters:
points (numpy.ndarray) – Numpy matrix containing the values of the tuple [X,Y,Z,F,S] coordinates.
- Returns:
None
- Return type:
None
- close(filename=None, verbose=False)#
Close and export a G-Code file.
The functions writes all the instructions in a .pgm file. The filename is specified during the class instatiation. If no extension is present, the proper one is automatically added.
- Parameters:
filename (str, optional) – Name of the .pgm file. The default value is
self.filename
.verbose (bool) – Flag to print info during .pgm file compilation.
- Return type:
None
- transform_points(x, y, z)#
Transform points.
The function takes in a set of points and apply a set of geometrical transformation (flip, translation, rotation and warp compensation).
- Parameters:
x (numpy.ndarray) – Array of the x-coordinates.
y (numpy.ndarray) – Array of the y-coordinates.
z (numpy.ndarray) – Array of the z-coordinates.
- Returns:
Transformed x, y and z arrays.
- Return type:
tuple(numpy.ndarray, numpy.ndarray, numpy.ndarray)
- flip(xc, yc)#
Flip path.
Flip the laser path along the x and y coordinates.
- Parameters:
xc (numpy.ndarray) – Array of the x-coordinates.
yc (numpy.ndarray) – Array of the y-coordinates.
- Returns:
Flipped x and y arrays.
- Return type:
tuple(numpy.ndarray, numpy.ndarray, numpy.ndarray)
- compensate(x, y, z)#
Warp compensation.
Returns the z-compensated points for the glass warp using
self.fwarp
function.- Parameters:
x (numpy.ndarray) – Array of the x-coordinates.
y (numpy.ndarray) – Array of the y-coordinates.
z (numpy.ndarray) – Array of the z-coordinates.
- Returns:
Untouched x, y arrays and z-compensated array.
- Return type:
tuple(numpy.ndarray, numpy.ndarray, numpy.ndarray)
- property t_matrix: ndarray[Any, dtype[float32]]#
Composition of xy rotation matrix and z refractive index compensation.
Given the rotation rotation_angle and the refractive index, the function compute the transformation matrix as composition of rotation matrix (RM) and a homothety matrix (SM).
- Returns:
Composition of xy rotation matrix and z compensation for the refractive change between air (or water) and glass interface.
- Return type:
numpy.ndarray
- antiwarp_management(opt, num=16)#
It fetches an antiwarp function in the current working direcoty. If it doesn’t exist, it lets you create a new one. The number of sampling points can be specified.
- Parameters:
opt (bool) – Flag to bypass the warp compensation.
num (int) – Number of points for the interpolation of the sample’s surface.
- Returns:
Interpolating function S(x, y) of the surface of the sample.
- Return type:
interpolate.interp2d
- static antiwarp_generation(samplesize, num, margin=2)#
Helper for the generation of antiwarp function. The minimum number of data points required is (k+1)**2, with k=1 for linear, k=3 for cubic and k=5 for quintic interpolation.
- Parameters:
samplesize (Tuple(float, float)) – glass substrate dimensions, (x-dim, y-dim)
num (int) – number of sampling points
margin (float) – margin [mm] from the borders of the glass samples
- Returns:
warp function, f(x, y)
- Return type:
scipy.interpolate.interp2d