def test_drill_optimisation(self): commands = list(parse_file("testdata/drill_cycle.ngc")) optimised = gcode_optimise.optimise(commands, 100) self.assertEqual(len(commands), len(optimised), "Should be same number of commands before/after") self.assertNotEqual(commands, optimised, "Optimised drill pass should use different order") for c in commands: self.assertTrue(c in optimised, "All commands in commands should be in optimised set, including %s" % c)
def test_drill_optimisation(self): commands = list(parse_file("testdata/drill_cycle.ngc")) optimised = gcode_optimise.optimise(commands, 100) self.assertEqual(len(commands), len(optimised), "Should be same number of commands before/after") self.assertNotEqual(commands, optimised, "Optimised drill pass should use different order") for c in commands: self.assertTrue(c in optimised, "All commands in commands should be in optimised set, including %s" % c)
def _deviation_commands(self, threshold): # test data is 10mm line w/1mm deviation commands = parse_file("testdata/deviate_1mm.ngc") old_moves = [c for c in commands if c["name"]=="G1"] not_moves = [c for c in commands if c["name"]!="G1"] optimised = gcode_optimise.optimise(commands, threshold) new_moves = [c for c in optimised if c["name"]=="G1"] new_not_moves = [c for c in optimised if c["name"]!="G1"] test_equal_commands(self, not_moves, new_not_moves) # everything but G1 should commands should be 100% the same for new in optimised: self.assertTrue(new in commands, "Every optimised command should already exist in old set, including %s" % new) self.assertTrue(optimised.index(new) <= commands.index(new), "Optimisation strips commands, so any new command should have index at or before it's position in the old command list (testing %s)" % new) return old_moves, new_moves
def _deviation_commands(self, threshold): # test data is 10mm line w/1mm deviation commands = parse_file("testdata/deviate_1mm.ngc") old_moves = [c for c in commands if c["name"] == "G1"] not_moves = [c for c in commands if c["name"] != "G1"] optimised = gcode_optimise.optimise(commands, threshold) new_moves = [c for c in optimised if c["name"] == "G1"] new_not_moves = [c for c in optimised if c["name"] != "G1"] test_equal_commands(self, not_moves, new_not_moves) # everything but G1 should commands should be 100% the same for new in optimised: self.assertTrue( new in commands, "Every optimised command should already exist in old set, including %s" % new ) self.assertTrue( optimised.index(new) <= commands.index(new), "Optimisation strips commands, so any new command should have index at or before it's position in the old command list (testing %s)" % new, ) return old_moves, new_moves
commands.append({"name" : "message", "value" : "Starting gcode file %s" % path }) if toolchange: commands += [ { "name" : "message", "value" : "Tool change requested on command line..." }, { "name" : "M6" } ] toolchange = False commands += list(gcode_parse.parse(f.read())) commands.append({"name" : "message", "value" : "End of gcode file %s" % path }) except gcode_parse.ParserException, err: print "Failed to parse %s: %s" % (path, err) sys.exit(1) if not args.no_optimise: print "Optimising gcode..." before = len(commands) commands = gcode_optimise.optimise(commands, args.max_deviation) print "(Before optimisation: %d commands. After optimisation: %d commands)" % (before, len(commands)) print "Connecting to AMC controller..." controller = SimController() if args.sim else AMC2500(port=args.serial_port) controller.trace = args.verbose controller.debug = args.verbose if not args.no_jog: if len(args.files) > 0: print "Jog the controller to set up the initial pass. When done, tool should be over the origin point." jog_controller(controller) if len(args.files) == 0: return print "Ready to start. Controller should be above origin of design." print "This is %s." % ("a simulated run only" if args.sim else