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 misc errors and errors found from users on discord and adding support for spoolman multicolors #203

Merged
merged 13 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 2 additions & 1 deletion config/macros/Cut.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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
Expand Down
130 changes: 76 additions & 54 deletions extras/AFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@

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:
Expand Down Expand Up @@ -231,7 +231,7 @@

# 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")
Expand Down Expand Up @@ -279,10 +279,10 @@
"""
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]
CUR_LANE.move(distance, self.short_moves_speed, self.short_moves_accel, True)

def save_pos(self):
Expand Down Expand Up @@ -361,10 +361,10 @@
"""
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]
CUR_HUB = self.printer.lookup_object('AFC_hub ' + CUR_LANE.unit)
CUR_HUB.hub_cut(CUR_LANE)
self.gcode.respond_info('Hub cut Done!')
Expand Down Expand Up @@ -394,10 +394,10 @@
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]
self.gcode.respond_info('Testing at full speed')
CUR_LANE.assist(-1)
self.reactor.pause(self.reactor.monotonic() + 1)
Expand Down Expand Up @@ -437,10 +437,10 @@
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]
CUR_HUB = self.printer.lookup_object('AFC_hub '+ CUR_LANE.unit)
if CUR_LANE.prep_state == False: return

Expand Down Expand Up @@ -477,11 +477,15 @@
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]
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
Expand All @@ -504,7 +508,7 @@
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):
Expand All @@ -525,10 +529,14 @@
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

Check failure on line 535 in extras/AFC.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W293)

extras/AFC.py:535:1: W293 Blank line contains whitespace
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]
self.TOOL_LOAD(CUR_LANE)

def TOOL_LOAD(self, CUR_LANE):
Expand All @@ -545,6 +553,10 @@
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
Expand Down Expand Up @@ -613,7 +625,7 @@
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')
self.ERROR.handle_lane_failure(CUR_LANE, message)
return False

Expand Down Expand Up @@ -671,11 +683,11 @@
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')
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')
self.ERROR.handle_lane_failure(CUR_LANE, message)
return False

Expand All @@ -702,10 +714,10 @@
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]
self.TOOL_UNLOAD(CUR_LANE)

# User manually unloaded spool from toolhead, remove spool from active status
Expand All @@ -724,6 +736,10 @@
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
Expand Down Expand Up @@ -811,7 +827,7 @@
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)
Expand All @@ -834,6 +850,9 @@
# 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.
Expand All @@ -843,7 +862,7 @@
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

Expand All @@ -857,14 +876,15 @@
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
Expand Down Expand Up @@ -895,7 +915,7 @@
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()
Expand Down Expand Up @@ -933,37 +953,39 @@
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]
# 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.
self.gcode.respond_info("Tool Change - {} -> {}".format(self.current, lane))

# 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('{} Unknown'.format(self.current.upper()))
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')
self.ERROR.fix(msg, CUR_LANE) #send to error handling
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]
# 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:
Expand Down
6 changes: 3 additions & 3 deletions extras/AFC_BoxTurtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
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]

Check failure on line 37 in extras/AFC_BoxTurtle.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

extras/AFC_BoxTurtle.py:37:42: W291 Trailing whitespace
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
Expand Down Expand Up @@ -184,7 +184,7 @@

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))
Expand Down
4 changes: 2 additions & 2 deletions extras/AFC_NightOwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
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]

Check failure on line 30 in extras/AFC_NightOwl.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

extras/AFC_NightOwl.py:30:42: W291 Trailing whitespace
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
Expand All @@ -52,8 +52,8 @@
msg = '<span class=error--text>CHECK FILAMENT Prep: False - Load: True</span>'
succeeded = False

else:

Check failure on line 55 in extras/AFC_NightOwl.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

extras/AFC_NightOwl.py:55:14: W291 Trailing whitespace

Check failure on line 56 in extras/AFC_NightOwl.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W293)

extras/AFC_NightOwl.py:56:1: W293 Blank line contains whitespace
self.AFC.afc_led(self.AFC.led_ready, CUR_LANE.led_index)
msg +="<span class=success--text>LOCKED</span>"
if CUR_LANE.load_state == False:
Expand Down
2 changes: 1 addition & 1 deletion extras/AFC_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "{} {}".format(CUR_LANE.name.upper(), message)
self.AFC_error(msg, pause)
self.AFC.afc_led(self.AFC.led_fault, CUR_LANE.led_index)

Expand Down
Loading
Loading