Commit b335a4cf authored by fsantini's avatar fsantini

G-codes and relevant M-codes implemented (check for tabs/spaces)

parent 60158d5e
......@@ -60,21 +60,22 @@ class GCodeAnalyzer():
self.maxZ = 150
# find a code in a gstring line
def findCode(self, gcode, codeStr):
# find a code in a gstring line
def findCode(self, gcode, codeStr):
pattern = re.compile(codeStr + "s*([\d.]*)",re.I)
m=re.match(pattern, gcode)
if m == None:
return None
return None
else
return m.group(1)
return m.group(1)
def Analyze(self, gcode):
def Analyze(self, gcode):
code_g = self.findCode(gcode, "G")
code_m = self.findCode(gcode, "M")
# we have a g_code
if code_g != None:
code_g = int(code_g)
code_g = int(code_g)
#get movement codes
if code_g == 0 or code_g == 1 or code_g == 2 or code_g == 3:
......@@ -97,7 +98,7 @@ class GCodeAnalyzer():
if e != 0:
eChanged = True
self.e += e
else:
else:
#absolute coordinates
if code_x != None: self.x = self.xOffset + float(code_x)
if code_y != None: self.y = self.yOffset + float(code_y)
......@@ -122,4 +123,55 @@ class GCodeAnalyzer():
code_e = self.findCode(gcode, "E")
homeAll = False
if code_x == None and code_y == None and code_z == None: homeAll = True
\ No newline at end of file
if code_x != None or homeAll:
self.xOffset = 0
self.x = self.homeX
if code_y != None or homeAll:
self.yOffset = 0
self.y = self.homeY
if code_z != None or homeAll:
self.zOffset = 0
self.z = self.homeZ
if code_e != None:
self.eOffset = 0
self.e = 0
elif code_g == 162:
code_x = self.findCode(gcode, "X")
code_y = self.findCode(gcode, "Y")
code_z = self.findCode(gcode, "Z")
homeAll = False
if code_x == None and code_y == None and code_z == None: homeAll = True
if code_x != None or homeAll:
self.xOffset = 0
self.x = self.maxX
if code_y != None or homeAll:
self.yOffset = 0
self.y = self.maxY
if code_z != None or homeAll:
self.zOffset = 0
self.z = self.maxZ
elif code_g == 90: self.relative = False
elif code_g == 91: self.relative = True
elif code_g == 92:
code_x = self.findCode(gcode, "X")
code_y = self.findCode(gcode, "Y")
code_z = self.findCode(gcode, "Z")
code_e = self.findCode(gcode, "E")
if code_x != None:
self.xOffset = self.x - float(code_x)
self.x = self.xOffset
if code_y != None:
self.yOffset = self.y - float(code_y)
self.y = self.yOffset
if code_z != None:
self.zOffset = self.z - float(code_z)
self.z = self.zOffset
if code_e != None:
self.xOffset = self.e - float(code_e)
self.e = self.eOffset
#End code_g != None
if code_m != None:
code_m = int(code_m)
if code_m == 82: self.eRelative = False
elif code_m == 83: self.eRelative = True
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment