<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4022.10">
  <POU Name="ExSetPostion" Id="{cddfe106-2c4f-4416-93b3-366f150d3cbe}" SpecialFunc="None">
    <Declaration><![CDATA[PROGRAM ExSetPostion
VAR
	fbxtSetPointGenEnable: MC_ExtSetPointGenEnable;
	fbExtSetPointGenDisable: MC_ExtSetPointGenDisable;
	bExtGenEnable: BOOL;
	rExGenPostion: LREAL;
	bExGenDisable: BOOL;
	rExGenSpeed: LREAL;
	fTaskCycleTime: LREAL;
	rtEXSet:Tc2_Standard.R_TRIG;
	rgap: LREAL;
	rgenpos: LREAL;
	X: LREAL;
	rhigh: LREAL:=360;
	rstart: LREAL;
	rf: LREAL := 1;
	rspeedgen: LREAL;
	sc: LREAL := 1000;
	ssine: LREAL;
	TaskInfo1												:	TaskInfoCtrl;
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[RETURN;
TaskInfo1(
	Index=> , 
	TaskName=> , 
	ObjId=> , 
	CycleTime=> , 
	CycleTimeMS=> , 
	CycleTimeFloat=> , 
	Priority=> , 
	AdsPort=> , 
	CycleCount=> , 
	DcTaskTime=> , 
	LastExecTime=> , 
	FirstCycle=> , 
	CycleTimeExceeded=> , 
	CycleTimeExceededCount=> );
//===================================外部设定值需要自己进行平滑，NC的路径规划对这个应用不起作用=========================
//fTaskCycleTime:=MAX(UDINT_TO_LREAL(SystemTaskInfoArr[1].cycleTime)/10000000.0,0.001);
rtEXSet(CLK:=bExtGenEnable , Q=> );
IF  rtEXSet.Q THEN
	rstart:=	motion[2].axis.NcToPlc.SetPos;
	X:=0;
END_IF

X:=X+0.001*360/rf;
IF X>=360 THEN
	X:=0;
END_IF
ssine:=SIN(X*2*3.14159/360);
   rgenpos:=SIN(X*2*3.14159/360)*rhigh;
   


	rExGenPostion:=rstart+rgenpos;
(*
IF   rExGenPostion>motion[2].axis.NcToPlc.SetPos THEN
	   IF  rExGenPostion-motion[2].axis.NcToPlc.SetPos>rExGenSpeed THEN
		rExGenPostion:=motion[2].axis.NcToPlc.SetPos+rExGenSpeed;
		ELSE
		;
		END_IF
		
ELSIF   rExGenPostion<motion[2].axis.NcToPlc.SetPos THEN
		IF  ABS(rExGenPostion-motion[2].axis.NcToPlc.SetPos)>rExGenSpeed THEN
		rExGenPostion:=motion[2].axis.NcToPlc.SetPos-rExGenSpeed;
		ELSE
		;
		END_IF
		
END_IF
	*)
	
	rspeedgen:=rgenpos*sc;
	
	fbxtSetPointGenEnable(
	Axis:=motion[2].axis , 
	Execute:=bExtGenEnable , 
	Position:=0 , 
	PositionType:= , 
	Done=> , 
	Busy=> , 
	Error=> , 
	ErrorID=> , 
	Enabled=> );
	
fbExtSetPointGenDisable(
	Axis:= motion[2].axis, 
	Execute:= NOT bExtGenEnable , 
	Done=> , 
	Busy=> , 
	Error=> , 
	ErrorID=> , 
	Enabled=> );
	MC_ExtSetPointGenFeed(
	0,//rExGenPostion , (*位置*)
	rspeedgen,// Motion[1].AXIS.NcToPlc.SetVelo,//rspeedgen,//Motion[1].AXIS.NcToPlc.SetVelo, (*速度*)
	0,//Motion[1].AXIS.NcToPlc.SetAcc, (*加速度*)
    1, (*方向*)
	motion[2].axis );
	
]]></ST>
    </Implementation>
    <LineIds Name="ExSetPostion">
      <LineId Id="103" Count="0" />
      <LineId Id="3" Count="78" />
      <LineId Id="2" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>