<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4022.10">
  <POU Name="PRG_GroupAxesToNCI" Id="{da88b50e-0907-4bf3-ab18-4011430cf8ee}" SpecialFunc="None">
    <Declaration><![CDATA[PROGRAM PRG_GroupAxesToNCI
VAR_INPUT
	stMachineMode : ST_MachineMode;
END_VAR
VAR
	nChan: 			UINT;
	bAxisHomeG1:	BOOL;
	bAxisHomeG2:	BOOL;

	fbTrigBuildGroup: R_TRIG;
	fbTrigReleaseGroup: R_TRIG;
	fbBuildGroup1: FB_BuildGroup;
	fbBuildGroup2: FB_BuildGroup;
	fbReleaseGroup1: FB_ReleaseGroup;
	fbReleaseGroup2: FB_ReleaseGroup;
	bGroup1Release: BOOL := FALSE;
	bGroup2Release: BOOL := FALSE;
	nState :	UINT;
	bBuildGroup: BOOL;
	bClearGroup: BOOL;
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[(* ==========================================================*)
(*   PRG: GroupAxisToNci			        		         *)
(* ----------------------------------------------------------*)
(*   Desc: 													 *)
(*   Auth: MiB / TV                                          *)
(*   Date: 02.09.2005                                        *)
(*   Last: 02.04.2013                                        *)
(*   Rev.: 1.1                                               *)
(* ==========================================================*)


(* build axis3d groups *)

(* homing status of 1st group *)




(* p.wang
bAxisHomeG1 :=	arrAxis_Ref[1].NcToPlc.StateDWord.1 AND
				arrAxis_Ref[2].NcToPlc.StateDWord.1 AND
				arrAxis_Ref[3].NcToPlc.StateDWord.1;
				
*)
bBuildGroup := stMachineMode.Automatic OR stMachineMode.MDI;			(* this is an example condition for building a group *)
bClearGroup := stMachineMode.Homing OR stMachineMode.Manual;		(* this is an exmaple condition for releasing a group *)


fbTrigBuildGroup( clk := bBuildGroup );
IF fbTrigBuildGroup.Q THEN
	bGroup1 := TRUE;
	bGroup1Release := FALSE;
	bGroup2 := TRUE;
	bGroup2Release := FALSE;
	nState := 0;

END_IF

fbTrigReleaseGroup( clk := (bClearGroup) );
IF fbTrigReleaseGroup.Q THEN
	bGroup1 := FALSE;
	bGroup1Release := TRUE;
	bGroup2 := FALSE;
	bGroup2Release := TRUE;
	nState := 0;
END_IF


CASE nState OF

0: (* Wait for action *)
	IF bGroup1 OR bGroup1Release THEN
		nState := nState + 1;
	END_IF

1: (* Reset axis *)
	PRG_ResetAllAxesWithError(execute := TRUE);
	IF PRG_ResetAllAxesWithError.Done THEN
		IF bGroup1 THEN   (* buid group *)
			nState := 10;
		END_IF;
		IF bGroup1Release THEN
			nState := 20;	(* release group *)
		END_IF

	END_IF


10:(* build 1st group in channel2 *)
	nChan:= 2;
	fbBuildGroup1(
		bExec:= bGroup1 , //bExec:= bGroup1 AND bAxisHomeG1, p.wang
		nChan:= nChan,
		nXAxisId:=  arrAxis_Ref[1].NcToPlc.AxisId,
		nYAxisId:= arrAxis_Ref[2].NcToPlc.AxisId,
		nZAxisId:= ,
		nQ1AxisId:= ,
		nQ2AxisId:= ,
		nQ3AxisId:= ,
		nQ4AxisId:= ,
		nQ5AxisId:= ,
		nGroup => nGroup[nChan-1],
		bBusy=> ,
		bErr=> ,
		nErrId=> );


		(* homing status of 2nd group *)
		//bAxisHomeG2 := arrAxis_Ref[5].NcToPlc.StateDWord.1 AND
		//				   arrAxis_Ref[6].NcToPlc.StateDWord.1 AND
		//				   arrAxis_Ref[7].NcToPlc.StateDWord.1;

		(* build 2nd group in channel3 *)
		(*
		nChan:= 3;
		fbBuildGroup2(
			bExec:=bGroup2 AND bAxisHomeG2,
			nChan:= nChan,
			nXAxisId:= ,
			nYAxisId:= ,
			nZAxisId:= ,
			nQ1AxisId:= ,
			nQ2AxisId:= ,
			nQ3AxisId:= ,
			nQ4AxisId:= ,
			nQ5AxisId:= ,
			nGroup => nGroup[nChan-1],
			bBusy=> ,
			bErr=> ,
			nErrId=> );
			*)

	IF (NOT fbBuildGroup1.bBusy) AND NOT fbBuildGroup1.bErr AND bGroup1 (*AND (NOT fbBuildGroup2.bBusy) AND NOT fbBuildGroup2.bErr AND bGroup2 *) THEN
		fbBuildGroup1( bExec := FALSE );
		fbBuildGroup2( bExec := FALSE );
		bGroup1 := FALSE;
		bGroup2 := FALSE;
		nState := 0;
	END_IF

	IF ((NOT fbBuildGroup1.bBusy) AND fbBuildGroup1.bErr) OR ((NOT fbBuildGroup2.bBusy) AND fbBuildGroup2.bErr) THEN
		fbBuildGroup1( bExec := FALSE );
		fbBuildGroup2( bExec := FALSE );
		bGroup1 := TRUE;   (*bei Fehler nochmal versuchen *)
		bGroup2 := TRUE;   (*bei Fehler nochmal versuchen *)
		nState := 0;
	END_IF


20: (* release Group *)
			nChan:= 2;
			fbReleaseGroup1(
			bExec:= bGroup1Release,
			nChan:= nChan);
		IF (NOT fbReleaseGroup1.bBusy) AND NOT fbReleaseGroup1.bErr  AND bGroup1Release THEN
			fbReleaseGroup1( bExec := FALSE );
			bGroup1Release := FALSE;
			nState := 0;
		END_IF

		IF (NOT fbReleaseGroup1.bBusy) AND fbReleaseGroup1.bErr THEN
			fbReleaseGroup1( bExec := FALSE );
			bGroup1Release := TRUE; (* bei Fehler weiter versuchen, Gruppe aufzulösen *)
			nState := 0;
		END_IF

(*
			nChan:= 3;
			fbReleaseGroup2(
			bExec:= bGroup2Release,
			nChan:= nChan);
		IF (NOT fbReleaseGroup2.bBusy) AND NOT fbReleaseGroup2.bErr  AND bGroup2Release THEN
			fbReleaseGroup2( bExec := FALSE );
			bGroup2Release := FALSE;
			nState := 0;
		END_IF

		IF (NOT fbReleaseGroup2.bBusy) AND fbReleaseGroup2.bErr THEN
			fbReleaseGroup2( bExec := FALSE );
			bGroup2Release := TRUE; (* bei Fehler weiter versuchen, Gruppe aufzulösen *)
			nState := 0;
		END_IF
*)
END_CASE]]></ST>
    </Implementation>
    <LineIds Name="PRG_GroupAxesToNCI">
      <LineId Id="3" Count="162" />
      <LineId Id="2" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>