Fixed zeroing with non-zero offset when unhomed. #211
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 16 Apr 2019 23:51:21 +0000 (16:51 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 16 Apr 2019 23:51:21 +0000 (16:51 -0700)
CHANGELOG.md
src/py/bbctrl/Mach.py

index 162e217acd47b21a4a9b4f48cd83918dc8eeb677..c3d7367f7e9298695aaa32a15f77daf4bc87ff94 100644 (file)
@@ -11,6 +11,7 @@ Buildbotics CNC Controller Firmware Changelog
  - Added warning about reliability in a noisy environment on WiFi config page.
  - EStop on motor fault.
  - Fixed ETA line wrapping on Web interface.
+ - Fixed zeroing with non-zero offset when unhomed. #211
 
 ## v0.4.6
  - Fixed a rare ``Negative s-curve time`` error.
index dfbd9c92fe9ec9337dae50da4d727a68ad32946d..347ad8e88f4bcf2c4fb5aad9a6c54bfb8181243b 100644 (file)
@@ -320,19 +320,21 @@ class Mach(Comm):
 
     def set_position(self, axis, position):
         axis = axis.lower()
+        state = self.ctrl.state
 
-        if self.ctrl.state.is_axis_homed(axis):
+        if state.is_axis_homed(axis):
             # If homed, change the offset rather than the absolute position
             self.mdi('G92%s%f' % (axis, position))
 
-        elif self.ctrl.state.is_axis_enabled(axis):
+        elif state.is_axis_enabled(axis):
             if self._get_cycle() != 'idle' and not self._is_paused():
                 raise Exception('Cannot set position during ' +
                                 self._get_cycle())
 
             # Set the absolute position both locally and via the AVR
-            self.ctrl.state.set(axis + 'p', position)
-            super().queue_command(Cmd.set_axis(axis, position))
+            target = position - state.get('offset_' + axis)
+            state.set(axis + 'p', target)
+            super().queue_command(Cmd.set_axis(axis, target))
 
 
     def override_feed(self, override):