Page 1 of 1
Automated tool change and touch off
Posted: Wed Sep 07, 2022 12:36 am
by BigE
I'm trying to automate my process a bit more. One thing I occasionally forget to do (not very often, but it has happened 3x now) is to zero off my new bit when I change tools. Adding this in to the gcode would force a zero every time.
I'm using a script for tool touch off (modified version of Jeremy Brown's code) that works perfectly when I call it from a button on the interface. Here are the key lines.
ProbeDown(); //Jogs down until tool touches off on touch plate
DoPCFloat(PC_COMM_SET_Z, ToolOffset); //ToolOffset is a pre-determined offset between zero of part and zero of touch plate
MoveUp(SAFEZ*3);
I can take and assign it to M101, with execute, wait, and sync, and it works just fine when I send M101 via the command interface.
However, when I call M101 from my gcode program, the DRO doesn't update. Everything else executes perfectly. I have spent way too much time on this without figuring anything out, so I guess it's time to ask for help. How can I get the DRO to update when called from gcode?
Re: Automated tool change and touch off
Posted: Wed Sep 07, 2022 9:19 pm
by TomKerekes
Hi BigE,
There is a safety mechanism where PC_COMM_SET_Z is not allowed while GCode is running which doesn't make sense in your situation (Somebody might have a button to set the Z DRO). I've been trying to think of a workaround. The best I could come up with is to have an MCode that halts the GCode and only sets a trigger for another Thread to perform the the PC_COMM_SET_Z and resume Execution.
Here is an example MCode that Halts and sets a trigger of Virtual Bit 1024
Code: Select all
#include "KMotionDef.h"
#define TMP 10
#include "KflopToKMotionCNCFunctions.c"
void main()
{
SetStateBit(1025,JOB_ACTIVE); // Remember if Job Was Running.
printf("JOB_ACTIVE = %d\n",ReadBit(1025));
if (ReadBit(1025))
DoPC(PC_COMM_HALT_NEXT_LINE); // if so, Halt
SetBit(1024); // Trigger Thread #1 to perform Tool Set
}
Here is code in Thread #1's forever loop to watch for the Trigger, perform the Probe, then resume Execution. (The probing and setting is dummy code)
Code: Select all
for (;;) // loop forever
{
if (ReadBit(1024))
{
while (JOB_ACTIVE) ; // wait for Job halted
MoveRel(2, -2000); // Jogs down until tool touches off on touch plate
while (!CheckDone(2)) ;
DoPCFloat(PC_COMM_SET_Z, 3); //ToolOffset is a pre-determined offset between zero of part and zero of touch plate
Move(2,1000);
while (!CheckDone(2)) ;
if (ReadBit(1025)) // was Job running?
DoPC(PC_COMM_EXECUTE); // if yes, restart
ClearBit(1024);
}
}
The problem is besides being complicated if the MCode is executed from the MDI it undesirably launches the GCode Program. There isn't currently a way to tell if GCode is executing or MDI is executing.
We will probably need to add some new capability to handle this properly.
Re: Automated tool change and touch off
Posted: Fri Sep 09, 2022 9:13 pm
by BigE
Thanks, Tom,
Well, at least now I know what I was trying to do isn't exactly impossible, but it is also not easy.
My other thought was to somehow update the tool length in the tool table and then force a reload of those values. I'm not currently using a tool table since I have an ER20 collet, but I could just update the same tool ID over and over as needed.
Another option I could add
DoPC(PC_COMM_HALT_NEXT_LINE);
and then manually hit the resume button. The tool change routinely would be the first thing that is called.
Leaving infinite loops running always seems to bite me in the end, so I'm not sure that is the best approach.
Side note: I keep having errors trying to reply to this. I'm getting 503 errors. Hopefully this reply goes through. 10+ attempts.
Regards,
-Steve
Re: Automated tool change and touch off
Posted: Sat Sep 10, 2022 6:51 pm
by TomKerekes
Hi Steve,
You helped me realize there is an alternate method. The GCode Offsets are stored in GCode Vars (52XX range). The code below adjusts the current Z Fixture Offset in the GCode Vars then Updates the Interpreter. This method doesn't have any safety protection. Please see if that works for you.
Code: Select all
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
#define Zaxis 2
#define SomeOffset 7
main()
{
int FixtureIndex;
double NewOriginOffset,OriginOffsetZ;
double DROx, DROy, DROz, DROa, DROb, DROc;
GetFixtureIndex(&FixtureIndex);
GetOriginOffset(&OriginOffsetZ, FixtureIndex, Zaxis);
GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);
// Adjust Origin Offset to make DRO some offset
NewOriginOffset = OriginOffsetZ + DROz - SomeOffset;
SetUserDataDouble(TMP,NewOriginOffset);
SetVars(5201+FixtureIndex*20+Zaxis, 1, TMP);
DoPC(PC_COMM_UPDATE_FIXTURE);
}
Let us know if you have more issues with the forum. We don't seem to be having any problems. What browser are you you using? What typr of internet connection do you have? What is your location? Thx
Re: Automated tool change and touch off
Posted: Sun Sep 11, 2022 11:00 pm
by BigE
Thanks, Tom, I'll give that a shot when my current order is finished. It looks like it should work.
I'm using Chrome for the forum. I've cleared cookies, deleted browsing data, etc. Might be just my internet connection, I guess. Preview works fine. Submit just sits there waiting for translate-pa.googleapis.com in Chrome or translate.googleapis.com in IE (message at the bottom).
Hmmm, looks like there is a quota for googleapis.
Regards,
-Steve