Sunday 12 May 2019

Tool length offset (M886) and WCS Z0 (M887) macros sorted

Tool length offset macro - done:

Notwithstanding the annoying way Blogger screws up the spacings when you paste text into a post, this macro seems to work for my purposes. Most of the changes seem to me to be adding comments and messages in English - simply understanding what needed to be done and how the simple BASIC-like macro language works was the main challenge.

STATUSINFO(Stop tool at tool setter top and "redeem" length offset);
MOVE(G90,F#386,Z#382);         // Move to machine coordinate Z#382
IF (+#387) THEN;                 // Setter is in "fixed" position
STATUSINFO(Moving to tool setter location);
MOVE(G90,F#386,X#380,Y#381);         // Move to machine coordinate X#380, Y#381
ENDIF;
// Now seek the tool setter
STATUSINFO(Seeking tool setter);
MOVE(G90,F#383,Z#388,W+25); // Move to Z#388, stop once X25 goes high
PAUS160;                          // Pause for 160ms
IF (-X25) THEN;                  // Error - didn't see X25 go high....
MESSAGEBOX(Fault: The tool setting signal wasn't detected!)
ERREXIT;                         // End macro due to error
ENDIF;                 // 
// Now back off and release the tool setter
STATUSINFO(Backing off from tool setter);
MOVE(G90,F#384,Z#382,W-25);         // Move towards Z#382 (Zmax) until X25 goes low
IF (+X25) THEN;         // Error - didn't see X25 go low again
MESSAGEBOX(Fault: The tool setting signal wasn't released!)
ERREXIT;                         // End macro due to error
ENDIF;
// Tool is now touched off on tool setter - need to "redeem" this tool length in the table
MESSAGEBOX("Enter" to clear message, "Redeem" > select tool # > "A" to save tool length offset)
RETURN;

To make it work, run it (M886 in the MDI interface), then close the final message and "redeem" the current position into the tool table as a length offset, making sure the correct tool his highlighted in the table first. Like this:



Macro M887 to set G54 etc Z0 coordinate:
Next, use the tool setter to find WCS (G54 etc) Z0. The tool setter height is stored in Other #389 (currently measures 42.240 mm), so it's a simple(?!) matter to touch off on the setter, subtract the tool setter height ("gap") and set the WCS Z0 height.

Need to make sure:

  • The correct tool is loaded ie it corresponds to the tool number shown on the main display.
  • We are in the correct WCS ie the WCS called up by the program you intend to run. This is also shown on the main display.
  • The setter height is correctly saved to Other #389.

Then:

  • Use same the seek function from above to locate the top surface of the tool setter.
  • Use SETWK(Z#389), which should set the current WCS Z0 at the bottom of the tool setter.
It's the same result as pressing the "Setup" button and touching off on the workpiece, with the added convenience(?) of automatic touchoff and reduced risk of The Stupid Fat Bloke damaging tools and/or work by touching off a fragile tool onto a hard surface.


Let's try that - M887:
STATUSINFO(Stop tool at tool setter top and set current G5# Z0 at tool setter base);
MESSAGEBOX(Ensure current Tool#, WCS and setter height are correctly set)
IF (+#387) THEN;            // Setter is in "fixed" position
STATUSINFO(Moving to tool setter location);
MOVE(G90,F#386,X#380,Y#381);      // Move to machine coordinate X#380, Y#381
ENDIF;         // 
                                                        // Now seek the tool setter
STATUSINFO(Seeking tool setter);
MOVE(G90,F#383,Z#388,W+25);       // Move to Z#388, stop once X25 goes high
PAUS160;                 // Pause for 160ms
IF (-X25) THEN;         // Error - didn't see X25 go high....
MESSAGEBOX(Fault: The tool setting signal wasn't detected!)
ERREXIT;                 // End macro due to error
ENDIF;         // 
                                                        // Now back off and release the tool setter
STATUSINFO(Backing off from tool setter);
MOVE(G90,F#384,Z#382,W-25); // Move towards Z#382 (Zmax) until X25 goes low
IF (+X25) THEN; // Error - didn't see X25 go low again
MESSAGEBOX(Fault: The tool setting signal wasn't released!)
ERREXIT;                  // End macro due to error
ENDIF;
// Tool is now touched off on tool setter - need to subtract setter height to find Z0
MESSAGEBOX(Current WCS Z0 is now set at base of tool setter with current tool)
SETWK(Z#389); // #389 is the height of the tool setter

RETURN;

That work nicely (finally!!). Placing the tool setter on the top surface of the workpiece and running 

A Few Issues:
That was a royal PITA, not least figuring out which variables to call up. Particularly frustrating to be struggling with something so simple but making such slow progress.

Without getting specific, it's clear that the macro documentation is missing a few details and contains a few errors. 

Tool Setter Hysteresis:
Occasionally I was getting the "Fault: The tool setting signal wasn't released!" error message at the end of the "backing off" phase. This is due to noise on the contact signal. The tool is backed off until the tool loses contact with the setter at which point input X25 is released. However, if the signal at X25 is intermittent / noisy, it can reappear in time to cause trouble with the next line ("IF (+X25) THEN;"). The simplest solution would be to have some mechanical hysteresis in the detector switch. But my Toytown tool setter has no such sophistication and isn't about to any time soon.

At this point, The Stupid Fat Bloke piped up with a typically dumb idea, namely why not implement some form of hysteresis in the macro? Cue the best part of an hour trying to compare the current machine height with the target height (#382), all to no avail. Finally I saw sense and told him to fuck off and leave me alone. I then simply removed the test of X25 and associated error message (bold in the last macro code above). Quite simply, if the tool manages to reach the top of travel, it clearly hasn't triggered the X25 input. That shouldn't have gone unnoticed by the operator, as it will have taken ages to get there. So the final part of the macro is now:

......
// Now back off and release the tool setter
STATUSINFO(Backing off from tool setter);
MOVE(G90,F#384,Z#382,W-25);  // Move towards Z#382 (Zmax) until X25 goes low
// Tool is now touched off on tool setter - need to subtract setter height to find Z0
MESSAGEBOX(Current WCS Z0 is now set at base of tool setter with current tool)
SETWK(Z#389);          // #389 is the height of the tool setter

RETURN;

Sometimes it's best to cut out the smartass buggerage and make a pragmatic judgement. 

Phew - so now I have M886 (tool length offsets) and M887 (set Z0 in current WCS).

No comments:

Post a Comment

Final assembly and test of the spindle nose adaptor - RESULT!!

After the recent distraction caused by the 3D scanner, resurrecting the 3D printer and buggering about with the throttle bodies for my Honda...