Skip to content

Commit

Permalink
Merge pull request #203 from jimmyjon711/error_fixes
Browse files Browse the repository at this point in the history
Fixing misc errors and errors found from users on discord and adding support for spoolman multicolors
  • Loading branch information
MG-longshot authored Dec 20, 2024
2 parents 9c9f557 + 0b3698e commit 50f330d
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 98 deletions.
17 changes: 10 additions & 7 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 All @@ -270,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
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
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 @@ 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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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]
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 @@ 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]
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 @@ 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]
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 @@ 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]
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 @@ 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]
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 @@ 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):
Expand All @@ -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]
self.TOOL_LOAD(CUR_LANE)

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

Expand Down Expand Up @@ -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')
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 @@ 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]
self.TOOL_UNLOAD(CUR_LANE)

# User manually unloaded spool from toolhead, remove spool from active status
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -834,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.
Expand All @@ -843,7 +862,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

Expand All @@ -857,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
Expand Down Expand Up @@ -895,7 +915,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()
Expand Down Expand Up @@ -933,37 +953,39 @@ 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]
# 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
8 changes: 4 additions & 4 deletions extras/AFC_BoxTurtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ 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]
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'
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 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))
Expand Down
Loading

0 comments on commit 50f330d

Please sign in to comment.