viesturz / tapchanger

Voron TapChanger
GNU General Public License v3.0
531 stars 32 forks source link

Add some tool functionality to user space #25

Open TheSin- opened 5 months ago

TheSin- commented 5 months ago

I haven't tested all this yet as I'm at work, but I'll test it once I'm home. I wanted to get this PR in incase I was going in the wrong direction you could tell me before I put more time in on it.

This would allow for macro overrides in a user area so we don't mess with toolchanger.cfg and can keep it in sync with git

Example of my vision

[tool T0]
...
before_change_gcode:
  MY_TOOL_BEFORE_CHANGE TN='T0'
after_change_gcode:
  MY_TOOL_AFTER_CHANGE TN='T0'
pickup_gcode:
  MY_TOOL_PICKUP TN='T0'
dropoff_gcode:
  MY_TOOL_DROPOFF TN='T0'

[tool T1]
...
before_change_gcode:
  MY_TOOL_BEFORE_CHANGE TN='T1'
after_change_gcode:
  MY_TOOL_AFTER_CHANGE TN='T1'
pickup_gcode:
  MY_TOOL_PICKUP TN='T1'
dropoff_gcode:
  MY_TOOL_DROPOFF TN='T1'

[gcode_macro MY_TOOL_BEFORE_CHANGE]
gcode:
  {% set tn = params.TN|string %}
  {% set tool = printer['tool ' + tn] %}
  RESPOND TYPE=echo MSG='Before change {tool.name}'
  STATUS_BUSY T={tool.tool_number}
  TOOL_BEFORE_CHANGE {rawparams}

[gcode_macro MY_TOOL_AFTER_CHANGE]
gcode:
  {% set tn = params.TN|string %}
  {% set tool = printer['tool ' + tn] %}
  RESPOND TYPE=echo MSG='After change {tool.name}'
  TOOL_AFTER_CHANGE {rawparams}

[gcode_macro MY_TOOL_DROPOFF]
gcode:
  {% set tn = params.TN|string %}
  {% set tool = printer['tool ' + tn] %}
  RESPOND TYPE=echo MSG='Dropping off {tool.name}'
  SET_FILAMENT_SENSOR SENSOR=filament_sensor_T{tool.tool_number} ENABLE=0
  TOOL_DROPOFF {rawparams}
  STATUS_READY T={tool.tool_number}

[gcode_macro MY_TOOL_PICKUP]
gcode:
  {% set tn = params.TN|string %}
  {% set tool = printer['tool ' + tn] %}
  RESPOND TYPE=echo MSG='Picking up {tool.name}'
  STATUS_HEATING T={tool.tool_number}
  SET_FILAMENT_SENSOR SENSOR=filament_sensor_T{tool.tool_number} ENABLE=1
  TOOL_PICKUP {rawparams}
  CLEAN_NOZZLE
  STATUS_PRINTING T={tool.tool_number}

Still want to make an other PR after this one to separate the path into 2 pieces, tool_path, dock_path and have the center marker for tool detection auto happen so that f isn't reused and can be used through out the path instead. it'll be really easy to do. I just didn't want to make this PR too large.

TheSin- commented 5 months ago

Updated the example for the new method

TheSin- commented 5 months ago

this plan might be totally flawed, I didn't know Klipper would only let you rename system macros

configparser.Error: Existing command 'TOOL_BEFORE_CHANGE' not found in gcode_macro rename

so I need to make this macros system versions via the toolchanger.py I suspect which I was trying to avoid.

Just putting my notes here as I figure this out, since I'm still new to the Klipper ecosystem

TheSin- commented 5 months ago

this plan might be totally flawed, I didn't know Klipper would only let you rename system macros

configparser.Error: Existing command 'TOOL_BEFORE_CHANGE' not found in gcode_macro rename

so I need to make this macros system versions via the toolchanger.py I suspect which I was trying to avoid.

Just putting my notes here as I figure this out, since I'm still new to the Klipper ecosystem

This is fixed with the new example now. I'm going to make a PR on klipper-toolchanger to expose before_change_gcode and after_change_gcode as well to go with this one

https://github.com/viesturz/klipper-toolchanger/pull/8

TheSin- commented 5 months ago

Everything is tested and 100% working now. Exactly what I was hoping for, LEDs change properly, I can clean on change now, and once I finish wiring I can add runout sensors for each tool and only check the active tool. This does require the changes to klipper-toolchanger for the before/after_change

viesturz commented 3 months ago

Thanks for the PR, overall reasonable changes to merge.

Please fix a few nits: