|
typedef int32_t | CNC_CALC_LOAD(const CNC_CALC_INIT_DATA *pInitData) |
| typedef for CNC_Calc_Load
|
|
typedef int32_t | CNC_CALC_UNLOAD() |
| typedef for CNC_Calc_Unload
|
|
typedef uint32_t | CNC_CALC_GET_STRUCTURES_SIZE(uint32_t structureIdx) |
| typedef for CNC_Calc_Get_Structures_Size
|
|
typedef int32_t | CNC_CALC_GET_COMPATIBILITY_IDS(uint32_t *pID_COMPATIBILITY, uint32_t *pID_MEMORY_COMPATIBILITY, uint32_t *pID_CNC_COMPATIBILITY) |
| typedef for CNC_Calc_Get_Compatibility_IDs
|
|
typedef int32_t | CNC_CALC_START(uint32_t intIdx, int32_t regime, const cnc::SIMPLE_GM_PARAMS_WIN32 *pInitPos, CNC_CALC_RETURN_VALUE *pChangedParts) |
| typedef for CNC_Calc_Start
|
|
typedef int32_t | CNC_CALC_GFUNC(uint32_t intIdx, const cnc::SIMPLE_GM_PARAMS_WIN32 *pGFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
| typedef for CNC_Calc_GFunc
|
|
typedef int32_t | CNC_CALC_MFUNC(uint32_t intIdx, const cnc::SIMPLE_GM_PARAMS_WIN32 *pMFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
| typedef for CNC_Calc_MFunc
|
|
typedef int32_t | CNC_CALC_FINISH(uint32_t intIdx, const cnc::SIMPLE_GM_PARAMS_WIN32 *pFinishMFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
| typedef for CNC_Calc_Finish
|
|
|
CNC_CALC_DLL_EXPORT int32_t | CNC_Calc_Load (const CNC_CALC_INIT_DATA *pInitData) |
| Plug-in DLL initialization. More...
|
|
CNC_CALC_DLL_EXPORT int32_t | CNC_Calc_Unload () |
| Plug-in DLL cleanup. More...
|
|
CNC_CALC_DLL_EXPORT uint32_t | CNC_Calc_Get_Structures_Size (uint32_t structureIdx) |
| Check structure sizes - test for compatibility. More...
|
|
CNC_CALC_DLL_EXPORT int32_t | 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 | CNC_Calc_Start (uint32_t intIdx, int32_t regime, const cnc::SIMPLE_GM_PARAMS_WIN32 *pInitPos, CNC_CALC_RETURN_VALUE *pChangedParts) |
| Called before the G-code execution. More...
|
|
CNC_CALC_DLL_EXPORT int32_t | CNC_Calc_GFunc (uint32_t intIdx, const cnc::SIMPLE_GM_PARAMS_WIN32 *pGFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
| Called for any G function inside G-code. More...
|
|
CNC_CALC_DLL_EXPORT int32_t | CNC_Calc_MFunc (uint32_t intIdx, const cnc::SIMPLE_GM_PARAMS_WIN32 *pMFunc, CNC_CALC_RETURN_VALUE *pChangedParts) |
| Called for any M function inside G-code. More...
|
|
CNC_CALC_DLL_EXPORT int32_t | CNC_Calc_Finish (uint32_t intIdx, const cnc::SIMPLE_GM_PARAMS_WIN32 *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::cnc_status::INVALID_00 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 (cnc::SIMPLE_GM_PARAMS_WIN32::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.
◆ CNC_Calc_Finish()
Called as the last function of the G-code.
Can be used to flush potential G or M functions accumulated in the plug-in.
- Parameters
-
- Note
- Implementation of this function is optional.
◆ CNC_Calc_Get_Compatibility_IDs()
CNC_CALC_DLL_EXPORT int32_t 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.
- Parameters
-
- Returns
- Always 1.
Example
uint32_t *pID_MEMORY_COMPATIBILITY,
uint32_t *pID_CNC_COMPATIBILITY)
{
assert(pID_COMPATIBILITY != nullptr);
assert(pID_MEMORY_COMPATIBILITY != nullptr);
assert(pID_CNC_COMPATIBILITY != nullptr);
}
constexpr int32_t CNC_CALC_RETURN_OK
Definition: tgm_cnc.h:3471
CNC_CALC_DLL_EXPORT int32_t 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.
constexpr uint32_t ID_COMPATIBILITY
Compatibility number.
Definition: tgm.h:121
constexpr uint32_t ID_CNC_COMPATIBILITY
CNC Compatibility ID.
Definition: tgm.h:127
constexpr uint32_t ID_MEMORY_COMPATIBILITY
Memory Compatibility number.
Definition: tgm.h:124
◆ CNC_Calc_Get_Structures_Size()
CNC_CALC_DLL_EXPORT uint32_t 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.
- Parameters
-
structureIdx | Determines which structure size is asked for:
|
- Returns
- Structure size in bytes for valid structureIdx or zero.
Example
{
switch (structureIdx)
{
default:
break;
}
return 0;
}
CNC_CALC_DLL_EXPORT uint32_t CNC_Calc_Get_Structures_Size(uint32_t structureIdx)
Check structure sizes - test for compatibility.
constexpr uint32_t CNC_CALC_IDX_SIMPLE_GM_PARAMS_BASE_STRUCT
parameter for CNC_Calc_Get_Structures_Size
Definition: tgm_cnc.h:3498
constexpr uint32_t CNC_CALC_IDX_RETURN_VALUE_STRUCT
parameter for CNC_Calc_Get_Structures_Size
Definition: tgm_cnc.h:3499
constexpr uint32_t CNC_CALC_IDX_INIT_DATA_STRUCT
parameter for CNC_Calc_Get_Structures_Size
Definition: tgm_cnc.h:3497
Initialization structure.
Definition: tgm_cnc.h:3376
Holds changed G-code parts.
Definition: tgm_cnc.h:3434
Describes one G-code part.
Definition: tgm_cnc.h:1059
◆ CNC_Calc_GFunc()
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.
- Parameters
-
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_WIN32::m_func plus the constant CNC_CALC_MFUNC_OFFSET. |
- Returns
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
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE
CNC_Calc_GFunc(uint32_t intIdx,
const SIMPLE_GM_PARAMS_WIN32 *pGFunc,
{
if (pGFunc->m_func == 1)
{
float64_t len = pGFunc->m_calcE.Length(pGFunc->m_calcS);
if (len > 10.0)
{
}
}
}
CNC_CALC_DLL_EXPORT int32_t CNC_Calc_GFunc(uint32_t intIdx, const cnc::SIMPLE_GM_PARAMS_WIN32 *pGFunc, CNC_CALC_RETURN_VALUE *pChangedParts)
Called for any G function inside G-code.
constexpr int32_t CNC_CALC_RETURN_IGNORE
Definition: tgm_cnc.h:3463
constexpr int32_t CNC_CALC_RETURN_FEED_ONLY
Definition: tgm_cnc.h:3476
constexpr size_t ADDR_IDX()
simplify G-code address indexing
Definition: tgm_cnc.h:163
float64_t dblFeed
new feed
Definition: tgm_cnc.h:3436
void UNREFERENCED_PARAM(T &P) noexcept
Definition: tgm.h:2275
Example2
CNC_CALC_DLL_EXPORT int32_t TOOLCHAIN_CALLTYPE
CNC_Calc_GFunc(uint32_t intIdx,
const SIMPLE_GM_PARAMS_WIN32 *pGFunc,
{
if (pGFunc->m_func == 1)
{
float64_t len = pGFunc->m_calcE.Length(pGFunc->m_calcS);
if (len > 20.0)
{
pChangedParts->
sParts0[0] = *pGFunc;
pChangedParts->
sParts0[1] = *pGFunc;
pChangedParts->
sParts0[2] = *pGFunc;
P10DOUBLE middleCalc(pGFunc->m_calcS + ((pGFunc->m_calcE - pGFunc->m_calcS) * 0.5));
P10DOUBLE middleOrig(pGFunc->m_s + ((pGFunc->m_e - pGFunc->m_s) * 0.5));
}
}
}
constexpr int32_t CNC_CALC_RETURN_USE
Definition: tgm_cnc.h:3468
constexpr int32_t CNC_CALC_MFUNC_OFFSET
Definition: tgm_cnc.h:3418
uint32_t nDynamicEntriesInPart1
number of entries in the dParts1 array
Definition: tgm_cnc.h:3451
uint32_t nEntriesInPart0
Definition: tgm_cnc.h:3443
cnc::SIMPLE_GM_PARAMS_WIN32 sParts0[CNC_CALC_MAX_STATIC_RETURNED_PARTS]
Definition: tgm_cnc.h:3447
P10DOUBLE m_calcS
Definition: tgm_cnc.h:1107
P10DOUBLE m_calcE
Definition: tgm_cnc.h:1110
P10DOUBLE m_e
Definition: tgm_cnc.h:1104
P10DOUBLE m_s
Definition: tgm_cnc.h:1089
int32_t m_func
G function number. If > 10000, it is M function. -1 is invalid function.
Definition: tgm_cnc.h:1061
- Note
- Implementation of this function is optional.
◆ CNC_Calc_Load()
Plug-in DLL initialization.
Called after DLL load. Allows to init internal variables. Must be implemented.
- Parameters
-
pInitData | Pointer to initialization structure with shared memory access functions. |
- Returns
Value | Description |
-1 | error, do not use the plug-in DLL |
any other value | success |
◆ CNC_Calc_MFunc()
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.
- Parameters
-
- Returns
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. |
- Note
- Implementation of this function is optional.
◆ CNC_Calc_Start()
Called before the G-code execution.
Allow to store initial value, insert special G-code parts at the beginning of G-code execution, etc. Also signals the mode in the regime parameter.
- Parameters
-
- Returns
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. |
- Note
- Implementation of this function is optional.
◆ CNC_Calc_Unload()
CNC_CALC_DLL_EXPORT int32_t CNC_Calc_Unload |
( |
| ) |
|
Plug-in DLL cleanup.
Called before DLL unload. Can be used for freeing memory etc. Must be implemented.
- Returns
- Return value is ignored.
◆ CNC_CALC_MAX_STATIC_RETURNED_PARTS
constexpr uint32_t CNC_CALC_MAX_STATIC_RETURNED_PARTS { 8U } |
|
constexpr |
◆ CNC_CALC_MFUNC_OFFSET
constexpr int32_t CNC_CALC_MFUNC_OFFSET { 10000 } |
|
constexpr |
◆ CNC_CALC_RETURN_ERROR
constexpr int32_t CNC_CALC_RETURN_ERROR { -1 } |
|
constexpr |
◆ CNC_CALC_RETURN_FEED_ONLY
constexpr int32_t CNC_CALC_RETURN_FEED_ONLY { 2 } |
|
constexpr |
◆ CNC_CALC_RETURN_IGNORE
constexpr int32_t CNC_CALC_RETURN_IGNORE { 0 } |
|
constexpr |
◆ CNC_CALC_RETURN_OK
constexpr int32_t CNC_CALC_RETURN_OK { 1 } |
|
constexpr |
◆ CNC_CALC_RETURN_USE
constexpr int32_t CNC_CALC_RETURN_USE { 1 } |
|
constexpr |