Create gcode file from image with arguments

#38-Create GCode from image
closes #38
This commit is contained in:
Marc-Antoine Lafreniere
2019-02-21 13:41:08 -05:00
parent e842141e59
commit f5599ce4b7
4 changed files with 20 additions and 14 deletions

View File

@@ -14,7 +14,7 @@ def listToGCode(listIndex, pHeight, pWidth):
gcodeCommand.append('G0 Z0')
toolUp = True
else:
gcodeCommand.append('G0 X' + str(coord.getX()*pWidth) + ' Y' + str(coord.getY()*pHeight))
gcodeCommand.append('G0 X' + str(round(coord.getX()*pWidth, 2)) + ' Y' + str(round(coord.getY()*pHeight, 2)))
if toolUp:
gcodeCommand.append('G0 Z3')
toolUp = False

View File

@@ -1,13 +1,19 @@
from pcbdevice.utils.path import path
from pcbdevice.utils.plotimg import plotPath
import math
from pcbdevice.gcode.GcodeBuilder import listToGCode
from pcbdevice.gcode.GcodeCreator import createSequence
from pcbdevice.gcode.path import path
from pcbdevice.utils.FileUtils import FileUtils
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog = 'main.py')
parser.add_argument('-i', required = True, help = 'PCB image path')
parser.add_argument('-o', required = True, help = 'Gcode output path')
parser.add_argument('-wi', required = True, type = int, help = 'Width of the PCB')
parser.add_argument('-he', required = True, type = int, help = 'Height of the PCB')
parser.add_argument('-t', required = True, type = int, help = 'Tool\'s radius in mm')
parser.add_argument('-u', required = False, help = 'PCB dimension unit')
args = parser.parse_args()
@@ -17,13 +23,9 @@ if __name__ == "__main__":
pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi, unit = args.u)
else:
pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi)
resourcesRawPath = 'tests/resources/raw/'
resourcesFormattedPath = 'tests/resources/formatted/'
resourcesPathOutput = 'resources/pathoutput/'
resourcesExpectedPath = 'tests/resources/expected/'
#FileUtils.saveMatrixToFile(FileUtils.pbmToMatrix(resourcesRawPath + 'test1ascii.pbm'), resourcesFormattedPath + 'test1.csv')
#plotPath(path(FileUtils.pbmToMatrix(resourcesRawPath + 'test100x100.pbm'), 5))
rTool = int(math.ceil(args.t * pxHeight if pxHeight > pxWidth else pxWidth))
matrixUpdated = path(matrix, rTool)
listIndexes = createSequence(matrixUpdated)
gcode = listToGCode(listIndexes, pxHeight, pxWidth)
FileUtils.saveStringListToFile(gcode, args.o)

View File

@@ -41,4 +41,5 @@ class TestFileUtils(TestCase):
self.assertEqual((10, 10), FileUtils.getPixelSize(10, 10, 10, 10, unit = 'cm'))
self.assertEqual((10, 10), FileUtils.getPixelSize(10, 10, 1, 1, unit = 'm'))
self.assertEqual((25.4, 25.4), FileUtils.getPixelSize(10, 10, 10, 10, unit = 'in'))
self.assertEqual((1, 2), FileUtils.getPixelSize(10, 10, 10, 20))
self.assertEqual((1, 2), FileUtils.getPixelSize(10, 10, 10, 20))
self.assertRaises(RuntimeError, lambda: FileUtils.getPixelSize(10, 10, 10, 10, 'ft'))