From 34436ee34b92e3ba55aa363b25f2507469111701 Mon Sep 17 00:00:00 2001 From: MG-longshot Date: Tue, 17 Dec 2024 22:18:48 -0600 Subject: [PATCH 1/7] added lane status --- extras/AFC.py | 22 ++++++++++++++++++---- extras/AFC_prep.py | 1 + extras/AFC_spool.py | 10 +++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index 31d76f57..57678379 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -27,6 +27,8 @@ def __init__(self, config): self.tool_cmds={} self.afc_monitoring = False + self.desired_order_list = config.get('Vdesired_order_list','') + # tool position when tool change was requested self.change_tool_pos = None self.in_toolchange = False @@ -441,7 +443,9 @@ def cmd_HUB_LOAD(self, gcmd): CUR_LANE.move(CUR_HUB.move_dis, self.short_moves_speed, self.short_moves_accel) while CUR_HUB.state == True: CUR_LANE.move(CUR_HUB.move_dis * -1, self.short_moves_speed, self.short_moves_accel) - CUR_LANE.status = 'Hubed' + CUR_LANE.status = '' + self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status + self.save_vars() CUR_LANE.do_enable(False) CUR_LANE.hub_load = True self.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = CUR_LANE.hub_load @@ -472,6 +476,8 @@ def cmd_LANE_UNLOAD(self, gcmd): # extruder motors are still running it does not trigger infinite spool or pause logic # once user removes filament lanes status will go to None CUR_LANE.status = 'ejecting' + self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status + self.save_vars() CUR_LANE.do_enable(True) if CUR_LANE.hub_load: CUR_LANE.move(CUR_LANE.dist_hub * -1, CUR_LANE.dist_hub_move_speed, CUR_LANE.dist_hub_move_accel, True if CUR_LANE.dist_hub > 200 else False) @@ -481,6 +487,8 @@ def cmd_LANE_UNLOAD(self, gcmd): CUR_LANE.move( CUR_HUB.move_dis * -5, self.short_moves_speed, self.short_moves_accel) CUR_LANE.do_enable(False) self.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = CUR_LANE.hub_load + CUR_LANE.status = '' + self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() # Removing spool from vars since it was ejected @@ -549,6 +557,8 @@ def TOOL_LOAD(self, CUR_LANE): # Set the lane status to 'loading' and activate the loading LED. CUR_LANE.status = 'loading' + self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status + self.save_vars() self.afc_led(self.led_loading, CUR_LANE.led_index) # Check if the lane is in a state ready to load and hub is clear. @@ -598,6 +608,8 @@ def TOOL_LOAD(self, CUR_LANE): # Synchronize lane's extruder stepper and finalize tool loading. CUR_LANE.status = 'Tooled' + self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status + self.save_vars() CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name) # Adjust tool position for loading. @@ -723,7 +735,8 @@ def TOOL_UNLOAD(self, CUR_LANE): extruder = self.toolhead.get_extruder() self.heater = extruder.get_heater() CUR_LANE.status = 'unloading' - + self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status + self.save_vars() # Disable the buffer if it's active. CUR_EXTRUDER.disable_buffer() @@ -846,6 +859,8 @@ def TOOL_UNLOAD(self, CUR_LANE): CUR_LANE.hub_load = True self.afc_led(self.led_ready, CUR_LANE.led_index) CUR_LANE.status = None + self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status + self.save_vars() self.current = None CUR_LANE.do_enable(False) @@ -983,9 +998,8 @@ def get_status(self, eventtime): str[UNIT][NAME]["runout_lane"]=self.lanes[LANE.unit][LANE.name]['runout_lane'] filiment_stat=self.get_filament_status(LANE).split(':') str[UNIT][NAME]['filament_status']=filiment_stat[0] - self.lanes[UNIT][NAME]['filament_status']=filiment_stat[0] str[UNIT][NAME]['filament_status_led']=filiment_stat[1] - self.lanes[UNIT][NAME]['filament_status_led']=filiment_stat[1] + str[UNIT][NAME]['status'] = LANE.status if LANE.status is not None else '' numoflanes +=1 str[UNIT]['system']={} str[UNIT]['system']['type'] = self.printer.lookup_object('AFC_hub '+ UNIT).type diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index dc96a2f4..54bc393c 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -110,6 +110,7 @@ def PREP(self, gcmd): if 'tool_loaded' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['tool_loaded'] = False if 'hub_loaded' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['hub_loaded'] = False if 'tool_loaded' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['tool_loaded'] = False + if 'status' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['status'] = '' tmp=[] for UNIT in self.AFC.lanes.keys(): diff --git a/extras/AFC_spool.py b/extras/AFC_spool.py index 12aed8c0..86ccbf6f 100644 --- a/extras/AFC_spool.py +++ b/extras/AFC_spool.py @@ -31,7 +31,7 @@ def handle_connect(self): self.URL = 'http://{}:{}/api/v1/spool/'.format(self.AFC.spoolman_ip, self.AFC.spoolman_port) - cmd_SET_MAP_help = "change filaments color" + cmd_SET_MAP_help = "change filaments map" def cmd_SET_MAP(self, gcmd): """ This function handles changing the GCODE tool change command for a Lane. @@ -42,7 +42,7 @@ def cmd_SET_MAP(self, gcmd): Args: gcmd: The G-code command object containing the parameters for the command. Expected parameters: - - LANE: The name of the lane whose color is to be changed. + - LANE: The name of the lane whose map is to be changed. - MAP: The new tool change gcode for lane (optional, defaults to None). Returns: @@ -112,7 +112,7 @@ def cmd_SET_WEIGHT(self, gcmd): Args: gcmd: The G-code command object containing the parameters for the command. Expected parameters: - + LANE: The name of the lane whose weight is to be changed. WEIGHT: The new weight (optional, defaults to ''). @@ -141,7 +141,7 @@ def cmd_SET_MATERIAL(self, gcmd): Args: gcmd: The G-code command object containing the parameters for the command. Expected parameters: - + LANE: The name of the lane whose material is to be changed. MATERIAL: The new material (optional, defaults to ''). @@ -157,7 +157,7 @@ def cmd_SET_MATERIAL(self, gcmd): CUR_LANE.material = material self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['material'] = material self.AFC.save_vars() - + def set_active_spool(self, ID): webhooks = self.printer.lookup_object('webhooks') if self.AFC.spoolman_ip != None: From c55dd79efaa75d5ba7e9457fdaa00c94b18786d2 Mon Sep 17 00:00:00 2001 From: MG-longshot Date: Tue, 17 Dec 2024 23:12:30 -0600 Subject: [PATCH 2/7] switched to cur lane variables --- extras/AFC.py | 64 +++++++++++++++++++++++++++++------------ extras/AFC_BoxTurtle.py | 10 +++++-- extras/AFC_prep.py | 2 +- extras/AFC_spool.py | 30 +++++++++++++++---- 4 files changed, 78 insertions(+), 28 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index 57678379..c259d527 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -24,6 +24,7 @@ def __init__(self, config): self.error_state = False self.lanes = {} self.extruders = {} + self.stepper = {} self.tool_cmds={} self.afc_monitoring = False @@ -169,7 +170,7 @@ def cmd_AFC_STATUS(self, gcmd): for LANE in self.lanes[UNIT].keys(): lane_msg = '' - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + LANE) + CUR_LANE = self.AFC.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: @@ -229,7 +230,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.printer.lookup_object('AFC_stepper ' + self.current) + CUR_LANE = self.AFC.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") @@ -277,7 +278,10 @@ def cmd_LANE_MOVE(self, gcmd): """ lane = gcmd.get('LANE', None) distance = gcmd.get_float('DISTANCE', 0) - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.move(distance, self.short_moves_speed, self.short_moves_accel, True) def save_pos(self): @@ -355,7 +359,10 @@ def cmd_HUB_CUT_TEST(self, gcmd): """ lane = gcmd.get('LANE', None) self.gcode.respond_info('Testing Hub Cut on Lane: ' + lane) - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.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!') @@ -385,11 +392,10 @@ def cmd_TEST(self, gcmd): self.ERROR.AFC_error('Must select LANE', False) return self.gcode.respond_info('TEST ROUTINE') - try: - CUR_LANE = self.printer.lookup_object('AFC_stepper '+lane) - except error: - self.ERROR.fix( 'could not find stepper {}'.format(lane), CUR_LANE ) #send to error handling - return + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] self.gcode.respond_info('Testing at full speed') CUR_LANE.assist(-1) self.reactor.pause(self.reactor.monotonic() + 1) @@ -429,7 +435,10 @@ def cmd_HUB_LOAD(self, gcmd): None """ lane = gcmd.get('LANE', None) - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] CUR_HUB = self.printer.lookup_object('AFC_hub '+ CUR_LANE.unit) if CUR_LANE.prep_state == False: return @@ -469,7 +478,10 @@ def cmd_LANE_UNLOAD(self, gcmd): None """ lane = gcmd.get('LANE', None) - CUR_LANE = self.printer.lookup_object('AFC_stepper '+ lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.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 @@ -516,7 +528,10 @@ def cmd_TOOL_LOAD(self, gcmd): None """ lane = gcmd.get('LANE', None) - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] self.TOOL_LOAD(CUR_LANE) def TOOL_LOAD(self, CUR_LANE): @@ -636,7 +651,7 @@ def TOOL_LOAD(self, CUR_LANE): break CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name) # Update tool and lane status. - self.printer.lookup_object('AFC_stepper ' + CUR_LANE.name).status = 'tool' + CUR_LANE.status = 'tool' self.lanes[CUR_LANE.unit][CUR_LANE.name]['tool_loaded'] = True self.current = CUR_LANE.name CUR_EXTRUDER.enable_buffer() @@ -692,7 +707,10 @@ def cmd_TOOL_UNLOAD(self, gcmd): lane = gcmd.get('LANE', self.current) if lane == None: return - CUR_LANE = self.printer.lookup_object('AFC_stepper '+ lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] self.TOOL_UNLOAD(CUR_LANE) # User manually unloaded spool from toolhead, remove spool from active status @@ -923,7 +941,10 @@ def cmd_CHANGE_TOOL(self, gcmd): self.in_toolchange = True # Lookup the lane object for the requested lane. - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.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. @@ -931,7 +952,10 @@ def cmd_CHANGE_TOOL(self, gcmd): # If a current lane is loaded, unload it first. if self.current is not None: - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + self.current) + if self.current not in self.AFC.stepper: + self.AFC.gcode.respond_info(self.current + ' Unknown') + return + CUR_LANE = self.AFC.stepper[self.current] if not self.TOOL_UNLOAD(CUR_LANE): # Abort if the unloading process fails. msg = (' UNLOAD ERROR NOT CLEARED') @@ -939,8 +963,10 @@ def cmd_CHANGE_TOOL(self, gcmd): return # Switch to the new lane for loading. - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) - + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.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)) @@ -983,7 +1009,7 @@ def get_status(self, eventtime): screen_mac = 'None' str[UNIT]={} for NAME in self.lanes[UNIT].keys(): - LANE=self.printer.lookup_object('AFC_stepper '+ NAME) + LANE=self.AFC.stepper[NAME] str[UNIT][NAME]={} str[UNIT][NAME]['LANE'] = LANE.index str[UNIT][NAME]['map'] = LANE.map diff --git a/extras/AFC_BoxTurtle.py b/extras/AFC_BoxTurtle.py index 78174eee..99ce0e0b 100644 --- a/extras/AFC_BoxTurtle.py +++ b/extras/AFC_BoxTurtle.py @@ -31,7 +31,10 @@ def handle_connect(self): def system_Test(self, UNIT, LANE, delay): msg = '' succeeded = True - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + LANE) + if LANE not in self.AFC.stepper: + self.AFC.gcode.respond_info(LANE + ' Unknown') + return + CUR_LANE = self.AFC.stepper[LANE.name] 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' @@ -165,7 +168,10 @@ def calc_position(lane, state, pos, short_move, tolerance): return pos def calibrate_lane(LANE): - CUR_LANE = self.printer.lookup_object('AFC_stepper {}'.format(LANE)) + if LANE not in self.AFC.stepper: + self.AFC.gcode.respond_info(LANE + ' Unknown') + return + CUR_LANE = self.AFC.stepper[LANE.name] CUR_HUB = self.printer.lookup_object('AFC_hub {}'.format(CUR_LANE.unit)) if CUR_HUB.state: self.AFC.gcode.respond_info('Hub is not clear, check before calibration') diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index 54bc393c..54071a8a 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -19,7 +19,6 @@ def __init__(self, config): self.delay = config.getfloat('delay_time', 0.1, minval=0.0) self.enable = config.getboolean("enable", False) - # Flag to set once resume rename as occured for the first time self.rename_occured = False @@ -75,6 +74,7 @@ def PREP(self, gcmd): for PO in self.printer.objects: if 'AFC_stepper' in PO and 'tmc' not in PO: LANE=self.printer.lookup_object(PO) + self.AFC.stepper[LANE.name]=LANE temp.append(LANE.name) if LANE.unit not in self.AFC.lanes: self.AFC.lanes[LANE.unit]={} if LANE.name not in self.AFC.lanes[LANE.unit]: self.AFC.lanes[LANE.unit][LANE.name]={} diff --git a/extras/AFC_spool.py b/extras/AFC_spool.py index 86ccbf6f..139ef796 100644 --- a/extras/AFC_spool.py +++ b/extras/AFC_spool.py @@ -55,7 +55,10 @@ def cmd_SET_MAP(self, gcmd): map_cmd = gcmd.get('MAP', None) lane_switch=self.AFC.tool_cmds[map_cmd] self.gcode.respond_info("lane to switch is " + lane_switch) - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] for UNIT_SERACH in self.AFC.lanes.keys(): self.gcode.respond_info("looking for "+lane+" in " + UNIT_SERACH) if lane in self.AFC.lanes[UNIT_SERACH]: @@ -95,7 +98,10 @@ def cmd_SET_COLOR(self, gcmd): self.gcode.respond_info("No LANE Defined") return color = gcmd.get('COLOR', '#000000') - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.color = '#' + color self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['color'] ='#'+ color self.AFC.save_vars() @@ -124,7 +130,10 @@ def cmd_SET_WEIGHT(self, gcmd): self.gcode.respond_info("No LANE Defined") return weight = gcmd.get('WEIGHT', '') - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.weight = weight self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['weight'] = weight self.AFC.save_vars() @@ -153,7 +162,10 @@ def cmd_SET_MATERIAL(self, gcmd): self.gcode.respond_info("No LANE Defined") return material = gcmd.get('MATERIAL', '') - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.material = material self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['material'] = material self.AFC.save_vars() @@ -197,7 +209,10 @@ def cmd_SET_SPOOLID(self, gcmd): self.gcode.respond_info("No LANE Defined") return SpoolID = gcmd.get('SPOOL_ID', '') - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] self.set_spoolID(CUR_LANE, SpoolID) def set_spoolID(self, CUR_LANE, SpoolID): @@ -243,7 +258,10 @@ def cmd_SET_RUNOUT(self, gcmd): self.gcode.respond_info("No LANE Defined") return runout = gcmd.get('RUNOUT', '') - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) + if lane not in self.AFC.stepper: + self.AFC.gcode.respond_info(lane + ' Unknown') + return + CUR_LANE = self.AFC.stepper[lane.name] self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['runout_lane'] = runout self.AFC.save_vars() self.gcode.respond_info("This is a feature WIP. Not functioning yet") From 62eb386991a4f0b6f6463b391e4ef99dfaa10023 Mon Sep 17 00:00:00 2001 From: MG-longshot Date: Wed, 18 Dec 2024 18:09:46 -0600 Subject: [PATCH 3/7] sepration of variables --- extras/AFC_BoxTurtle.py | 11 ++++--- extras/AFC_prep.py | 64 ++++++++++++++++------------------------- extras/AFC_stepper.py | 31 +++++++++++++------- 3 files changed, 50 insertions(+), 56 deletions(-) diff --git a/extras/AFC_BoxTurtle.py b/extras/AFC_BoxTurtle.py index 99ce0e0b..3db6ea6a 100644 --- a/extras/AFC_BoxTurtle.py +++ b/extras/AFC_BoxTurtle.py @@ -60,7 +60,6 @@ def system_Test(self, UNIT, LANE, delay): succeeded = False else: - CUR_LANE.hub_load = self.AFC.lanes[UNIT][LANE]['hub_loaded'] # Setting hub load state so it can be retained between restarts self.AFC.afc_led(self.AFC.led_ready, CUR_LANE.led_index) msg +="LOCKED" if CUR_LANE.load_state == False: @@ -78,7 +77,7 @@ def system_Test(self, UNIT, LANE, delay): msg +=" in ToolHead" if CUR_EXTRUDER.tool_start == "buffer": msg += "\n Ram sensor enabled, confirm tool is loaded" - self.AFC.SPOOL.set_active_spool(self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['spool_id']) + self.AFC.SPOOL.set_active_spool(CUR_LANE.spool_id) self.AFC.afc_led(self.AFC.led_tool_loaded, CUR_LANE.led_index) if len(self.AFC.extruders) == 1: self.AFC.current = CUR_LANE.name @@ -200,8 +199,8 @@ def calibrate_lane(LANE): if lanes != 'all': lane_to_calibrate = None # Search for the lane within the units - for UNIT in self.AFC.lanes.keys(): - if lanes in self.AFC.lanes[UNIT]: + for UNIT in self.AFC.units.keys(): + if lanes in self.AFC.units[UNIT]: lane_to_calibrate = lanes break if lane_to_calibrate is None: @@ -214,8 +213,8 @@ def calibrate_lane(LANE): cal_msg += msg else: # Calibrate all lanes if no specific lane is provided - for UNIT in self.AFC.lanes.keys(): - for LANE in self.AFC.lanes[UNIT].keys(): + for UNIT in self.AFC.units.keys(): + for LANE in self.AFC.units[UNIT].keys(): # Calibrate the specific lane checked, msg = calibrate_lane(LANE) if(not checked): return diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index 54071a8a..1b1bf3c6 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -77,56 +77,40 @@ def PREP(self, gcmd): self.AFC.stepper[LANE.name]=LANE temp.append(LANE.name) if LANE.unit not in self.AFC.lanes: self.AFC.lanes[LANE.unit]={} + self.AFC.units[LANE.unit]={} if LANE.name not in self.AFC.lanes[LANE.unit]: self.AFC.lanes[LANE.unit][LANE.name]={} + self.AFC.units[LANE.unit][LANE.name] if LANE.extruder_name not in self.AFC.extruders: self.AFC.extruders[LANE.extruder_name]={} - if 'lane_loaded' not in self.AFC.extruders[LANE.extruder_name]: self.AFC.extruders[LANE.extruder_name]['lane_loaded']='' - - if 'spool_id' not in self.AFC.lanes[LANE.unit][LANE.name]: - self.AFC.lanes[LANE.unit][LANE.name]['spool_id']='' - else: - if self.AFC.spoolman_ip !=None and self.AFC.lanes[LANE.unit][LANE.name]['spool_id'] != '': - 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)) - self.AFC.lanes[LANE.unit][LANE.name]['material'] = result['filament']['material'] - self.AFC.lanes[LANE.unit][LANE.name]['color'] = '#' + result['filament']['color_hex'] - if 'remaining_weight' in result: self.AFC.lanes[LANE.unit][LANE.name]['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) - - if 'material' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['material']='' - if 'color' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['color']='#000000' - if 'weight' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['weight'] = 0 - if 'runout_lane' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['runout_lane']='NONE' - if 'map' not in self.AFC.lanes[LANE.unit][LANE.name] or self.AFC.lanes[LANE.unit][LANE.name]['map'] is None: - self.AFC.lanes[LANE.unit][LANE.name]['map'] = 'NONE' + 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) else: - LANE.map = self.AFC.lanes[LANE.unit][LANE.name]['map'] + 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'] + if 'weight' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.weight=self.AFC.lanes[LANE.unit][LANE.name]['weight'] + + if 'runout_lane' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.runout_lane = self.AFC.lanes[LANE.unit][LANE.name]['runout_lane'] + if 'map' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.map = self.AFC.lanes[LANE.unit][LANE.name]['map'] if LANE.map != 'NONE': - self.AFC.lanes[LANE.unit][LANE.name]['map'] = LANE.map self.AFC.tool_cmds[LANE.map] = LANE.name - if 'index' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['index'] = LANE.index - if 'tool_loaded' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['tool_loaded'] = False - if 'hub_loaded' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['hub_loaded'] = False - if 'tool_loaded' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['tool_loaded'] = False - if 'status' not in self.AFC.lanes[LANE.unit][LANE.name]: self.AFC.lanes[LANE.unit][LANE.name]['status'] = '' - - tmp=[] - for UNIT in self.AFC.lanes.keys(): - if UNIT !='system': - for LANE in self.AFC.lanes[UNIT].keys(): - if LANE !='system': - if LANE not in temp: tmp.append(LANE) - for erase in tmp: - del self.AFC.lanes[UNIT][erase] + if 'hub_loaded' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.hub_loaded = self.AFC.lanes[LANE.unit][LANE.name]['hub_loaded'] + if 'tool_loaded' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.tool_loaded = self.AFC.lanes[LANE.unit][LANE.name]['tool_loaded'] + if 'status' in self.AFC.lanes[LANE.unit][LANE.name]: LANE.status = self.AFC.lanes[LANE.unit][LANE.name]['status'] + self.AFC.lanes={} self.AFC.save_vars() - if self.enable == False: self.AFC.gcode.respond_info('Prep Checks Disabled') return elif len(self.AFC.lanes) >0: - for UNIT in self.AFC.lanes.keys(): + for UNIT in self.AFC.units.keys(): logo='' logo_error = '' try: CUR_HUB = self.printer.lookup_object('AFC_hub '+ UNIT) @@ -142,7 +126,7 @@ def PREP(self, gcmd): logo_error+=' ' + UNIT + '\n' LaneCheck = True - for LANE in self.AFC.lanes[UNIT].keys(): + for LANE in self.AFC.units[UNIT].keys(): if not CUR_HUB.unit.system_Test(UNIT,LANE, self.delay): LaneCheck = False diff --git a/extras/AFC_stepper.py b/extras/AFC_stepper.py index dc19be6b..0f1ffef0 100644 --- a/extras/AFC_stepper.py +++ b/extras/AFC_stepper.py @@ -49,11 +49,30 @@ def __init__(self, config): self.printer = config.get_printer() self.AFC = self.printer.lookup_object('AFC') self.gcode = self.printer.lookup_object('gcode') - self.name = config.get_name().split()[-1] self.reactor = self.printer.get_reactor() self.extruder_stepper = extruder.ExtruderStepper(config) + + #stored status variables + self.name = config.get_name().split()[-1] self.extruder_name = config.get('extruder') + self.map = config.get('cmd','NONE') + self.tool_loaded = False + self.loaded_to_hub = False + self.spool_id = None + self.material = None + self.color = None + self.weight = None + self.runout_lane = None + self.status = None + unit = config.get('unit', None) + if unit != None: + self.unit = unit.split(':')[0] + self.index = int(unit.split(':')[1]) + else: + self.unit = 'Unknown' + self.index = 0 + self.hub= '' self.motion_queue = None self.status = None @@ -66,15 +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 - # Units - unit = config.get('unit', None) - if unit != None: - self.unit = unit.split(':')[0] - self.index = int(unit.split(':')[1]) - else: - self.unit = 'Unknown' - self.index = 0 - self.hub= '' + self.hub_dist = config.getfloat('hub_dist',20) self.dist_hub = config.getfloat('dist_hub', 60) # distance to retract filament from the hub From 1091d9ddc999d52974eb087e8370c472e4fcd751 Mon Sep 17 00:00:00 2001 From: MG-longshot Date: Wed, 18 Dec 2024 19:10:23 -0600 Subject: [PATCH 4/7] removed LANES with CUR_LANE --- extras/AFC.py | 71 ++++++++++++++++++------------------------- extras/AFC_spool.py | 36 ++++++++++------------ extras/AFC_stepper.py | 6 ++-- 3 files changed, 49 insertions(+), 64 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index c259d527..2b41147e 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -158,9 +158,9 @@ def cmd_AFC_STATUS(self, gcmd): """ status_msg = '' - for UNIT in self.lanes.keys(): + for UNIT in self.units.keys(): # Find the maximum length of lane names to determine the column width - max_lane_length = max(len(lane) for lane in self.lanes[UNIT].keys()) + max_lane_length = max(len(lane) for lane in self.units[UNIT].keys()) status_msg += '{} Status\n'.format(UNIT) @@ -168,7 +168,7 @@ def cmd_AFC_STATUS(self, gcmd): header_format = '{:<{}} | Prep | Load |\n' status_msg += header_format.format("LANE", max_lane_length) - for LANE in self.lanes[UNIT].keys(): + for LANE in self.units[UNIT].keys(): lane_msg = '' CUR_LANE = self.AFC.stepper[LANE] CUR_HUB = self.printer.lookup_object('AFC_hub '+ UNIT) @@ -335,7 +335,7 @@ def save_vars(self): make it more readable for users """ with open(self.VarFile+ '.unit', 'w') as f: - f.write(json.dumps(self.lanes, indent=4)) + f.write(json.dumps(self.get_status, indent=4)) with open(self.VarFile+ '.tool', 'w') as f: f.write(json.dumps(self.extruders, indent=4)) @@ -453,11 +453,9 @@ def cmd_HUB_LOAD(self, gcmd): while CUR_HUB.state == True: CUR_LANE.move(CUR_HUB.move_dis * -1, self.short_moves_speed, self.short_moves_accel) CUR_LANE.status = '' - self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() CUR_LANE.do_enable(False) CUR_LANE.hub_load = True - self.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = CUR_LANE.hub_load self.save_vars() cmd_LANE_UNLOAD_help = "Unload lane from extruder" @@ -488,7 +486,6 @@ def cmd_LANE_UNLOAD(self, gcmd): # extruder motors are still running it does not trigger infinite spool or pause logic # once user removes filament lanes status will go to None CUR_LANE.status = 'ejecting' - self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() CUR_LANE.do_enable(True) if CUR_LANE.hub_load: @@ -498,9 +495,7 @@ def cmd_LANE_UNLOAD(self, gcmd): CUR_LANE.move( CUR_HUB.move_dis * -1, self.short_moves_speed, self.short_moves_accel, True) CUR_LANE.move( CUR_HUB.move_dis * -5, self.short_moves_speed, self.short_moves_accel) CUR_LANE.do_enable(False) - self.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = CUR_LANE.hub_load CUR_LANE.status = '' - self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() # Removing spool from vars since it was ejected @@ -572,7 +567,6 @@ def TOOL_LOAD(self, CUR_LANE): # Set the lane status to 'loading' and activate the loading LED. CUR_LANE.status = 'loading' - self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() self.afc_led(self.led_loading, CUR_LANE.led_index) @@ -623,7 +617,6 @@ def TOOL_LOAD(self, CUR_LANE): # Synchronize lane's extruder stepper and finalize tool loading. CUR_LANE.status = 'Tooled' - self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name) @@ -652,7 +645,7 @@ def TOOL_LOAD(self, CUR_LANE): CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name) # Update tool and lane status. CUR_LANE.status = 'tool' - self.lanes[CUR_LANE.unit][CUR_LANE.name]['tool_loaded'] = True + CUR_LANE.tool_loaded = True self.current = CUR_LANE.name CUR_EXTRUDER.enable_buffer() @@ -668,9 +661,9 @@ def TOOL_LOAD(self, CUR_LANE): self.gcode.run_script_from_command(self.wipe_cmd) # Update lane and extruder state for tracking. - self.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = True + CUR_LANE.hub_loaded = True self.extruders[CUR_LANE.extruder_name]['lane_loaded'] = CUR_LANE.name - self.SPOOL.set_active_spool(self.lanes[CUR_LANE.unit][CUR_LANE.name]['spool_id']) + self.SPOOL.set_active_spool(CUR_LANE.spool_id) self.afc_led(self.led_tool_loaded, CUR_LANE.led_index) self.save_vars() else: @@ -753,7 +746,6 @@ def TOOL_UNLOAD(self, CUR_LANE): extruder = self.toolhead.get_extruder() self.heater = extruder.get_heater() CUR_LANE.status = 'unloading' - self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() # Disable the buffer if it's active. CUR_EXTRUDER.disable_buffer() @@ -838,8 +830,7 @@ def TOOL_UNLOAD(self, CUR_LANE): CUR_LANE.move(CUR_HUB.afc_bowden_length * -1, self.long_moves_speed, self.long_moves_accel, True) # Clear toolhead's loaded state for easier error handling later. - self.lanes[CUR_LANE.unit][CUR_LANE.name]['tool_loaded'] = False - self.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = CUR_LANE.hub_load + CUR_LANE.tool_loaded = False self.extruders[CUR_LANE.extruder_name]['lane_loaded'] = '' self.save_vars() @@ -877,7 +868,6 @@ def TOOL_UNLOAD(self, CUR_LANE): CUR_LANE.hub_load = True self.afc_led(self.led_ready, CUR_LANE.led_index) CUR_LANE.status = None - self.lanes[CUR_LANE.unit][CUR_LANE.name]['status']=CUR_LANE.status self.save_vars() self.current = None CUR_LANE.do_enable(False) @@ -1002,30 +992,30 @@ def HexConvert(self,tmp): def get_status(self, eventtime): str = {} numoflanes = 0 - for UNIT in self.lanes.keys(): + for UNIT in self.units.keys(): try: screen_mac = self.printer.lookup_object('AFC_screen ' + UNIT).mac except error: screen_mac = 'None' str[UNIT]={} - for NAME in self.lanes[UNIT].keys(): - LANE=self.AFC.stepper[NAME] + for NAME in self.units[UNIT].keys(): + CUR_LANE=self.AFC.stepper[NAME] str[UNIT][NAME]={} - str[UNIT][NAME]['LANE'] = LANE.index - str[UNIT][NAME]['map'] = LANE.map - str[UNIT][NAME]['load'] = bool(LANE.load_state) - str[UNIT][NAME]["prep"] =bool(LANE.prep_state) - str[UNIT][NAME]["tool_loaded"] = self.lanes[UNIT][NAME]['tool_loaded'] - str[UNIT][NAME]["loaded_to_hub"] = self.lanes[UNIT][NAME]['hub_loaded'] - str[UNIT][NAME]["material"]=self.lanes[UNIT][NAME]['material'] - str[UNIT][NAME]["spool_id"]=self.lanes[UNIT][NAME]['spool_id'] - str[UNIT][NAME]["color"]=self.lanes[UNIT][NAME]['color'] - str[UNIT][NAME]["weight"]=self.lanes[UNIT][NAME]['weight'] - str[UNIT][NAME]["runout_lane"]=self.lanes[LANE.unit][LANE.name]['runout_lane'] - filiment_stat=self.get_filament_status(LANE).split(':') + str[UNIT][NAME]['LANE'] = CUR_LANE.index + str[UNIT][NAME]['map'] = CUR_LANE.map + str[UNIT][NAME]['load'] = bool(CUR_LANE.load_state) + str[UNIT][NAME]["prep"] =bool(CUR_LANE.prep_state) + str[UNIT][NAME]["tool_loaded"] = CUR_LANE.tool_loaded + str[UNIT][NAME]["loaded_to_hub"] = CUR_LANE.hub_loaded + str[UNIT][NAME]["material"]=CUR_LANE.material + str[UNIT][NAME]["spool_id"]=CUR_LANE.spool_id + str[UNIT][NAME]["color"]=CUR_LANE.color + str[UNIT][NAME]["weight"]=CUR_LANE.weight + str[UNIT][NAME]["runout_lane"]=CUR_LANE.runout_lane + filiment_stat=self.get_filament_status(CUR_LANE).split(':') str[UNIT][NAME]['filament_status']=filiment_stat[0] str[UNIT][NAME]['filament_status_led']=filiment_stat[1] - str[UNIT][NAME]['status'] = LANE.status if LANE.status is not None else '' + str[UNIT][NAME]['status'] = CUR_LANE.status if CUR_LANE.status is not None else '' numoflanes +=1 str[UNIT]['system']={} str[UNIT]['system']['type'] = self.printer.lookup_object('AFC_hub '+ UNIT).type @@ -1035,7 +1025,7 @@ def get_status(self, eventtime): str["system"]={} str["system"]['current_load']= self.current - str["system"]['num_units'] = len(self.lanes) + str["system"]['num_units'] = len(self.unites) str["system"]['num_lanes'] = numoflanes str["system"]['num_extruders'] = len(self.extruders) str["system"]["extruders"]={} @@ -1043,9 +1033,9 @@ def get_status(self, eventtime): for EXTRUDE in self.extruders.keys(): str["system"]["extruders"][EXTRUDE]={} CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + EXTRUDE) - str["system"]["extruders"][EXTRUDE]['lane_loaded'] = self.extruders[LANE.extruder_name]['lane_loaded'] + str["system"]["extruders"][EXTRUDE]['lane_loaded'] = self.extruders[CUR_LANE.extruder_name]['lane_loaded'] if CUR_EXTRUDER.tool_start == "buffer": - if self.extruders[LANE.extruder_name]['lane_loaded'] == '': + if self.extruders[CUR_LANE.extruder_name]['lane_loaded'] == '': str ["system"]["extruders"][EXTRUDE]['tool_start_sensor'] = False else: str["system"]["extruders"][EXTRUDE]['tool_start_sensor'] = True @@ -1096,14 +1086,13 @@ def TcmdAssign(self, CUR_LANE): for x in range(99): cmd = 'T'+str(x) if cmd not in self.tool_cmds: - self.lanes[CUR_LANE.unit][CUR_LANE.name]['map'] = cmd CUR_LANE.map = cmd break - self.tool_cmds[self.lanes[CUR_LANE.unit][CUR_LANE.name]['map']]=CUR_LANE.name + self.tool_cmds[CUR_LANE.map]=CUR_LANE.name try: - self.gcode.register_command(self.lanes[CUR_LANE.unit][CUR_LANE.name]['map'], self.cmd_CHANGE_TOOL, desc=self.cmd_CHANGE_TOOL_help) + self.gcode.register_command(CUR_LANE.map, self.cmd_CHANGE_TOOL, desc=self.cmd_CHANGE_TOOL_help) except: - self.gcode.respond_info("Error trying to map lane {lane} to {tool_macro}, please make sure there are no macros already setup for {tool_macro}".format(lane=[CUR_LANE.name], tool_macro=self.lanes[CUR_LANE.unit][CUR_LANE.name]['map']), ) + self.gcode.respond_info("Error trying to map lane {lane} to {tool_macro}, please make sure there are no macros already setup for {tool_macro}".format(lane=[CUR_LANE.name], tool_macro=CUR_LANE.map), ) self.save_vars() def load_config(config): diff --git a/extras/AFC_spool.py b/extras/AFC_spool.py index 139ef796..c8fa4257 100644 --- a/extras/AFC_spool.py +++ b/extras/AFC_spool.py @@ -59,19 +59,18 @@ def cmd_SET_MAP(self, gcmd): self.AFC.gcode.respond_info(lane + ' Unknown') return CUR_LANE = self.AFC.stepper[lane.name] - for UNIT_SERACH in self.AFC.lanes.keys(): + for UNIT_SERACH in self.AFC.units.keys(): self.gcode.respond_info("looking for "+lane+" in " + UNIT_SERACH) - if lane in self.AFC.lanes[UNIT_SERACH]: + if lane in self.AFC.units[UNIT_SERACH]: self.AFC.tool_cmds[map_cmd]=lane - map_switch=self.AFC.lanes[UNIT_SERACH][CUR_LANE.name]['map'] - self.AFC.lanes[UNIT_SERACH][CUR_LANE.name]['map']=map_cmd + map_switch=CUR_LANE.map CUR_LANE.map=map_cmd - for UNIT_SERACH in self.AFC.lanes.keys(): - if lane_switch in self.AFC.lanes[UNIT_SERACH]: - SW_LANE = self.printer.lookup_object('AFC_stepper ' + lane_switch) + for UNIT_SERACH in self.AFC.units.keys(): + if lane_switch in self.AFC.units[UNIT_SERACH]: + SW_LANE = self.AFC.stepper(lane_switch) self.AFC.tool_cmds[map_switch]=lane_switch - self.AFC.lanes[UNIT_SERACH][lane_switch]['map']=map_switch + SW_LANE.map = map_switch SW_LANE.map=map_switch self.AFC.save_vars() @@ -103,7 +102,6 @@ def cmd_SET_COLOR(self, gcmd): return CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.color = '#' + color - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['color'] ='#'+ color self.AFC.save_vars() cmd_SET_WEIGHT_help = "change filaments color" @@ -135,7 +133,6 @@ def cmd_SET_WEIGHT(self, gcmd): return CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.weight = weight - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['weight'] = weight self.AFC.save_vars() cmd_SET_MATERIAL_help = "change filaments color" @@ -167,7 +164,6 @@ def cmd_SET_MATERIAL(self, gcmd): return CUR_LANE = self.AFC.stepper[lane.name] CUR_LANE.material = material - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['material'] = material self.AFC.save_vars() def set_active_spool(self, ID): @@ -221,17 +217,17 @@ def set_spoolID(self, CUR_LANE, SpoolID): try: url = "{}{}".format(self.URL, SpoolID) result = json.load(urlopen(url)) - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['spool_id'] = SpoolID - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['material'] = result['filament']['material'] - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['color'] = '#' + result['filament']['color_hex'] - if 'remaining_weight' in result: self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['weight'] = result['remaining_weight'] + CUR_LANE.spool_id = 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) else: - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['spool_id'] = '' - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['material'] = '' - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['color'] = '' - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['weight'] = '' + CUR_LANE.spool_id = '' + CUR_LANE.material = '' + CUR_LANE.color = '' + CUR_LANE.weight = '' self.AFC.save_vars() cmd_SET_RUNOUT_help = "change filaments ID" @@ -262,7 +258,7 @@ def cmd_SET_RUNOUT(self, gcmd): self.AFC.gcode.respond_info(lane + ' Unknown') return CUR_LANE = self.AFC.stepper[lane.name] - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['runout_lane'] = runout + CUR_LANE.runout_lane = runout self.AFC.save_vars() self.gcode.respond_info("This is a feature WIP. Not functioning yet") diff --git a/extras/AFC_stepper.py b/extras/AFC_stepper.py index 0f1ffef0..8e1724c8 100644 --- a/extras/AFC_stepper.py +++ b/extras/AFC_stepper.py @@ -250,12 +250,12 @@ def prep_callback(self, eventtime, state): self.AFC.afc_led(self.AFC.led_ready, led) elif self.name == self.AFC.current and self.AFC.IDLE.state == 'Printing' and self.load_state and self.status != 'ejecting': # Checking to make sure runout_lane is set and does not equal 'NONE' - if self.AFC.lanes[self.unit][self.name]['runout_lane'] and self.AFC.lanes[self.unit][self.name]['runout_lane'] != 'NONE': + if self.runout_lane and self.runout_lane != 'NONE': self.status = None self.AFC.afc_led(self.AFC.led_not_ready, led) self.AFC.gcode.respond_info("Infinite Spool triggered for {}".format(self.name)) - empty_LANE = self.printer.lookup_object('AFC_stepper ' + self.AFC.current) - change_LANE = self.printer.lookup_object('AFC_stepper ' + self.AFC.lanes[self.unit][self.name]['runout_lane']) + empty_LANE = self.AFC.stepper(self.AFC.current) + change_LANE = self.AFC.stepper(self.runout_lane) self.gcode.run_script_from_command(change_LANE.map) self.gcode.run_script_from_command('SET_MAP LANE=' + change_LANE.name + ' MAP=' + empty_LANE.map) else: From e9c9ae8d9ccf9803f0d623258834a1071c102a7d Mon Sep 17 00:00:00 2001 From: MG-longshot Date: Wed, 18 Dec 2024 19:23:10 -0600 Subject: [PATCH 5/7] removing self.AFC.lanes --- extras/AFC_NightOwl.py | 4 ++-- extras/AFC_prep.py | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/extras/AFC_NightOwl.py b/extras/AFC_NightOwl.py index 461d30ac..5f4b6408 100644 --- a/extras/AFC_NightOwl.py +++ b/extras/AFC_NightOwl.py @@ -49,8 +49,8 @@ def system_Test(self, UNIT, LANE, delay): msg = 'CHECK FILAMENT Prep: False - Load: True' succeeded = False - else: - CUR_LANE.hub_load = self.AFC.lanes[UNIT][LANE]['hub_loaded'] # Setting hub load state so it can be retained between restarts + 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 1b1bf3c6..3525df74 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -60,8 +60,6 @@ def PREP(self, gcmd): ## load Unit variables if os.path.exists(self.AFC.VarFile + '.unit') and os.stat(self.AFC.VarFile + '.unit').st_size > 0: self.AFC.lanes=json.load(open(self.AFC.VarFile + '.unit')) - else: - self.AFC.lanes={} ## load Toolhead variables if os.path.exists(self.AFC.VarFile + '.tool') and os.stat(self.AFC.VarFile + '.tool').st_size > 0: self.AFC.extruders=json.load(open(self.AFC.VarFile + '.tool')) @@ -76,12 +74,10 @@ def PREP(self, gcmd): LANE=self.printer.lookup_object(PO) self.AFC.stepper[LANE.name]=LANE temp.append(LANE.name) - if LANE.unit not in self.AFC.lanes: self.AFC.lanes[LANE.unit]={} - self.AFC.units[LANE.unit]={} - if LANE.name not in self.AFC.lanes[LANE.unit]: self.AFC.lanes[LANE.unit][LANE.name]={} - self.AFC.units[LANE.unit][LANE.name] if LANE.extruder_name not in self.AFC.extruders: self.AFC.extruders[LANE.extruder_name]={} - LANE.spool_id = self.AFC.lanes[LANE.unit][LANE.name]['spool_id'] + if LANE.unit not in self.AFC.units: self.AFC.units[LANE.unit]={} + if LANE.name not in self.AFC.units[LANE.unit]: self.AFC.units[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'] @@ -109,7 +105,7 @@ def PREP(self, gcmd): if self.enable == False: self.AFC.gcode.respond_info('Prep Checks Disabled') return - elif len(self.AFC.lanes) >0: + elif len(self.AFC.units) >0: for UNIT in self.AFC.units.keys(): logo='' logo_error = '' From 465dbad827e744c4c60e50b60592e0d1c464960f Mon Sep 17 00:00:00 2001 From: MG-longshot Date: Wed, 18 Dec 2024 19:46:04 -0600 Subject: [PATCH 6/7] finshed removing slef.AFC.lanes --- extras/AFC.py | 10 ++++++---- extras/AFC_BoxTurtle.py | 5 ++--- extras/AFC_prep.py | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/extras/AFC.py b/extras/AFC.py index 2b41147e..eb7b5448 100644 --- a/extras/AFC.py +++ b/extras/AFC.py @@ -22,6 +22,7 @@ def __init__(self, config): self.VarFile = config.get('VarFile') self.current = None self.error_state = False + self.units = {} self.lanes = {} self.extruders = {} self.stepper = {} @@ -335,7 +336,8 @@ def save_vars(self): make it more readable for users """ with open(self.VarFile+ '.unit', 'w') as f: - f.write(json.dumps(self.get_status, indent=4)) + status = self.get_status(0) + f.write(json.dumps(status, indent=4)) with open(self.VarFile+ '.tool', 'w') as f: f.write(json.dumps(self.extruders, indent=4)) @@ -999,14 +1001,14 @@ def get_status(self, eventtime): screen_mac = 'None' str[UNIT]={} for NAME in self.units[UNIT].keys(): - CUR_LANE=self.AFC.stepper[NAME] + CUR_LANE=self.stepper[NAME] str[UNIT][NAME]={} str[UNIT][NAME]['LANE'] = CUR_LANE.index str[UNIT][NAME]['map'] = CUR_LANE.map str[UNIT][NAME]['load'] = bool(CUR_LANE.load_state) str[UNIT][NAME]["prep"] =bool(CUR_LANE.prep_state) str[UNIT][NAME]["tool_loaded"] = CUR_LANE.tool_loaded - str[UNIT][NAME]["loaded_to_hub"] = CUR_LANE.hub_loaded + str[UNIT][NAME]["loaded_to_hub"] = CUR_LANE.loaded_to_hub str[UNIT][NAME]["material"]=CUR_LANE.material str[UNIT][NAME]["spool_id"]=CUR_LANE.spool_id str[UNIT][NAME]["color"]=CUR_LANE.color @@ -1025,7 +1027,7 @@ def get_status(self, eventtime): str["system"]={} str["system"]['current_load']= self.current - str["system"]['num_units'] = len(self.unites) + str["system"]['num_units'] = len(self.units) str["system"]['num_lanes'] = numoflanes str["system"]['num_extruders'] = len(self.extruders) str["system"]["extruders"]={} diff --git a/extras/AFC_BoxTurtle.py b/extras/AFC_BoxTurtle.py index 3db6ea6a..8b5508d0 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(LANE + ' Unknown') return - CUR_LANE = self.AFC.stepper[LANE.name] + 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' @@ -70,7 +70,7 @@ def system_Test(self, UNIT, LANE, delay): CUR_LANE.status = 'Loaded' msg +=" AND LOADED" - if self.AFC.lanes[UNIT][CUR_LANE.name]['tool_loaded']: + if CUR_LANE.tool_loaded: if CUR_EXTRUDER.tool_start_state == True or CUR_EXTRUDER.tool_start == "buffer": if self.AFC.extruders[CUR_LANE.extruder_name]['lane_loaded'] == CUR_LANE.name: CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name) @@ -186,7 +186,6 @@ def calibrate_lane(LANE): if CUR_HUB.state: CUR_LANE.move(CUR_HUB.move_dis * -1, self.AFC.short_moves_speed, self.AFC.short_moves_accel, True) CUR_LANE.hub_load = True - self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = CUR_LANE.hub_load CUR_LANE.do_enable(False) cal_msg = "\n{} dist_hub: {}".format(CUR_LANE.name.upper(), (hub_pos - CUR_HUB.hub_clear_move_dis)) return True, cal_msg diff --git a/extras/AFC_prep.py b/extras/AFC_prep.py index 3525df74..86d907f2 100644 --- a/extras/AFC_prep.py +++ b/extras/AFC_prep.py @@ -75,8 +75,10 @@ def PREP(self, gcmd): self.AFC.stepper[LANE.name]=LANE temp.append(LANE.name) if LANE.extruder_name not in self.AFC.extruders: self.AFC.extruders[LANE.extruder_name]={} - if LANE.unit not in self.AFC.units: self.AFC.units[LANE.unit]={} + if LANE.unit not in self.AFC.units: self.AFC.units[LANE.unit] = {} + 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 self.AFC.spoolman_ip !=None and LANE.spool_id != None: try: From 6a93ea48587504b5f6affaacc53e5b645e915541 Mon Sep 17 00:00:00 2001 From: MG-longshot Date: Thu, 19 Dec 2024 21:28:19 -0600 Subject: [PATCH 7/7] Update AFC_NightOwl.py --- extras/AFC_NightOwl.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extras/AFC_NightOwl.py b/extras/AFC_NightOwl.py index 5f4b6408..1426f7aa 100644 --- a/extras/AFC_NightOwl.py +++ b/extras/AFC_NightOwl.py @@ -24,7 +24,10 @@ def handle_connect(self): def system_Test(self, UNIT, LANE, delay): msg = '' succeeded = True - CUR_LANE = self.printer.lookup_object('AFC_stepper ' + LANE) + if LANE not in self.AFC.stepper: + self.AFC.gcode.respond_info(LANE + ' Unknown') + return + 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' @@ -61,14 +64,14 @@ def system_Test(self, UNIT, LANE, delay): CUR_LANE.status = 'Loaded' msg +=" AND LOADED" - if self.AFC.lanes[UNIT][CUR_LANE.name]['tool_loaded']: + if CUR_LANE.tool_loaded: if CUR_EXTRUDER.tool_start_state == True or CUR_EXTRUDER.tool_start == "buffer": if self.AFC.extruders[CUR_LANE.extruder_name]['lane_loaded'] == CUR_LANE.name: CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name) msg +=" in ToolHead" if CUR_EXTRUDER.tool_start == "buffer": msg += "\n Ram sensor enabled, confirm tool is loaded" - self.AFC.SPOOL.set_active_spool(self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['spool_id']) + self.AFC.SPOOL.set_active_spool(CUR_LANE.spool_id) self.AFC.afc_led(self.AFC.led_tool_loaded, CUR_LANE.led_index) if len(self.AFC.extruders) == 1: self.AFC.current = CUR_LANE.name