gSender - understanding tool macros

So I am starting to use gSender for my machine rather than CM and am in the process of learning how to manage tool changes and offsets. Has anyone already built the code that goes into the M6 before and after sections in gSender? If so, would you mind walking me through your thought process?

I know that GRBL doesn’t support tool length offsets so you need to offset the whole job for each tool instead. I am just trying to wrap my head around the math that is going on. You have to set an initial offset just like CM does when you start and I have the macros from @neilferreri for the bitsetter. The only part that I don’t understand is what is going into the “global.state.TOOL_REFERENCE” variable in the “Initial_Tool_BitSetter” macro. I think my issue is that I don’t understand exactly what a G38.2/4 does. Does it return a machine coordinate for the axis that you are probing? How do you capture that return? Is it setting some variable that you can read? Also, is there a way to view the global variables in gSender?

So a little more study on my part tells me that G38.x just stops the motion when the probe switch is turned on or off depending on what type you pick. I had it in my head the it was the whole probe and retract sequence. Since it stops, it means you can read the axis position at that time and then do something with it. That is what is going into the “global.state.TOOL_REFERENCE” variable. So what needs to be done in an M6 macro is read that global variable before you probe the new tool, probe the new tool and then offset the work by the difference between the 2.

Now my question is about what is happening when the “New_Tool_BitSetter” macro calls “G10 L20 Z[global.state.TOOL_REFERENCE]” after doing a G38? I think that is just offsetting the current work offset with the original tool reference. I don’t get how that would work though. Don’t we need to find the difference between the tools in order to offset the z correctly?

Hey Nick,
First, is something not working with the macros? I may need to update a link somewhere or just start a gender macro repo (they’re slightly different than cncjs).
Anyway, secondly, essentially what I’m doing is finding the work Z with the initial probe and resetting that with the new tool probe.
So after Z zero is established for the job, the initial tool macro is run. Let’s say your bitsetter is found to be exactly 3mm below your Z-zero, that -3mm is stored in a global variable. When you probe the new tool, the macro sets the new probe location as Z-3. The bitsetter is always 3mm below work zero, so the macro just re-established Z-zero based on Z-3.

Does that make sense?

For what it’s worth, I just ran several multiple tool jobs with gSender and I think I’m officially moving away from cncjs for now.

As far as I know they are working fine. I haven’t actually used them on the machine yet. I just want to understand what is going on.

I am still not sure I understand from reading your post and the macros again. I get that the initial macro is saving the z location of the bitsetter with your first tool. I just don’t understand how the new tool macro adjusts the work offset. Do you use one file per tool or a single file with an M6 for each tool?

I use a single file and therefore want to use the custom code option for handling an M6. Once I understand these macros I figured I could fill those in appropriately. Is there a reference anywhere for what can be done in a gender macro?

Macros work the the same either way. You can run based on an M6 or just run when you change end mill between operations. When the M6 is encountered, I have it set to run a macro of my choice. I don’t want to run it automatically.

Another way to think of it is that the bitsetter is just a probe. Just like the BitZero establishes Z-zero by measuring to a known point above the stock. The bitsetter macros just establish that known distance with the initial tool macro. And then re-establish the zero when the new tool is run.
The top of your stock is Z0 (if you set it up that way) and you want every endmill at the top of your stock when you’re at Z0, regardless of how far you are from your limit switch.

I just realized that you are doing your first tool probe after setting your work zero. So you are basing your tool probing off of work zero and not machine coordinates? I still don’t quite understand how the new tool offset works.

A G10L20 command says “change the work offset so that my current tool location is where I say”. For example, G10L20X5Y5 means the current location becomes X5Y5 in my current work coordinate system.
When you establish Z zero, you’re sending G10L20Z0.

After that Z-zero has been established, we probe with the initial tool macro to find the WORK position of the bitsetter. In my example above, it was 3mm below work zero. When any new tool is used, we use that bitsetter as our reference. So every new tool probes to the exact location of the bitsetter and we say “this is 3mm below work zero” or send G10L20Z-3.
It doesn’t matter how long the tool is. The only thing that matters is that the bottom of the tool is at the work position we want it to be.

1 Like

Thanks! That explanation makes sense now.

1 Like

Do you know of any reference material on what can or can’t be done in a gsender macro?

I haven’t had much time or reason to dig into new capabilities recently.

Thanks for the link. I have read through their whole documentation and there was very little on macros. It just says look at the examples from the “Macro Variables” dropdown or they send you to the documentation of the library they are using to parse the macro. I can find no list of predefined variables that are available or an explanation of how they expect the syntax to be. Documentation of macros seems to be lacking. I have made an account over on their forum and I am planning on asking my questions there when I have a second.

Most of what they do is carried over from CNCjs. You might check there. Are you trying to do something specific? I’m happy to help if I can…been pretty busy lately.

Right now I am trying to see if I can read the machine coordinates for G54-G59 without moving there and then do some math on it. I would be happy with just G54 though.

Machine coordinates are the same regardless of your current work coordinate system.

Yes, but I am looking for the machine coordinates of the the G54 work zero. It is what is stored in eeprom.

I don’t think you can directly interact with the offsets.
What, exactly, are you trying to do?

I am looking to make a set of tool change macros that are not dependent on the work zero. One to run right after homing the machine and one to touch off a new tool when an M6 is called in my gcode or when I manually change a tool. I often change my work zero several times during a single session on my machine and I would rather not have to redo my initial tool macro every time I move the zero. I can easily see myself forgetting to do that. I can’t see a way to do that without knowing the machine coordinates offset of G54 or whatever coordinate system I am in.

Also, I like learning and this seemed like a good place to start learning to write macros in gsender since I will use it every time I use my machine.

Use machine coordinates and a G43.1 command for dynamic tool length offset.

I had it in my head that grbl didn’t support G43 forgot about G43.1

Let me know if this is on the right track:

-Initial macro
Save state
G53
Move to safe z height
Move to probe xy
G38.2/4 sequence
Save Z position to global variable (will always be a negative number)
Move to safe z height
Return to saved state

-M6 tool change macro
Turn off spindle
Save state
G53
G49 - see my questions below
Move to safe z height
Move to tool change xy
M0 (change tool)
Move to probe xy
G38.2/4 sequence
Save z position to different global variable
Move to safe z height
G43.1 Z(math.abs([initial tool z]) - math.abs([new tool z])) - Not sure on the syntax here. Since the probed position will always be negative, subtracting the absolute value of the new measurement from the absolute value of the initial measurement should give me an appropriate offset.
Return to saved state

Does G43.1 apply to the G53 coord. system? If yes, I would need to make sure and clear it (G49) before measuring another tool right?

This thread might be off interest. Specifically the old attachment on this post.

2 Likes