From 7e9b042ebe7226216359f369ef993e3ce0a915a9 Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 10:43:21 -0700 Subject: [PATCH 01/12] Fixing places where AFC_error was not referenced correctly --- extras/AFC_BoxTurtle.py | 2 +- extras/AFC_NightOwl.py | 2 +- extras/AFC_prep.py | 2 +- extras/AFC_stepper.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/AFC_BoxTurtle.py b/extras/AFC_BoxTurtle.py index 73a64fd0..dbfd4e67 100644 --- a/extras/AFC_BoxTurtle.py +++ b/extras/AFC_BoxTurtle.py @@ -38,7 +38,7 @@ def system_Test(self, UNIT, LANE, delay): try: CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) except: error_string = 'Error: No config found for extruder: ' + CUR_LANE.extruder_name + ' in [AFC_stepper ' + CUR_LANE.name + ']. Please make sure [AFC_extruder ' + CUR_LANE.extruder_name + '] config exists in AFC_Hardware.cfg' - self.AFC.AFC_error(error_string, False) + self.AFC.ERROR.AFC_error(error_string, False) return False # Run test reverse/forward on each lane diff --git a/extras/AFC_NightOwl.py b/extras/AFC_NightOwl.py index 1426f7aa..6516c187 100644 --- a/extras/AFC_NightOwl.py +++ b/extras/AFC_NightOwl.py @@ -31,7 +31,7 @@ def system_Test(self, UNIT, LANE, delay): try: CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) except: error_string = 'Error: No config found for extruder: ' + CUR_LANE.extruder_name + ' in [AFC_stepper ' + CUR_LANE.name + ']. Please make sure [AFC_extruder ' + CUR_LANE.extruder_name + '] config exists in AFC_Hardware.cfg' - self.AFC.AFC_error(error_string, False) + self.AFC.ERROR.AFC_error(error_string, False) return False # Run test reverse/forward on each lane diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index 59187394..b547787d 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -113,7 +113,7 @@ def PREP(self, gcmd): try: CUR_HUB = self.printer.lookup_object('AFC_hub '+ UNIT) except: error_string = 'Error: Hub for ' + UNIT + ' not found in AFC_Hardware.cfg. Please add the [AFC_Hub ' + UNIT + '] config section.' - self.AFC.AFC_error(error_string, False) + self.AFC.ERROR.AFC_error(error_string, False) return self.AFC.gcode.respond_info(CUR_HUB.type + ' ' + UNIT +' Prepping lanes') diff --git a/extras/AFC_stepper.py b/extras/AFC_stepper.py index 8e1724c8..7caf10e4 100644 --- a/extras/AFC_stepper.py +++ b/extras/AFC_stepper.py @@ -239,7 +239,7 @@ def prep_callback(self, eventtime, state): self.reactor.pause(self.reactor.monotonic() + 0.1) if x> 40: msg = (' FAILED TO LOAD, CHECK FILAMENT AT TRIGGER\n||==>--||----||------||\nTRG LOAD HUB TOOL') - self.AFC.AFC_error(msg, False) + self.AFC.ERROR.AFC_error(msg, False) self.AFC.afc_led(self.AFC.led_fault, led) self.status='' break From 7f616f5b3475a91a0b147bb995fe6f39dff9e5ba Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 14:12:37 -0700 Subject: [PATCH 02/12] Fixing misc errors - Fixing self.AFC in AFC.py file, updated to self - Adding more checking to make sure printer was homed if user was to call TOOL_LOAD and TOOL_UNLOAD macros - Adding more error print outs to help the user --- extras/AFC.py | 110 ++++++++++++++++++++++++++------------------ extras/AFC_error.py | 2 +- 2 files changed, 65 insertions(+), 47 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index eb7b5448..4f01fd16 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -171,7 +171,7 @@ def cmd_AFC_STATUS(self, gcmd): for LANE in self.units[UNIT].keys(): lane_msg = '' - CUR_LANE = self.AFC.stepper[LANE] + CUR_LANE = self.stepper[LANE] CUR_HUB = self.printer.lookup_object('AFC_hub '+ UNIT) CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) if self.current != None: @@ -231,7 +231,7 @@ def cmd_SET_BOWDEN_LENGTH(self, gcmd): # If hub is not passed in try and get hub if a lane is currently loaded if hub is None and self.current is not None: - CUR_LANE = self.AFC.stepper[self.current] + CUR_LANE = self.stepper[self.current] hub = CUR_LANE.unit elif hub is None and self.current is None: self.gcode.respond_info("A lane is not loaded please specify hub to adjust bowden length") @@ -279,10 +279,10 @@ def cmd_LANE_MOVE(self, gcmd): """ lane = gcmd.get('LANE', None) distance = gcmd.get_float('DISTANCE', 0) - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') - return - CUR_LANE = self.AFC.stepper[lane.name] + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) + return + CUR_LANE = self.stepper[lane.name] CUR_LANE.move(distance, self.short_moves_speed, self.short_moves_accel, True) def save_pos(self): @@ -361,10 +361,10 @@ def cmd_HUB_CUT_TEST(self, gcmd): """ lane = gcmd.get('LANE', None) self.gcode.respond_info('Testing Hub Cut on Lane: ' + lane) - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') - return - CUR_LANE = self.AFC.stepper[lane.name] + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) + return + CUR_LANE = self.stepper[lane.name] CUR_HUB = self.printer.lookup_object('AFC_hub ' + CUR_LANE.unit) CUR_HUB.hub_cut(CUR_LANE) self.gcode.respond_info('Hub cut Done!') @@ -394,10 +394,10 @@ def cmd_TEST(self, gcmd): self.ERROR.AFC_error('Must select LANE', False) return self.gcode.respond_info('TEST ROUTINE') - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') - return - CUR_LANE = self.AFC.stepper[lane.name] + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) + return + CUR_LANE = self.stepper[lane.name] self.gcode.respond_info('Testing at full speed') CUR_LANE.assist(-1) self.reactor.pause(self.reactor.monotonic() + 1) @@ -437,10 +437,10 @@ def cmd_HUB_LOAD(self, gcmd): None """ lane = gcmd.get('LANE', None) - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') - return - CUR_LANE = self.AFC.stepper[lane.name] + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) + return + CUR_LANE = self.stepper[lane.name] CUR_HUB = self.printer.lookup_object('AFC_hub '+ CUR_LANE.unit) if CUR_LANE.prep_state == False: return @@ -477,11 +477,15 @@ def cmd_LANE_UNLOAD(self, gcmd): Returns: None """ + if not self.is_homed(): + self.ERROR.AFC_error("Please home printer before doing a tool unload", False) + return False + lane = gcmd.get('LANE', None) - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') - return - CUR_LANE = self.AFC.stepper[lane.name] + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) + return + CUR_LANE = self.stepper[lane.name] CUR_HUB = self.printer.lookup_object('AFC_hub '+ CUR_LANE.unit) if CUR_LANE.name != self.current: # Setting status as ejecting so if filament is removed and de-activates the prep sensor while @@ -504,7 +508,7 @@ def cmd_LANE_UNLOAD(self, gcmd): self.SPOOL.set_spoolID( CUR_LANE, "") else: - self.gcode.respond_info('LANE ' + CUR_LANE.name + ' IS TOOL LOADED') + self.gcode.respond_info("LANE {} is loaded in toolhead, can't unload.".format(CUR_LANE.name)) cmd_TOOL_LOAD_help = "Load lane into tool" def cmd_TOOL_LOAD(self, gcmd): @@ -525,10 +529,14 @@ def cmd_TOOL_LOAD(self, gcmd): None """ lane = gcmd.get('LANE', None) - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') - return - CUR_LANE = self.AFC.stepper[lane.name] + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) + return + + if self.current is not None: + self.ERROR.AFC_error("Cannot load {}, {} currently loaded".format(lane.upper(), self.current.upper()), pause=False) + return + CUR_LANE = self.stepper[lane.name] self.TOOL_LOAD(CUR_LANE) def TOOL_LOAD(self, CUR_LANE): @@ -545,6 +553,10 @@ def TOOL_LOAD(self, CUR_LANE): Returns: bool: True if load was successful, False if an error occurred. """ + if not self.is_homed(): + self.ERROR.AFC_error("Please home printer before doing a tool load", False) + return False + if CUR_LANE is None: # Exit early if no lane is provided. return False @@ -613,7 +625,7 @@ def TOOL_LOAD(self, CUR_LANE): tool_attempts += 1 CUR_LANE.move(self.short_move_dis, CUR_EXTRUDER.tool_load_speed, self.long_moves_accel) if tool_attempts > 20: - message = ('FAILED TO LOAD ' + CUR_LANE.name.upper() + ' TO TOOL, CHECK FILAMENT PATH\n||=====||====||==>--||\nTRG LOAD HUB TOOL') + message = ('FAILED TO LOAD {} TO TOOL, CHECK FILAMENT PATH\n||=====||====||==>--||\nTRG LOAD HUB TOOL'.format(CUR_LANE.name.upper())) self.ERROR.handle_lane_failure(CUR_LANE, message) return False @@ -671,11 +683,11 @@ def TOOL_LOAD(self, CUR_LANE): else: # Handle errors if the hub is not clear or the lane is not ready for loading. if CUR_HUB.state: - message = ('HUB NOT CLEAR TRYING TO LOAD ' + CUR_LANE.name.upper() + '\n||-----||----|x|-----||\nTRG LOAD HUB TOOL') + message = ('HUB NOT CLEAR WHEN TRYING TO LOAD {}\n||-----||----|x|-----||\nTRG LOAD HUB TOOL'.format(CUR_LANE.name.upper())) self.ERROR.handle_lane_failure(CUR_LANE, message) return False if not CUR_LANE.load_state: - message = (CUR_LANE.name.upper() + ' NOT READY\n||==>--||----||-----||\nTRG LOAD HUB TOOL') + message = ('{} NOT READY, LOAD TRIGGER NOT TRIGGERED\n||==>--||----||-----||\nTRG LOAD HUB TOOL'.format(CUR_LANE.name.upper())) self.ERROR.handle_lane_failure(CUR_LANE, message) return False @@ -702,10 +714,10 @@ def cmd_TOOL_UNLOAD(self, gcmd): lane = gcmd.get('LANE', self.current) if lane == None: return - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') - return - CUR_LANE = self.AFC.stepper[lane.name] + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) + return + CUR_LANE = self.stepper[lane.name] self.TOOL_UNLOAD(CUR_LANE) # User manually unloaded spool from toolhead, remove spool from active status @@ -724,6 +736,10 @@ def TOOL_UNLOAD(self, CUR_LANE): Returns: bool: True if unloading was successful, False if an error occurred. """ + if not self.is_homed(): + self.ERROR.AFC_error("Please home printer before doing a tool unload", False) + return False + if CUR_LANE is None: # If no lane is provided, exit the function early with a failure. return False @@ -811,7 +827,7 @@ def TOOL_UNLOAD(self, CUR_LANE): num_tries += 1 if num_tries > self.tool_max_unload_attempts: # Handle failure if the filament cannot be unloaded. - message = ('FAILED TO UNLOAD {}. FILAMENT STUCK IN TOOLHEAD.'.format(CUR_LANE.name.upper())) + message = ('FAILED TO UNLOAD. FILAMENT STUCK IN TOOLHEAD.') self.ERROR.handle_lane_failure(CUR_LANE, message) return False CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name) @@ -843,7 +859,7 @@ def TOOL_UNLOAD(self, CUR_LANE): num_tries += 1 if num_tries > (CUR_HUB.afc_bowden_length / self.short_move_dis): # Handle failure if the filament doesn't clear the hub. - message = 'HUB NOT CLEARING' + message = 'HUB NOT CLEARING\n' self.ERROR.handle_lane_failure(CUR_LANE, message) return False @@ -895,7 +911,7 @@ def cmd_CHANGE_TOOL(self, gcmd): None """ if not self.is_homed(): - self.ERROR.AFC_error("Please home printer before doing a toolchange", False) + self.ERROR.AFC_error("Please home printer before doing a tool change", False) return tmp = gcmd.get_commandline() @@ -933,10 +949,10 @@ def cmd_CHANGE_TOOL(self, gcmd): self.in_toolchange = True # Lookup the lane object for the requested lane. - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.AFC.stepper[lane.name] + CUR_LANE = self.stepper[lane.name] # Check if the lane has completed the preparation process required for tool changes. if CUR_LANE._afc_prep_done: # Log the tool change operation for debugging or informational purposes. @@ -944,10 +960,10 @@ def cmd_CHANGE_TOOL(self, gcmd): # If a current lane is loaded, unload it first. if self.current is not None: - if self.current not in self.AFC.stepper: - self.AFC.gcode.respond_info(self.current + ' Unknown') + if self.current not in self.stepper: + self.gcode.respond_info(self.current + ' Unknown') return - CUR_LANE = self.AFC.stepper[self.current] + CUR_LANE = self.stepper[self.current] if not self.TOOL_UNLOAD(CUR_LANE): # Abort if the unloading process fails. msg = (' UNLOAD ERROR NOT CLEARED') @@ -955,15 +971,17 @@ def cmd_CHANGE_TOOL(self, gcmd): return # Switch to the new lane for loading. - if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + if lane not in self.stepper: + self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.AFC.stepper[lane.name] + CUR_LANE = self.stepper[lane.name] # Load the new lane and restore the toolhead position if successful. if self.TOOL_LOAD(CUR_LANE) and not self.error_state: self.gcode.respond_info("{} is now loaded in toolhead".format(lane)) self.restore_pos() self.in_toolchange = False + else: + self.gcode.respond_info("{} already loaded".format(lane)) def get_filament_status(self, LANE): if LANE.prep_state: diff --git a/extras/AFC_error.py b/extras/AFC_error.py index 5dcf4cfd..e219f36c 100644 --- a/extras/AFC_error.py +++ b/extras/AFC_error.py @@ -136,7 +136,7 @@ def handle_lane_failure(self, CUR_LANE, message, pause=True): # Disable the stepper for this lane CUR_LANE.do_enable(False) CUR_LANE.status = 'Error' - msg = (CUR_LANE.name.upper() + ' NOT READY' + message) + msg = (CUR_LANE.name.upper() + message) self.AFC_error(msg, pause) self.AFC.afc_led(self.AFC.led_fault, CUR_LANE.led_index) From 5641d9b61ce1adc77bc6dd71230b566d708af9a5 Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 14:24:22 -0700 Subject: [PATCH 03/12] Using common set_spoolid function when setting spoolid during prep - Added check to see if spoolman color is multicolor --- extras/AFC_prep.py | 10 ++-------- extras/AFC_spool.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index b547787d..0930c353 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -80,15 +80,9 @@ def PREP(self, gcmd): if LANE.name not in self.AFC.units[LANE.unit]: self.AFC.units[LANE.unit][LANE.name]={} if LANE.name not in self.AFC.lanes[LANE.unit]: self.AFC.lanes[LANE.unit][LANE.name] = {} if 'spool_id' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.spool_id = self.AFC.lanes[LANE.unit][LANE.name]['spool_id'] + if self.AFC.spoolman_ip !=None and LANE.spool_id != None: - try: - url = 'http://' + self.AFC.spoolman_ip + ':'+ self.AFC.spoolman_port +"/api/v1/spool/" + self.AFC.lanes[LANE.unit][LANE.name]['spool_id'] - result = json.load(urlopen(url)) - LANE.material = result['filament']['material'] - LANE.color = '#' + result['filament']['color_hex'] - if 'remaining_weight' in result: LANE.weight = result['remaining_weight'] - except: - self.AFC.ERROR.AFC_error("Error when trying to get Spoolman data for ID:{}".format(self.AFC.lanes[LANE.unit][LANE.name]['spool_id']), False) + self.AFC.SPOOL.set_spoolID(LANE, LANE.spool_id) else: if 'material' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.material = self.AFC.lanes[LANE.unit][LANE.name]['material'] if 'color' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.color = self.AFC.lanes[LANE.unit][LANE.name]['color'] diff --git a/extras/AFC_spool.py b/extras/AFC_spool.py index a081e417..e29e8d72 100644 --- a/extras/AFC_spool.py +++ b/extras/AFC_spool.py @@ -220,8 +220,14 @@ def set_spoolID(self, CUR_LANE, SpoolID): CUR_LANE.material = result['filament']['material'] CUR_LANE.color = '#' + result['filament']['color_hex'] if 'remaining_weight' in result: CUR_LANE.weight = result['remaining_weight'] - except: - self.AFC.ERROR.AFC_error("Error when trying to get Spoolman data for ID:{}".format(SpoolID), False) + # Check to see if filament is defined as multi color and take the first color for now + # Once support for multicolor is added this needs to be updated + if "multi_color_hexes" in result['filament']: + CUR_LANE.color = '#' + result['filament']['multi_color_hexes'].split(",")[0] + else: + CUR_LANE.color = '#' + result['filament']['color_hex'] + except Exception as e: + self.AFC.ERROR.AFC_error("Error when trying to get Spoolman data for ID:{}, Error: {}".format(SpoolID, e), False) else: CUR_LANE.spool_id = '' CUR_LANE.material = '' From 5cf952b87d43c872af7354a3ce05a3109ee08d2f Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 14:54:32 -0700 Subject: [PATCH 04/12] Updating reporting of lane to be uppercase so it consistent with other reporting --- extras/AFC.py | 2 +- extras/AFC_BoxTurtle.py | 4 ++-- extras/AFC_NightOwl.py | 2 +- extras/AFC_spool.py | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index 4f01fd16..88a20bb3 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -961,7 +961,7 @@ def cmd_CHANGE_TOOL(self, gcmd): # If a current lane is loaded, unload it first. if self.current is not None: if self.current not in self.stepper: - self.gcode.respond_info(self.current + ' Unknown') + self.gcode.respond_info('{} Unknown'.format(self.current.upper())) return CUR_LANE = self.stepper[self.current] if not self.TOOL_UNLOAD(CUR_LANE): diff --git a/extras/AFC_BoxTurtle.py b/extras/AFC_BoxTurtle.py index dbfd4e67..1b82992d 100644 --- a/extras/AFC_BoxTurtle.py +++ b/extras/AFC_BoxTurtle.py @@ -32,7 +32,7 @@ def system_Test(self, UNIT, LANE, delay): msg = '' succeeded = True if LANE not in self.AFC.stepper: - self.AFC.gcode.respond_info(LANE + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(LANE.upper())) return CUR_LANE = self.AFC.stepper[LANE] try: CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) @@ -184,7 +184,7 @@ def calc_position(lane, state, pos, short_move, tolerance): def calibrate_lane(LANE): if LANE not in self.AFC.stepper: - self.AFC.gcode.respond_info(LANE + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(LANE.upper())) return CUR_LANE = self.AFC.stepper[LANE.name] CUR_HUB = self.printer.lookup_object('AFC_hub {}'.format(CUR_LANE.unit)) diff --git a/extras/AFC_NightOwl.py b/extras/AFC_NightOwl.py index 6516c187..538f829f 100644 --- a/extras/AFC_NightOwl.py +++ b/extras/AFC_NightOwl.py @@ -25,7 +25,7 @@ def system_Test(self, UNIT, LANE, delay): msg = '' succeeded = True if LANE not in self.AFC.stepper: - self.AFC.gcode.respond_info(LANE + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(LANE.upper())) return CUR_LANE = self.AFC.stepper[LANE] try: CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) diff --git a/extras/AFC_spool.py b/extras/AFC_spool.py index e29e8d72..15534ab3 100644 --- a/extras/AFC_spool.py +++ b/extras/AFC_spool.py @@ -56,7 +56,7 @@ def cmd_SET_MAP(self, gcmd): lane_switch=self.AFC.tool_cmds[map_cmd] self.gcode.respond_info("lane to switch is " + lane_switch) if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(lane.upper())) return CUR_LANE = self.AFC.stepper[lane.name] for UNIT_SERACH in self.AFC.units.keys(): @@ -98,7 +98,7 @@ def cmd_SET_COLOR(self, gcmd): return color = gcmd.get('COLOR', '#000000') if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(lane.upper())) return CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.color = '#' + color @@ -129,7 +129,7 @@ def cmd_SET_WEIGHT(self, gcmd): return weight = gcmd.get('WEIGHT', '') if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(lane.upper())) return CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.weight = weight @@ -160,7 +160,7 @@ def cmd_SET_MATERIAL(self, gcmd): return material = gcmd.get('MATERIAL', '') if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(lane.upper())) return CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.material = material @@ -205,7 +205,7 @@ def cmd_SET_SPOOLID(self, gcmd): return SpoolID = gcmd.get('SPOOL_ID', '') if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(lane.upper())) return CUR_LANE = self.AFC.stepper[lane.name] self.set_spoolID(CUR_LANE, SpoolID) @@ -238,7 +238,7 @@ def set_spoolID(self, CUR_LANE, SpoolID): cmd_SET_RUNOUT_help = "change filaments ID" def cmd_SET_RUNOUT(self, gcmd): """ - This function handles setting the runout lane (infanet spool) for a specified lane. It retrieves the lane + This function handles setting the runout lane (infinite spool) for a specified lane. It retrieves the lane specified by the 'LANE' parameter and updates its the lane to use if filament is empty based on the information retrieved from the Spoolman API. @@ -260,7 +260,7 @@ def cmd_SET_RUNOUT(self, gcmd): return runout = gcmd.get('RUNOUT', '') if lane not in self.AFC.stepper: - self.AFC.gcode.respond_info(lane + ' Unknown') + self.AFC.gcode.respond_info('{} Unknown'.format(lane.upper())) return CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.runout_lane = runout From 66e66099be05a0a18983bc741edaa7f5e2ee153c Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 15:04:30 -0700 Subject: [PATCH 05/12] Indenting while loop that should be under hub cut if statement --- extras/AFC.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index 88a20bb3..82a3aa43 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -850,6 +850,9 @@ def TOOL_UNLOAD(self, CUR_LANE): # Clear toolhead's loaded state for easier error handling later. CUR_LANE.tool_loaded = False self.extruders[CUR_LANE.extruder_name]['lane_loaded'] = '' + CUR_LANE.status = None + self.current = None + self.save_vars() # Ensure filament is fully cleared from the hub. @@ -873,14 +876,15 @@ def TOOL_UNLOAD(self, CUR_LANE): else: self.gcode.run_script_from_command(CUR_HUB.cut_cmd) - # Confirm the hub is clear after the cut. - while CUR_HUB.state: - CUR_LANE.move(self.short_move_dis * -1, self.short_moves_speed, self.short_moves_accel, True) - num_tries += 1 - if num_tries > (CUR_HUB.afc_bowden_length / self.short_move_dis): - message = 'HUB NOT CLEARING' - self.ERROR.handle_lane_failure(CUR_LANE, message) - return False + # Confirm the hub is clear after the cut. + while CUR_HUB.state: + CUR_LANE.move(self.short_move_dis * -1, self.short_moves_speed, self.short_moves_accel, True) + num_tries += 1 + # TODO: Figure out max number of tries + if num_tries > (CUR_HUB.afc_bowden_length / self.short_move_dis): + message = 'HUB NOT CLEARING after hub cut\n' + self.ERROR.handle_lane_failure(CUR_LANE, message) + return False # Finalize unloading and reset lane state. CUR_LANE.hub_load = True From 9ffdb70a00a42d5df97e634de2e58d158e2f5004 Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 15:09:40 -0700 Subject: [PATCH 06/12] Fixing changelog, combining dates and making sure dates are in the right order --- CHANGELOG.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5981495..db996941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -243,17 +243,12 @@ Optional: ### Fixed - Fixed places where gcode was not referencing AFC and would cause crashes - -## [2024-12-09] - -### Added -- Added logic to pause print when filament goes past prep sensor. Verify that PAUSE macro move's toolhead off print when it's called. -======= ## [2024-12-08] ### Added - When updating the AFC software, the `install-afc.sh` script will now remove any instances of `[gcode_macro T#]` found in the `AFC_Macros.cfg` file as the code now generates them automatically. +- Added logic to pause print when filament goes past prep sensor. Verify that PAUSE macro move's toolhead off print when it's called. ## [2024-12-09] From 6e09b7d8d69f382b7f457a4b98311d1cdf3748c5 Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 15:18:26 -0700 Subject: [PATCH 07/12] Changing lane.name to lane since lane is the name --- extras/AFC.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index 82a3aa43..e98b9b9c 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -282,7 +282,7 @@ def cmd_LANE_MOVE(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] CUR_LANE.move(distance, self.short_moves_speed, self.short_moves_accel, True) def save_pos(self): @@ -364,7 +364,7 @@ def cmd_HUB_CUT_TEST(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] CUR_HUB = self.printer.lookup_object('AFC_hub ' + CUR_LANE.unit) CUR_HUB.hub_cut(CUR_LANE) self.gcode.respond_info('Hub cut Done!') @@ -397,7 +397,7 @@ def cmd_TEST(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] self.gcode.respond_info('Testing at full speed') CUR_LANE.assist(-1) self.reactor.pause(self.reactor.monotonic() + 1) @@ -440,7 +440,7 @@ def cmd_HUB_LOAD(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] CUR_HUB = self.printer.lookup_object('AFC_hub '+ CUR_LANE.unit) if CUR_LANE.prep_state == False: return @@ -485,7 +485,7 @@ def cmd_LANE_UNLOAD(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] CUR_HUB = self.printer.lookup_object('AFC_hub '+ CUR_LANE.unit) if CUR_LANE.name != self.current: # Setting status as ejecting so if filament is removed and de-activates the prep sensor while @@ -536,7 +536,7 @@ def cmd_TOOL_LOAD(self, gcmd): if self.current is not None: self.ERROR.AFC_error("Cannot load {}, {} currently loaded".format(lane.upper(), self.current.upper()), pause=False) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] self.TOOL_LOAD(CUR_LANE) def TOOL_LOAD(self, CUR_LANE): @@ -717,7 +717,7 @@ def cmd_TOOL_UNLOAD(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] self.TOOL_UNLOAD(CUR_LANE) # User manually unloaded spool from toolhead, remove spool from active status @@ -956,7 +956,7 @@ def cmd_CHANGE_TOOL(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] # Check if the lane has completed the preparation process required for tool changes. if CUR_LANE._afc_prep_done: # Log the tool change operation for debugging or informational purposes. @@ -978,7 +978,7 @@ def cmd_CHANGE_TOOL(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - CUR_LANE = self.stepper[lane.name] + CUR_LANE = self.stepper[lane] # Load the new lane and restore the toolhead position if successful. if self.TOOL_LOAD(CUR_LANE) and not self.error_state: self.gcode.respond_info("{} is now loaded in toolhead".format(lane)) From a6dc0d455e312b14db20afef23aac792557b3142 Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 15:22:13 -0700 Subject: [PATCH 08/12] Fixing cut macro so it only rips on the last cut like originally intended --- config/macros/Cut.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/macros/Cut.cfg b/config/macros/Cut.cfg index a85233e8..61f0c157 100644 --- a/config/macros/Cut.cfg +++ b/config/macros/Cut.cfg @@ -191,6 +191,8 @@ description: Helper to do a single horizontal cut movement gcode: {% set pin_park_x_loc = params.PIN_PARK_X_LOC|float %} {% set pin_park_y_loc = params.PIN_PARK_Y_LOC|float %} + {% set rip_length = params.RIP_LENGTH|float %} + {% set vars = printer['gcode_macro _AFC_CUT_TIP_VARS'] %} {% set cut_move_dist = vars['cut_move_dist']|float %} {% set cut_direction = vars['cut_direction']|default('')|lower %} @@ -200,7 +202,6 @@ gcode: {% set cut_slow_move_speed = vars['cut_slow_move_speed'] * 60|float %} {% set cut_dwell_time = vars['cut_dwell_time']|float %} {% set evacuate_speed = vars['evacuate_speed'] * 60|float %} - {% set rip_length = vars['rip_length']|float %} {% set rip_speed = vars['rip_speed'] * 60|float %} # Get printer bounds to make sure none of our cut moves fall outside of them From 95d4be5511314a59f7022304e39978c9ce5b8df5 Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 15:28:26 -0700 Subject: [PATCH 09/12] Removing lane name from message when calling handle_lane_failure error function --- extras/AFC.py | 6 +++--- extras/AFC_error.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index e98b9b9c..3adddd54 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -625,7 +625,7 @@ def TOOL_LOAD(self, CUR_LANE): tool_attempts += 1 CUR_LANE.move(self.short_move_dis, CUR_EXTRUDER.tool_load_speed, self.long_moves_accel) if tool_attempts > 20: - message = ('FAILED TO LOAD {} TO TOOL, CHECK FILAMENT PATH\n||=====||====||==>--||\nTRG LOAD HUB TOOL'.format(CUR_LANE.name.upper())) + message = ('FAILED TO LOAD TO TOOL, CHECK FILAMENT PATH\n||=====||====||==>--||\nTRG LOAD HUB TOOL') self.ERROR.handle_lane_failure(CUR_LANE, message) return False @@ -683,11 +683,11 @@ def TOOL_LOAD(self, CUR_LANE): else: # Handle errors if the hub is not clear or the lane is not ready for loading. if CUR_HUB.state: - message = ('HUB NOT CLEAR WHEN TRYING TO LOAD {}\n||-----||----|x|-----||\nTRG LOAD HUB TOOL'.format(CUR_LANE.name.upper())) + message = ('HUB NOT CLEAR WHEN TRYING TO LOAD\n||-----||----|x|-----||\nTRG LOAD HUB TOOL') self.ERROR.handle_lane_failure(CUR_LANE, message) return False if not CUR_LANE.load_state: - message = ('{} NOT READY, LOAD TRIGGER NOT TRIGGERED\n||==>--||----||-----||\nTRG LOAD HUB TOOL'.format(CUR_LANE.name.upper())) + message = ('NOT READY, LOAD TRIGGER NOT TRIGGERED\n||==>--||----||-----||\nTRG LOAD HUB TOOL') self.ERROR.handle_lane_failure(CUR_LANE, message) return False diff --git a/extras/AFC_error.py b/extras/AFC_error.py index e219f36c..f4a6561a 100644 --- a/extras/AFC_error.py +++ b/extras/AFC_error.py @@ -136,7 +136,7 @@ def handle_lane_failure(self, CUR_LANE, message, pause=True): # Disable the stepper for this lane CUR_LANE.do_enable(False) CUR_LANE.status = 'Error' - msg = (CUR_LANE.name.upper() + message) + msg = "{} {}".format(CUR_LANE.name.upper(), message) self.AFC_error(msg, pause) self.AFC.afc_led(self.AFC.led_fault, CUR_LANE.led_index) From ad07848fbe7ff59e7fb9d00d3c4c2401d6a26b5b Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 15:58:21 -0700 Subject: [PATCH 10/12] Updating changelog --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db996941..11554220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -265,4 +265,12 @@ file as the code now generates them automatically. ### Updated - Updated Cut.cfg macro to have the ability to up stepper current when doing filament cutting, - see layer shift troubleshooting section on what values need to be set \ No newline at end of file + see layer shift troubleshooting section on what values need to be set + +## [2024-12-20] + +### Added +- More error printouts to aid users + +### Fixes +- Misc error fixes \ No newline at end of file From 577ac2942c7dfa1e10d6c015f116cd638c8ae82c Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 16:00:21 -0700 Subject: [PATCH 11/12] Fixing linting whitespaces --- extras/AFC.py | 2 +- extras/AFC_BoxTurtle.py | 2 +- extras/AFC_NightOwl.py | 6 +++--- extras/AFC_prep.py | 2 +- extras/AFC_stepper.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index 3adddd54..f59124d6 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -532,7 +532,7 @@ def cmd_TOOL_LOAD(self, gcmd): if lane not in self.stepper: self.gcode.respond_info('{} Unknown'.format(lane.upper())) return - + if self.current is not None: self.ERROR.AFC_error("Cannot load {}, {} currently loaded".format(lane.upper(), self.current.upper()), pause=False) return diff --git a/extras/AFC_BoxTurtle.py b/extras/AFC_BoxTurtle.py index 1b82992d..db6dda43 100644 --- a/extras/AFC_BoxTurtle.py +++ b/extras/AFC_BoxTurtle.py @@ -34,7 +34,7 @@ def system_Test(self, UNIT, LANE, delay): if LANE not in self.AFC.stepper: self.AFC.gcode.respond_info('{} Unknown'.format(LANE.upper())) return - CUR_LANE = self.AFC.stepper[LANE] + CUR_LANE = self.AFC.stepper[LANE] try: CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) except: error_string = 'Error: No config found for extruder: ' + CUR_LANE.extruder_name + ' in [AFC_stepper ' + CUR_LANE.name + ']. Please make sure [AFC_extruder ' + CUR_LANE.extruder_name + '] config exists in AFC_Hardware.cfg' diff --git a/extras/AFC_NightOwl.py b/extras/AFC_NightOwl.py index 538f829f..f753c72d 100644 --- a/extras/AFC_NightOwl.py +++ b/extras/AFC_NightOwl.py @@ -27,7 +27,7 @@ def system_Test(self, UNIT, LANE, delay): if LANE not in self.AFC.stepper: self.AFC.gcode.respond_info('{} Unknown'.format(LANE.upper())) return - CUR_LANE = self.AFC.stepper[LANE] + CUR_LANE = self.AFC.stepper[LANE] try: CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) except: error_string = 'Error: No config found for extruder: ' + CUR_LANE.extruder_name + ' in [AFC_stepper ' + CUR_LANE.name + ']. Please make sure [AFC_extruder ' + CUR_LANE.extruder_name + '] config exists in AFC_Hardware.cfg' @@ -52,8 +52,8 @@ def system_Test(self, UNIT, LANE, delay): msg = 'CHECK FILAMENT Prep: False - Load: True' succeeded = False - else: - + else: + self.AFC.afc_led(self.AFC.led_ready, CUR_LANE.led_index) msg +="LOCKED" if CUR_LANE.load_state == False: diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index 0930c353..1ac6eb59 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -79,7 +79,7 @@ def PREP(self, gcmd): if LANE.unit not in self.AFC.lanes: self.AFC.lanes[LANE.unit] = {} if LANE.name not in self.AFC.units[LANE.unit]: self.AFC.units[LANE.unit][LANE.name]={} if LANE.name not in self.AFC.lanes[LANE.unit]: self.AFC.lanes[LANE.unit][LANE.name] = {} - if 'spool_id' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.spool_id = self.AFC.lanes[LANE.unit][LANE.name]['spool_id'] + if 'spool_id' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.spool_id = self.AFC.lanes[LANE.unit][LANE.name]['spool_id'] if self.AFC.spoolman_ip !=None and LANE.spool_id != None: self.AFC.SPOOL.set_spoolID(LANE, LANE.spool_id) diff --git a/extras/AFC_stepper.py b/extras/AFC_stepper.py index 7caf10e4..c53ac55c 100644 --- a/extras/AFC_stepper.py +++ b/extras/AFC_stepper.py @@ -85,7 +85,7 @@ def __init__(self, config): self.stepper_kinematics = ffi_main.gc( ffi_lib.cartesian_stepper_alloc(b'x'), ffi_lib.free) self.assist_activate=False - + self.hub_dist = config.getfloat('hub_dist',20) self.dist_hub = config.getfloat('dist_hub', 60) # distance to retract filament from the hub From 0b3698e00d3a32ff0186e2c61886117b7bbdd8a3 Mon Sep 17 00:00:00 2001 From: jimmyjon711 Date: Fri, 20 Dec 2024 16:04:45 -0700 Subject: [PATCH 12/12] Removing unused import from AFC_prep.py --- extras/AFC_prep.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index 14a9a0f8..dd9cbd15 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -6,11 +6,6 @@ import os import json -try: - from urllib.request import urlopen -except: - # Python 2.7 support - from urllib2 import urlopen class afcPrep: def __init__(self, config):