Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issues with changing hub_loaded to loaded_to_hub in saved variables file #204

Merged
merged 10 commits into from
Dec 22, 2024
46 changes: 25 additions & 21 deletions docs/command_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ current lane and loading the new lane.
Usage: ``CHANGE_TOOL LANE=<lane>``
Example: ``CHANGE_TOOL LANE=leg1``

### CALIBRATE_AFC
_Description_: This function performs the calibration of the hub and Bowden length for one or more lanes within an AFC
(Automated Filament Changer) system. The function uses precise movements to adjust the positions of the
steppers, check the state of the hubs and tools, and calculate distances for calibration based on the
user-provided input. If no specific lane is provided, the function defaults to notifying the user that no lane has been selected. The function also includes
the option to calibrate the Bowden length for a particular lane, if specified.
Usage: ``CALIBRATE_AFC LANES=<lane> DISTANCE=<distance> TOLERANCE=<tolerance> BOWDEN=<lane>``
Example: `CALIBRATE_AFC LANES=all Bowden=leg1`

### SET_MULTIPLIER
_Description_: This function handles the adjustment of the buffer multipliers for the turtleneck buffer.
It retrieves the multiplier type ('HIGH' or 'LOW') and the factor to be applied. The function
Expand Down Expand Up @@ -119,20 +110,41 @@ specified by the 'LANE' parameter and sets its color to the value provided by th
Usage: ``SET_COLOR LANE=<lane> COLOR=<color>``
Example: ``SET_COLOR LANE=leg1 COLOR=FF0000``

### SET_SPOOLID
### SET_WEIGHT
_Description_: This function handles changing the material of a specified lane. It retrieves the lane
specified by the 'LANE' parameter and sets its material to the value provided by the 'MATERIAL' parameter.
Usage: `SET_WEIGHT LANE=<lane> WEIGHT=<weight>`
Example: `SET_WEIGHT LANE=leg1 WEIGHT=850`

### SET_MATERIAL
_Description_: This function handles changing the material of a specified lane. It retrieves the lane
specified by the 'LANE' parameter and sets its material to the value provided by the 'MATERIAL' parameter.
Usage: `SET_MATERIAL LANE=<lane> MATERIAL=<material>`
Example: `SET_MATERIAL LANE=leg1 MATERIAL=ABS`

### SET_SPOOL_ID
_Description_: This function handles setting the spool ID for a specified lane. It retrieves the lane
specified by the 'LANE' parameter and updates its spool ID, material, color, and weight
based on the information retrieved from the Spoolman API.
Usage: ``SET_SPOOLID LANE=<lane> SPOOL_ID=<spool_id>``
Example: ``SET_SPOOLID LANE=leg1 SPOOL_ID=12345``
Usage: ``SET_SPOOL_ID LANE=<lane> SPOOL_ID=<spool_id>``
Example: ``SET_SPOOL_IDD LANE=leg1 SPOOL_ID=12345``

### SET_RUNOUT
_Description_: This function handles setting the runout lane (infanet spool) for a specified lane. It retrieves the lane
_Description_: 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.
Usage: ``SET_RUNOUT LANE=<lane> RUNOUT=<lane>``
Example: ``SET_RUNOUT LANE=lane1 RUNOUT=lane4``

### CALIBRATE_AFC
_Description_: This function performs the calibration of the hub and Bowden length for one or more lanes within an AFC
(Automated Filament Changer) system. The function uses precise movements to adjust the positions of the
steppers, check the state of the hubs and tools, and calculate distances for calibration based on the
user-provided input. If no specific lane is provided, the function defaults to notifying the user that no lane has been selected. The function also includes
the option to calibrate the Bowden length for a particular lane, if specified.
Usage: ``CALIBRATE_AFC LANES=<lane> DISTANCE=<distance> TOLERANCE=<tolerance> BOWDEN=<lane>``
Example: `CALIBRATE_AFC LANE=leg1`

## AFC Macros

The following macros are defined in the `config/macros/AFC_macros.cfg` file.
Expand All @@ -151,11 +163,3 @@ _Description_: Move the specified lane the specified amount
_Description_: Resume the print after an error
### BT_PREP
_Description_: Run the AFC PREP sequence
### T0
_Description_: Change to tool 0
### T1
_Description_: Change to tool 1
### T2
_Description_: Change to tool 2
### T3
_Description_: Change to tool 3
45 changes: 26 additions & 19 deletions extras/AFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import json
from configparser import Error as error

