Skip to content

Commit 9dc88d8

Browse files
authored
Adding filament density to SET_MATERIAL macro/pulling density from spoolman data (#440)
- Added pulling density, diameter, and empty spool weight from spoolman data - Added density, diameter, and empty spool weight optional values to SET_MATERIAL macro. If density is not supplied AFC tries to look up density from default values based on material passed in - Removed upper bounds for fwd/rwd values when calling SET_SPEED_MULTIPLIER macro - Removed slashes in macro help as this causes the character afterwards to be escaped leading to help being displayed weird in gui's
1 parent dd2b915 commit 9dc88d8

6 files changed

Lines changed: 106 additions & 41 deletions

File tree

config/AFC.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ short_move_dis: 10 # Move distance for failsafe moves. Default is 1
1414
# This value can also be set per stepper with print_current: 0.6
1515
enable_sensors_in_gui: True # Uncomment to show all sensor switches as filament sensors in mainsail/fluidd gui
1616
# this can also be set at individual levels in your config file
17-
default_material_temps: default: 235, PLA:210, ABS:235, ASA:235 # Default temperature to set extruder when loading/unloading lanes.
17+
default_material_temps: default: 235, PLA:210, PETG:235, ABS:235, ASA:235 # Default temperature to set extruder when loading/unloading lanes.
1818
# Material needs to be either manually set or uses material from spoolman if extruder temp is not
1919
# set in spoolman. Follow current format to add more
20+
common_density_values: PLA:1.24, PETG:1.23, ABS:1.04, ASA:1.07 # Generic default density values. Follow current format to add more
2021
#default_material_type: PLA # Default material type to assign to a spool once loaded into a lane
2122

2223
load_to_hub: True # Fast loads filament to hub when inserted, set to False to disable. This is a global setting and can be overridden at AFC_stepper

extras/AFC.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
try: from extras.AFC_stats import AFCStats
2828
except: raise error(ERROR_STR.format(import_lib="AFC_stats", trace=traceback.format_exc()))
2929

30-
AFC_VERSION="1.0.18"
30+
AFC_VERSION="1.0.20"
3131

3232
# Class for holding different states so its clear what all valid states are
3333
class State:
@@ -111,9 +111,13 @@ def __init__(self, config):
111111
self.unit_order_list = config.get('unit_order_list','')
112112
self.VarFile = config.get('VarFile','../printer_data/config/AFC/AFC.var')# Path to the variables file for AFC configuration.
113113
self.cfgloc = self._remove_after_last(self.VarFile,"/")
114-
self.default_material_temps = config.getlists("default_material_temps", None)# Default temperature to set extruder when loading/unloading lanes. Material needs to be either manually set or uses material from spoolman if extruder temp is not set in spoolman.
114+
self.default_material_temps = config.getlists("default_material_temps",
115+
("default: 235", "PLA:210", "PETG:235", "ABS:235", "ASA:235"))# Default temperature to set extruder when loading/unloading lanes. Material needs to be either manually set or uses material from spoolman if extruder temp is not set in spoolman.
115116
self.default_material_temps = list(self.default_material_temps) if self.default_material_temps is not None else None
116117
self.default_material_type = config.get("default_material_type", None) # Default material type to assign to a spool once loaded into a lane
118+
self.common_density_values = config.getlists("common_density_values",
119+
("PLA:1.24", "PETG:1.23", "ABS:1.04", "ASA:1.07"))
120+
self.common_density_values = list(self.common_density_values)
117121

118122
#LED SETTINGS
119123
self.ind_lights = None
@@ -796,7 +800,7 @@ def save_vars(self):
796800
name=[]
797801
for NAME in cur_unit.lanes:
798802
cur_lane=self.lanes[NAME]
799-
str[cur_unit.name][cur_lane.name]=cur_lane.get_status()
803+
str[cur_unit.name][cur_lane.name]=cur_lane.get_status(save_to_file=True)
800804
name.append(cur_lane.name)
801805

802806
str["system"]={}

extras/AFC_extruder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _update_tool_after_extr(self, length):
130130
else:
131131
self.logger.error("tool_sensor_after_extruder length should be greater than zero")
132132

133-
cmd_UPDATE_TOOLHEAD_SENSORS_help = "Gives ability to update tool_stn\tool_stn_unload\tool_sensor_after_extruder values without restarting klipper"
133+
cmd_UPDATE_TOOLHEAD_SENSORS_help = "Gives ability to update tool_stn, tool_stn_unload, tool_sensor_after_extruder values without restarting klipper"
134134
cmd_UPDATE_TOOLHEAD_SENSORS_options = {
135135
"EXTRUDER": {"type": "string", "default": "extruder"},
136136
"TOOL_STN": {"type": "float", "default": 0},

extras/AFC_lane.py

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,17 @@ def __init__(self, config):
6767
self.tool_loaded = False
6868
self.loaded_to_hub = False
6969
self.spool_id = None
70-
self.material = None
7170
self.color = None
7271
self.weight = 0
73-
self.material = None
72+
self._material = None
7473
self.extruder_temp = None
7574
self.runout_lane = 'NONE'
7675
self.status = AFCLaneState.NONE
7776
self.multi_hubs_found = False
7877
self.drive_stepper = None
7978
unit = config.get('unit') # Unit name(AFC_BoxTurtle/NightOwl/etc) that belongs to this stepper.
8079
# Overrides buffers set at the unit level
81-
self.hub = config.get('hub',None) # Hub name(AFC_hub) that belongs to this stepper, overrides hub that is set in unit(AFC_BoxTurtle/NightOwl/etc) section.
80+
self.hub = config.get('hub',None) # Hub name(AFC_hub) that belongs to this stepper, overrides hub that is set in unit(AFC_BoxTurtle/NightOwl/etc) section.
8281
# Overrides buffers set at the unit and extruder level
8382
self.buffer_name = config.get("buffer", None) # Buffer name(AFC_buffer) that belongs to this stepper, overrides buffer that is set in extruder(AFC_extruder) or unit(AFC_BoxTurtle/NightOwl/etc) sections.
8483
self.unit = unit.split(':')[0]
@@ -90,26 +89,26 @@ def __init__(self, config):
9089

9190
self.extruder_name = config.get('extruder', None) # Extruder name(AFC_extruder) that belongs to this stepper, overrides extruder that is set in unit(AFC_BoxTurtle/NightOwl/etc) section.
9291
self.map = config.get('cmd','NONE')
93-
self.led_index = config.get('led_index', None) # LED index of lane in chain of lane LEDs
94-
self.led_fault = config.get('led_fault',None) # LED color to set when faults occur in lane (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
95-
self.led_ready = config.get('led_ready',None) # LED color to set when lane is ready (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
96-
self.led_not_ready = config.get('led_not_ready',None) # LED color to set when lane not ready (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
97-
self.led_loading = config.get('led_loading',None) # LED color to set when lane is loading (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
98-
self.led_prep_loaded = config.get('led_loading',None) # LED color to set when lane is loaded (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
99-
self.led_unloading = config.get('led_unloading',None) # LED color to set when lane is unloading (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
100-
self.led_tool_loaded = config.get('led_tool_loaded',None) # LED color to set when lane is loaded into tool (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
92+
self.led_index = config.get('led_index', None) # LED index of lane in chain of lane LEDs
93+
self.led_fault = config.get('led_fault',None) # LED color to set when faults occur in lane (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
94+
self.led_ready = config.get('led_ready',None) # LED color to set when lane is ready (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
95+
self.led_not_ready = config.get('led_not_ready',None) # LED color to set when lane not ready (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
96+
self.led_loading = config.get('led_loading',None) # LED color to set when lane is loading (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
97+
self.led_prep_loaded = config.get('led_loading',None) # LED color to set when lane is loaded (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
98+
self.led_unloading = config.get('led_unloading',None) # LED color to set when lane is unloading (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
99+
self.led_tool_loaded = config.get('led_tool_loaded',None) # LED color to set when lane is loaded into tool (R,G,B,W) 0 = off, 1 = full brightness. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
101100
self.led_spool_index = config.get('led_spool_index', None) # LED index to illuminate under spool
102101
self.led_spool_illum = config.get('led_spool_illuminate', None) # LED color to illuminate under spool
103102

104-
self.long_moves_speed = config.getfloat("long_moves_speed", None) # Speed in mm/s to move filament when doing long moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
105-
self.long_moves_accel = config.getfloat("long_moves_accel", None) # Acceleration in mm/s squared when doing long moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
106-
self.short_moves_speed = config.getfloat("short_moves_speed", None) # Speed in mm/s to move filament when doing short moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
107-
self.short_moves_accel = config.getfloat("short_moves_accel", None) # Acceleration in mm/s squared when doing short moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
108-
self.short_move_dis = config.getfloat("short_move_dis", None) # Move distance in mm for failsafe moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
103+
self.long_moves_speed = config.getfloat("long_moves_speed", None) # Speed in mm/s to move filament when doing long moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
104+
self.long_moves_accel = config.getfloat("long_moves_accel", None) # Acceleration in mm/s squared when doing long moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
105+
self.short_moves_speed = config.getfloat("short_moves_speed", None) # Speed in mm/s to move filament when doing short moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
106+
self.short_moves_accel = config.getfloat("short_moves_accel", None) # Acceleration in mm/s squared when doing short moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
107+
self.short_move_dis = config.getfloat("short_move_dis", None) # Move distance in mm for failsafe moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
109108
self.max_move_dis = config.getfloat("max_move_dis", None) # Maximum distance to move filament. AFC breaks filament moves over this number into multiple moves. Useful to lower this number if running into timer too close errors when doing long filament moves. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
110109
self.n20_break_delay_time= config.getfloat("n20_break_delay_time", None) # Time to wait between breaking n20 motors(nSleep/FWD/RWD all 1) and then releasing the break to allow coasting. Setting value here overrides values set in unit(AFC_BoxTurtle/NightOwl/etc) section
111110

112-
self.rev_long_moves_speed_factor = config.getfloat("rev_long_moves_speed_factor", None) # scalar speed factor when reversing filamentalist
111+
self.rev_long_moves_speed_factor = config.getfloat("rev_long_moves_speed_factor", None) # scalar speed factor when reversing filamentalist
113112

114113
self.dist_hub = config.getfloat('dist_hub', 60) # Bowden distance between Box Turtle extruder and hub
115114
self.park_dist = config.getfloat('park_dist', 10) # Currently unused
@@ -176,6 +175,30 @@ def __init__(self, config):
176175
def __str__(self):
177176
return self.name
178177

178+
@property
179+
def material(self):
180+
"""
181+
Returns lanes filament material type
182+
"""
183+
return self._material
184+
185+
@material.setter
186+
def material(self, value):
187+
"""
188+
Sets filament material type and sets filament density based off material type.
189+
To use custom density, set density after setting material
190+
"""
191+
self._material = value
192+
if not value:
193+
self.filament_density = 1.24 # Setting to a default value
194+
return
195+
196+
for density in self.afc.common_density_values:
197+
v = density.split(":")
198+
if v[0] in value:
199+
self.filament_density = float(v[1])
200+
break
201+
179202
def _handle_ready(self):
180203
"""
181204
Handles klippy:ready callback and verifies that steppers have units defined in their config
@@ -894,7 +917,7 @@ def cmd_SET_LONG_MOVE_SPEED(self, gcmd):
894917
def cmd_SET_SPEED_MULTIPLIER(self, gcmd):
895918
"""
896919
Macro call to update fwd_speed_multiplier or rwd_speed_multiplier values without having to set in config and restart klipper. This macro allows adjusting
897-
these values while printing. Multiplier values must be between 0.0 - 1.0
920+
these values while printing.
898921
899922
Use `FWD` variable to set forward multiplier, use `RWD` to set reverse multiplier
900923
@@ -914,8 +937,8 @@ def cmd_SET_SPEED_MULTIPLIER(self, gcmd):
914937
old_fwd_value = self.fwd_speed_multi
915938
old_rwd_value = self.rwd_speed_multi
916939

917-
self.fwd_speed_multi = gcmd.get_float("FWD", self.fwd_speed_multi, minval=0.0, maxval=1.0)
918-
self.rwd_speed_multi = gcmd.get_float("RWD", self.rwd_speed_multi, minval=0.0, maxval=1.0)
940+
self.fwd_speed_multi = gcmd.get_float("FWD", self.fwd_speed_multi, minval=0.0)
941+
self.rwd_speed_multi = gcmd.get_float("RWD", self.rwd_speed_multi, minval=0.0)
919942

920943
if self.fwd_speed_multi != old_fwd_value:
921944
self.logger.info("{name} forward speed multiplier set, New: {new}, Old: {old}".format(name=self.name, new=self.fwd_speed_multi, old=old_fwd_value))
@@ -993,7 +1016,7 @@ def cmd_SAVE_HUB_DIST(self, gcmd):
9931016
"""
9941017
self.afc.function.ConfigRewrite(self.fullname, 'dist_hub', self.dist_hub, '')
9951018

996-
def get_status(self, eventtime=None):
1019+
def get_status(self, eventtime=None, save_to_file=False):
9971020
response = {}
9981021
if not self.connect_done: return response
9991022
response['name'] = self.name
@@ -1009,14 +1032,19 @@ def get_status(self, eventtime=None):
10091032
response["tool_loaded"] = self.tool_loaded
10101033
response["loaded_to_hub"] = self.loaded_to_hub
10111034
response["material"]=self.material
1035+
if save_to_file:
1036+
response["density"]=self.filament_density
1037+
response["diameter"]=self.filament_diameter
1038+
response["empty_spool_weight"]=self.empty_spool_weight
1039+
10121040
response["spool_id"]= int(self.spool_id) if self.spool_id else None
10131041
response["color"]=self.color
10141042
response["weight"]=self.weight
10151043
response["extruder_temp"] = self.extruder_temp
10161044
response["runout_lane"]=self.runout_lane
1017-
filiment_stat=self.afc.function.get_filament_status(self).split(':')
1018-
response['filament_status'] = filiment_stat[0]
1019-
response['filament_status_led'] = filiment_stat[1]
1045+
filament_stat=self.afc.function.get_filament_status(self).split(':')
1046+
response['filament_status'] = filament_stat[0]
1047+
response['filament_status_led'] = filament_stat[1]
10201048
response['status'] = self.status
10211049
return response
10221050

extras/AFC_prep.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,19 @@ def PREP(self, gcmd):
9999
if self.afc.spoolman is not None and cur_lane.spool_id:
100100
self.afc.spool.set_spoolID(cur_lane, cur_lane.spool_id, save_vars=False)
101101
else:
102-
if 'material' in units[cur_lane.unit][cur_lane.name]: cur_lane.material = units[cur_lane.unit][cur_lane.name]['material']
103-
if 'color' in units[cur_lane.unit][cur_lane.name]: cur_lane.color = units[cur_lane.unit][cur_lane.name]['color']
104-
if 'weight' in units[cur_lane.unit][cur_lane.name]: cur_lane.weight = units[cur_lane.unit][cur_lane.name]['weight']
102+
if 'material' in units[cur_lane.unit][cur_lane.name]:
103+
cur_lane.material = units[cur_lane.unit][cur_lane.name]['material']
104+
if 'color' in units[cur_lane.unit][cur_lane.name]:
105+
cur_lane.color = units[cur_lane.unit][cur_lane.name]['color']
106+
if 'weight' in units[cur_lane.unit][cur_lane.name]:
107+
cur_lane.weight = units[cur_lane.unit][cur_lane.name]['weight']
108+
if 'density' in units[cur_lane.unit][cur_lane.name]:
109+
cur_lane.filament_density= units[cur_lane.unit][cur_lane.name]["density"]
110+
if 'diameter' in units[cur_lane.unit][cur_lane.name]:
111+
cur_lane.filament_diameter= units[cur_lane.unit][cur_lane.name]["diameter"]
112+
if 'empty_spool_weight' in units[cur_lane.unit][cur_lane.name]:
113+
cur_lane.empty_spool_weight= units[cur_lane.unit][cur_lane.name]["empty_spool_weight"]
114+
105115
if not isinstance(cur_lane.weight, int):
106116
if cur_lane.weight:
107117
cur_lane.weight = int(cur_lane.weight)

0 commit comments

Comments
 (0)