Hi together,
I am in the process of refactoring all the macro files of my E3D ToolChanger - it got quite some conditional gcode happending.
As for tool changing, each tool has its own tpre#.g, tpost#.g and tfree#.g, despite having almost the same content. To eliminate this redundancy I created a 'global' tpre.g, tpost.g and tfree.g for all tools. Now I call each of those macros with a parameter (param.T).
With this change I can put together a common logic for all tools and call it in each specific file via 'M98 P"tpre.g" T#'.
Example of the 'global' tfree.g:
; tfree.g
; can be called with param.T: tool number to be freed
; abort if axes are not homed: 0:X 1:Y 2:Z 4:C
if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed || !move.axes[4].homed
M291 T5 P"Please home axes before a toolchange" R"Cannot change tool"
abort
; create vars
var toolXpos = 0
var toolYpos = 0
; set tool dock position (and check for valid num)
if param.T == 0
set var.toolXpos = -157.7
set var.toolYpos = 115.5
elif param.T == 1
set var.toolXpos = -67.5
set var.toolYpos = 115.7
elif param.T == 2
set var.toolXpos = 61.3
set var.toolYpos = 115.3
elif param.T == 3
set var.toolXpos = 170.0
set var.toolYpos = 115.2
else
M291 "var.toolXpos or var.toolYpos was not set" R"error in tfree.g"
abort
; drop the bed
G91
G1 H4 Z5 F1200
G90
; move to location
G53 G1 X{var.toolXpos} Y55 F40000
; move in
G53 G1 Y110 F4000
; move slowly to final position
G53 G1 Y{var.toolYpos} F2500
; open coupler
M98 P"/macros/Coupler/unlock.g"
; move out
G53 G1 Y113 F2000
G53 G1 Y110 F4000
G53 G1 Y100 F6000
Example of tfree1.g:
; tfree1.g
; called when tool 1 is freed
M98 P"tfree.g" T1
This works well so far, but I would like to get rid of the individual toolchange files.
Therefore I would like to discuss the following ideas for calling tool change macros in RRF (changes are bold) :
-
If another tool is already selected, run macro tfree#.g where # is the number of that tool. If tfree#.g is not found, run tfree.g (with parameter T = #) instead.
-
If another tool is already selected, deselect it and set its heaters to their standby temperatures (as defined by the R parameter in the most recent G10/M568 command for that tool)
-
Run macro tpre#.g where # is the number of the new tool. If tpre#.g is not found run tpre.g (with parameter T = #) instead.
-
Set the new tool to its operating temperatures specified by the S parameter in the most recent G10/M568 command for that tool
-
Run macro tpost#.g where # is the number of the new tool. If tpost#.g is not found run tpost.g (with parameter T = #) instead.
-
Apply any X, Y, Z offset for the new tool specified by G10
-
Use the new tool.
What do you guys think? Is this a good idea or am I proposing a solution where no one has a problem?