• Scam Alert. Members are reminded to NOT send money to buy anything. Don't buy things remote and have it shipped - go get it yourself, pay in person, and take your equipment with you. Scammers have burned people on this forum. Urgency, secrecy, excuses, selling for friend, newish members, FUD, are RED FLAGS. A video conference call is not adequate assurance. Face to face interactions are required. Please report suspicions to the forum admins. Stay Safe - anyone can get scammed.

JCDammeyer's 42 projects

I think for now I can put the bevel gear and backlash aside. I changed the height of the 1-2-3 blocks by 0.125" (half turn of the lead screw and other side of the bevel gears)
Same set of tests. This time repeatability in one direction had zero error. In the other direction short by 0.0005". At this point in time, not enough to worry about.

Time to look at home/limit switch repeatability.
Had to set the soft limits to be past the mechanical switch in order to jog onto the home/limit switch.
Five times, each stepping 0.001" per button press. And each time the switch engaged at 0.301" moving from 0.300".

I've remeasured the probe and tweaked the value to within 0.0001"

I've remeasured tool #4 (3/8" 2 flute) and probed the top of the two 1-2-3 blocks and set Z=0.000 there using the probing utility. The cutting edges just rub the 1-2-3 blocks as they should.

Told the system to load tool #5 which doesn't have a length but left Tool #4 in place. It then went to the tool setter and measured it. Like on Friday, the system hung with the tool setter pressed. A continue button had it go back up and reset Z 0 G54 offset. And no, the tool was not in the right position for rubbing the 1-2-3 block.

So I've definitely got to look at what I screwed up in the M6-Remap code. Will also measure the tool setter again but it hasn't changed in height by over 3" so that's not the problem.

More as this mystery develops.
 
Sounds to me like either:
- the interrupt register is not being masked correctly on entry
- interrupt flag is not being cleared corectly on exit of IRQ
- not taking care of the stack correctly

Probably another IRQ comes along while executing the first one and then jumps back into the original one instead of the other one.

I didn't look at your code but recall something similar 30 years back.
 
Had to set the soft limits to be past the mechanical switch in order to jog onto the home/limit switch.
Five times, each stepping 0.001" per button press. And each time the switch engaged at 0.301" moving from 0.300".

I've remeasured the probe and tweaked the value to within 0.0001"

I've remeasured tool #4 (3/8" 2 flute) and probed the top of the two 1-2-3 blocks and set Z=0.000 there using the probing utility. The cutting edges just rub the 1-2-3 blocks as they should.

Told the system to load tool #5 which doesn't have a length but left Tool #4 in place. It then went to the tool setter and measured it. Like on Friday, the system hung with the tool setter pressed. A continue button had it go back up and reset Z 0 G54 offset. And no, the tool was not in the right position for rubbing the 1-2-3 block.

So I've definitely got to look at what I screwed up in the M6-Remap code. Will also measure the tool setter again but it hasn't changed in height by over 3" so that's not the problem.

More as this mystery develops.
Can you post the code?
 
Sounds to me like either:
- the interrupt register is not being masked correctly on entry
- interrupt flag is not being cleared corectly on exit of IRQ
- not taking care of the stack correctly

Probably another IRQ comes along while executing the first one and then jumps back into the original one instead of the other one.

I didn't look at your code but recall something similar 30 years back.
When I set up the system I thought Port D8..D15 bits were all bidirectional. Turns out D8 wasn't so I had to cut traces and set up one of the PORT A bits for that. Between the processor is a bidirectional level translator so part of the read and write operations to the LCD display and reading/scanning the keypad also involve swapping that buffer.

It's when the keypad is being polled that electrical noise shows up on the index pin input. very narrow spikes less than 2V in the 5V world but high enough to generate an interrupt on the index pin input.

When the code polls that pin and requires 200uS worth of index pulses the noise has no effect. But the edge triggered interrupt creates an RPM change from 120 for example to 10,706.

Yikes eh?

