diff --git a/src/asmcnc/comms/router_machine.py b/src/asmcnc/comms/router_machine.py index 04a606a72..0c377ac56 100644 --- a/src/asmcnc/comms/router_machine.py +++ b/src/asmcnc/comms/router_machine.py @@ -1979,6 +1979,12 @@ def jog_spindle_to_laser_datum(self, axis): return True + def set_machine_unit_to_inch(self): + self.s.write_command('G20') + + def set_machine_unit_to_mm(self): + self.s.write_command('G21') + # Realtime XYZ feed adjustment def feed_override_reset(self): self.s.write_realtime('\x90', altDisplayText = 'Feed override RESET') diff --git a/src/asmcnc/comms/serial_connection.py b/src/asmcnc/comms/serial_connection.py index 3b078c4f3..804c53eb6 100644 --- a/src/asmcnc/comms/serial_connection.py +++ b/src/asmcnc/comms/serial_connection.py @@ -695,6 +695,9 @@ def end_stream(self): Logger.info("Ending stream...") + # Always switch to mm, in case the job put you in inches + self.m.set_machine_unit_to_mm() + # Reset flags self.is_job_streaming = False self.is_stream_lines_remaining = False @@ -738,6 +741,9 @@ def end_stream(self): def cancel_stream(self): + # Always switch to mm, in case the job put you in inches + self.m.set_machine_unit_to_mm() + self.is_job_streaming = False # make grbl_scanner() stop stuffing buffer self.is_stream_lines_remaining = False self.m.set_pause(False) diff --git a/src/asmcnc/skavaUI/screen_job_recovery.py b/src/asmcnc/skavaUI/screen_job_recovery.py index 725b28f9f..d8256e1a2 100644 --- a/src/asmcnc/skavaUI/screen_job_recovery.py +++ b/src/asmcnc/skavaUI/screen_job_recovery.py @@ -339,6 +339,8 @@ class JobRecoveryScreen(Screen): scroll_up_event = None scroll_down_event = None + using_inches = False + def __init__(self, **kwargs): super(JobRecoveryScreen, self).__init__(**kwargs) self.sm = kwargs["screen_manager"] @@ -531,6 +533,14 @@ def update_display(self): ) else: self.pos_z = 0.0 + + # Check if these distances are measured in inches, so that GO XY can work correctly + unit_line = next((s for s in reversed(self.jd.job_gcode[:self.selected_line_index + 1]) if re.search("G2[0,1]", s)), None) + if unit_line: + self.using_inches = "G20" in unit_line + else: + self.using_inches = False + self.pos_label.text = "wX: %s | wY: %s | wZ: %s" % ( str(self.pos_x), str(self.pos_y), @@ -584,13 +594,18 @@ def get_info(self): popup_info.PopupScrollableInfo(self.sm, self.l, 760, info) def go_xy(self): + # Pick min out of safe z height and limit_switch_safety_distance, in case positive value is calculated, which causes errors z_safe_height = min( self.m.z_wco() + self.sm.get_screen("home").job_box.range_z[1], -self.m.limit_switch_safety_distance, ) + # If Z is below safe height, then raise it up if self.m.mpos_z() < z_safe_height: self.m.s.write_command("G53 G0 Z%s F750" % z_safe_height) - self.m.s.write_command("G90 G0 X%s Y%s" % (self.pos_x, self.pos_y)) + if self.using_inches: + self.m.set_machine_unit_to_inch() + self.m.s.write_command('G90 G0 X%s Y%s' % (self.pos_x, self.pos_y)) + self.m.set_machine_unit_to_mm() def back_to_home(self): self.jd.reset_recovery()