TG Motion
version 421 - 4033/904 cnc 121
Real-time system for controlling servo drives and I/O modules
|
Classes | |
struct | CNC_CALC_INIT_DATA |
Initialization structure. More... | |
struct | CNC_CALC_RETURN_VALUE |
Holds changed G-code parts. More... | |
Macros | |
#define | CNC_CALC_MFUNC_OFFSET 10000 |
M function number offset to distinguish between G and M functions in SIMPLE_GM_PARAMS_BASE::m_func field. | |
#define | CNC_CALC_DISABLE_AUTOMATIC_GCODEINDEX_UPDATE_BIT 0x01 |
if used, TGMotion does not automatically update GCodeIndex value of the inserted parts | |
#define | CNC_CALC_MAX_STATIC_RETURNED_PARTS 8 |
#define | CNC_CALC_RETURN_ERROR (-1) |
Notify TGMotion of an error inside plug-in. More... | |
#define | CNC_CALC_RETURN_IGNORE 0 |
The call to the function is ignored and original part is used (no modification). More... | |
#define | CNC_CALC_RETURN_USE 1 |
TG Motion use the values in the CNC_CALC_RETURN_VALUE struct. The original part is not used. If needed, must be copied by the plug-in. More... | |
#define | CNC_CALC_RETURN_OK 1 |
Success value of non-calc funcions. More... | |
#define | CNC_CALC_RETURN_FEED_ONLY 2 |
Only the CNC_CALC_RETURN_VALUE::dblFeed value is used to modify the part feed, all other values are ignored. More... | |
Functions | |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE | CNC_Calc_Load (const CNC_CALC_INIT_DATA *pInitData) |
Plug-in DLL initialization. More... | |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE | CNC_Calc_Unload () |
Plug-in DLL cleanup. More... | |
CNC_CALC_DLL_EXPORT uint32_t TOOLCHAIN_CALLTYPE | CNC_Calc_Get_Structures_Size (uint32_t structureIdx) |
Check structure sizes - test for compatibility. More... | |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE | CNC_Calc_Get_Compatibility_IDs (uint32_t *pID_COMPATIBILITY, uint32_t *pID_MEMORY_COMPATIBILITY, uint32_t *pID_CNC_COMPATIBILITY) |
Returns compatibility numbers at the time of plug-in build. More... | |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE | CNC_Calc_Start (uint32_t intIdx, int32_t regime, const SIMPLE_GM_PARAMS_BASE *pInitPos, CNC_CALC_RETURN_VALUE *pChangedParts) |
Called before the G-code execution. More... | |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE | CNC_Calc_GFunc (uint32_t intIdx, const SIMPLE_GM_PARAMS_BASE *pGFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
Called for any G function inside G-code. More... | |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE | CNC_Calc_MFunc (uint32_t intIdx, const SIMPLE_GM_PARAMS_BASE *pMFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
Called for any M function inside G-code. More... | |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE | CNC_Calc_Finish (uint32_t intIdx, const SIMPLE_GM_PARAMS_BASE *pFinishMFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
Called as the last function of the G-code. More... | |
The CNC module can use an external PLC-like DLL plug-in for dynamic G-code recalculation. This plug-in DLL must NOT use any external OS libraries, the standard C library must be statically linked. Its functions will be called during G-code execution which allow to change almost any part or insert new parts to G-code flow.
It is not necessary to implement all exported functions, see their detailed description, but some functions are mandatory. There is just one plug-in common for all CNC cores.
Loading of plug-in can be done only during stop CNC statuses (not inside a movement). After load, the status is set to cnc_status::statusINVALID (0) and the G-code must be loaded (compile & test (and/or simulation)) again. The same status is set after plug-in unload.
Since changing and inserting new G-code parts leads to different number of total G-code parts of the G-code, also the GCodeIndex (SIMPLE_GM_PARAMS_BASE::m_gCodeIndex) values are different. TG Motion automatically handles the number of inserted parts and increments the G-code index value accordingly, so its value is monotonically increasing. However the plug-in can manage the G-code index values itself by setting bit CNC_CALC_DISABLE_AUTOMATIC_GCODEINDEX_UPDATE_BIT (0x01) to returned CNC_CALC_RETURN_VALUE::options value.
#define CNC_CALC_MAX_STATIC_RETURNED_PARTS 8 |
To speed up G-code parts insertion, up to 8 parts can be inserted just by using statically allocated memory in CNC_CALC_RETURN_VALUE::sParts0 array. If there is a need of more parts to be inserted, dynamically allocated memory must be used and set to the CNC_CALC_RETURN_VALUE::dParts1 pointer.
#define CNC_CALC_RETURN_ERROR (-1) |
Notify TGMotion of an error inside plug-in.
For displaying error text, use CNC_CALC_INIT_DATA::pPrintf function.
#define CNC_CALC_RETURN_IGNORE 0 |
The call to the function is ignored and original part is used (no modification).
Used by CNC_Calc_Start(), CNC_Calc_GFunc(), CNC_Calc_MFunc(), CNC_Calc_Finish() functions.
#define CNC_CALC_RETURN_USE 1 |
TG Motion use the values in the CNC_CALC_RETURN_VALUE struct. The original part is not used. If needed, must be copied by the plug-in.
Used by CNC_Calc_Start(), CNC_Calc_GFunc(), CNC_Calc_MFunc(), CNC_Calc_Finish() functions.
#define CNC_CALC_RETURN_OK 1 |
Success value of non-calc funcions.
(the same value as CNC_CALC_RETURN_USE)
#define CNC_CALC_RETURN_FEED_ONLY 2 |
Only the CNC_CALC_RETURN_VALUE::dblFeed value is used to modify the part feed, all other values are ignored.
Used by CNC_Calc_Start(), CNC_Calc_GFunc(), CNC_Calc_MFunc(), CNC_Calc_Finish() functions.
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE CNC_Calc_Load | ( | const CNC_CALC_INIT_DATA * | pInitData | ) |
Plug-in DLL initialization.
Called after DLL load. Allows to init internal variables. Must be implemented.
pInitData | Pointer to initialization structure with shared memory access functions. |
Value | Description |
---|---|
-1 | error, do not use the plug-in DLL |
any other value | success |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE CNC_Calc_Unload | ( | ) |
Plug-in DLL cleanup.
Called before DLL unload. Can be used for freeing memory etc. Must be implemented.
CNC_CALC_DLL_EXPORT uint32_t TOOLCHAIN_CALLTYPE CNC_Calc_Get_Structures_Size | ( | uint32_t | structureIdx | ) |
Check structure sizes - test for compatibility.
This function must be implemented. It is necessary for checking the versions of the plug-in and TG Motion.
structureIdx | Determines which structure size is asked for:
|
Example
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE CNC_Calc_Get_Compatibility_IDs | ( | uint32_t * | pID_COMPATIBILITY, |
uint32_t * | pID_MEMORY_COMPATIBILITY, | ||
uint32_t * | pID_CNC_COMPATIBILITY | ||
) |
Returns compatibility numbers at the time of plug-in build.
This function must be implemented. It is necessary for checking the versions of the plug-in and TG Motion.
pID_COMPATIBILITY | pointer to variable where the ID_COMPATIBILITY number is returned |
pID_MEMORY_COMPATIBILITY | pointer to variable where the ID_MEMORY_COMPATIBILITY number is returned |
pID_CNC_COMPATIBILITY | pointer to variable where the ID_CNC_COMPATIBILITY number is returned |
Example
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE CNC_Calc_Start | ( | uint32_t | intIdx, |
int32_t | regime, | ||
const SIMPLE_GM_PARAMS_BASE * | pInitPos, | ||
CNC_CALC_RETURN_VALUE * | pChangedParts | ||
) |
Called before the G-code execution.
Allow to store initial value, insert special G-code parts at the begining of G-code execution, etc. Also signals the mode in the regime parameter.
intIdx | Interpolator number. Value from 0 to (MAX_CORES - 1). |
regime | Actual regime. Regime is kept until call to CNC_Calc_Finish(). Can be: START_CNC_SIMULATION (10), START_CNC_TEST (20), START_CNC_FORWARD (30), START_CNC_FORWARD_NO_MFUNC (31), START_CNC_BACKWARD (32), START_CNC_FORWARD_SKIP_FIRST_M (33), START_CNC_CONNECT (40) |
pInitPos | Initial position is set in SIMPLE_GM_PARAMS_BASE::m_s field. SIMPLE_GM_PARAMS_BASE::m_planeTool is set to initial plane (G17, G18, G19 or -18 for lathe (ZX)) SIMPLE_GM_PARAMS_BASE::m_func is -33. |
pChangedParts | G-code parts to be sent to the system, if the return value is CNC_CALC_RETURN_USE. |
Value | Description |
---|---|
1 | the pChangedParts structure contains valid values and will be used |
0 | no change to original G-code (call is ignored) |
-1 | error - stops from calling any plug-in function till unload/load of the plug-in. |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE CNC_Calc_GFunc | ( | uint32_t | intIdx, |
const SIMPLE_GM_PARAMS_BASE * | pGFunc, | ||
CNC_CALC_RETURN_VALUE * | pChangedParts | ||
) |
Called for any G function inside G-code.
This function is called for all the G functions (with any number) situated in the G-code text. Usually will be used to modify movement functions like G1, G2, G3, but can be used also to implement special functions ("macros") or machining cycles. If necessary, can also return CNC_CALC_RETURN_USE, but set the number of entries in CNC_CALC_RETURN_VALUE to zero (CNC_CALC_RETURN_VALUE::nEntriesInPart0 = 0, CNC_CALC_RETURN_VALUE::nDynamicEntriesInPart1 = 0). In this case no parts will be sent to system for that original G-code. The plug-in can remember this part and send it in the next call of CNC_Calc_GFunc(), CNC_Calc_MFunc() or CNC_Calc_Finish(). This would allow e.g. to rotate a plasma head between parts.
intIdx | Interpolator number. Value from 0 to (MAX_CORES - 1) |
pGFunc | The original G function from G-code text. |
pChangedParts | Sequence of G-code parts (G or M functions) to be sent to the system, if the return value is CNC_CALC_RETURN_USE or CNC_CALC_RETURN_FEED_ONLY. If the modified function shall be a M function, its number must be set to SIMPLE_GM_PARAMS_BASE::m_func plus the constant CNC_CALC_MFUNC_OFFSET. |
Value | Description |
---|---|
2 | the CNC_CALC_RETURN_VALUE::dblFeed is used to modify original (pGFunc) feed. No other fields of pChangedParts are used. |
1 | the pChangedParts structure contains valid values |
0 | no change to original G-code (call is ignored and the original values in pGFunc are used) |
-1 | error - stops from calling any plug-in function till unload/load of the plug-in. |
Example1
Example2
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE CNC_Calc_MFunc | ( | uint32_t | intIdx, |
const SIMPLE_GM_PARAMS_BASE * | pMFunc, | ||
CNC_CALC_RETURN_VALUE * | pChangedParts | ||
) |
Called for any M function inside G-code.
This function is called for all the M functions (with any number) situated in the G-code text. Can be used to expand special M functions to set of movements and other M functions, already implemented in PLC.
intIdx | Interpolator number. Value from 0 to (MAX_CORES - 1) |
pMFunc | Original M function description from G-code text. |
pChangedParts | Sequence (or just one) of G-code parts to be sent to the system, if the return value is CNC_CALC_RETURN_USE or CNC_CALC_RETURN_FEED_ONLY. If the modified function shall be a M function, its number must be set to SIMPLE_GM_PARAMS_BASE::m_func plus the constant CNC_CALC_MFUNC_OFFSET. |
Value | Description |
---|---|
1 | the pChangedParts structure contains valid values |
0 | no change to original G-code (call is ignored and the original values in pMFunc are used) |
-1 | error - stops from calling any plug-in function till unload/load of the plug-in. |
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE CNC_Calc_Finish | ( | uint32_t | intIdx, |
const SIMPLE_GM_PARAMS_BASE * | pFinishMFunc, | ||
CNC_CALC_RETURN_VALUE * | pChangedParts | ||
) |
Called as the last function of the G-code.
Can be used to flush potential G or M functions accumulated in the plug-in.
intIdx | Interpolator number. Value from 0 to (MAX_CORES - 1) |
pFinishMFunc | Contains the last G-code postion in SIMPLE_GM_PARAMS_BASE::m_s field. The SIMPLE_GM_PARAMS_BASE::m_func value is set to -30. |
pChangedParts | Sequence (or just one) of G-code parts to be sent to the system, if the return value is CNC_CALC_RETURN_USE. |