It has something, I think, to do with the buffer and the port both changing direction via the TRIS register and the DIR pin to the buffer. Somehow that introduces the noise. I haven't been able to suppress it yet.
 
Can you post the code?
It's pretty confusing stuff. I've been trying to figure out how to do this all day and still haven't got a solution.

With tool in the table with a length it's working perfectly. Go measure the tool because the tool length is 0 and the value gotten from that probing operation c/w tool setter length etc still create the incorrect G54.Z offset and therefore not the right value to make something like a chuck with changed drill bit useful.

Key code is here:
(Here we could set the tool length based on a check box set or not)
G10 L2 P#<coordinate_system> Z[#[4000+#<coordinate_system>]+#5063]

My head hurts from all this now. Going to take a break for a few hours.
 

Attachments

It's when the keypad is being polled that electrical noise shows up on the index pin input. very narrow spikes less than 2V in the 5V world but high enough to generate an interrupt on the index pin input.

My number one troubleshooting rule is " What am I assuming that isn't correct?"

The Mark Twain version...
"It ain't what you don't know that gets you into trouble; it's what you know for sure that just ain't so".

Kludgy solution is to mask the spindle IRQ while polling the index pin. Perhaps not as a real solution but to confirm your hypothesis.

This really smells like one of the three possible issues I posted earlier.

On the noise issue, is this a 2 layer board?
Does the board use one layer as a backplane?

If in Altium can you post the project?
 
My number one troubleshooting rule is " What am I assuming that isn't correct?"

The Mark Twain version...
"It ain't what you don't know that gets you into trouble; it's what you know for sure that just ain't so".

Kludgy solution is to mask the spindle IRQ while polling the index pin. Perhaps not as a real solution but to confirm your hypothesis.

This really smells like one of the three possible issues I posted earlier.

On the noise issue, is this a 2 layer board?
Does the board use one layer as a backplane?

If in Altium can you post the project?
The noise isn't there on the stock ELS board. It only shows up with the PIC32 upgrade board.

The original was always meant for polling surplus hall,opto sensors. Remember when the ELS was designed AliExpress didn't exist and quadrature encoders cost well over $100 and more like $500. Even glass quadrature disks were $100. So polling a slot that even at 6000 RPM was still easily 200uS was a logical solution to amateur construction of encoder slots or disks.

The new board is 4 layer with ground plane and 3.3V plane.

Done in Protel-99 so I can supply it but I've decided to switch to the PMP (Parallel Master Port) pins which are all 5V tolerant and so I can get rid of the bi-directional level translator. So the layout will change dramatically. If anything has to be done to the original board to stop the noise the project is a no-go.

At this point I'm not sure I'm going on with this project. I can't compete financially with China. Just the 32 bit processor costs more than an ESP32 or Arduino 32 bit processor board. And now that encoders are cheap ($5) the world has moved to Electronic Gearing Systems where they count encoder pulses and use a ratio on those to create stepping pulses.

Add that with a Pi4 and a MESA card you can create a Linux based Lathe CNC machine that does most of what an ELS does there's little point.

Anyway, here's the Protel-99 files and a photo. The layout is already upgraded with the jumper wires etc. But not for the PMP port update.

Right now I really want to get the tool height sensor working on the mill so this project is on the back burner and I don't know if I want to get another package of 4 layer boards made. The interface throuigh the 40 pin socket, header and fan power connection was more difficult than I expected so I'm not sure this would be a project for anyone other than an electronics expert.
 

Attachments

I have to signup or something to give it G-Code. Nothing in that link that gave the results you may have seen. Perhaps capture the text and paste it in a reply?
Sounds interesting...
Paste your code into ChatGPT4. Ask it to debug the code.
 
Thanks for sharing your CNC G-code subroutine (likely for LinuxCNC or similar), which appears to be a remap of M6 for tool changes and probing. You mentioned you'd like it debugged.
Here’s a structured debug review of your code, addressing:
  • ✅ Correctness and syntax
  • Potential issues / risks
  • ❌ Likely bugs or logic errors
  • Suggestions / improvements

