Page 1 of 1
DoPCFloat in M6
Posted: Wed Jun 25, 2025 10:47 am
by Wayne
Hi all,
I hope you are doing well.
I'm trying to figure out how to make the code "DoPCFloat(PC_COMM_SET_Z, 1.25)" work within the M6 tool change routine. My ultimate goal is to measure the tool and assign a new Z value immediately after a tool change. However, it seems that this DoPCFloat is ignored when placed in M6 (below). Interestingly, when I run the exact same code from a user-defined button, the new Z value is applied correctly. I’d be very grateful if anyone could guide me through how to get this working properly within the M6 routine.
Code: Select all
#include "KMotionDef.h"
#include "PC-DSP.h" // already in KMotionDef.h?
#define TMP 10
#include "KflopToKMotionCNCFunctions.c"
float NewZZero;
int main()
{
NewZZero = 1.25;
int slot = persist.UserData[9]; // value stored is an int
int id = persist.UserData[9+1]; // value stored is an int
DoPCFloat(PC_COMM_SET_Z, NewZZero);
printf("Tool Set to slot %d id %d\n",slot,id); // print the slot and id
return 0;
}
Thank you very much!
Re: DoPCFloat in M6
Posted: Wed Jun 25, 2025 5:50 pm
by TomKerekes
Hi Wayne,
KMotionCNC doesn't allow Setting/Zeroing the DROs while GCode is running. The method used in the SetFixtureZ.c example should work.
Re: DoPCFloat in M6
Posted: Thu Jun 26, 2025 10:58 am
by Wayne
Hi Tom,
Thanks for your prompt reply. From my testing, this function "DoPCFloat(PC_COMM_SET_Z, (float)NewZZero);" sets the current Z DRO to NewZZero, and it appears that a G92 Z offset is automatically applied. In addition to setting Fixture Z, could you kindly guide me through the correct method to set a G92 Z offset in a G-code-compatible way?
Another concern I have is about the G-code-compatibility of DoPC functions when used within G-code-triggered macros. While DoPC(PC_COMM_UPDATE_FIXTURE) works, DoPCFloat(PC_COMM_SET_Z, ...) does not. Both functions appears to communicate with the PC, so it's unclear to users why one is allowed and the other is not. Is there a list or guideline that distinguishes which DoPC commands works within G-code macros? This would be extremely helpful, as my code compiles without error and runs correctly when triggered from a user-defined button — making it difficult to debug when it silently fails in a G-code macro.
Additionally, I’d appreciate any documentation or guidance on how to determine the correct starting variable numbers for functions like SetVars(...). For example, in: SetVars(5201+FixtureIndex*20+Zaxis, 1, TMP); how do we know that 5201 is the correct number for fixture offsets?
Understanding these distinctions would help us avoid compatibility issues and ensure consistent behavior across both development and G-code execution environments.
Thank you for your time and support!
Re: DoPCFloat in M6
Posted: Thu Jun 26, 2025 8:31 pm
by Moray
I can't comment on the G-code macros, but the emc.var file values are based on the same original source as EMC(now LinuxCNC).
KMotion related ones are defined in <install dir>\GCodeInterpreter\rs274ngc.cpp at line 552, but there are tables in the LinuxCNC documentation that give them in a better layout -
https://linuxcnc.org/docs/html/gcode/g-code.html (easiest option is to just search for the number you're looking for)
Although the codes used do vary between KMotion and LinuxCNC.
What option do you have set in the KMotionCNC setup for the dropdown options for M6?
Re: DoPCFloat in M6
Posted: Thu Jun 26, 2025 10:25 pm
by TomKerekes
Hi Wayne,
In addition to setting Fixture Z, could you kindly guide me through the correct method to set a G92 Z offset in a G-code-compatible way?
There currently isn't a method to change the G92 Offset directly from a C Program. It could be added if necessary. Normally a tool change would update the Tool's Length.
A workaround might be to set a GCode Var with the offset then follow the M6 with a G92 Z#1 block.
Another concern I have is about the G-code-compatibility of DoPC functions when used within G-code-triggered macros. While DoPC(PC_COMM_UPDATE_FIXTURE) works, DoPCFloat(PC_COMM_SET_Z, ...) does not. Both functions appears to communicate with the PC, so it's unclear to users why one is allowed and the other is not. Is there a list or guideline that distinguishes which DoPC commands works within G-code macros?
The PC_COMM_SET commands mimic the on screen Set Buttons which are disabled when GCode is running. You can always check the source code to see exactly how things are handled. Search for 'PC_COMM_SET_Z' in *.cpp files.
my code compiles without error and runs correctly when triggered from a user-defined button — making it difficult to debug when it silently fails in a G-code macro.
Actually the function returns an non-zero error code of -1 to indicate it failed that can be checked.
Additionally, I’d appreciate any documentation or guidance on how to determine the correct starting variable numbers for functions like SetVars(...). For example, in: SetVars(5201+FixtureIndex*20+Zaxis, 1, TMP); how do we know that 5201 is the correct number for fixture offsets?
rs274ngc.cpp contains a table of '_required_parameters' that shows the layout.