G43 Hxx with C Code?
Moderators: TomKerekes, dynomotion
G43 Hxx with C Code?
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
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
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G43 Hxx with C Code?
Hi Andrew,
You might try this:
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);
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: G43 Hxx with C Code?
Worked great! Thanks again!
-
- Posts: 25
- Joined: Mon Dec 23, 2019 9:18 pm
Re: G43 Hxx with C Code?
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
Thanks,
Larry
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G43 Hxx with C Code?
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.
HTH
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");
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 25
- Joined: Mon Dec 23, 2019 9:18 pm
Re: G43 Hxx with C Code?
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
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
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G43 Hxx with C Code?
Hi Larry,
Thanks for the program.
Otherwise from GCode G53 can be used to move in Machine Coordinates.
HTH
Thanks for the program.
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.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.
Otherwise from GCode G53 can be used to move in Machine Coordinates.
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 25
- Joined: Mon Dec 23, 2019 9:18 pm
Re: G43 Hxx with C Code?
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
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
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G43 Hxx with C Code?
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.
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.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 25
- Joined: Mon Dec 23, 2019 9:18 pm
Re: G43 Hxx with C Code?
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!
Thanks again!