KEY OBSERVATIONS​

✅ 1. Remap structure looks correct​

You're using:
Code:
o<m6remap> sub
...
o<m6remap> endsub
M2
Which is the right way to define a remapped M6 subroutine.

✅ 2. Initial parameter setup​

You're assigning feed rates and probe parameters depending on #<_imperial> or #<_metric>:
Code:
o300 if[#<_imperial>]
...
o310 if[#<_metric>]
These are environment variables defined by LinuxCNC, so this setup looks fine.

❌ 3. Logic: Use of #5403 without checking tool number​

You're checking:
Code:
o500 if [ [#<_current_tool> EQ #<_selected_tool>] AND [#5403 NE 0.00000] ]
Issue:
#5403 refers to the length of the current tool in the tool table.
But #5403 only updates after a successful M6 and G43. Before that, it may still reflect the last active tool or even be zero if no tool has been loaded.
⚠️ You might want to use #[5330 + #<_selected_tool>] to directly access the length of the selected tool in the tool table.

✅ Suggested fix:​

Code:
#<selected_tool_length> = #[5330 + #<_selected_tool>]

o500 if [ [#<_current_tool> EQ #<_selected_tool>] AND [#<selected_tool_length> NE 0.00000] ]

❌ 4. Potential bug in tool length probing logic​

In the probing section:
Code:
G38.2 Z[-2*#2001] F#2003
If #2001 is still 0 (which it is unless #<_imperial> or #<_metric> is correctly defined), this command becomes:
Code:
G38.2 Z0 F#2003
Which is a no-op and could fail or not probe at all.
✅ Fix: Ensure a fallback default:
Code:
o320 if[ #2001 EQ 0 ]
  #2001 = 2.5 (or 0.1 depending on machine)
o320 endif

5. Hardcoded probing offsets without tool setter presence check​

You assume the tool setter exists at:
Code:
G53 X#<_ini[TOOLSENSOR]X_LOC> Y#<_ini[TOOLSENSOR]Y_LOC>
But there’s no check if the probe is available or enabled.
✅ Suggestion: Add an optional INI parameter to enable/disable probing:
Code:
#<use_probe> = #<_ini[TOOLSENSOR]ENABLE>
o400 if [#<use_probe> EQ 1]
   (run probing routine)
o400 else
   (skip probing, maybe throw a warning)
o400 endif

6. G10 L2 logic is unclear​

Code:
G10 L2 P#<coordinate_system> Z#[4000 + #<coordinate_system>]
You're trying to set the Z-offset in the active work coordinate system, but:
  • #[4000 + #<coordinate_system>] isn't standard; you may be intending to pull from a probe value?
  • This line may not have the effect you want.
Check if your intention is to set the Z-zero to match the probe length + previous zero?
If you're doing dynamic tool length probing, you might instead want:
Code:
G10 L1 P#<_selected_tool> Z[#<workspace_z> - #5063]
But this depends heavily on your coordinate system setup.

❌ 7. Missing oendif inside nested probing logic​

Your nested o600 block ends with:
Code:
G53 Z#1702
But if #5403 NE 0.00000, it runs:
Code:
G10 L2 P#<coordinate_system> Z#[4000 + #<coordinate_system>]
Then it continues into the else path, because you're missing an o600 endif before the else.
✅ Fix:
Code:
o600 if[#5403 NE 0.00000]
   ...
o600 else
   ...
o600 endif

8. Restore coordinate system​

This block is fine but verbose:
Code:
o100 if[#1900 EQ 540]
  G54
...
o107 endif
✅ Alternative: Use expression-based G-code if your controller supports it:
Code:
G#<1900>
But this may not be portable or safe depending on your interpreter.

✅ Summary of Fixes​

Line/SectionIssueFix or Suggestion
#5403 tool length checkMay not be accurate for selected toolUse #[5330 + #<_selected_tool>]
Probing feed/Z distance#2001 could be 0Add fallback default if zero
Probing logic G38.2 Z0Risk of no movementGuard with a valid probe distance
G10 L2 usePossibly misused or unclear intentDouble-check your coordinate setting logic
Missing o600 endifLogic bug, causes both if/else to runAdd proper endif
Tool setter existenceAssumed always presentAdd check via #<_ini> param
Coordinate system restore blockVerboseOptionally simplify with G#<1900>

✅ Final Notes​

If you apply the above fixes, your tool change remap should be far more robust and safer to run.
Would you like me to return a corrected version of this entire G-code subroutine with fixes applied?
 
Sure, here you go! It loses a bit without formatting but you can prolly follow it anyway. If not, maybe I could do screen shots for you.

This is a custom M6 tool change remap subroutine (likely for LinuxCNC, based on the syntax, named parameters like #<var>, G38.2 probing, G59.3 for tool measurement, and G10 L2 usage). It handles tool changes by:
Skipping if the same tool is already loaded and has a fixed length in the tool table.
Moving to a safe position, executing M6 T# to prompt the physical tool swap.
Canceling offsets for T0 (no tool).
For non-zero tools:
If the tool table has a length (#5403 ≠ 0), it applies G43 and adjusts the work coordinate Z offset using a stored base value.
If #5403 = 0, it probes the tool length using a two-stage G38.2 (gross then fine), applies G43, and adjusts the work Z offset.
Restores the original work coordinate system after any changes (e.g., from G59.3 during probing).
The code is mostly well-structured and handles imperial/metric units, safe retracts, and zero-length tools (per the 2023 update). However, there are a few logical inconsistencies, potential inefficiencies, and one clear bug that could cause incorrect Z offsets for fixed-length tools. I'll break it down step by step: execution flow, then identified issues with fixes.
Step-by-Step Execution Flow
Initialization (Lines 1-20):
Sets probing parameters (#2001–#2004) based on units (#<_imperial> or #<_metric>).
Sets safe machine Z (#1702 = -0.1).
Saves current work system as #1900 = #<_coord_system> (e.g., 540 for G54).
Sets #<coordinate_system> = #5220 (1–9 for G54–G59.3).
Computes #<workspace_z> = parameter address for current Z offset (correctly calculates e.g., 5223 for G54).
Prints diagnostics.
M5 (spindle off).
Skip Check (o500):
If same tool (#<_current_tool> == #<_selected_tool>) and fixed length (#5403 ≠ 0), exit early (no change needed).
Tool Change Sequence (o500 else):
Rapid to safe Z (G53 Z#<_ini[CHANGE_POSITION]Z>), then X/Y position.
M6 T#<_selected_tool> (prompts tool swap; updates #5403 from tool table).
Handle T0 (o550):
If T=0, G49 (cancel Z offset).
Apply Offset for T≠0 (o550 else):
G43 (enable length comp, no H—relies on work offset adjustment instead).
Fixed Length (o600 if #5403 ≠ 0):
Prints tool length.
G10 L2 P#<coordinate_system> Z#[4000 + #<coordinate_system>] (sets work Z offset to stored base value from #4001–#4009).
Probe if Zero (o600 else):
Rapid to tool sensor Z start (G53 Z#<_ini[TOOLSENSOR]Z_PROBE_START>), then X/Y.
G91 (incremental).
Gross probe: G38.2 Z#<_ini[TOOLSENSOR]MAXPROBE> F#2002 (fast, large negative move).
G43.1 Z0 (reset dynamic comp to 0).
Retract: G1 Z#2001 F#2004.
G59.3 (switch to tool measurement system).
Fine probe: G38.2 Z[-2*#2001] F#2003 (slow, small negative move for precision).
G10 L2 P#<coordinate_system> Z[#[4000 + #<coordinate_system>] + #5063] (adjust work Z: stored base + probed delta; #5063 is negative distance to tip).
Retract: G1 Z0.1 F40.
G90 G0 (absolute/rapid).
G53 Z#1702 (safe retract).
Restore Work System (After o550/o600):
Chain of o100–o107: Selects G54–G59.2 based on saved #1900 (e.g., if 540, G54).
Note: G59.3 is not restored here (assumes it's only temporary for probing; if needed, add o108 if[#1900 EQ 593] G59.3).
End: o endsub, M2 (program end; M2 may be extraneous in a sub but harmless).
Identified Issues and Fixes
I analyzed for syntax (valid G-code), logic (flow/consistency), and runtime risks (e.g., crashes from bad moves). No syntax errors (blocks close properly, conditionals valid). Here's what's wrong:
Bug: Fixed-Length Tools Ignore Tool Length in Work Offset Adjustment
In the o600 if branch (fixed #5403 ≠ 0), the G10 L2 sets Z to just the stored base #[4000 + #<coordinate_system>] (e.g., #4001 for G54—a presumed machine Z for workpiece zero).
But in the probe branch, it correctly adds #5063 (negative probed length) to subtract the tool length effectively.
Result: For fixed tools, the work Z offset isn't adjusted for tool length, so the tool tip won't align with the workpiece zero (e.g., tool acts as if length=0). Probing works because #5063 handles it.
This breaks consistency—fixed tools behave like zero-length tools.
Fix: Add #5403 (assuming it's negative like #5063) to the G10 Z expression. Update the line to:
G10 L2 P#<coordinate_system> Z[#[4000 + #<coordinate_system>] + #5403]
Matches probe logic: stored base + negative length = base - |length|.
Test: Simulate with known #5403 (e.g., -50) and verify work Z updates correctly.
Inefficiency: Re-Probing the Same Zero-Length Tool Every Time
The skip check requires both same tool and #5403 ≠ 0.
After probing a zero-length tool, #5403 remains 0 (code doesn't update the tool table entry).
Result: Next M6 for the same tool triggers probing again (unnecessary cycle time, wear on probe).
The 2023 update handles zero lengths but doesn't persist the result.
Fix: After the fine probe (after second PRINT, Tool Length 2nd touch = #5063), add:
#5403 = #5063 (Store probed length in current tool offset)
Now #5403 ≠ 0, so same-tool changes skip probing.
Note: This updates the in-memory offset for the current session. For persistence across runs, you'd need to write back to the tool table file (e.g., via a shell call or custom INI handler—not in core G-code). If that's intended, add a comment or separate utility.
Minor: G59.3 Not Explicitly Restored
Probing switches to G59.3, but restore only covers G54–G59.2 (o100–o107).
The chain restore runs after, but if original was G59.3 (#1900=593?), it won't select it.
Result: If starting in G59.3, ends in last restored (G59.2) or undefined.
Fix: Add after o107:
o108 if[#1900 EQ 593]
G59.3
o108 endif
Covers full range (1–9 for #5220, or 540–593 for #<_coord_system>).
Potential Runtime Risk: Unhandled Edge Cases
Probe Failure: If G38.2 misses (e.g., broken tool, dirty sensor), #5063=0 or invalid; G10 uses it anyway (could set bad offset). Add alarm: IF[#5063 EQ 0] THEN #3000=1(PROBE FAILED)(M2) before G10.
INI Parameters: Relies on #<_ini[TOOLSENSOR]Z_PROBE_START>, etc. If undefined, alarms/crashes. Ensure INI file has them (e.g., [TOOLSENSOR]Z_PROBE_START = -10).
Dynamic Comp (G43.1): Used post-gross probe. If not enabled in config, ignores silently—ok, but document.
Tool Table Convention: Assumes #5403 negative (like #5063). If table stores positive lengths, flip signs in G10 (e.g., -#5403).
No spindle/tool orientation check post-M6 (e.g., if manual swap fails).
Style/Readability Suggestions (No Functional Impact)
Remove trailing "9" after G54 (line ~140)—looks like a stray label.
Add more PRINTs for debugging (e.g., after G10: PRINT, New work Z offset: #[5203 + [20*#5220]]).
The M2 at end is fine for standalone testing but unnecessary in a remap sub (M6 returns control).
Variable #1702=-0.1 is very low—confirm it's above clamps/fixtures.
Recommendations
Test Sequence: Dry-run in simulator (e.g., LinuxCNC Axis) with T1 (fixed length ≠0), T2 (zero, probe), then re-T1/T2. Check work Z offsets (#5223 etc.) before/after.
Overall: Solid macro—probing logic is precise (gross/fast + fine/slow). Fix #1 first (critical for fixed tools). With updates, it efficiently handles mixed fixed/probed tools.
 
Thanks for sharing your CNC G-code subroutine (likely for LinuxCNC or similar), which appears to be a remap of M6 for tool changes and probing. You mentioned you'd like it debugged.
Here’s a structured debug review of your code, addressing:
  • ✅ Correctness and syntax
  • Potential issues / risks
  • ❌ Likely bugs or logic errors
  • Suggestions / improvements

KEY OBSERVATIONS​

✅ 1. Remap structure looks correct​

You're using:
Code:
o<m6remap> sub
...
o<m6remap> endsub
M2
Which is the right way to define a remapped M6 subroutine.

✅ 2. Initial parameter setup​

You're assigning feed rates and probe parameters depending on #<_imperial> or #<_metric>:
Code:
o300 if[#<_imperial>]
...
o310 if[#<_metric>]
These are environment variables defined by LinuxCNC, so this setup looks fine.

❌ 3. Logic: Use of #5403 without checking tool number​

You're checking:
Code:
o500 if [ [#<_current_tool> EQ #<_selected_tool>] AND [#5403 NE 0.00000] ]
Issue:
#5403 refers to the length of the current tool in the tool table.
But #5403 only updates after a successful M6 and G43. Before that, it may still reflect the last active tool or even be zero if no tool has been loaded.
⚠️ You might want to use #[5330 + #<_selected_tool>] to directly access the length of the selected tool in the tool table.

✅ Suggested fix:​

Code:
#<selected_tool_length> = #[5330 + #<_selected_tool>]

o500 if [ [#<_current_tool> EQ #<_selected_tool>] AND [#<selected_tool_length> NE 0.00000] ]

❌ 4. Potential bug in tool length probing logic​

In the probing section:
Code:
G38.2 Z[-2*#2001] F#2003
If #2001 is still 0 (which it is unless #<_imperial> or #<_metric> is correctly defined), this command becomes:
Code:
G38.2 Z0 F#2003
Which is a no-op and could fail or not probe at all.
✅ Fix: Ensure a fallback default:
Code:
o320 if[ #2001 EQ 0 ]
  #2001 = 2.5 (or 0.1 depending on machine)
o320 endif

5. Hardcoded probing offsets without tool setter presence check​

You assume the tool setter exists at:
Code:
G53 X#<_ini[TOOLSENSOR]X_LOC> Y#<_ini[TOOLSENSOR]Y_LOC>
But there’s no check if the probe is available or enabled.
✅ Suggestion: Add an optional INI parameter to enable/disable probing:
Code:
#<use_probe> = #<_ini[TOOLSENSOR]ENABLE>
o400 if [#<use_probe> EQ 1]
   (run probing routine)
o400 else
   (skip probing, maybe throw a warning)
o400 endif

6. G10 L2 logic is unclear​

Code:
G10 L2 P#<coordinate_system> Z#[4000 + #<coordinate_system>]
You're trying to set the Z-offset in the active work coordinate system, but:
  • #[4000 + #<coordinate_system>] isn't standard; you may be intending to pull from a probe value?
  • This line may not have the effect you want.
Check if your intention is to set the Z-zero to match the probe length + previous zero?
If you're doing dynamic tool length probing, you might instead want:
Code:
G10 L1 P#<_selected_tool> Z[#<workspace_z> - #5063]
But this depends heavily on your coordinate system setup.

❌ 7. Missing oendif inside nested probing logic​

Your nested o600 block ends with:
Code:
G53 Z#1702
But if #5403 NE 0.00000, it runs:
Code:
G10 L2 P#<coordinate_system> Z#[4000 + #<coordinate_system>]
Then it continues into the else path, because you're missing an o600 endif before the else.
✅ Fix:
Code:
o600 if[#5403 NE 0.00000]
   ...
o600 else
   ...
o600 endif

8. Restore coordinate system​

This block is fine but verbose:
Code:
o100 if[#1900 EQ 540]
  G54
...
o107 endif
✅ Alternative: Use expression-based G-code if your controller supports it:
Code:
G#<1900>
But this may not be portable or safe depending on your interpreter.

✅ Summary of Fixes​

Line/SectionIssueFix or Suggestion
#5403 tool length checkMay not be accurate for selected toolUse #[5330 + #<_selected_tool>]
Probing feed/Z distance#2001 could be 0Add fallback default if zero
Probing logic G38.2 Z0Risk of no movementGuard with a valid probe distance
G10 L2 usePossibly misused or unclear intentDouble-check your coordinate setting logic
Missing o600 endifLogic bug, causes both if/else to runAdd proper endif
Tool setter existenceAssumed always presentAdd check via #<_ini> param
Coordinate system restore blockVerboseOptionally simplify with G#<1900>

✅ Final Notes​

If you apply the above fixes, your tool change remap should be far more robust and safer to run.
Would you like me to return a corrected version of this entire G-code subroutine with fixes applied?
Cool. I'll take a look and make some changes. The problem is with the G10 L2 use and the suggestion I think I've tried but I'll try again.
The rest of the issues are true for really robust code but aren't what are causing the problem.
The reality is I still don't quite understand how some of the G10 commands work and the description of those commands are missing something for my brain.
 
Oh and the inefficiency of same probe comment.

At the moment it goes to the tool change position and then goes and probes. What the AI code doesn't realize is that eventually I want it to actually stop at the Tool Change position if it's the same tool. That's so I can put a different drill into the chuck and then have it go measure that.

The other alternative is to spend $500 on 3 more chucks and TTS holders so that I have 4 pre-measured drill bits mounted in the chuck.

And I've often thought that for an R8 based tool I have two choices. For the facing mill it probably registers in the same position. Same with a flycutter perhaps. But if I decide to chuck a 5/16" end mill into an R8 holder that could be the same tool number for all R8 tools and just measure before use.
 
Oh and one other thing. The AI isn't clever enough to understand that I don't want to update the tool table. I want to leave that tool number length at zero. So the suggestion to use G10 L1 is not useful.

So all in all other than some safety checks it doesn't really solve the problem on how to use the existing zero position in the G54 workspace with the measured tool length to create a new G54.z offset so the tip of the drill bit in the chuck is no the Z zero.

All just so a G81 to a depth of -0.5" is done correctly.
 
So all in all other than some safety checks it doesn't really solve the problem on how to use the existing zero position in the G54 workspace with the measured tool length to create a new G54.z offset so the tip of the drill bit in the chuck is no the Z zero.

Well, to be fair, I didn't ask it to solve any problem, just debug what you had. If you want me to ask it to solve that problem, please describe what you want as objectively and simply as possible and I'll happily ask.
 
I think I'm closer to solving this problem. One of the LinuxCNC forum members posted a section of code to measure his tool. The clue was his comment "My m6remap uses the G59.3 location to measure the variable length tools."
But what sets the G59.2 location and what happens if some other code modifies it?

Code:
%
(measure_toolsetter_inch v1.2)
(PROBEOPEN toolsetterlog.txt)
G20               (Switch to Inch units)
M5                (Turn spindle off)
M61 Q99           (Select tool 99 so probe will work)
G49               (Cancel tool length offset)
G92.1             (Cancel and reset G92 offsets)
G59.3             (switch to G59.3 coordinate system)
G91               (Incremental mode)
G38.2 Z-.25 F1    (Measure fine  var=5063)
G38.4 Z.01 F1     (Measure fine  var=5063)
G10 L20 P9 Z.0000 (Set Coordinate System)
G4 P.5            (Dwell)
G0 Z1             (Move Z up 1 inch)
G54               (Switch to G54 coordinate system)
G90               (Switch to absolute mode)
(PROBECLOSE)
M2
%

There are a number of measure_tool_setter.ngc programs all with the comment (measure_toolsetter_inch v1.2) but slightly different code.

Here's what happens:
1. Remove the R8 holder from the spindle.
2. Move the table so the quill is centred over the tool setter.
3. Lower it until the quill is almost touching the tool setter. Within 0.25"
4. Run the program which stores the Z distance from home when the tool setter switch opened (in the above example).

Some background information. Starting from machine home move the table up (or the head downwards) until it contacts a 1-2-3 block (2" height) with just enough friction to move the block. The Machine Coordinate Z value plus the 1-2-3 block dimension is the total distance the table (head) can move before hitting the table or another way of saying it is the distance from the table in Home Position to the bottom of the quill.

So in my case that total distance is 12.7045". When the tool setter is probed the G-Code statements:
G38.4 Z.01 F1 (Measure fine var=5063)
G10 L20 P9 Z.0000 (Set Coordinate System)

Puts a value close to -9.0505" into the G59.3 Z location stored in the linuxcnc.var file. If I add that value to my 12.7045 max Z distance I get 3.6540" which is the height of the toolsetter.

Now when a new tool is probed that G59.3 workspace means the top of the tool setter, when the switch is activated returns the distance to the quill from the top of the tool setter.

Original coordinate system is 1.000000 identified as 540.000000
Workspace_Z is -3.690977
Old Tool 99.000000 New tool 5.000000
Use Selected Tool offset
Coordinate System is 1.000000 and Z is -3.690977
Tool 1st touch is 2.407862
touch_result=2.418012 setterheight=3.663800 workheight=12.704500
Coordinate System is 1.000000 and new Z is -3.690977
In this case I've just measured the same tool again. The 2.418012 is the value that could be entered into the tool table for that tool.

So two issues. When I use that G-Code to measure the tool setter and save this offset into the linuxcnc.var file, that -9.095058 value is used for every single tool I measure. But the tool is about 0.045" above the work piece. Doesn't matter what the length of the tool is. Always that amount.

By trial and error, changing that G59.3 location, I've now got reliable scuffing of the work surface on every tool that is measured.

While playing around over the last few months I likely accidentally changed that G59.3 location resulting in the tool measurement sometimes being off by as much as a few inches.

The second issue might not be the tool setter but the actual measured length of the probe that sets the part Z=0.0000 location so that then the various length tools that are measured are put to that Z=0.0 location.

The Z axis in this mill is definitely a weak point. But at least now I have an idea or where it's going wrong.

More in a bit.
 
I have to read and reread this a few times.
No worries. I'm not even sure I explained it very well. The comments in that measure tool setter program outlines the issues so many people face when trying to read code written by non-programmers.

For example how do you feel about this comment for a pascal program.

Pi := 3.14; { Put value of Pi into variable Pi }

Duh... We can see that. But why? So often people document what they are doing which is usually pretty obvious rather than why.

For example here you have to know that the 38.2 stops when the sensor switch is activated.
G38.2 Z-.25 F1 (Measure fine var=5063)
Or that the 38.4 goes in the opposite direction and stores the current Machine Coordinate Z into #5063
G38.4 Z.01 F1 (Measure fine var=5063)

The whole point of the routine is to set a value into the G95.3_Z position that can identify the point when the switch deactivates to become equal to 0.0000 in the G95.3 workspace.

Once you have that and are in the G95.3 workspace then when a tool going back up deactivates the tool sensor switch you have the new value to set for the currently active workspace. So the tip of the tool matches the same spot as the previous tool.

In my case between re-probing etc. I'm still off by as much as 0.005" when I measure things. I think the backlash in the Z axis, even with compensation is screwing things up.
 
Back
Top