def save_to_txt(self, fp, name): g = Gcode(name, self).to_string_list() with open(fp + name + '.txt', 'w') as f: for line in g: f.write("%s\n" % line) return None
def __init__(self, jsonName, outputFileName, gRobot, layerParamLabels, partParamLabels): self.outputFileName = outputFileName with open(jsonName, 'r') as fp: data = json.load(fp) self.pr = makeParamObj(data[0], data[1], layerParamLabels, partParamLabels) if gRobot == c.GCODE: self.gc = Gcode(self.pr) elif gRobot == c.ROBOTCODE: self.gc = RobotCode(self.pr)
def setUp(self): self.a=Gcode()
class TestGcodeReader(unittest.TestCase): def setUp(self): self.a=Gcode() def test_empty(self): code=StringIO('') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0)]) def test_onlyM2(self): code=StringIO('M2') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0)]) def test_onlyM30(self): code=StringIO('M30') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0)]) def test_singleG0(self): code=StringIO('G0') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,0,0,0)]) def test_singleG1(self): code=StringIO('G1') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,0,0,0)]) def test_emptyLine(self): code=StringIO('G0\n\nM2') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,0,0,0)]) def test_allG0(self): code=StringIO('G0 W1 X2 Y3 Z4') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(1,2,3,4)]) def test_allG1(self): code=StringIO('G1 W1 X2 Y3 Z4') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(1,2,3,4)]) def test_G0X(self): code=StringIO('G0 X2') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,2,0,0)]) def test_G02digits(self): code=StringIO('G0 X20') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,20,0,0)]) def test_MoveEndMove(self): code=StringIO('G0 X2\nM2\nG0 X2') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,2,0,0)]) #two moves one coord def test_2MovesX(self): code=StringIO('G0 X2\nG0 X3') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,2,0,0),(0,3,0,0)]) def test_2MovesXY(self): code=StringIO('G0 X2\nG0 Y3') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,2,0,0),(0,2,3,0)]) def test_MoveOffset0Move(self): code=StringIO('G0 X1\nG92 X0\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,1,0,0),(0,2,0,0)]) def test_MoveOffset1Move(self): code=StringIO('G0 X1\nG92 X1\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,1,0,0),(0,1,0,0)]) def test_twoRelMoves(self): code=StringIO('G91\nG0 X1\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,1,0,0),(0,2,0,0)]) def test_absRelAbs(self): code=StringIO('G0 X1\nG91\nG0 X1\nG90\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,1,0,0),(0,2,0,0),(0,1,0,0)]) def test_absOffRel(self): code=StringIO('G0 X1\nG92 X10\nG91\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,1,0,0),(0,2,0,0)]) def test_negatives(self): code=StringIO('G0 X-1') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,-1,0,0)]) def test_decimals(self): code=StringIO('G0 X1.5') self.a.interpret(code) self.assertEqual(self.a.coords,[(0,0,0,0),(0,1.5,0,0)]) def test_illegal(self): code=StringIO('R5') with self.assertRaises(pyparsing.ParseException): self.a.interpret(code) def test_illegalCmd(self): code=StringIO('G9999') with self.assertRaises(RuntimeError): self.a.interpret(code)
from crease import Crease from patternLoader import PatternLoader from gcode import Gcode from pattern import Pattern # c1 = Crease((95, 20),(5, 65)) # c2 = Crease((5, 45),(95, 80)) # c3 = Crease((45, 5),(45, 95)) # creases = (c1, c2, c3) # x = Pattern("anarchy", (100, 100), creases) # g_list = Gcode("anarchy", x).to_string_list() # for c in g_list: # print(c) pl = PatternLoader("images/") p = pl.loadPattern("frog.png") #p.save_to_text("patterndb/", "frog") g = Gcode("frog", p).to_string_list() # for c in g: # print(c) # print(sum((1,2)))
def setUp(self): self.a = Gcode()
class TestGcodeReader(unittest.TestCase): def setUp(self): self.a = Gcode() def test_empty(self): code = StringIO('') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0)]) def test_onlyM2(self): code = StringIO('M2') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0)]) def test_onlyM30(self): code = StringIO('M30') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0)]) def test_singleG0(self): code = StringIO('G0') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 0, 0, 0)]) def test_singleG1(self): code = StringIO('G1') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 0, 0, 0)]) def test_emptyLine(self): code = StringIO('G0\n\nM2') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 0, 0, 0)]) def test_allG0(self): code = StringIO('G0 W1 X2 Y3 Z4') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (1, 2, 3, 4)]) def test_allG1(self): code = StringIO('G1 W1 X2 Y3 Z4') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (1, 2, 3, 4)]) def test_G0X(self): code = StringIO('G0 X2') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 2, 0, 0)]) def test_G02digits(self): code = StringIO('G0 X20') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 20, 0, 0)]) def test_MoveEndMove(self): code = StringIO('G0 X2\nM2\nG0 X2') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 2, 0, 0)]) #two moves one coord def test_2MovesX(self): code = StringIO('G0 X2\nG0 X3') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 2, 0, 0), (0, 3, 0, 0)]) def test_2MovesXY(self): code = StringIO('G0 X2\nG0 Y3') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 2, 0, 0), (0, 2, 3, 0)]) def test_MoveOffset0Move(self): code = StringIO('G0 X1\nG92 X0\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 1, 0, 0), (0, 2, 0, 0)]) def test_MoveOffset1Move(self): code = StringIO('G0 X1\nG92 X1\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 1, 0, 0), (0, 1, 0, 0)]) def test_twoRelMoves(self): code = StringIO('G91\nG0 X1\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 1, 0, 0), (0, 2, 0, 0)]) def test_absRelAbs(self): code = StringIO('G0 X1\nG91\nG0 X1\nG90\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 1, 0, 0), (0, 2, 0, 0), (0, 1, 0, 0)]) def test_absOffRel(self): code = StringIO('G0 X1\nG92 X10\nG91\nG0 X1') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 1, 0, 0), (0, 2, 0, 0)]) def test_negatives(self): code = StringIO('G0 X-1') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, -1, 0, 0)]) def test_decimals(self): code = StringIO('G0 X1.5') self.a.interpret(code) self.assertEqual(self.a.coords, [(0, 0, 0, 0), (0, 1.5, 0, 0)]) def test_illegal(self): code = StringIO('R5') with self.assertRaises(pyparsing.ParseException): self.a.interpret(code) def test_illegalCmd(self): code = StringIO('G9999') with self.assertRaises(RuntimeError): self.a.interpret(code)
for fname, color, angle in zip(fnames, colors, angles): mesh = trimesh.load_mesh(path + fname) meshes.append(mesh) section = mesh.section(plane_origin=[0, 0, 0.01], plane_normal=[0, 0, 1]) loops = section.discrete for loop in loops: outline = Outline() outline._name = fname outline.addCoordLoop(loop * 1000) # 1000 to convert from meters to mm outline = outline.translate(-50, -12) secAngs.append(SecAng(Section(outline), angle)) plt.plot(loop[:, 0] - 0.050, loop[:, 1] - 0.012, color) params.outline = [tuple(secAngs)] gCode = Gcode(params) plt.show() def run(): startTime = time.time() print('\nGenerating code, please wait...') fig = fg.Figura(params, gCode) with open(path + params.outputFileName, 'w') as f: for string in fig.masterGcode_gen(): f.write(string) endTime = time.time() print('\nCode generated.')
from deck import Deck from gcode import Gcode deck = Deck("./deck.yaml") gcode = Gcode(deck)
382 159 755 6 381 758 491 491 395 583 491 491 395 583 603 379 435 624 491 491 435 624 752 755 491 491 625 435 491 491 752 755 491 491 758 381 491 269 603 379 491 269 755 6 603 379 625 435 603 379 755 6 603 379 758 381 ''' pl = PatternLoader("../images/") p = pl.loadPattern("frog.png") textLoader = Pattern(None, None, None) cranep = textLoader.load_from_string("cranep", x) g = Gcode("cranep", cranep).to_string_list() for c in g: print(c)