Reading the State of the Interpolator
See the CNC13_ReadInterpolatorState.project sample project in the installation directory of CODESYS under ..\CODESYS SoftMotion\Examples.
The sample project shows how to read the state of the CNC interpolator. The state is used to display the position of the machine in both machine and decoder coordinates.
Structure of the application
The structure is typical for CNC applications. The G-code is read in the background task. The interpolation is performed in the bus task.
During the interpolation, the SMC_ReadAdditionalIpoState function block called.
As soon as the interpolation begins, the Valid output is TRUE. The position of the interpolator, which is always output in the machine coordinate system (MCS), is then converted using the current decoder coordinate system (DCS) and output in the visualization.
SMC_V3_Set(pos_MCS, ipo.piSetPosition.dX, ipo.piSetPosition.dY, ipo.piSetPosition.dZ);
readState(
Enable:= TRUE,
ipo:= ipo);
IF readState.Valid THEN
SMC_PosInfo_Trf_Inverse(
piOut:= piMCS_to_DCS,
piIn:= readState.State.DCS,
eOriConv:= readState.State.OriConv);
SMC_PosInfo_Trf_Apply(
vDst:= pos_DCS,
piTrf:= piMCS_to_DCS,
vSrc:= pos_MCS,
eOriConv:= readState.State.OriConv);
END_IFFor more information about the decoder coordinate system, see the following: Shifting, Rotating, and Scaling the Coordinate System.
Commissioning
Build the application and download it to a controller.
Open the visualization.
Start the application and press the Start button of the visualization.
You can track the movement of the X and Y coordinates in MCS and DCS.