Skip to content

Viewing imported G-code #684

@letrow

Description

@letrow

An imported gcode file of some 2700 lines is properly displayed in its entirety in the viewer when first opened, but when I move the sim slider back and forth the last part of the pattern disappears and only a part is shown. Buffer size restrictions in the sim?

Also the Doc tab has no effect on an imported gcode file, whereas zooming with the mouse works OK.

Here is the python code that generates the gcode:
`

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
This program generates test patterns as G-Code that
help in determining the optimal settings for speed 
and power when cutting polyester film stencils on
my 20W diode laser.

The generated G-code should cut SMD-land patterns
for 16-pin chips. In the pattern the power is constant
in a row, whilst the speed is constant in a column.
'''


class Pattern():
    # 16-pin JEDEC Small Outline / Shrink Small Outline Packages (SOP and SSOP)
    
    def __init__(self):
        # pattern origin pitch:
        self.colPitch = 15
        self.rowPitch = 13
            
        # pitch between pads:
        self.xPitch = 5.6
        self.yPitch = 1.27
        
        # the G-Code must compensate for the laser beam thickness:
        self.laserBeamXwidth = 0.1
        self.laserBeamYwidth = 0.1
        
        # each pattern has 16 pads, each pad has 4 corners:
        # (coordinates rounded for 1/80 mm step size of my laser)
        self.C0 = (0.0+self.laserBeamXwidth, 0.0+self.laserBeamYwidth)
        self.C1 = (0.0+self.laserBeamXwidth, 0.7-self.laserBeamYwidth)
        self.C2 = (2.55-self.laserBeamXwidth, 0.7-self.laserBeamYwidth)
        self.C3 = (2.55-self.laserBeamXwidth, 0.0+self.laserBeamYwidth)
        
        # default settings:
        # S: power - actually Spindle speed hence the S; n/1000 * 20 W
        # F: speed - is called Feedrate hence F; mm/s
        self.power = 30  # initial S-setting
        self.speed = 10  # initial feedrate
        self.powerInc = 10  # increment for power values
        self.speedInc = 5   # increment for speed values

    def generate(self, col, row):
        ''' Return G-Code for the pattern at (col,row) as a string.'''
        # set power and speed:
        Sval = self.power + row*self.powerInc
        Fval = self.speed + col*self.speedInc
        
        code = ""
        
        for side in range(2):   # left / right side pins
            xOrg = col * self.colPitch + side*self.xPitch
            for pad in range(8):    # pads per side
                yOrg = row * self.rowPitch + pad*self.yPitch

                # move to origin of the pad (G0 turns laser off):
                code += "G0 X{:3.3f} Y{:3.3f}\n".format(
                    xOrg+self.C0[0], yOrg+self.C0[1])

                # laser power on
                code += "S{}\n".format(Sval)

                # cut the sides:
                code += "G1 X{:3.3f} Y{:3.3f} F{:3.2f}\n".format(
                    xOrg+self.C1[0], yOrg+self.C1[1], Fval)
                code += "G1 X{:3.3f} Y{:3.3f} F{:3.2f}\n".format(
                    xOrg+self.C2[0], yOrg+self.C2[1], Fval)
                code += "G1 X{:3.3f} Y{:3.3f} F{:3.2f}\n".format(
                    xOrg+self.C3[0], yOrg+self.C3[1], Fval)
                code += "G1 X{:3.3f} Y{:3.3f} F{:3.2f}\n".format(
                    xOrg+self.C0[0], yOrg+self.C0[1], Fval)
        return code

#------------------------------------------------------------------------------
# GENERATOR SETTINGS
#------------------------------------------------------------------------------

NROWS = 4
NCOLS = 7

gcFile = "lasertestfile.nc" # <move to sys arg?>

preamble = '''
G17 G90     (select XY-plane, absolute coordinates)
G21         (metric units)
G54         (workspace offset)
M4 S0       (enable laser, power off)
'''

postamble = '''
M5          (laser off)
M9          (mist off)
M68 E1 Q0   (fan off)
G53 G0 Y200 (move head out of the way)
M2          (end of job)
'''

def main():
    p = Pattern()
    try:
        with open(gcFile, 'w') as gcode:
            gcode.write(preamble)
            for row in range(NROWS):
                for col in range(NCOLS):
                    gcode.write(p.generate(col, row))
            gcode.write(postamble)

    except Exception as e:
        print(e)
        
if __name__ == "__main__":
    main()



`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions