Example Pitch Compensation

[This is preliminary documentation and subject to change.]

Example Pitch Compensation 1:

This sample should illustrate how to use FB_PositionCompensation and FB_WritePositionCorrection for a pitch compensation of a spindle. Depending on the required accuracy it is recommended to run the PLC task with the same cycle time as the NC-SAF task. It is also necessary to enable the actual position correction of the axis (System Manager).

 

Example Pitch Compensation 2:

 

 

VAR
   fbPitchCompensation      :FB_PositionCompensation;
   fbWritePosCorrection     :FB_WritePositionCorrection;
   bAxisIsHomed             : BOOL;
   bEnablePitchCompensation : BOOL := FALSE;
   fCompensationValue       : LREAL;
   bError                   : BOOL;
   nErrorId                 : UDINT;
   bActive                  : BOOL;
   bLimiting                : BOOL;
END_VAR

VAR CONSTANT
   stXDescPitch: ST_CompensationDesc :=
(fPosMin:=0.0, fPosMax:=100.0, nTableElements:=11);
   stXPitchTable: ARRAY[0..10] OF ST_CompensationElement
:=(fPos:=0.0, fCompensation:=0.0),
  (fPos:=10.0, fCompensation:=0.1),
  (fPos:=20.0, fCompensation:=0.2),
  (fPos:=30.0, fCompensation:=0.3),
  (fPos:=40.0, fCompensation:=0.4),
  (fPos:=50.0, fCompensation:=0.5),
  (fPos:=60.0, fCompensation:=0.6),
  (fPos:=70.0, fCompensation:=0.7),
  (fPos:=80.0, fCompensation:=0.8),
  (fPos:=90.0, fCompensation:=0.9),
  (fPos:=100.0, fCompensation:=1.0);
END_VAR

 

The compensation table and description is defined as constant in this case. fPos holds the uncorrected absolute position and for each position there is a compensation value fCompensation.

 

In almost all applications the compensation is just useful if the axis is referenced (homed). So FB_PositionCompensation should only be enabled if this is given.

IF bAxisIsHomed THEN
   (* generally the compensation is just allowed if the axis is referenced *)
   (* so we check here, if the axis is homed & enable the pitch compensation if so *)
   bEnablePitchCompensation := TRUE;
ELSE
   bEnablePitchCompensation := FALSE;
END_IF
fbPitchCompensation(
   Enable:= bEnablePitchCompensation ,
   pTable:= ADR(stXPitchTable),
   cbSize:= SIZEOF(stXPitchTable),
   ReferenceAxis:= in_stXNcToPlc,
   Desc:= stXDescPitch,
   Compensation=>fCompensationValue,
   Error=>bError,
   ErrorId=>nErrorId,
   Active=>bActive);

fbWritePosCorrection(
   Enable:=TRUE,
   PositionCorrectionValue:=fCompensationValue,
   CorrectionMode:= POSITIONCORRECTIONMODE_FAST,
   Acceleration:= 500,
   CorrectionLength:= ,
   AxisRefIn:= in_stXNcToPlc,
   AxisRefOut:= out_stXPlcToNc,
   Busy=> bLimiting,
   Error=> ,
   ErrorID=> ,
   Limiting=> );

 

Requirements

Development environment

Target system type

PLC libraries to be linked

from TwinCAT v2.10 Build 1314

PC (i386)

TcNc.Lib