After watching Bart’s video about g-code coordinate systems again, I made some changes.
I setup G54 for my work coordinates. For me, that’s X90 Y0 Z0. So, after homing, I entered this.
G90 G53 X90 Y0 Z0
G54
G10 L20 P0 X0 Y0 Z0
Then I setup G28 to be store that same XY location but at Z10. So, it’s a quick way to jog there.
G90 G53 X90 Y0 Z10
G28.1
Then I setup G30 to be the starting point for tool changes. For me, that’s X90 Y500 Z10.
G90 G53 X90 Y500 Z10
G30.1
So, that means instead of doing this, I can just enter G30.
Also, instead of the 66mm X moves (90 for me), I do this instead so I don’t have that hardcoded number.
G1 G53 X1 (move to X1 in machine coords)
Then I got M6 macros working.
Updated the startup macro in the config.yaml:
macros:
startup_line0: $SD/Run=init.gcode
init.gcode
#<_PenActive>=#5400
$H
Updated the m6 macro for the BESC spindle in config.yaml:
BESC:
...
m6_macro: $SD/Run=penmacro.gcode
...
penmacro.gcode
#<Feedrate>=5000
#<PenNew>=#5400
#<PenOld>=#<_PenActive>
G54
F#<Feedrate>
(Return the old pen)
o100 if[#<PenOld> GT 0]
#<YOffset>=[[#<PenOld>-1]*-30]
G30 (move to the toolbin entry point)
G1 Z10 (lift the pen so it clears the well)
G91 (switch to relative)
G1 Y#<YOffset>
G1 G53 X1 (move to X1 in machine coords)
G1 Z-9.5 (lower the pen into the well)
M3S100 (release the claw)
G1 Y4 (move the claw away from the pen)
G90
G1 X0 (move back to the entry point X)
G91
G1 Y-4 (move back to the entry point Y)
G90 (switch back to absolute coords)
#<_PenActive>=0
o100 endif
(Get the new pen)
o101 if[#<PenNew> GT 0]
#<YOffset>=[[#<PenNew>-1]*-30]
G30 (move to the toolbin entry point)
G1 Z1 (this is the height at which the claw grabs the pens)
G91 (switch to relative)
G1 Y#<YOffset>
M3S100 (ensure servo is open)
G1 Y4 (move 4mm up)
G1 G53 X1 (move to X1 in machine coords)
G1 Y-4 (move down 4mm so the claw is around the pen)
M3S0 (grab the pen with the servo)
G1 Z10 (lift the pen out of the well)
G90 (switch back to absolute coords)
G1 X0 (move back to the toolbin entry point)
#<_PenActive>=#<PenNew>
o101 endif
That should simplify post processing a bit. Here’s a video. This is just running “M6 T2” and then “M6 T1”. I may make some minor tweaks but it works. If you send “M6 T0” it will put the current pen back. I might update the script to send an alarm if you use a tool number higher than 5.