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)#
- Return type
GC
- property xsample: float#
This function returns the absolute value of the first element of the samplesize array :return: The absolute value of the first element of the samplesize array.
- property ysample: float#
This function returns the absolute value of the y-axis sample size :return: The absolute value of the y-component of the sample size.
- property neff: float#
> The function neff returns the effective index of refraction of the waveguide :return: The refractive index of the glass.
- property pso_label: str#
If the laser is ANT, return Z, otherwise return X :return: The label of the PSO.
- property tshutter: float#
Function that set the shuttering time given the fabrication laboratory.
- Returns
shuttering time
- Return type
float
- property dwell_time: float#
This function returns the total dwell time of the user :return: The total dwell time of the customer.
- header()#
It reads the header file for the laser cutter and adds it to the instructions
The function print the header file of the G-Code file. The user can specify the fabrication line to work in
ANT,CARBIDE,PHAROSorUWEas parameter when the G-Code Compiler obj is instantiated.- Returns
None
- Return type
None
- dvar(variables)#
Adds the declaration of variables in a G-Code file.
- Parameters
variables (List[str]) – List of G-Code variables
- Returns
None
- Return type
None
- mode(mode='abs')#
- comment(comstring)#
Adds a comment to a G-Code file.
- Parameters
comstring (str) – Content of the comment (without line-break character).
- Returns
None
- Return type
None
- shutter(state)#
Adds the instruction to open (close) the shutter to a G-Code file only when necessary. 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). The instruction is printed to file only if the new state differs from the current one.
- Parameters
state (str) – New state of the shutter.
ONorOFF- Returns
None
- Raises
ValueError – Shutter state not valid.
- Return type
None
- dwell(pause)#
Adds pause instruction to a G-Code file.
- Parameters
pause (float) – Value of the pause time [s].
- Returns
None
- Return type
None
- set_home(home_pos)#
Defines a preset position or a software home position to the one specified in the input list. To exclude a variable set it to None.
- Parameters
home_pos (list[float]) – Ordered coordinate list that specifies software home position [mm].
- ::
home_pos[0]-> Xhome_pos[1]-> Yhome_pos[2]-> Z
- Returns
None
- Raises
ValueError – Final position is not valid.
- Return type
None
- move_to(position, speed_pos=None)#
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]) – Ordered coordinate list that specifies the target position [mm]. position[0] -> X position[1] -> Y position[2] -> Z
speed_pos (float) – Positioning speed [mm/s]. The default is self.speed_pos.
- Returns
None
- Return type
None
- go_origin()#
Utility function, return to the origin (0,0,0) with shutter OFF.
- Returns
None
- Return type
None
- go_init()#
Utility function to return to the initial point of fabrication (-2,0,0) with shutter OFF.
- Returns
None
- Return type
None
- axis_rotation(angle=None)#
- Return type
Generator[PGMCompiler, None, None]
- for_loop(var, num)#
Context manager that manages a FOR loop in a G-Code file.
- Parameters
var (str) – Name of the variable used for iteration.
num (int) – Number of iterations.
- Returns
None
- Return type
Generator[PGMCompiler, None, None]
- repeat(num)#
Context manager that manages a REPEAT loop in a G-Code file.
- Parameters
num (int) – Number of iterations.
- Returns
None
- Return type
Generator[PGMCompiler, None, None]
- tic()#
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.
- Returns
None
- Return type
None
- toc()#
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.
- Returns
None
- Return type
None
- instruction(instr)#
Adds a G-Code instruction passed as parameter to the PGM file.
- Parameters
instr (str) – Instruction line to be added to the PGM file. The
\ncharacter is optional.- Returns
None
- Return type
None
- load_program(filename, task_id=0)#
Adds the instruction to LOAD a program in a G-Code file.
- Parameters
filename (str) – Name of the file that have to be loaded.
task_id (int) – ID of the task associated to the process.
- Returns
None
- Return type
None
- programstop(task_id=0)#
- remove_program(filename, task_id=0)#
Adds the instruction to REMOVE a program from memory buffer in a G-Code file.
- Parameters
filename (str) – Name of the file to remove.
task_id (int) – ID of the task associated to the process.
- Returns
None
- Return type
None
- farcall(filename)#
Adds the FARCALL instruction in a G-Code file.
- Parameters
filename (str) – Name of the file to call.
- Returns
None
- Return type
None
- buffercall(filename, task_id=0)#
Adds the BUFFEREDRUN instruction in a G-Code file.
- Parameters
filename (str) – Name of the file to call.
task_id (int) – ID of the task associated to the process.
- Returns
None
- Return type
None
- call_list(filenames, task_id=0)#
- 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 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)#
Dumps all the instruction in self._instruction 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) – Different filename. The default is None, using self.filename.
verbose (bool) – Print when G-Code export is finished. The default is False.
- Returns
None
- Return type
None
- transform_points(x, y, z)#
- Return type
tuple[npt.NDArray[np.float32], npt.NDArray[np.float32], npt.NDArray[np.float32]]
- flip(xc, yc)#
Flip the laser path along the x-, y- and z-coordinates :return: None
- Return type
tuple[npt.NDArray[np.float32], npt.NDArray[np.float32]]
- compensate(x, y, z)#
Returns the points compensated along z-direction for the refractive index, the offset and the glass warp.
- Parameters
x (np.ndarray) – array of the x-coordinates
y (np.ndarray) – array of the y-coordinates
z (np.ndarray) – array of the z-coordinates
- Returns
(x, y, zc) tuple of x, y and compensated z points
- Return type
tuple(np.ndarray, np.ndarray, np.ndarray)
- property t_matrix: ndarray[Any, dtype[float32]]#
Given the rotation rotation_angle and the rifraction index, the function compute the transformation matrix as composition of rotatio matrix (RM) and a homothety matrix (SM).
- Returns
Transformation matrix, TM = SM*RM
- Return type
np.array
- Raises
ValueError – Dimension not valid
- 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) – if True apply antiwarp.
num (int) – number of sampling points
- Returns
warp function, f(x, y)
- Return type
scipy.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