Commit 12d32a2b authored by Guillaume Seguin's avatar Guillaume Seguin

Add home position handling to GCoder

parent 5eabffce
...@@ -109,10 +109,15 @@ class GCode(object): ...@@ -109,10 +109,15 @@ class GCode(object):
relative = False relative = False
relative_e = False relative_e = False
current_tool = 0 current_tool = 0
# Home position: current absolute position counted from machine origin
home_x = 0
home_y = 0
home_z = 0
# Current position: current absolute position counted from machine origin # Current position: current absolute position counted from machine origin
current_x = 0 current_x = 0
current_y = 0 current_y = 0
current_z = 0 current_z = 0
# For E this is the absolute position from machine start
current_e = 0 current_e = 0
# Offset: current offset between the machine origin and the machine current # Offset: current offset between the machine origin and the machine current
# absolute coordinate system (as shifted by G92s) # absolute coordinate system (as shifted by G92s)
...@@ -122,8 +127,9 @@ class GCode(object): ...@@ -122,8 +127,9 @@ class GCode(object):
offset_e = 0 offset_e = 0
# Expected behavior: # Expected behavior:
# - G28 X => X axis is homed, offset_x <- 0, current_x <- home_x # - G28 X => X axis is homed, offset_x <- 0, current_x <- home_x
# - G92 Xk => X axis does not move, offset_x <- current_x - k, # - G92 Xk => X axis does not move, so current_x does not change
# current_x does not change # and offset_x <- current_x - k,
# - absolute G1 Xk => X axis moves, current_x <- offset_x + k
# How to get... # How to get...
# current abs X from machine origin: current_x # current abs X from machine origin: current_x
# current abs X in machine current coordinate system: current_x - offset_x # current abs X in machine current coordinate system: current_x - offset_x
...@@ -141,10 +147,12 @@ class GCode(object): ...@@ -141,10 +147,12 @@ class GCode(object):
est_layer_height = None est_layer_height = None
def __init__(self, data): def __init__(self, data, home_pos = None):
self.lines = [Line(l2) for l2 in self.lines = [Line(l2) for l2 in
(l.strip() for l in data) (l.strip() for l in data)
if l2] if l2]
if home_pos:
self.home_x, self.home_y, self.home_z = home_pos
if self.lines: if self.lines:
self._preprocess_lines() self._preprocess_lines()
self.filament_length = self._preprocess_extrusion() self.filament_length = self._preprocess_extrusion()
...@@ -237,11 +245,20 @@ class GCode(object): ...@@ -237,11 +245,20 @@ class GCode(object):
elif line.command == "G28": elif line.command == "G28":
if not any([line.x, line.y, line.z]): if not any([line.x, line.y, line.z]):
current_x = current_y = current_z = 0 offset_x = offset_y = offset_z = 0
current_x = self.home_x
current_y = self.home_y
current_z = self.home_z
else: else:
if line.x is not None: current_x = 0 if line.x is not None:
if line.y is not None: current_y = 0 offset_x = 0
if line.z is not None: current_z = 0 current_x = self.home_x
if line.y is not None:
offset_y = 0
current_y = self.home_y
if line.z is not None:
offset_z = 0
current_z = self.home_z
elif line.command == "G92": elif line.command == "G92":
if line.x is not None: offset_x = current_x - line.x if line.x is not None: offset_x = current_x - line.x
......
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