From d47d8e4876b38dc1292fbffb27855566fb31d94c Mon Sep 17 00:00:00 2001 From: DennisKiselev Date: Wed, 6 Sep 2023 15:58:19 +0100 Subject: [PATCH 1/6] Add inch move to go xy button --- src/asmcnc/skavaUI/screen_job_recovery.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/asmcnc/skavaUI/screen_job_recovery.py b/src/asmcnc/skavaUI/screen_job_recovery.py index f71263c768..a816899807 100644 --- a/src/asmcnc/skavaUI/screen_job_recovery.py +++ b/src/asmcnc/skavaUI/screen_job_recovery.py @@ -330,6 +330,8 @@ class JobRecoveryScreen(Screen): scroll_up_event = None scroll_down_event = None + using_inches = False + def __init__(self, **kwargs): super(JobRecoveryScreen, self).__init__(**kwargs) @@ -476,6 +478,13 @@ 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), str(self.pos_z)) self.speed_label.text = "%s: %s | %s: %s" % (self.l.get_str("F"), str(self.feed), self.l.get_str("S"), str(self.speed)) @@ -499,11 +508,15 @@ 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 self.using_inches: + self.m.s.write_command('G20') + # 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)) + self.m.s.write_command('G21') def back_to_home(self): self.jd.reset_recovery() From c7f91f7c72cdee40313b6ad67926b93146de524b Mon Sep 17 00:00:00 2001 From: DennisKiselev Date: Wed, 6 Sep 2023 16:13:39 +0100 Subject: [PATCH 2/6] Switch to mm when a stream is cancelled --- src/asmcnc/comms/serial_connection.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/asmcnc/comms/serial_connection.py b/src/asmcnc/comms/serial_connection.py index 7cce390967..1a2aafcd1d 100644 --- a/src/asmcnc/comms/serial_connection.py +++ b/src/asmcnc/comms/serial_connection.py @@ -639,6 +639,9 @@ def end_stream(self): log("Ending stream...") + # Always switch to mm, in case the job put you in inches + self.write_command('G21') + # Reset flags self.is_job_streaming = False self.is_stream_lines_remaining = False From 98cb33f3412f060bf5d8f7a43789f3a62c6e49b5 Mon Sep 17 00:00:00 2001 From: DennisKiselev Date: Tue, 23 Apr 2024 23:20:02 +0100 Subject: [PATCH 3/6] Create router machine functions for changing unit --- src/asmcnc/comms/router_machine.py | 6 ++++++ src/asmcnc/comms/serial_connection.py | 2 +- src/asmcnc/skavaUI/screen_job_recovery.py | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/asmcnc/comms/router_machine.py b/src/asmcnc/comms/router_machine.py index 04a606a72a..0c377ac562 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 d1dc392a81..adada621ed 100644 --- a/src/asmcnc/comms/serial_connection.py +++ b/src/asmcnc/comms/serial_connection.py @@ -696,7 +696,7 @@ def end_stream(self): Logger.info("Ending stream...") # Always switch to mm, in case the job put you in inches - self.write_command('G21') + self.m.set_machine_unit_to_mm() # Reset flags self.is_job_streaming = False diff --git a/src/asmcnc/skavaUI/screen_job_recovery.py b/src/asmcnc/skavaUI/screen_job_recovery.py index 081361313e..62d598ca57 100644 --- a/src/asmcnc/skavaUI/screen_job_recovery.py +++ b/src/asmcnc/skavaUI/screen_job_recovery.py @@ -600,12 +600,12 @@ def go_xy(self): -self.m.limit_switch_safety_distance, ) if self.using_inches: - self.m.s.write_command('G20') + self.m.set_machine_unit_to_inch() # 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)) - self.m.s.write_command('G21') + self.m.set_machine_unit_to_mm() def back_to_home(self): self.jd.reset_recovery() From 332dc399cfe638cf82199f2934a31f496a3b5020 Mon Sep 17 00:00:00 2001 From: DennisKiselev Date: Tue, 23 Apr 2024 23:23:55 +0100 Subject: [PATCH 4/6] Set to inches after doing calculations --- src/asmcnc/skavaUI/screen_job_recovery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/asmcnc/skavaUI/screen_job_recovery.py b/src/asmcnc/skavaUI/screen_job_recovery.py index 62d598ca57..6ae2c5e53d 100644 --- a/src/asmcnc/skavaUI/screen_job_recovery.py +++ b/src/asmcnc/skavaUI/screen_job_recovery.py @@ -594,13 +594,13 @@ def get_info(self): popup_info.PopupScrollableInfo(self.sm, self.l, 760, info) def go_xy(self): + if self.using_inches: + self.m.set_machine_unit_to_inch() # 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 self.using_inches: - self.m.set_machine_unit_to_inch() # 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) From 95aa03ab2cb992564f8e3fd0f2ad37c7ec6fd877 Mon Sep 17 00:00:00 2001 From: DennisKiselev Date: Tue, 23 Apr 2024 23:24:13 +0100 Subject: [PATCH 5/6] Fix last commit --- src/asmcnc/skavaUI/screen_job_recovery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/asmcnc/skavaUI/screen_job_recovery.py b/src/asmcnc/skavaUI/screen_job_recovery.py index 6ae2c5e53d..d8256e1a23 100644 --- a/src/asmcnc/skavaUI/screen_job_recovery.py +++ b/src/asmcnc/skavaUI/screen_job_recovery.py @@ -594,8 +594,6 @@ def get_info(self): popup_info.PopupScrollableInfo(self.sm, self.l, 760, info) def go_xy(self): - if self.using_inches: - self.m.set_machine_unit_to_inch() # 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], @@ -604,6 +602,8 @@ def go_xy(self): # 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) + 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() From 6d8bd34e1ded8f30ec1e6d2b56fc10a720c28e82 Mon Sep 17 00:00:00 2001 From: DennisKiselev Date: Tue, 23 Apr 2024 23:38:45 +0100 Subject: [PATCH 6/6] Set to mm when cancelling --- src/asmcnc/comms/serial_connection.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/asmcnc/comms/serial_connection.py b/src/asmcnc/comms/serial_connection.py index adada621ed..804c53eb68 100644 --- a/src/asmcnc/comms/serial_connection.py +++ b/src/asmcnc/comms/serial_connection.py @@ -741,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)