2 A simple generator for GCode. To assist in creation of simple GCode instructions.
3 This is not intended for advanced use or complex paths. The CuraEngine generates the real GCode instructions.
5 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
9 from Cura.util import profile
11 class gcodeGenerator(object):
13 Generates a simple set of GCode commands for RepRap GCode firmware.
14 Use the add* commands to build the GCode, and then use the list function to retrieve the resulting gcode.
17 self._feedPrint = profile.getProfileSettingFloat('print_speed') * 60
18 self._feedTravel = profile.getProfileSettingFloat('travel_speed') * 60
19 self._feedRetract = profile.getProfileSettingFloat('retraction_speed') * 60
20 filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
21 filamentArea = math.pi * filamentRadius * filamentRadius
22 self._ePerMM = (profile.getProfileSettingFloat('nozzle_size') * 0.1) / filamentArea
28 self._list = ['M110', 'G92 E0']
30 def setPrintSpeed(self, speed):
31 self._feedPrint = speed * 60
33 def setExtrusionRate(self, lineWidth, layerHeight):
34 filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
35 filamentArea = math.pi * filamentRadius * filamentRadius
36 self._ePerMM = (lineWidth * layerHeight) / filamentArea
44 def addMove(self, x=None, y=None, z=None):
55 cmd += "F%d" % (self._feedTravel)
58 def addPrime(self, amount=5):
59 self._eValue += amount
60 self._list += ['G1 E%f F%f' % (self._eValue, self._feedRetract)]
62 def addRetract(self, amount=5):
63 self._eValue -= amount
64 self._list += ['G1 E%f F%f' % (self._eValue, self._feedRetract)]
66 def _addExtrude(self, x=None, y=None, z=None):
79 self._eValue += math.sqrt((self._x - oldX) * (self._x - oldX) + (self._y - oldY) * (self._y - oldY)) * self._ePerMM
80 cmd += "E%f F%d" % (self._eValue, self._feedPrint)
83 def addExtrude(self, x=None, y=None, z=None):
84 if x is not None and abs(self._x - x) > 10:
85 self.addExtrude((self._x + x) / 2.0, y, z)
86 self.addExtrude(x, y, z)
88 if y is not None and abs(self._y - y) > 10:
89 self.addExtrude(x, (self._y + y) / 2.0, z)
90 self.addExtrude(x, y, z)
92 self._addExtrude(x, y, z)
97 def addCmd(self, cmd):