Create gcode file from image with arguments
#38-Create GCode from image closes #38
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,3 +2,6 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
|
|
||||||
\.idea/
|
\.idea/
|
||||||
|
|
||||||
|
pcbdevice/resources/output/
|
||||||
|
pcbdevice/tests/resources/output/
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def listToGCode(listIndex, pHeight, pWidth):
|
|||||||
gcodeCommand.append('G0 Z0')
|
gcodeCommand.append('G0 Z0')
|
||||||
toolUp = True
|
toolUp = True
|
||||||
else:
|
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:
|
if toolUp:
|
||||||
gcodeCommand.append('G0 Z3')
|
gcodeCommand.append('G0 Z3')
|
||||||
toolUp = False
|
toolUp = False
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
from pcbdevice.utils.path import path
|
import math
|
||||||
from pcbdevice.utils.plotimg import plotPath
|
|
||||||
|
from pcbdevice.gcode.GcodeBuilder import listToGCode
|
||||||
|
|
||||||
|
from pcbdevice.gcode.GcodeCreator import createSequence
|
||||||
|
from pcbdevice.gcode.path import path
|
||||||
from pcbdevice.utils.FileUtils import FileUtils
|
from pcbdevice.utils.FileUtils import FileUtils
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(prog = 'main.py')
|
parser = argparse.ArgumentParser(prog = 'main.py')
|
||||||
parser.add_argument('-i', required = True, help = 'PCB image path')
|
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('-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('-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')
|
parser.add_argument('-u', required = False, help = 'PCB dimension unit')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -18,12 +24,8 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi)
|
pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi)
|
||||||
|
|
||||||
|
rTool = int(math.ceil(args.t * pxHeight if pxHeight > pxWidth else pxWidth))
|
||||||
resourcesRawPath = 'tests/resources/raw/'
|
matrixUpdated = path(matrix, rTool)
|
||||||
resourcesFormattedPath = 'tests/resources/formatted/'
|
listIndexes = createSequence(matrixUpdated)
|
||||||
resourcesPathOutput = 'resources/pathoutput/'
|
gcode = listToGCode(listIndexes, pxHeight, pxWidth)
|
||||||
resourcesExpectedPath = 'tests/resources/expected/'
|
FileUtils.saveStringListToFile(gcode, args.o)
|
||||||
|
|
||||||
#FileUtils.saveMatrixToFile(FileUtils.pbmToMatrix(resourcesRawPath + 'test1ascii.pbm'), resourcesFormattedPath + 'test1.csv')
|
|
||||||
|
|
||||||
#plotPath(path(FileUtils.pbmToMatrix(resourcesRawPath + 'test100x100.pbm'), 5))
|
|
||||||
@@ -42,3 +42,4 @@ class TestFileUtils(TestCase):
|
|||||||
self.assertEqual((10, 10), FileUtils.getPixelSize(10, 10, 1, 1, unit = 'm'))
|
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((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'))
|
||||||
Reference in New Issue
Block a user