Garchev,
I understand the code part of what you are asking. I still do not know what you are using for your visualization i.e. Visual basic.net, wonderware, indusoft...etc. that's my first question as to the code I am trying to understand if you are intentionally trying to re-invent the wheel here?
the function blocks that are predefined in the PLC Open library meet most all of the requirements for doing industrial projects and in considering that someday there will be somebody else maintaining the machine they will be more easily recognizable by them.
If as it appears that you do not wish to use them then the first order of business that you will have to address is to create custom data types to handle the passing of the axis information similar to the ones that are in the NC control provided. shown here:
TYPE NCTOPLC_AXLESTRUCT
STRUCT
nStateDWord : DWORD; (* Status double word *)
nErrorCode : DWORD; (* Axis error code *)
nAxisState : DWORD; (* Axis moving status *)
nAxisModeCon : DWORD; (* Axis mode (feedback from NC) *)
nCalibrationState : DWORD; (* State of axis calibration (homing) *)
nCoupleState : DWORD; (* Axis coupling state *)
nSvbEntries : DWORD; (* SVB entries/orders (SVB = Set preparation task) *)
nSafEntries : DWORD; (* SAF entries/orders (SAF = Set execution task *)
nAxisId : DWORD; (* Axis ID *)
nOpModeDWord : DWORD; (* Current operation mode *)
nCtrlLoopIndex : DWORD; (* Axis control loop index ( old variable: nReserved2_HIDDEN : DWORD )*)
fPosIst : LREAL; (* Current position (absolut value from NC) *)
fModuloPosIst : LREAL; (* Current position as modulo value (e.g. in degrees) *)
nModuloTurns : DINT; (* Modulo turns *)
fVeloIst : LREAL; (* Current velocity (optional) *)
fPosDiff : LREAL; (* Position difference (lag distance) *)
fPosSoll : LREAL; (* Setpoint position *)
fVeloSoll : LREAL; (* Setpoint velocity *)
fAccSoll : LREAL; (* Setpoint acceleration ( old variable: fReserve1_HIDDEN : LREAL ) *)
fReserve2_HIDDEN : LREAL; (* reserved *)
fReserve3_HIDDEN : LREAL; (* reserved *)
fReserve4_HIDDEN : LREAL; (* reserved *)
END_STRUCT
END_TYPE
and here:
TYPE PLCTONC_AXLESTRUCT
STRUCT
nDeCtrlDWord : DWORD; (* Control double word *)
nOverride : DWORD; (* Velocity override *)
nAxisModeReq : DWORD; (* Axis operating mode (PLC request) *)
nAxisModeDWord : DWORD; (* *)
fAxisModeLReal : LREAL; (* *)
fActPosCorrection : LREAL; (* Correction value for current position *)
nReserved_HIDDEN : ARRAY [32..127] OF BYTE;
END_STRUCT
END_TYPE
then you will need to set the scan time of your plc in such a way that the information is passed to the PLC as soon as there is new information available which will require you to know your network update time and re-act accordingly.
Then you will need to begin writing move blocks with your PIDs integrated into them to do your corrections on the fly no mean feat in and of itself especially when they have been done in advance for you as shown here:
MC_MoveAbsolute(
Execute:= ,
Position:= ,
Velocity:= ,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
Axis:= ,
Done=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
or
MC_MoveAbsoluteOrRestart(
Execute:= ,
Position:= ,
Velocity:= ,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
Axis:= ,
Done=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
These blocks are defined for all controllers not just TwinCAT which means that everyone following behind you will be able to read them and understand what your trying to do.
If you still want to follow this course set up the structures and I will try to help as I am able as long as you understand that this is no small project.
good luck
Keeper