Page 1 of 2
G43 Hxx with C Code?
Posted: Fri Aug 31, 2018 2:29 am
by a_j_p
Hi All,
Does anyone know how to execute a G43 Hxx command via C Code? Or get the equivalent result? I have been using a tool height offset sensor to set the tool length and store it in the table and it works just fine. The problem that I have is that when it sets the tool length it does not apply that offset without me going into the tool file and re-selecting that tool OR typing in G43 Hxx.
When running actual programs, the post-processor always includes Txx G43 Hxx and it's not a big deal in that situation. But when I want to go in and hand load a new tool and do some more manual operations (which is rather frequent for me) I find that I often forget this extra step and plunge into the part on accident.
I have looked around online to see if anyone else has an answer but have been unsuccessful... I have also tried the MDI command, but have yet to figure out how to pass the Hxx number into the MDI string... I was hoping I could do something like MDI("G43 H%d",TWORD); but that doesn't work.
Let me know if you have this same issue or a good work around.
-Andrew
Re: G43 Hxx with C Code?
Posted: Fri Aug 31, 2018 7:21 pm
by TomKerekes
Hi Andrew,
You might try this:
Code: Select all
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
main()
{
char s[40];
int Units, TWORD, HWORD, DWORD;
GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
sprintf(s,"G43 H%d",TWORD);
MDI(s);
}
Re: G43 Hxx with C Code?
Posted: Sat Sep 01, 2018 1:41 pm
by a_j_p
Worked great! Thanks again!
Re: G43 Hxx with C Code?
Posted: Sun Feb 02, 2020 4:49 am
by larryjamessmith
I have created a C-program to perform tool changes. It takes all the active offsets into consideration when moving the mill head to the tool change position. There is one piece of information which I have not been able to find. I need to know if tool length compensation is enabled (G43 active). Where can I get to the state of H43? I assume it is controlled by the Gcode interpreter but it does affect the DROs so KMotionCNC must use this information as well... Does anyone have suggestions?
Thanks,
Larry
Re: G43 Hxx with C Code?
Posted: Sun Feb 02, 2020 6:48 pm
by TomKerekes
Hi Larry,
If you get the Misc Settings from KMotionCNC the H word will be the Active Tool Table Index and -1 if Tool Length Compensation is off.
Code: Select all
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
main()
{
int Units, TWORD, HWORD, DWORD;
GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
printf("%d %d %d\n",TWORD, HWORD, DWORD);
if (HWORD >= 0)
printf("Tool Length/Offset Comp on\n");
else
printf("Tool Length/Offset Comp off\n");
}
HTH
Re: G43 Hxx with C Code?
Posted: Sun Feb 02, 2020 10:42 pm
by larryjamessmith
Tom,
That works great! Thanks so much. I am just getting into the use of offsets to support multiple setups since I have limited my NC files to supporting a single setup in the past. My CAD/CAM software supports multiple setups along with tool changes so I am making an effort to visualize how that plays in KMotionCNC. I found this little program helped me to get my head around the effect of all the offsets and tool length and I am sharing here.
One other question: Is there a way to command a move using machine coordinates rather than user workspace coordinates? That would be useful while executing tool changes and work setup changes.
Thanks again,
Larry
Re: G43 Hxx with C Code?
Posted: Mon Feb 03, 2020 4:32 pm
by TomKerekes
Hi Larry,
Thanks for the program.
Is there a way to command a move using machine coordinates rather than user workspace coordinates? That would be useful while executing tool changes and work setup changes.
Not exactly sure what you mean. KFLOP 'Move()" commands are in absolute machine coordinates. Although in counts or steps rather than in GCode Units. But that is normally fine for moving to some fixed position to do a tool change or such.
Otherwise from GCode G53 can be used to move in Machine Coordinates.
HTH
Re: G43 Hxx with C Code?
Posted: Mon Feb 03, 2020 9:52 pm
by larryjamessmith
Tom,
I have my machine configured in units of inches, so for me a "Move(0,1.0)" results in a 1" move. This avoids a lot of unnecessary scaling in my programs.
My confusion was due to reading the DROx value rather than using "Ch0->Position" to get the current position. I was starting a move and then popping up a MsgBox for the user without waiting for the move to end. The DRO values were not what I expected and I attributed the difference to the effect of offsets rather than the fact that the DRO did not reflect the position because the message came up too early. Even though this was frustrating, I learned a great deal about offsets in the process!
Thank you for your patience,
Larry
Re: G43 Hxx with C Code?
Posted: Mon Feb 03, 2020 11:25 pm
by TomKerekes
Hi Larry,
Note normally one would use ch0->Dest as that is the last commanded theoretical destination. ch0->Position is the actual measured position. ch0->Position will only be valid on systems with feedback and may include small servo errors. Depending on what you are doing one or the other may be more appropriate.
Re: G43 Hxx with C Code?
Posted: Tue Feb 04, 2020 1:09 am
by larryjamessmith
Is ch0->Dest maintained during jogging? If so that would be preferable. I am using very accurate encoders but there is no sense in adding error. I will switch to Dest...
Thanks again!