AFC_VERSION="1.0.0"

class afc:
def __init__(self, config):
self.printer = config.get_printer()
Expand All @@ -23,7 +25,6 @@ def __init__(self, config):
self.current = None
self.error_state = False
self.units = {}
self.lanes = {}
self.extruders = {}
self.stepper = {}
self.tool_cmds={}
Expand Down Expand Up @@ -102,6 +103,9 @@ def __init__(self, config):
#self.debug = True == config.get('debug', 0)
self.debug = False

# Printing here will not display in console but it will go to klippy.log
self.print_version()

def _update_trsync(self, config):
# Logic to update trsync values
update_trsync = config.getboolean("trsync_update", False)
Expand Down Expand Up @@ -142,6 +146,14 @@ def handle_connect(self):
self.gcode.register_mux_command('SET_BOWDEN_LENGTH', 'AFC', None, self.cmd_SET_BOWDEN_LENGTH, desc=self.cmd_SET_BOWDEN_LENGTH_help)
self.gcode.register_command('AFC_STATUS', self.cmd_AFC_STATUS, desc=self.cmd_AFC_STATUS_help)

def print_version(self):
import subprocess
import os
afc_dir = os.path.dirname(os.path.realpath(__file__))
git_hash = subprocess.check_output(['git', '-C', '{}'.format(afc_dir), 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
git_commit_num = subprocess.check_output(['git', '-C', '{}'.format(afc_dir), 'rev-list', 'HEAD', '--count']).decode('ascii').strip()
self.gcode.respond_info("AFC Version: v{}-{}-{}".format(AFC_VERSION, git_commit_num, git_hash))

cmd_AFC_STATUS_help = "Return current status of AFC"
def cmd_AFC_STATUS(self, gcmd):
"""
Expand Down Expand Up @@ -448,7 +460,7 @@ def cmd_HUB_LOAD(self, gcmd):
CUR_LANE.do_enable(True)
while CUR_LANE.load_state == False:
CUR_LANE.move( CUR_HUB.move_dis, self.short_moves_speed, self.short_moves_accel)
if CUR_LANE.hub_load == False:
if CUR_LANE.loaded_to_hub == False:
CUR_LANE.move(CUR_LANE.dist_hub, CUR_LANE.dist_hub_move_speed, CUR_LANE.dist_hub_move_accel, True if CUR_LANE.dist_hub > 200 else False)
while CUR_HUB.state == False:
CUR_LANE.move(CUR_HUB.move_dis, self.short_moves_speed, self.short_moves_accel)
Expand All @@ -457,7 +469,7 @@ def cmd_HUB_LOAD(self, gcmd):
CUR_LANE.status = ''
self.save_vars()
CUR_LANE.do_enable(False)
CUR_LANE.hub_load = True
CUR_LANE.loaded_to_hub = True
self.save_vars()

cmd_LANE_UNLOAD_help = "Unload lane from extruder"
Expand All @@ -477,10 +489,6 @@ 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.stepper:
self.gcode.respond_info('{} Unknown'.format(lane.upper()))
Expand All @@ -494,9 +502,9 @@ def cmd_LANE_UNLOAD(self, gcmd):
CUR_LANE.status = 'ejecting'
self.save_vars()
CUR_LANE.do_enable(True)
if CUR_LANE.hub_load:
if CUR_LANE.loaded_to_hub:
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)
CUR_LANE.hub_load = False
CUR_LANE.loaded_to_hub = False
while CUR_LANE.load_state == True:
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)
Expand Down Expand Up @@ -597,10 +605,10 @@ def TOOL_LOAD(self, CUR_LANE):
CUR_LANE.do_enable(True)

# Move filament to the hub if it's not already loaded there.
if not CUR_LANE.hub_load:
if not CUR_LANE.loaded_to_hub:
CUR_LANE.move(CUR_LANE.dist_hub, CUR_LANE.dist_hub_move_speed, CUR_LANE.dist_hub_move_accel, CUR_LANE.dist_hub > 200)

CUR_LANE.hub_load = True
CUR_LANE.loaded_to_hub = True
hub_attempts = 0

# Ensure filament moves past the hub.
Expand Down Expand Up @@ -658,7 +666,7 @@ def TOOL_LOAD(self, CUR_LANE):
break
CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name)
# Update tool and lane status.
CUR_LANE.status = 'tool'
CUR_LANE.status = 'Tooled'
CUR_LANE.tool_loaded = True
self.current = CUR_LANE.name
CUR_EXTRUDER.enable_buffer()
Expand All @@ -675,8 +683,7 @@ def TOOL_LOAD(self, CUR_LANE):
self.gcode.run_script_from_command(self.wipe_cmd)

# Update lane and extruder state for tracking.
CUR_LANE.hub_loaded = True
self.extruders[CUR_LANE.extruder_name]['lane_loaded'] = CUR_LANE.name
CUR_EXTRUDER.lane_loaded = CUR_LANE.name
self.SPOOL.set_active_spool(CUR_LANE.spool_id)
self.afc_led(self.led_tool_loaded, CUR_LANE.led_index)
self.save_vars()
Expand Down Expand Up @@ -849,7 +856,7 @@ 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_EXTRUDER.lane_loaded = ''
CUR_LANE.status = None
self.current = None

Expand Down Expand Up @@ -887,7 +894,7 @@ def TOOL_UNLOAD(self, CUR_LANE):
return False

# Finalize unloading and reset lane state.
CUR_LANE.hub_load = True
CUR_LANE.loaded_to_hub = True
self.afc_led(self.led_ready, CUR_LANE.led_index)
CUR_LANE.status = None
self.save_vars()
Expand Down Expand Up @@ -990,7 +997,7 @@ def cmd_CHANGE_TOOL(self, gcmd):
def get_filament_status(self, LANE):
if LANE.prep_state:
if LANE.load_state:
if self.extruders[LANE.extruder_name]['lane_loaded'] == LANE.name:
if LANE.extruder_obj is not None and LANE.extruder_obj.lane_loaded == LANE.name:
return 'In Tool:' + self.HexConvert(self.led_tool_loaded)
return "Ready:" + self.HexConvert(self.led_ready)
return 'Prep:' + self.HexConvert(self.led_prep_loaded)
Expand Down Expand Up @@ -1057,9 +1064,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[CUR_LANE.extruder_name]['lane_loaded']
str["system"]["extruders"][EXTRUDE]['lane_loaded'] = CUR_EXTRUDER.lane_loaded
if CUR_EXTRUDER.tool_start == "buffer":
if self.extruders[CUR_LANE.extruder_name]['lane_loaded'] == '':
if CUR_EXTRUDER.lane_loaded == '':
str ["system"]["extruders"][EXTRUDE]['tool_start_sensor'] = False
else:
str["system"]["extruders"][EXTRUDE]['tool_start_sensor'] = True
Expand Down
20 changes: 11 additions & 9 deletions extras/AFC_BoxTurtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def system_Test(self, UNIT, LANE, delay):
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)
try:
CUR_LANE.extruder_obj = 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.ERROR.AFC_error(error_string, False)
Expand All @@ -53,7 +54,6 @@ def system_Test(self, UNIT, LANE, delay):
msg += 'EMPTY READY FOR SPOOL'
else:
self.AFC.afc_led(self.AFC.led_fault, CUR_LANE.led_index)
CUR_LANE.status = None
msg +="<span class=error--text> NOT READY</span>"
CUR_LANE.do_enable(False)
msg = '<span class=error--text>CHECK FILAMENT Prep: False - Load: True</span>'
Expand All @@ -71,19 +71,21 @@ def system_Test(self, UNIT, LANE, delay):
msg +="<span class=success--text> AND LOADED</span>"

if CUR_LANE.tool_loaded:
if CUR_EXTRUDER.tool_start_state == True or CUR_EXTRUDER.tool_start == "buffer":
if CUR_LANE.extruder_obj.tool_start_state == True or CUR_LANE.extruder_obj.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 +="<span class=primary--text> in ToolHead</span>"
if CUR_EXTRUDER.tool_start == "buffer":
if CUR_LANE.extruder_obj.tool_start == "buffer":
msg += "<span class=warning--text>\n Ram sensor enabled, confirm tool is loaded</span>"
self.AFC.SPOOL.set_active_spool(CUR_LANE.spool_id)
self.AFC.afc_led(self.AFC.led_tool_loaded, CUR_LANE.led_index)
CUR_LANE.status = 'Tooled'
if len(self.AFC.extruders) == 1:
self.AFC.current = CUR_LANE.name
CUR_EXTRUDER.enable_buffer()
CUR_LANE.extruder_obj.enable_buffer()
CUR_LANE.extruder_obj.lane_loaded = CUR_LANE.name
else:
if CUR_EXTRUDER.tool_start_state == True:
if CUR_LANE.extruder_obj.tool_start_state == True:
msg +="<span class=error--text> error in ToolHead. \nLane identified as loaded in AFC.vars.unit file\n but not identified as loaded in AFC.var.tool file</span>"
succeeded = False
else:
Expand Down Expand Up @@ -143,8 +145,8 @@ def find_lane_to_calibrate(lane_name):

Returns: The lane name if found, otherwise None
"""
for UNIT in self.AFC.lanes.keys():
if lane_name in self.AFC.lanes[UNIT]:
for UNIT in self.AFC.unit.keys():
if lane_name in self.AFC.unit[UNIT]:
return lane_name

# If the lane was not found
Expand Down Expand Up @@ -201,7 +203,7 @@ def calibrate_lane(LANE):
hub_pos = calibrate_hub(CUR_LANE, CUR_HUB)
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
CUR_LANE.loaded_to_hub = True
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
Expand Down
14 changes: 8 additions & 6 deletions extras/AFC_NightOwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def system_Test(self, UNIT, LANE, delay):
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)
try:
CUR_LANE.extruder_obj = 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.ERROR.AFC_error(error_string, False)
Expand All @@ -46,7 +47,6 @@ def system_Test(self, UNIT, LANE, delay):
msg += 'EMPTY READY FOR SPOOL'
else:
self.AFC.afc_led(self.AFC.led_fault, CUR_LANE.led_index)
CUR_LANE.status = None
msg +="<span class=error--text> NOT READY</span>"
CUR_LANE.do_enable(False)
msg = '<span class=error--text>CHECK FILAMENT Prep: False - Load: True</span>'
Expand All @@ -65,19 +65,21 @@ def system_Test(self, UNIT, LANE, delay):
msg +="<span class=success--text> AND LOADED</span>"

if CUR_LANE.tool_loaded:
if CUR_EXTRUDER.tool_start_state == True or CUR_EXTRUDER.tool_start == "buffer":
if CUR_LANE.extruder_obj.tool_start_state == True or CUR_LANE.extruder_obj.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 +="<span class=primary--text> in ToolHead</span>"
if CUR_EXTRUDER.tool_start == "buffer":
if CUR_LANE.extruder_obj.tool_start == "buffer":
msg += "<span class=warning--text>\n Ram sensor enabled, confirm tool is loaded</span>"
self.AFC.SPOOL.set_active_spool(CUR_LANE.spool_id)
self.AFC.afc_led(self.AFC.led_tool_loaded, CUR_LANE.led_index)
CUR_LANE.status = 'Tooled'
if len(self.AFC.extruders) == 1:
self.AFC.current = CUR_LANE.name
CUR_EXTRUDER.enable_buffer()
CUR_LANE.extruder_obj.enable_buffer()
CUR_LANE.extruder_obj.lane_loaded = CUR_LANE.name
else:
if CUR_EXTRUDER.tool_start_state == True:
if CUR_LANE.extruder_obj.tool_start_state == True:
msg +="<span class=error--text> error in ToolHead. \nLane identified as loaded in AFC.vars.unit file\n but not identified as loaded in AFC.var.tool file</span>"
succeeded = False
else:
Expand Down
6 changes: 4 additions & 2 deletions extras/AFC_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def ToolHeadFix(self, CUR_LANE):
CUR_LANE.move(-5, self.AFC.short_moves_speed, self.AFC.short_moves_accel, True)
while CUR_LANE.load_state == False: # reload lane extruder
CUR_LANE.move(5, self.AFC.short_moves_speed, self.AFC.short_moves_accel, True)
self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['tool_loaded'] = False
self.AFC.extruders[CUR_LANE.extruder_name]['lane_loaded']= ''

CUR_LANE.tool_load = False
CUR_LANE.loaded_to_hub = False
CUR_LANE.extruder_obj.lane_loaded = ''
self.AFC.save_vars()
self.pause = False
return True
Expand Down
2 changes: 2 additions & 0 deletions extras/AFC_extruder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __init__(self, config):
self.tool_start = config.get('pin_tool_start', None)
self.tool_end = config.get('pin_tool_end', None)

self.lane_loaded = ''

# RAMMING
# Use buffer sensors for loading and unloading filament
if self.tool_start == "buffer":
Expand Down
Loading
Loading