(*********************************************

  Import-Export
  Version   := RSLogix 5000 v19.01
  Owner     := Danaher Associate, Danaher Motion
  Exported  := Fri Dec 05 10:55:26 2014

  Note:  File encoded in UTF-8.  Only edit file in a program 
         which supports UTF-8 (like Notepad, not Wordpad).

**********************************************)
IE_VER := 2.10;

CONTROLLER Example_PLC (ProcessorType := "1769-L32E",
                        Major := 19,
                        TimeSlice := 20,
                        ShareUnusedTimeSlice := 1,
                        RedundancyEnabled := 0,
                        KeepTestEditsOnSwitchOver := 0,
                        DataTablePadPercentage := 50,
                        SecurityCode := 0,
                        SFCExecutionControl := "CurrentActive",
                        SFCRestartPosition := "MostRecent",
                        SFCLastScan := "DontScan",
                        SerialNumber := 16#4054_9ec2,
                        MatchProjectToController := No,
                        CanUseRPIFromProducer := No,
                        InhibitAutomaticFirmwareUpdate := 0)
	DATATYPE AKD_Axis (Description := "Axis Data:$N",
	                   FamilyType := NoFamily)
		AKD_Control Control (Description := "Control bits to send to the drive");
		AKD_Status Status (Description := "Status bits received from the drive");
		AB:ETHERNET_MODULE_SINT_64Bytes:I:0 Input (Description := "Data from the drive");
		AB:ETHERNET_MODULE_SINT_64Bytes:O:0 Output (Description := "Data to the drive");
		SINT ResponseMsgType (Description := "Response type contained in latest IO response from drive. Used to check for errors");
		INT CommandTimeout (Description := "Time to allow for command response from drive. Dependent on scan rate and communicaiton rate");
		DINT PositionFeedback (Description := "Actual Position Value");
		DINT VelocityFeedback (Description := "Actual Velocity Value");
	END_DATATYPE

	DATATYPE AKD_Control (Description := "Send Explicit Message",
	                      FamilyType := NoFamily)
		SINT ZZZZZZZZZZAKD_Contro0 (Hidden := 1);
		BIT Load_Data_Start_Profile ZZZZZZZZZZAKD_Contro0 : 0 (Description := "Load Command Data / $NStart Profile Move");
		BIT Start_Block ZZZZZZZZZZAKD_Contro0 : 1 (Description := "Execute Command block or block chain");
		BIT Incremental ZZZZZZZZZZAKD_Contro0 : 2 (Description := "Incremental Position (0=Absolute, 1=Incremental)");
		BIT Direction ZZZZZZZZZZAKD_Contro0 : 3 (Description := "Direction in Velocity Mode (0=Reverse, 1=Forward)");
		BIT Smooth_Stop ZZZZZZZZZZAKD_Contro0 : 4 (Description := "Smooth / Controlled Stop w/ Deceleration");
		BIT Hard_Stop ZZZZZZZZZZAKD_Contro0 : 5 (Description := "Hard / Immediate Stop");
		BIT Reg_Arm ZZZZZZZZZZAKD_Contro0 : 6 (Description := "Arm the Registration Input");
		BIT Enable ZZZZZZZZZZAKD_Contro0 : 7 (Description := "Enable Output");
	END_DATATYPE

	DATATYPE AKD_Status (Description := "All connections to the drive ethernet module are established and data is successfully transferring.",
	                     FamilyType := NoFamily)
		SINT ZZZZZZZZZZAKD_Status0 (Hidden := 1);
		BIT Profile_In_Progress ZZZZZZZZZZAKD_Status0 : 0 (Description := "Profile Move In Progress");
		BIT Block_In_Execution ZZZZZZZZZZAKD_Status0 : 1 (Description := "Block In Execution");
		BIT On_Target_Position ZZZZZZZZZZAKD_Status0 : 2 (Description := "On Target Position (1=Current Position Equals Last Target Position)");
		BIT General_Fault ZZZZZZZZZZAKD_Status0 : 3 (Description := "General Fault");
		BIT Current_Direction ZZZZZZZZZZAKD_Status0 : 4 (Description := "Current Motor Direction (0=Reverse, 1=Forward)");
		BIT Home_Level ZZZZZZZZZZAKD_Status0 : 5 (Description := "Level of Home Input");
		BIT Reg_Level ZZZZZZZZZZAKD_Status0 : 6 (Description := "Level of Registration Input");
		BIT Enable ZZZZZZZZZZAKD_Status0 : 7 (Description := "State of Enable Output");
		SINT ZZZZZZZZZZAKD_Status9 (Hidden := 1);
		BIT Fault_Input_Fault ZZZZZZZZZZAKD_Status9 : 0 (Description := "Fault Input Active");
		BIT Fwd_Limit ZZZZZZZZZZAKD_Status9 : 1 (Description := "Forward Input Active");
		BIT Rev_Limit ZZZZZZZZZZAKD_Status9 : 2 (Description := "Reverse Input Active");
		BIT Positive_Limit ZZZZZZZZZZAKD_Status9 : 3 (Description := "Positive Software Limit Exceeded");
		BIT Negative_Limit ZZZZZZZZZZAKD_Status9 : 4 (Description := "Negative Software Limit Exceeded");
		BIT FE_Fault ZZZZZZZZZZAKD_Status9 : 5 (Description := "Following Error Fault");
		BIT Block_Fault ZZZZZZZZZZAKD_Status9 : 6 (Description := "Block Execution Fault");
		BIT Load_Complete ZZZZZZZZZZAKD_Status9 : 7 (Description := "Command Message Successfully Loaded");
	END_DATATYPE

	DATATYPE Motion_Task (FamilyType := NoFamily)
		LINT Accel (Description := "MT.ACC Acceleration");
		DINT ControlWord (Description := "MT.CNTL",
		                 Radix := Hex);
		LINT Decel (Description := "MT.DEC");
		INT Delay (Description := "MT.TNEXT Delay before executing next task");
		SINT NextNum (Description := "MT.TNEXT Number of next task to execute");
		LINT Position (Description := "MT.P Target Position");
		SINT Num (Description := "MT.NUM Number of this task in the table");
		LINT Velocity (Description := "MT.V Target Velocity");
		SINT Set (Description := "Used to command a set of the MT. Should always equal 1");
	END_DATATYPE

	MODULE Controller (Parent := "Controller",
	                   ParentModPortId := 1,
	                   CatalogNumber := "1769-L32E",
	                   Vendor := 1,
	                   ProductType := 14,
	                   ProductCode := 77,
	                   Major := 19,
	                   Minor := 11,
	                   PortLabel := "RxBACKPLANE",
	                   ChassisSize := 4,
	                   Slot := 0,
	                   Mode := 2#0000_0000_0000_0001,
	                   CompatibleModule := 0,
	                   KeyMask := 2#0000_0000_0001_1111)
	END_MODULE

	MODULE LocalENB (Parent := "Controller",
	                 ParentModPortId := 1,
	                 CatalogNumber := "1769-L32E Ethernet Port",
	                 Vendor := 1,
	                 ProductType := 12,
	                 ProductCode := 158,
	                 Major := 19,
	                 Minor := 11,
	                 PortLabel := "RxBACKPLANE",
	                 Slot := 1,
	                 NodeAddress := "10.8.46.172",
	                 Mode := 2#0000_0000_0000_0000,
	                 CompatibleModule := 0,
	                 KeyMask := 2#0000_0000_0000_0000)
	END_MODULE

	MODULE AKD_1 (Parent := "LocalENB",
	              ParentModPortId := 2,
	              CatalogNumber := "ETHERNET-MODULE",
	              Vendor := 1,
	              ProductType := 0,
	              ProductCode := 18,
	              Major := 1,
	              Minor := 1,
	              PortLabel := "ENet",
	              NodeAddress := "10.8.46.174",
	              CommMethod := 536870916,
	              ConfigMethod := 8388612,
	              Mode := 2#0000_0000_0000_0000,
	              CompatibleModule := 0,
	              KeyMask := 2#0000_0000_0000_0000,
	              PrimCxnInputSize := 64,
	              PrimCxnOutputSize := 64,
	              SecCxnInputSize := 0,
	              SecCxnOutputSize := 0)
			ConfigData  := [4,100,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];
			CONNECTION Standard (Rate := 40000,
			                     InputCxnPoint := 102,
			                     InputSize := 64,
			                     OutputCxnPoint := 101,
			                     OutputSize := 64,
			                     EventID := 0,
			                     Unicast := Yes)
					InputData  := [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];
					InputForceData := [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
					OutputData  := [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];
					OutputForceData := [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
			END_CONNECTION

	END_MODULE

	MODULE Local (Parent := "Controller",
	              ParentModPortId := 1,
	              CatalogNumber := "CompactBus",
	              Vendor := 1,
	              ProductType := 12,
	              ProductCode := 71,
	              Major := 19,
	              Minor := 11,
	              PortLabel := "RxBACKPLANE",
	              ChassisSize := 17,
	              Slot := 3,
	              CommMethod := 805306369,
	              Mode := 2#0000_0000_0000_0001,
	              CompatibleModule := 0,
	              KeyMask := 2#0000_0000_0001_1111)
			ExtendedProp := [[[___<public><ConfigID>901</ConfigID></public>___]]]
	END_MODULE

	ADD_ON_INSTRUCTION_DEFINITION AKD_Disable (Description := "Disable Drive",
	                                           Revision := "2.1",
	                                           RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                           ExecutePrescan := Yes,
	                                           ExecutePostscan := No,
	                                           ExecuteEnableInFalse := Yes,
	                                           CreatedDate := "2011-02-23T21:41:33.886Z",
	                                           CreatedBy := "DMC-678852CBE2A\Administrator",
	                                           EditedDate := "2014-10-29T18:11:02.240Z",
	                                           EditedBy := "DHRMOTION\radprod075",
	                                           SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,200,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse 
				RC: "Initialize Instruction Variables when Not Executing";
				N: RES(Command_Timeout);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Clear enable bit";
				N: OTU(Axis.Control.Enable);
				RC: "Set Done bit when the disabled response is returned";
				N: XIO(Axis.Status.Enable)OTE(DN);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: XIC(Axis.Status.Enable)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTE(ER);
		END_ROUTINE

		ROUTINE Prescan 
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Drive (Description := "Drive Communication",
	                                         Revision := "2.0",
	                                         ExecutePrescan := Yes,
	                                         ExecutePostscan := No,
	                                         ExecuteEnableInFalse := No,
	                                         CreatedDate := "2011-03-08T16:31:06.014Z",
	                                         CreatedBy := "DMC-678852CBE2A\Administrator",
	                                         EditedDate := "2014-10-29T18:11:02.246Z",
	                                         EditedBy := "DHRMOTION\radprod075",
	                                         SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			Axis_Input : AB:ETHERNET_MODULE_SINT_64Bytes:I:0 (Usage := InOut,
			                      Required := Yes,
			                      Visible := Yes);
			Axis_Output : AB:ETHERNET_MODULE_SINT_64Bytes:O:0 (Usage := InOut,
			                       Required := Yes,
			                       Visible := Yes);
			Axis_Internal : AKD_Axis (Usage := InOut,
			                         Required := Yes,
			                         Visible := Yes);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			Response_Bytes : SINT[8] (RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := "[0,0,0,0,0,0,0,0]");
		END_LOCAL_TAGS

		ROUTINE Logic 
				RC: "=========================$N"
				    "Response Message$N"
				    "=========================$N"
				    "$N"
				    "Read Response Message from Drive";
				N: CPS(Axis_Input,Axis_Internal.Input,1);
				RC: "Read Status Byte 0 to internal structure";
				N: XIC(Axis_Internal.Input.Data[0].0)OTE(Axis_Internal.Status.Profile_In_Progress);
				N: XIC(Axis_Internal.Input.Data[0].1)OTE(Axis_Internal.Status.Block_In_Execution);
				N: XIC(Axis_Internal.Input.Data[0].2)OTE(Axis_Internal.Status.On_Target_Position);
				N: XIC(Axis_Internal.Input.Data[0].3)OTE(Axis_Internal.Status.General_Fault);
				N: XIC(Axis_Internal.Input.Data[0].4)OTE(Axis_Internal.Status.Current_Direction);
				N: XIC(Axis_Internal.Input.Data[0].5)OTE(Axis_Internal.Status.Home_Level);
				N: XIC(Axis_Internal.Input.Data[0].6)OTE(Axis_Internal.Status.Reg_Level);
				N: XIC(Axis_Internal.Input.Data[0].7)OTE(Axis_Internal.Status.Enable);
				RC: "Read Status Byte 2 to internal structure";
				N: XIC(Axis_Internal.Input.Data[2].0)OTE(Axis_Internal.Status.Fault_Input_Fault);
				N: XIC(Axis_Internal.Input.Data[2].1)OTE(Axis_Internal.Status.Fwd_Limit);
				N: XIC(Axis_Internal.Input.Data[2].2)OTE(Axis_Internal.Status.Rev_Limit);
				N: XIC(Axis_Internal.Input.Data[2].3)OTE(Axis_Internal.Status.Positive_Limit);
				N: XIC(Axis_Internal.Input.Data[2].4)OTE(Axis_Internal.Status.Negative_Limit);
				N: XIC(Axis_Internal.Input.Data[2].5)OTE(Axis_Internal.Status.FE_Fault);
				N: XIC(Axis_Internal.Input.Data[2].6)OTE(Axis_Internal.Status.Block_Fault);
				N: XIC(Axis_Internal.Input.Data[2].7)OTE(Axis_Internal.Status.Load_Complete);
				RC: "Copy response type into data variable";
				N: AND(Axis_Internal.Input.Data[3],16#1F,Axis_Internal.ResponseMsgType);
				RC: "Read Position from Bytes 8-11.";
				N: COP(Axis_Internal.Input.Data[8],Axis_Internal.PositionFeedback,4);
				RC: "Read Velocity from Bytes 12-15";
				N: COP(Axis_Internal.Input.Data[12],Axis_Internal.VelocityFeedback,4);
				RC: "=========================$N"
				    "Command Message$N"
				    "=========================$N"
				    "$N"
				    "Write Control to internal Byte 0";
				N: XIC(Axis_Internal.Control.Load_Data_Start_Profile)OTE(Axis_Internal.Output.Data[0].0);
				N: XIC(Axis_Internal.Control.Start_Block)OTE(Axis_Internal.Output.Data[0].1);
				N: XIC(Axis_Internal.Control.Incremental)OTE(Axis_Internal.Output.Data[0].2);
				N: XIC(Axis_Internal.Control.Direction)OTE(Axis_Internal.Output.Data[0].3);
				N: XIC(Axis_Internal.Control.Smooth_Stop)OTE(Axis_Internal.Output.Data[0].4);
				N: XIC(Axis_Internal.Control.Hard_Stop)OTE(Axis_Internal.Output.Data[0].5);
				N: XIC(Axis_Internal.Control.Reg_Arm)OTE(Axis_Internal.Output.Data[0].6);
				N: XIC(Axis_Internal.Control.Enable)OTE(Axis_Internal.Output.Data[0].7);
				RC: "Write the command data from the internal Axis object to the externally communicated Axis_Output.";
				N: CPS(Axis_Internal.Output,Axis_Output,1);
		END_ROUTINE

		ROUTINE Prescan 
				RC: "Initialize control structure bits before the first scan.";
				N: OTU(Axis_Internal.Control.Load_Data_Start_Profile)OTU(Axis_Internal.Control.Start_Block)OTU(Axis_Internal.Control.Incremental)OTU(Axis_Internal.Control.Direction);
				N: OTU(Axis_Internal.Control.Smooth_Stop)OTU(Axis_Internal.Control.Hard_Stop)OTU(Axis_Internal.Control.Reg_Arm)OTU(Axis_Internal.Control.Enable);
				N: FLL(0,Axis_Internal.Output.Data[0],64);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Enable (Description := "Enables Drive",
	                                          Revision := "2.0",
	                                          ExecutePrescan := Yes,
	                                          ExecutePostscan := No,
	                                          ExecuteEnableInFalse := Yes,
	                                          CreatedDate := "2011-02-23T21:41:33.886Z",
	                                          CreatedBy := "DMC-678852CBE2A\Administrator",
	                                          EditedDate := "2014-10-29T18:11:02.248Z",
	                                          EditedBy := "DHRMOTION\radprod075",
	                                          SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,2000,0]");
			Transition : BOOL (Description := "Marker to transition enable bit if required.",
			                     RADIX := Decimal,
			                     ExternalAccess := Read/Write,
			                     DefaultData := 0);
			Transition_Complete : BOOL (Description := "Flag to indicate that no further transistion is required.",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse 
				RC: "Initialize Instruction Variables when Not Executing";
				N: RES(Command_Timeout);
		END_ROUTINE

		ROUTINE Logic 
				N: XIO(Axis.Status.General_Fault)OTL(Axis.Control.Enable);
				RC: "Set Done bit when the enabled response is returned";
				N: XIC(Axis.Status.Enable)OTE(DN);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: XIO(Axis.Status.Enable)TON(Command_Timeout,?,?);
				RC: "Set Error bit when a general fault is present on the drive or the command message has timed out without the desired response.";
				N: [XIC(Axis.Status.General_Fault) ,XIC(Command_Timeout.DN) ]OTE(ER);
		END_ROUTINE

		ROUTINE Prescan 
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: RES(Command_Timeout)MOV(2000,Command_Timeout.PRE);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Accel (Description := "Set Drive Acceleration",
	                                             Revision := "2.1",
	                                             RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                             ExecutePrescan := Yes,
	                                             ExecutePostscan := No,
	                                             ExecuteEnableInFalse := Yes,
	                                             CreatedDate := "2011-02-23T21:41:33.886Z",
	                                             CreatedBy := "DMC-678852CBE2A\Administrator",
	                                             EditedDate := "2014-10-29T18:11:02.289Z",
	                                             EditedBy := "DHRMOTION\radprod075",
	                                             SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Accel : DINT (Description := "Acceleration",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Response_Bytes : SINT[8] (RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := "[0,0,0,0,0,0,0,0]");
			Accel_Internal : DINT (Description := "Scaled Accel Value for Drive",
			                         RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := 0);
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,100,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Response_Message_Type : SINT (Description := "Response Message Type",
			                                RADIX := Decimal,
			                                ExternalAccess := Read/Write,
			                                DefaultData := 0);
			Response_Axis_Number : SINT (Description := "Response Axis Number",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 03 hex Acceleration.";
				N: MOV(16#03,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Response Axis Number (bits 5-7) to Byte 3 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Response_Axis_Number);
				N: XIC(Response_Axis_Number.2)OTE(Command_Bytes[3].7);
				N: XIC(Response_Axis_Number.1)OTE(Command_Bytes[3].6);
				N: XIC(Response_Axis_Number.0)OTE(Command_Bytes[3].5);
				RC: "Write Command Data to Command Bytes 4-7.";
				N: MUL(Accel,1,Accel_Internal)COP(Accel_Internal,Command_Bytes[4],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Decel (Description := "Set Drive Deceleration",
	                                             Revision := "2.1",
	                                             RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                             ExecutePrescan := Yes,
	                                             ExecutePostscan := No,
	                                             ExecuteEnableInFalse := Yes,
	                                             CreatedDate := "2011-02-23T21:41:33.886Z",
	                                             CreatedBy := "DMC-678852CBE2A\Administrator",
	                                             EditedDate := "2014-10-29T18:11:02.300Z",
	                                             EditedBy := "DHRMOTION\radprod075",
	                                             SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Decel : DINT (Description := "Acceleration",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Response_Bytes : SINT[8] (RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Decel_Internal : DINT (Description := "Scaled Decel Value for Drive",
			                         RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := 0);
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,100,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Response_Message_Type : SINT (Description := "Response Message Type",
			                                RADIX := Decimal,
			                                ExternalAccess := Read/Write,
			                                DefaultData := 0);
			Response_Axis_Number : SINT (Description := "Response Axis Number",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 04 hex Deceleration.";
				N: MOV(16#04,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Response Axis Number (bits 5-7) to Byte 3 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Response_Axis_Number);
				N: XIC(Response_Axis_Number.2)OTE(Command_Bytes[3].7);
				N: XIC(Response_Axis_Number.1)OTE(Command_Bytes[3].6);
				N: XIC(Response_Axis_Number.0)OTE(Command_Bytes[3].5);
				RC: "Write Command Data to Command Bytes 4-7.";
				N: MUL(Decel,1,Decel_Internal)COP(Decel_Internal,Command_Bytes[4],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Velocity (Description := "Set Drive Velocity",
	                                                Revision := "2.1",
	                                                RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                                ExecutePrescan := Yes,
	                                                ExecutePostscan := No,
	                                                ExecuteEnableInFalse := Yes,
	                                                CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                EditedDate := "2014-10-29T18:11:02.324Z",
	                                                EditedBy := "DHRMOTION\radprod075",
	                                                SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Velocity : DINT (Description := "Velocity",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := Yes,
			                    Visible := Yes,
			                    DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Response_Bytes : SINT[8] (RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Velocity_Internal : DINT (Description := "Scaled Velocity Value for Drive",
			                            RADIX := Decimal,
			                            ExternalAccess := Read/Write,
			                            DefaultData := 0);
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,100,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Response_Message_Type : SINT (Description := "Response Message Type",
			                                RADIX := Decimal,
			                                ExternalAccess := Read/Write,
			                                DefaultData := 0);
			Response_Axis_Number : SINT (Description := "Response Axis Number",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 02 hex Target Velocity";
				N: MOV(16#02,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Response Axis Number (bits 5-7) to Byte 3 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Response_Axis_Number);
				N: XIC(Response_Axis_Number.2)OTE(Command_Bytes[3].7);
				N: XIC(Response_Axis_Number.1)OTE(Command_Bytes[3].6);
				N: XIC(Response_Axis_Number.0)OTE(Command_Bytes[3].5);
				RC: "Write Command Data to Command Bytes 4-7.";
				N: MUL(Velocity,1,Velocity_Internal)COP(Velocity_Internal,Command_Bytes[4],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Jog (Description := "Motion Axis Jog",
	                                       Revision := "2.3",
	                                       RevisionNote := "Remove unused IP output",
	                                       ExecutePrescan := Yes,
	                                       ExecutePostscan := No,
	                                       ExecuteEnableInFalse := Yes,
	                                       CreatedDate := "2011-02-23T21:41:33.886Z",
	                                       CreatedBy := "DMC-678852CBE2A\Administrator",
	                                       EditedDate := "2014-10-29T18:11:02.275Z",
	                                       EditedBy := "DHRMOTION\radprod075",
	                                       SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Accel : DINT (Description := "Acceleration",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
			Decel : DINT (Description := "Deceleration",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
			Direction : BOOL (Description := "1=Forward/Positive, 0=Reverse/Negative",
			                     Usage := Input,
			                     RADIX := Decimal,
			                     Required := Yes,
			                     Visible := Yes,
			                     DefaultData := 0);
			Speed : DINT (Description := "Jog Speed",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
			DN : BOOL (Description := "Command Successfully Initiated",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Accel_Internal : DINT (Description := "Scaled Accel Value for Drive",
			                         RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := 0);
			Set_Enable : AKD_Enable (ExternalAccess := Read/Write,
			                     DefaultData := "[1,[0,0,0]]");
			Set_Accel : AKD_Set_Accel (ExternalAccess := Read/Write,
			                    DefaultData := "[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0]");
			Set_Decel : AKD_Set_Decel (ExternalAccess := Read/Write,
			                    DefaultData := "[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0]");
			Set_Velocity : AKD_Set_Velocity (ExternalAccess := Read/Write,
			                       DefaultData := "[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0]");
			Step : SINT (Description := "Sequence Step Number",
			               RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Command_Axis_Number : SINT (RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Response_Axis_Number : SINT (RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			OS_Start_Sequence : BOOL (RADIX := Decimal,
			                            ExternalAccess := Read/Write,
			                            DefaultData := 0);
			Command_Bytes : SINT[64] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]");
			ErrorData : SINT[8] (RADIX := Hex,
			                    ExternalAccess := Read/Write,
			                    DefaultData := "[0,0,0,0,0,0,0,0]");
			Command_Timeout : TIMER (ExternalAccess := Read/Write,
			                          DefaultData := "[0,100,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_Start_Sequence)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_Start_Sequence)OTU(ER)OTU(DN)MOV(0,Step);
				RC: "Set Error bit when a general fault is present on the drive or the drive is disabled";
				N: XIC(Axis.Status.General_Fault)OTL(ER)MOV(-5,Step);
				N: XIO(Axis.Status.Enable)OTL(ER)MOV(-6,Step);
				N: XIC(Direction)OTE(Axis.Control.Direction);
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 07 Jog";
				N: MOV(16#07,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Response Axis Number (bits 5-7) to Byte 3 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Response_Axis_Number);
				N: XIC(Response_Axis_Number.2)OTE(Command_Bytes[3].7);
				N: XIC(Response_Axis_Number.1)OTE(Command_Bytes[3].6);
				N: XIC(Response_Axis_Number.0)OTE(Command_Bytes[3].5);
				RC: "Write Velocity to Command Bytes 12-15";
				N: COP(Speed,Command_Bytes[12],4);
				RC: "Write Acceleration to Command Bytes 16-19";
				N: COP(Accel,Command_Bytes[16],4);
				RC: "Write Deceleration to Command Bytes 20-23";
				N: COP(Decel,Command_Bytes[20],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)COP(Axis.Input.Data[0],ErrorData[0],8)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],24);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_Start_Sequence)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Parameter (Description := "Set Drive Parameter",
	                                                 Revision := "2.0",
	                                                 ExecutePrescan := Yes,
	                                                 ExecutePostscan := No,
	                                                 ExecuteEnableInFalse := Yes,
	                                                 CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                 CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                 EditedDate := "2014-10-29T18:11:02.309Z",
	                                                 EditedBy := "DHRMOTION\radprod075",
	                                                 SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Parameter_Number : INT (Description := "See help (F1) for parameter list.",
			                            Usage := Input,
			                            RADIX := Decimal,
			                            Required := No,
			                            Visible := Yes,
			                            DefaultData := 0);
			Parameter_Value : DINT (Description := "Parameter Value",
			                           Usage := Input,
			                           RADIX := Decimal,
			                           Required := Yes,
			                           Visible := Yes,
			                           DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,10000,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Temp_Bytes : SINT[2] (Description := "Temporary Bytes to Split into Command Bytes",
			                     RADIX := Decimal,
			                     ExternalAccess := Read/Write,
			                     DefaultData := "[0,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 1F hex Position Controller Parameter";
				N: MOV(16#1F,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.$N"
				    "$N"
				    "TODO:  Add axis ID number to the AKD_Axis data type to be supplied dynamically here.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Parameter Instance Number to Command Bytes 4-5";
				N: COP(Parameter_Number,Command_Bytes[4],2);
				RC: "Write Get/Set Parameter Flag to byte 6$N"
				    "Get parameter = 0$N"
				    "Set parameter = 1";
				N: MOV(1,Command_Bytes[6]);
				RC: "Write Parameter Value to bytes 24-27";
				N: COP(Parameter_Value,Axis.Output.Data[24],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(10000,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Fault_Reset (Description := "Drive Fault Reset",
	                                               Revision := "2.0",
	                                               ExecutePrescan := Yes,
	                                               ExecutePostscan := No,
	                                               ExecuteEnableInFalse := Yes,
	                                               CreatedDate := "2011-02-23T21:41:33.886Z",
	                                               CreatedBy := "DMC-678852CBE2A\Administrator",
	                                               EditedDate := "2014-10-29T18:11:02.251Z",
	                                               EditedBy := "DHRMOTION\radprod075",
	                                               SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
		END_PARAMETERS

		LOCAL_TAGS
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Set_Parameter : AKD_Set_Parameter (ExternalAccess := Read/Write,
			                        DefaultData := "[1,113,0,[0,10000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: MOV(0,Step);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Parameter 113 - Drive Clear Faults";
				N: EQU(Step,1)AKD_Set_Parameter(Set_Parameter,Axis,1)[XIC(Set_Parameter.DN) OTL(DN) MOV(2,Step) ,XIC(Set_Parameter.ER) OTL(ER) MOV(-1,Step) ];
				RC: "Reset DN (Done) and ER (Error) Status Output Bits";
				N: EQU(Step,0)OTU(DN)OTU(ER)MOV(1,Step);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: MOV(0,Step);
				RC: "Parameter 113 - CLRFAULTS. Set value 1 to execute a command";
				N: MOV(113,Set_Parameter.Parameter_Number)MOV(1,Set_Parameter.Parameter_Value);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Get_Attribute (Description := "Get Position Controller Attribute",
	                                                 Revision := "2.1",
	                                                 RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                                 ExecutePrescan := Yes,
	                                                 ExecutePostscan := No,
	                                                 ExecuteEnableInFalse := Yes,
	                                                 CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                 CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                 EditedDate := "2014-10-29T18:11:02.254Z",
	                                                 EditedBy := "DHRMOTION\radprod075",
	                                                 SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Attribute_Number : INT (Description := "Attribute Number (see help for options)",
			                            Usage := Input,
			                            RADIX := Decimal,
			                            Required := No,
			                            Visible := Yes,
			                            DefaultData := 0);
			Attribute_Value : DINT (Description := "Attribute Value",
			                           Usage := Output,
			                           RADIX := Decimal,
			                           Required := Yes,
			                           Visible := Yes,
			                           ExternalAccess := Read Only,
			                           DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,100,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			ErrorSource : SINT (RADIX := Decimal,
			                      ExternalAccess := Read/Write,
			                      DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)OTU(ER)OTU(DN);
				RC: "Write Attribute to Get to Byte 32$N"
				    "Attribute Number Input.";
				N: MOV(Attribute_Number,Axis.Output.Data[32]);
				RC: "Check for an error response";
				N: EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,ErrorSource);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: XIO(DN)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,ErrorSource);
				RC: "Wait for attribute we are requesting to show up in response$N"
				    "set done bit and copy data (bytes 24-27) to output.$N"
				    "Continue to read value as long as instruction is enabled";
				N: XIO(ER)EQU(Axis.Input.Data[32],Attribute_Number)COP(Axis.Input.Data[24],Attribute_Value,4)OTL(DN);
				RC: "If there is an error, clear the attribute request so we don$'t cause further errors";
				N: XIC(ER)MOV(0,Axis.Output.Data[32]);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Attribute (Description := "Set Position Controller Attribute",
	                                                 Revision := "2.1",
	                                                 RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                                 ExecutePrescan := Yes,
	                                                 ExecutePostscan := No,
	                                                 ExecuteEnableInFalse := Yes,
	                                                 CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                 CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                 EditedDate := "2014-10-29T18:11:02.295Z",
	                                                 EditedBy := "DHRMOTION\radprod075",
	                                                 SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Attribute_Number : INT (Description := "Attribute Number (see help for options)",
			                            Usage := Input,
			                            RADIX := Decimal,
			                            Required := No,
			                            Visible := Yes,
			                            DefaultData := 0);
			Attribute_Value : DINT (Description := "Attribute Value",
			                           Usage := Input,
			                           RADIX := Decimal,
			                           Required := Yes,
			                           Visible := Yes,
			                           DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,200,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 1B hex Position Controller Attribute";
				N: MOV(16#1B,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.$N"
				    "$N"
				    "TODO:  Add axis ID number to the AKD_Axis data type to be supplied dynamically here.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Attribute to Set to Bytes 4-5.$N"
				    "Attribute Number Input";
				N: COP(Attribute_Number,Command_Bytes[4],2);
				RC: "Write Value to bytes 24-27";
				N: COP(Attribute_Value,Axis.Output.Data[24],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Mode (Description := "Set Drive Mode",
	                                            Revision := "2.2",
	                                            RevisionNote := "Recover properly from errors (previously could not recover if AKD_Set_Attribute errored)",
	                                            ExecutePrescan := Yes,
	                                            ExecutePostscan := No,
	                                            ExecuteEnableInFalse := Yes,
	                                            CreatedDate := "2011-02-23T21:41:33.886Z",
	                                            CreatedBy := "DMC-678852CBE2A\Administrator",
	                                            EditedDate := "2014-10-29T18:11:02.304Z",
	                                            EditedBy := "DHRMOTION\radprod075",
	                                            SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Mode_Requested : SINT (Description := "Drive Mode Requested (0=Position, 1=Velocity, 2=Torque)",
			                          Usage := Input,
			                          RADIX := Decimal,
			                          Required := Yes,
			                          Visible := Yes,
			                          DefaultData := 0);
			DN : BOOL (Description := "Command Successfully Initiated",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Mode_Actual : SINT (Description := "Drive Mode Actual (0=Position, 1=Velocity, 2=Torque)",
			                       Usage := Output,
			                       RADIX := Decimal,
			                       Required := Yes,
			                       Visible := Yes,
			                       ExternalAccess := Read Only,
			                       DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Accel_Internal : DINT (Description := "Scaled Accel Value for Drive",
			                         RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := 0);
			Step : SINT (Description := "Sequence Step Number",
			               RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			ErrorSource : SINT (Description := "Source of Error",
			                      RADIX := Decimal,
			                      ExternalAccess := Read/Write,
			                      DefaultData := 0);
			StartONS : BOOL (RADIX := Decimal,
			                   ExternalAccess := Read/Write,
			                   DefaultData := 0);
			Pause_Timer : TIMER (Description := "Pause During Jog Command Sequence",
			                      ExternalAccess := Read/Write,
			                      DefaultData := "[0,0,0]");
			Get_Mode : AKD_Get_Attribute (ExternalAccess := Read/Write,
			                   DefaultData := "[1,3,0,[0,2000,0],0]");
			Set_Mode : AKD_Set_Attribute (ExternalAccess := Read/Write,
			                   DefaultData := "[1,3,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0]]");
			Command_Timeout : TIMER (ExternalAccess := Read/Write,
			                          DefaultData := "[0,100,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(StartONS)RES(Command_Timeout)MOV(0,Step);
		END_ROUTINE

		ROUTINE Logic 
				N: EQU(Step,1)AKD_Set_Attribute(Set_Mode,Axis,Mode_Requested)[XIC(Set_Mode.DN) MOV(2,Step) ,XIC(Set_Mode.ER) OTL(ER) MOV(-1,ErrorSource) ];
				N: EQU(Step,2)AKD_Get_Attribute(Get_Mode,Axis,Mode_Actual)[XIC(Get_Mode.DN) EQU(Mode_Requested,Mode_Actual) MOV(3,Step) ,XIC(Get_Mode.ER) OTL(ER) MOV(-2,ErrorSource) ];
				RC: "Allow 100ms for opmode to switch";
				N: EQU(Step,2)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-3,ErrorSource);
				N: EQU(Step,3)OTL(DN);
				N: XIC(ER)MOV(-1,Step);
				RC: "Reset DN (Done) and ER (Error) Status Output Bits";
				N: ONS(StartONS)OTU(DN)OTU(ER)MOV(1,Step);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(StartONS)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)MOV(0,Step);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Get_Parameter (Description := "Get Drive Parameter",
	                                                 Revision := "2.0",
	                                                 ExecutePrescan := Yes,
	                                                 ExecutePostscan := No,
	                                                 ExecuteEnableInFalse := Yes,
	                                                 CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                 CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                 EditedDate := "2014-10-29T18:11:02.261Z",
	                                                 EditedBy := "DHRMOTION\radprod075",
	                                                 SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Parameter_Number : INT (Description := "See help (F1) for parameter list.",
			                            Usage := Input,
			                            RADIX := Decimal,
			                            Required := No,
			                            Visible := Yes,
			                            DefaultData := 0);
			Parameter_Value : DINT (Description := "Parameter Value",
			                           Usage := Output,
			                           RADIX := Decimal,
			                           Required := Yes,
			                           Visible := Yes,
			                           ExternalAccess := Read Only,
			                           DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,2000,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Temp_Bytes : SINT[2] (Description := "Temporary Bytes to Split into Command Bytes",
			                     RADIX := Decimal,
			                     ExternalAccess := Read/Write,
			                     DefaultData := "[0,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 1F hex Position Controller Parameter";
				N: MOV(16#1F,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.$N"
				    "$N"
				    "TODO:  Add axis ID number to the AKD_Axis data type to be supplied dynamically here.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Parameter Instance Number to Command Bytes 4-5";
				N: COP(Parameter_Number,Command_Bytes[4],2);
				RC: "Write Get/Set Parameter Flag to byte 6$N"
				    "Get parameter = 0$N"
				    "Set parameter = 1";
				N: MOV(0,Command_Bytes[6]);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "Stop checking for errors/timeouts when load completes";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)MOV(2,Step);
				RC: "set done bit and copy data to output.$N"
				    "Read Attribute Value from Command Bytes 24-27.";
				N: EQU(Step,2)COP(Axis.Input.Data[24],Parameter_Value,4)OTL(DN)MOV(3,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(2000,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Get_Parameter_LINT (Description := "Get 8 byte Drive Parameter",
	                                                      Revision := "0.0",
	                                                      ExecutePrescan := Yes,
	                                                      ExecutePostscan := No,
	                                                      ExecuteEnableInFalse := Yes,
	                                                      CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                      CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                      EditedDate := "2014-12-05T13:36:42.055Z",
	                                                      EditedBy := "DHRMOTION\radprod075",
	                                                      SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Parameter_Number : INT (Description := "See help (F1) for parameter list.",
			                            Usage := Input,
			                            RADIX := Decimal,
			                            Required := No,
			                            Visible := Yes,
			                            DefaultData := 0);
			Parameter_Value_LSB : DINT (Description := "Lower Parameter Value",
			                               Usage := Output,
			                               RADIX := Decimal,
			                               Required := Yes,
			                               Visible := Yes,
			                               ExternalAccess := Read Only,
			                               DefaultData := 0);
			Parameter_Value_MSB : DINT (Description := "Upper Parameter Value",
			                               Usage := Output,
			                               RADIX := Decimal,
			                               Required := Yes,
			                               Visible := Yes,
			                               ExternalAccess := Read Only,
			                               DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,2000,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Temp_Bytes : SINT[2] (Description := "Temporary Bytes to Split into Command Bytes",
			                     RADIX := Decimal,
			                     ExternalAccess := Read/Write,
			                     DefaultData := "[0,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 1F hex Position Controller Parameter";
				N: MOV(16#1F,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.$N"
				    "$N"
				    "TODO:  Add axis ID number to the AKD_Axis data type to be supplied dynamically here.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Parameter Instance Number to Command Bytes 4-5";
				N: COP(Parameter_Number,Command_Bytes[4],2);
				RC: "Write Get/Set Parameter Flag to byte 6$N"
				    "Get parameter = 0$N"
				    "Set parameter = 1";
				N: MOV(0,Command_Bytes[6]);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "Stop checking for errors/timeouts when load completes";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)MOV(2,Step);
				RC: "set done bit and copy data to output.$N"
				    "Read Attribute Value from Command Bytes 24-27.";
				N: EQU(Step,2)COP(Axis.Input.Data[24],Parameter_Value_LSB,4)COP(Axis.Input.Data[28],Parameter_Value_MSB,4)OTL(DN)MOV(3,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(2000,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Home (Description := "Home Axis",
	                                        Revision := "2.1",
	                                        RevisionNote := "IP ouput bit should be turned off when the enable input is false",
	                                        ExecutePrescan := Yes,
	                                        ExecutePostscan := No,
	                                        ExecuteEnableInFalse := Yes,
	                                        CreatedDate := "2011-02-23T21:41:33.886Z",
	                                        CreatedBy := "DMC-678852CBE2A\Administrator",
	                                        EditedDate := "2014-10-29T18:11:02.266Z",
	                                        EditedBy := "DHRMOTION\radprod075",
	                                        SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successfully Initiated",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			IP : BOOL (Description := "Command in Process",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			PC : BOOL (Description := "Command Process Complete",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
		END_PARAMETERS

		LOCAL_TAGS
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Set_Attribute : AKD_Set_Attribute (ExternalAccess := Read/Write,
			                        DefaultData := "[1,0,0,[0,100,0],0,0,0,[0,0,0,0,0,0,0,0]]");
			Value : DINT (RADIX := Decimal,
			                ExternalAccess := Read/Write,
			                DefaultData := 0);
			StartONS : BOOL (RADIX := Decimal,
			                   ExternalAccess := Read/Write,
			                   DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(StartONS)MOV(0,Step);
				N: OTU(IP);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Set Error bit when a general fault is present on the drive or the command message has timed out without a response.";
				N: [XIC(Axis.Status.General_Fault) ,XIO(Axis.Status.Enable) ]OTL(ER)MOV(-2,Step);
				N: EQU(Step,1)AKD_Set_Attribute(Set_Attribute,Axis,Value)[XIC(Set_Attribute.DN) OTL(DN) MOV(2,Step) ,XIC(Set_Attribute.ER) OTL(ER) MOV(-1,Step) ];
				RC: "Set IP bit if a profile in progress status occurs (indicating motion needed to execute homing procedure).";
				N: EQU(2,Step)XIC(Axis.Status.Profile_In_Progress)OTE(IP);
				RC: "If command is no longer in process and the home status is received, then command process is complete .";
				N: EQU(2,Step)XIO(Axis.Status.Profile_In_Progress)XIC(Axis.Status.Home_Level)OTL(PC);
				RC: "Reset DN (Done) and ER (Error) Status Output Bits";
				N: ONS(StartONS)OTU(DN)OTU(ER)OTU(PC)MOV(1,Step);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(StartONS)MOV(0,Step);
				RC: "Attribute 101 - Home.Move. Send 1 to execute command.";
				N: MOV(101,Set_Attribute.Attribute_Number)MOV(1,Value);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Position (Description := "Set Drive Position",
	                                                Revision := "2.1",
	                                                RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                                ExecutePrescan := Yes,
	                                                ExecutePostscan := No,
	                                                ExecuteEnableInFalse := Yes,
	                                                CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                EditedDate := "2014-10-29T18:11:02.317Z",
	                                                EditedBy := "DHRMOTION\radprod075",
	                                                SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Incremental : BOOL (Description := "Position Definition (0=Absolute, 1=Incremental)",
			                       Usage := Input,
			                       RADIX := Decimal,
			                       Required := No,
			                       Visible := Yes,
			                       DefaultData := 0);
			Position : DINT (Description := "Position Value",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := Yes,
			                    Visible := Yes,
			                    DefaultData := 0);
			PC : BOOL (Description := "Process Complete",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			IP : BOOL (Description := "In Process",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Response_Bytes : SINT[8] (RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Position_Internal : DINT (Description := "Scaled Position Value for Drive",
			                            RADIX := Decimal,
			                            ExternalAccess := Read/Write,
			                            DefaultData := 0);
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,200,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Response_Message_Type : SINT (Description := "Response Message Type",
			                                RADIX := Decimal,
			                                ExternalAccess := Read/Write,
			                                DefaultData := 0);
			Response_Axis_Number : SINT (Description := "Response Axis Number",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
				RC: "If command is no longer in progress for any reason, reset IP bit.";
				N: XIO(Axis.Status.Profile_In_Progress)OTU(IP);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)OTU(PC)OTU(DN)OTU(ER)MOV(0,Step);
				RC: "Set Error bit when a general fault is present on the drive or the drive is disabled";
				N: [XIC(Axis.Status.General_Fault) ,XIO(Axis.Status.Enable) ]OTL(ER);
				RC: "Stop the sequence if there is an error";
				N: XIC(ER)MOV(-5,Step);
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 01 hex Target Position";
				N: MOV(16#01,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Response Axis Number (bits 5-7) to Byte 3 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Response_Axis_Number);
				N: XIC(Response_Axis_Number.2)OTE(Command_Bytes[3].7);
				N: XIC(Response_Axis_Number.1)OTE(Command_Bytes[3].6);
				N: XIC(Response_Axis_Number.0)OTE(Command_Bytes[3].5);
				RC: "Write desired position move type to the axis control structure.$N"
				    "";
				N: XIC(Incremental)OTE(Axis.Control.Incremental);
				RC: "Write Command Data to Command Bytes 4-7.";
				N: COP(Position,Command_Bytes[4],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				RC: "IP bit indicates that the command is in progress.";
				N: EQU(Step,2)XIC(Axis.Status.Profile_In_Progress)OTE(IP);
				RC: "Set .PC bit when move command has successfully completed.";
				N: EQU(Step,2)XIO(Axis.Status.Profile_In_Progress)XIC(Axis.Status.On_Target_Position)OTL(PC);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Move (Description := "Motion Axis Move - Position Move",
	                                        Revision := "3.1",
	                                        RevisionNote := "Don$'t error if Command_Timeout preset is 0",
	                                        ExecutePrescan := Yes,
	                                        ExecutePostscan := No,
	                                        ExecuteEnableInFalse := Yes,
	                                        CreatedDate := "2011-02-23T21:41:33.886Z",
	                                        CreatedBy := "DMC-678852CBE2A\Administrator",
	                                        EditedDate := "2014-10-29T18:11:02.284Z",
	                                        EditedBy := "DHRMOTION\radprod075",
	                                        SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Move_Type : SINT (Description := "Move Type (0=Absolute, 1=Incremental)",
			                     Usage := Input,
			                     RADIX := Decimal,
			                     Required := Yes,
			                     Visible := Yes,
			                     DefaultData := 0);
			Accel : DINT (Description := "Acceleration",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
			Decel : DINT (Description := "Deceleration",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
			Speed : DINT (Description := "Move Speed",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
			Position : DINT (Description := "Target Position",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := Yes,
			                    Visible := Yes,
			                    DefaultData := 0);
			DN : BOOL (Description := "Command Successfully Initiated",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			IP : BOOL (Description := "Command in Process",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			PC : BOOL (Description := "Command Process Complete",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Step : SINT (Description := "Sequence Step Number",
			               RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Command_Axis_Number : SINT (RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Response_Axis_Number : SINT (RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Set_Accel : AKD_Set_Accel (ExternalAccess := Read/Write,
			                    DefaultData := "[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0]");
			Set_Decel : AKD_Set_Decel (ExternalAccess := Read/Write,
			                    DefaultData := "[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0]");
			Set_Velocity : AKD_Set_Velocity (ExternalAccess := Read/Write,
			                       DefaultData := "[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0]");
			OS_Start_Sequence : BOOL (RADIX := Decimal,
			                            ExternalAccess := Read/Write,
			                            DefaultData := 0);
			Set_Position : AKD_Set_Position (ExternalAccess := Read/Write,
			                       DefaultData := "[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0]");
			Command_Timeout : TIMER (ExternalAccess := Read/Write,
			                          DefaultData := "[0,200,0]");
			Command_Bytes : SINT[64] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]");
			ErrorData : SINT[8] (RADIX := Decimal,
			                    ExternalAccess := Read/Write,
			                    DefaultData := "[0,0,0,0,0,0,0,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_Start_Sequence)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
				RC: "If command is no longer in progress for any reason, reset IP bit.";
				N: XIO(Axis.Status.Profile_In_Progress)OTU(IP);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_Start_Sequence)OTU(PC)OTU(DN)OTU(ER)MOV(0,Step);
				RC: "Set Error bit when a general fault is present on the drive or the drive is disabled";
				N: [XIC(Axis.Status.General_Fault) ,XIO(Axis.Status.Enable) ]OTL(ER)MOV(-5,Step);
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 06 hex Motion Task";
				N: MOV(6,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Response Axis Number (bits 5-7) to Byte 3 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Response_Axis_Number);
				N: XIC(Response_Axis_Number.2)OTE(Command_Bytes[3].7);
				N: XIC(Response_Axis_Number.1)OTE(Command_Bytes[3].6);
				N: XIC(Response_Axis_Number.0)OTE(Command_Bytes[3].5);
				RC: "Write desired position move type to the axis control structure.$N"
				    "";
				N: EQU(Move_Type,1)OTE(Axis.Control.Incremental);
				RC: "Write Position to Command Bytes 8-11.";
				N: COP(Position,Command_Bytes[8],4);
				RC: "Write Velocity to Command Bytes 12-15";
				N: COP(Speed,Command_Bytes[12],4);
				RC: "Write Acceleration to Command Bytes 16-19";
				N: COP(Accel,Command_Bytes[16],4);
				RC: "Write Deceleration to Command Bytes 20-23";
				N: COP(Decel,Command_Bytes[20],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)COP(Axis.Input.Data[0],ErrorData[0],8)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				RC: "IP bit indicates that the command is in progress.";
				N: EQU(Step,2)XIC(Axis.Status.Profile_In_Progress)OTE(IP);
				RC: "Set .PC bit when move command has successfully completed.";
				N: EQU(Step,2)XIO(Axis.Status.Profile_In_Progress)XIC(Axis.Status.On_Target_Position)OTL(PC);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],64);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_Start_Sequence)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Home_Mode (Description := "Set Homing Mode",
	                                                 Revision := "2.0",
	                                                 ExecutePrescan := Yes,
	                                                 ExecutePostscan := No,
	                                                 ExecuteEnableInFalse := Yes,
	                                                 CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                 CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                 EditedDate := "2014-10-29T18:11:02.302Z",
	                                                 EditedBy := "DHRMOTION\radprod075",
	                                                 SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Mode : SINT (Description := "Home Mode:",
			                Usage := Input,
			                RADIX := Decimal,
			                Required := Yes,
			                Visible := Yes,
			                DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			Step : DINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Set_Attribute : AKD_Set_Attribute (ExternalAccess := Read/Write,
			                        DefaultData := "[1,0,0,[0,100,0],0,0,0,[0,0,0,0,0,0,0,0]]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: MOV(0,Step);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Attribute 100 - Home Mode.$N"
				    "Write Command Data to Command Bytes 4-7.$N"
				    "Mode Description:$N"
				    "0 = Home using current position$N"
				    "1 = Find limit input$N"
				    "2 = Find input limit then find zero angle$N"
				    "3 = Find input limit then find index $N"
				    "4 = Find home input, including hardware limit switches$N"
				    "5 = Find home input then find zero angle, including hardware limit switches$N"
				    "6 = Find home input then find index, including hardware limit switches.$N"
				    "7 = Find zero angle$N"
				    "8 = Move until position error exceeded $N"
				    "9 = Move until position error exceeded, then find zero angle$N"
				    "10 = Move until position error exceeded, then find index$N"
				    "11 = Find index signal, without any precondition$N"
				    "12 = Homing to a home-switch, including mechanical stop detection";
				N: EQU(Step,1)AKD_Set_Attribute(Set_Attribute,Axis,Mode)[XIC(Set_Attribute.DN) OTL(DN) MOV(2,Step) ,XIC(Set_Attribute.ER) OTL(ER) MOV(-1,Step) ];
				RC: "Reset DN (Done) and ER (Error) Status Output Bits";
				N: EQU(Step,0)OTU(DN)OTU(ER)MOV(1,Step);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: MOV(0,Step);
				RC: "Attribute 100 - Home Mode";
				N: MOV(100,Set_Attribute.Attribute_Number);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Units (Description := "Set Drive Units for Motion Commands",
	                                             Revision := "2.2",
	                                             RevisionNote := "Clean up instruction, especially for error recovery.",
	                                             ExecutePrescan := Yes,
	                                             ExecutePostscan := No,
	                                             ExecuteEnableInFalse := Yes,
	                                             CreatedDate := "2011-02-23T21:41:33.886Z",
	                                             CreatedBy := "DMC-678852CBE2A\Administrator",
	                                             EditedDate := "2014-10-29T18:11:02.319Z",
	                                             EditedBy := "DHRMOTION\radprod075",
	                                             SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Units : SINT (Description := "Drive Units (0=Counts 16 bit)",
			                 Usage := Input,
			                 RADIX := Decimal,
			                 Required := Yes,
			                 Visible := Yes,
			                 DefaultData := 0);
			DN : BOOL (Description := "Command Successfully Initiated",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Set_POSUNIT : AKD_Set_Attribute (ExternalAccess := Read/Write,
			                      DefaultData := "[1,4,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0]]");
			Set_PROFUNIT : AKD_Set_Attribute (ExternalAccess := Read/Write,
			                       DefaultData := "[1,5,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0]]");
			Step : SINT (Description := "Sequence Step Number",
			               RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			OS_Start_Sequence : BOOL (RADIX := Decimal,
			                            ExternalAccess := Read/Write,
			                            DefaultData := 0);
			Profile_Ratio : DINT (Description := "The number of actual feedback counts per second or second2 equal to one velocity or acceleration unit",
			                        RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := 0);
			Position_Ratio : DINT (Description := "The$Nnumber of actual position$Nfeedback counts equal to one$Nposition unit",
			                         RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := 0);
			Invalid_Input : BOOL (Description := "Invalid Units Input",
			                        RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_Start_Sequence)MOV(0,Step);
		END_ROUTINE

		ROUTINE Logic 
				N: EQU(Step,1)[EQU(Units,0) MOV(65536,Position_Ratio) MOV(65536,Profile_Ratio) MOV(2,Step) ,NEQ(Units,0) OTL(Invalid_Input) OTL(ER) MOV(-1,Step) ];
				N: EQU(Step,2)AKD_Set_Attribute(Set_POSUNIT,Axis,Position_Ratio)[XIC(Set_POSUNIT.DN) MOV(3,Step) ,XIC(Set_POSUNIT.ER) OTL(ER) ];
				N: EQU(Step,3)AKD_Set_Attribute(Set_PROFUNIT,Axis,Profile_Ratio)[XIC(Set_PROFUNIT.DN) MOV(4,Step) ,XIC(Set_PROFUNIT.ER) OTL(ER) ];
				RC: "Set Done bit when critical commands completed.  DN bit signifies that the command is complete";
				N: EQU(Step,4)OTL(DN);
				RC: "Reset Sequence When Instruction Is Called";
				N: XIC(EnableIn)ONS(OS_Start_Sequence)OTU(DN)OTU(ER)OTU(Invalid_Input)MOV(1,Step);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_Start_Sequence)MOV(0,Step);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Set_Parameter_LINT (Description := "Set 8 byte Drive Parameter",
	                                                      Revision := "0.0",
	                                                      ExecutePrescan := Yes,
	                                                      ExecutePostscan := No,
	                                                      ExecuteEnableInFalse := Yes,
	                                                      CreatedDate := "2011-02-23T21:41:33.886Z",
	                                                      CreatedBy := "DMC-678852CBE2A\Administrator",
	                                                      EditedDate := "2014-12-05T13:11:46.953Z",
	                                                      EditedBy := "DHRMOTION\radprod075",
	                                                      SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Parameter_Number : INT (Description := "See help (F1) for parameter list.",
			                            Usage := Input,
			                            RADIX := Decimal,
			                            Required := No,
			                            Visible := Yes,
			                            DefaultData := 0);
			Parameter_Value_LSB : DINT (Description := "Parameter Value",
			                               Usage := Input,
			                               RADIX := Decimal,
			                               Required := Yes,
			                               Visible := Yes,
			                               DefaultData := 0);
			Parameter_Value_MSB : DINT (Usage := Input,
			                               RADIX := Decimal,
			                               Required := Yes,
			                               Visible := Yes,
			                               DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,10000,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Temp_Bytes : SINT[2] (Description := "Temporary Bytes to Split into Command Bytes",
			                     RADIX := Decimal,
			                     ExternalAccess := Read/Write,
			                     DefaultData := "[0,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 1F hex Position Controller Parameter";
				N: MOV(16#1F,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.$N"
				    "$N"
				    "TODO:  Add axis ID number to the AKD_Axis data type to be supplied dynamically here.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Parameter Instance Number to Command Bytes 4-5";
				N: COP(Parameter_Number,Command_Bytes[4],2);
				RC: "Write Get/Set Parameter Flag to byte 6$N"
				    "Get parameter = 0$N"
				    "Set parameter = 1";
				N: MOV(1,Command_Bytes[6]);
				RC: "Write Parameter Value to bytes 24-27";
				N: COP(Parameter_Value_LSB,Axis.Output.Data[24],4);
				RC: "Write Parameter Value to bytes 28-31";
				N: COP(Parameter_Value_MSB,Axis.Output.Data[28],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(10000,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Shutdown (Description := "Motion Hard Stop",
	                                            Revision := "2.0",
	                                            ExecutePrescan := Yes,
	                                            ExecutePostscan := No,
	                                            ExecuteEnableInFalse := Yes,
	                                            CreatedDate := "2011-02-23T21:41:33.886Z",
	                                            CreatedBy := "DMC-678852CBE2A\Administrator",
	                                            EditedDate := "2014-10-29T18:11:02.327Z",
	                                            EditedBy := "DHRMOTION\radprod075",
	                                            SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
		END_PARAMETERS

		LOCAL_TAGS
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,2000,0]");
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "Enable In False")
				RC: "Reset Hard Stop Bit in the Command Message When Instruction is not called.";
				N: OTU(Axis.Control.Hard_Stop);
				RC: "Initialize Instruction Variables when Not Executing";
				N: RES(Command_Timeout);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Set Hard Stop Bit in the Command Message unconditionally.";
				N: OTL(Axis.Control.Hard_Stop);
				RC: "Set Done bit when the axis is disabled and no motion profile in progress.";
				N: XIO(Axis.Status.Enable)XIO(Axis.Status.Profile_In_Progress)OTE(DN);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: XIO(DN)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTE(ER);
		END_ROUTINE

		ROUTINE Prescan 
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: RES(Command_Timeout)MOV(2000,Command_Timeout.PRE);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Stop_Smooth (Description := "Motion Smooth Stop",
	                                               Revision := "2.3",
	                                               RevisionNote := "Remove the command timeout (allow unlimited time to stop). Add an IP In Progress bit which is active while stopping.",
	                                               ExecutePrescan := Yes,
	                                               ExecutePostscan := No,
	                                               ExecuteEnableInFalse := Yes,
	                                               CreatedDate := "2011-02-23T21:41:33.886Z",
	                                               CreatedBy := "DMC-678852CBE2A\Administrator",
	                                               EditedDate := "2014-10-29T18:11:02.331Z",
	                                               EditedBy := "DHRMOTION\radprod075",
	                                               SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			IP : BOOL (Description := "In Progress",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "Enable In False")
				RC: "Reset Smooth Stop Bit in the Command Message When Instruction is not called.";
				N: OTU(Axis.Control.Smooth_Stop);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Set Smooth Stop Bit in the Command Message unconditionally.";
				N: OTL(Axis.Control.Smooth_Stop);
				RC: "Set Done bit when axis has stopped";
				N: XIO(Axis.Status.Profile_In_Progress)OTE(DN);
				RC: "Set IP bit when axis is stopping";
				N: XIC(Axis.Status.Profile_In_Progress)OTE(IP);
		END_ROUTINE

		ROUTINE Prescan 
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	ADD_ON_INSTRUCTION_DEFINITION AKD_Torque_Move (Description := "Set Torque Command",
	                                               Revision := "2.1",
	                                               ExecutePrescan := Yes,
	                                               ExecutePostscan := No,
	                                               ExecuteEnableInFalse := Yes,
	                                               CreatedDate := "2011-02-23T21:41:33.886Z",
	                                               CreatedBy := "DMC-678852CBE2A\Administrator",
	                                               EditedDate := "2014-10-29T18:11:02.336Z",
	                                               EditedBy := "DHRMOTION\radprod075",
	                                               SoftwareRevision := "v19.01")
		
		PARAMETERS
			EnableIn : BOOL (Description := "Enable Input - System Defined Parameter",
			                    Usage := Input,
			                    RADIX := Decimal,
			                    Required := No,
			                    Visible := No,
			                    ExternalAccess := Read Only);
			EnableOut : BOOL (Description := "Enable Output - System Defined Parameter",
			                     Usage := Output,
			                     RADIX := Decimal,
			                     Required := No,
			                     Visible := No,
			                     ExternalAccess := Read Only);
			DN : BOOL (Description := "Command Successful",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			ER : BOOL (Description := "Error",
			              Usage := Output,
			              RADIX := Decimal,
			              Required := No,
			              Visible := Yes,
			              ExternalAccess := Read Only,
			              DefaultData := 0);
			Axis : AKD_Axis (Usage := InOut,
			                Required := Yes,
			                Visible := Yes);
			Torque : DINT (Description := "Torque Command",
			                  Usage := Input,
			                  RADIX := Decimal,
			                  Required := Yes,
			                  Visible := Yes,
			                  DefaultData := 0);
		END_PARAMETERS

		LOCAL_TAGS
			Response_Bytes : SINT[8] (RADIX := Decimal,
			                         ExternalAccess := Read/Write,
			                         DefaultData := "[0,0,0,0,0,0,0,0]");
			OS_LoadStart : BOOL (RADIX := Decimal,
			                       ExternalAccess := Read/Write,
			                       DefaultData := 0);
			Command_Timeout : TIMER (Description := "Timeout Timer",
			                          ExternalAccess := Read/Write,
			                          DefaultData := "[0,100,0]");
			Command_Message_Type : SINT (Description := "Command Message Type",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Axis_Number : SINT (Description := "Command Axis Number",
			                              RADIX := Decimal,
			                              ExternalAccess := Read/Write,
			                              DefaultData := 0);
			Response_Message_Type : SINT (Description := "Response Message Type",
			                                RADIX := Decimal,
			                                ExternalAccess := Read/Write,
			                                DefaultData := 0);
			Response_Axis_Number : SINT (Description := "Response Axis Number",
			                               RADIX := Decimal,
			                               ExternalAccess := Read/Write,
			                               DefaultData := 0);
			Command_Bytes : SINT[8] (RADIX := Decimal,
			                        ExternalAccess := Read/Write,
			                        DefaultData := "[0,0,0,0,0,0,0,0]");
			Step : SINT (RADIX := Decimal,
			               ExternalAccess := Read/Write,
			               DefaultData := 0);
		END_LOCAL_TAGS

		ROUTINE EnableInFalse (Description := "EnableIn_False")
				RC: "Initialize Instruction Variables when Not Executing";
				N: OTU(OS_LoadStart)RES(Command_Timeout)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

		ROUTINE Logic 
				RC: "Initialize data values";
				N: XIC(EnableIn)ONS(OS_LoadStart)[MOV(0,Step) ,OTU(DN) ,OTU(ER) ];
				RC: "Write Command Message Type (bits 0-4) to Byte 2.$N"
				    "Command Message Type 05 hex Target Velocity";
				N: MOV(16#05,Command_Message_Type)MOV(Command_Message_Type,Command_Bytes[2]);
				RC: "Write Command Axis Number (bits 5-7) to Byte 2 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Command_Axis_Number);
				N: XIC(Command_Axis_Number.2)OTE(Command_Bytes[2].7);
				N: XIC(Command_Axis_Number.1)OTE(Command_Bytes[2].6);
				N: XIC(Command_Axis_Number.0)OTE(Command_Bytes[2].5);
				RC: "Write Response Axis Number (bits 5-7) to Byte 3 by copying the 3 Low Bits to the 3 High Bits.";
				N: MOV(1,Response_Axis_Number);
				N: XIC(Response_Axis_Number.2)OTE(Command_Bytes[3].7);
				N: XIC(Response_Axis_Number.1)OTE(Command_Bytes[3].6);
				N: XIC(Response_Axis_Number.0)OTE(Command_Bytes[3].5);
				RC: "Write Command Data to Command Bytes 4-7.";
				N: COP(Torque,Command_Bytes[4],4);
				RC: "$N"
				    "$N"
				    "$N"
				    "******************** Send command and do handshake *****************$N"
				    "$N"
				    "$N"
				    "Clear handshake on Load/Start b";
				N: XIC(Axis.Status.Load_Complete)OTU(Axis.Control.Load_Data_Start_Profile);
				RC: "Set handshake on load/start once LoadComplete has cleared (ready for new command)";
				N: EQU(Step,0)XIO(Axis.Status.Load_Complete)OTL(Axis.Control.Load_Data_Start_Profile)MOV(1,Step);
				RC: "Check for an error response";
				N: EQU(Step,1)EQU(Axis.ResponseMsgType,16#14)OTL(ER)MOV(-1,Step);
				RC: "Verify that the command successfully executes in a timely fashion.";
				N: EQU(Step,1)NEQ(Command_Timeout.PRE,0)TON(Command_Timeout,?,?)XIC(Command_Timeout.DN)OTL(ER)MOV(-2,Step);
				RC: "DN bit signifies that the command completed successfully";
				N: EQU(Step,1)XIC(Axis.Status.Load_Complete)OTL(DN)MOV(2,Step);
				N: XIC(ER)OTU(Axis.Control.Load_Data_Start_Profile);
				N: COP(Axis.Control,Command_Bytes[0],1)COP(Command_Bytes[0],Axis.Output.Data[0],8);
		END_ROUTINE

		ROUTINE Prescan (Description := "Prescan")
				RC: "Initialize Instruction Variables Before 1st Scan";
				N: OTU(OS_LoadStart)RES(Command_Timeout)MOV(Axis.CommandTimeout,Command_Timeout.PRE)FLL(0,Command_Bytes[0],8);
		END_ROUTINE

	END_ADD_ON_INSTRUCTION_DEFINITION

	TAG
		AKD_1 : AKD_Drive  := [1,[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];
		Axis_1 : AKD_Drive  := [1,[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];
		Axis_1_Dis : AKD_Disable  := [1,[0,200,0]];
		Axis_1_EN : AKD_Enable  := [1,[0,2000,0]];
		Axis_1_HOME : AKD_Home  := [1,0,[1,0,0,[0,100,0],0,0,0,[0,0,0,0,0,0,0,0]],0];
		Axis_1_Move : AKD_Move  := [1,0,0,0,0,0,0,0,0,[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0],[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0],[1,0,[0,0,0,0,0,0,0,0],0,[0
				,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0],[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0],[0,200,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
				,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];
		AXIS_ONE : AKD_Axis  := [[0],[0,0],[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0,0,0,0,0,0,0
				,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],0,0,0,0];
		BLK_DRV_DISSOURCE : AKD_Get_Parameter  := [1,121,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_DRV_MOTIONSTAT : AKD_Get_Parameter  := [1,135,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_FAULT_RESET : AKD_Fault_Reset  := [1,0,[1,113,0,[0,10000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]]];
		BLK_GET_FAULT1 : AKD_Get_Parameter  := [1,478,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT10 : AKD_Get_Parameter  := [1,487,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT2 : AKD_Get_Parameter  := [1,479,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT3 : AKD_Get_Parameter  := [1,480,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT4 : AKD_Get_Parameter  := [1,481,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT5 : AKD_Get_Parameter  := [1,482,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT6 : AKD_Get_Parameter  := [1,483,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT7 : AKD_Get_Parameter  := [1,484,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT8 : AKD_Get_Parameter  := [1,485,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_GET_FAULT9 : AKD_Get_Parameter  := [1,486,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		BLK_JOG : AKD_Jog  := [1,0,0,0,0,[1,[0,0,0]],[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0],[1,0,[0,0,0,0,0,0,0,0],0,[0,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0],[1,0,[0,0,0,0,0,0,0,0],0,[0
				,2000,0],0,0,0,0,[0,0,0,0,0,0,0,0],0],0,0,0,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
				,0,0,0,0],[0,0,0,0,0,0,0,0],[0,100,0]];
		BLK_STOP : AKD_Stop_Smooth  := [1];
		B_DRV_ACTIVE : AKD_Get_Parameter  := [1,0,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		CLRFAULT_1_SHOT : BOOL (RADIX := Decimal) := 0;
		DATA_DRV_DISSOURCE : DINT (RADIX := Decimal) := 0;
		DATA_DRV_MOTIONSTAT : DINT (RADIX := Decimal) := 0;
		DISABLE : BOOL (RADIX := Decimal) := 0;
		DISABLE_1_SHOT : BOOL (RADIX := Decimal) := 0;
		DISSOURCE_1_SHOT : BOOL (RADIX := Decimal) := 0;
		ENABLE : BOOL (RADIX := Decimal) := 0;
		ENABLE_1_SHOT : BOOL (RADIX := Decimal) := 0;
		FAULT_1 : DINT (RADIX := Decimal) := 0;
		FAULT_10 : DINT (RADIX := Decimal) := 0;
		FAULT_2 : DINT (RADIX := Decimal) := 0;
		FAULT_3 : DINT (RADIX := Decimal) := 0;
		FAULT_4 : DINT (RADIX := Decimal) := 0;
		FAULT_5 : DINT (RADIX := Decimal) := 0;
		FAULT_6 : DINT (RADIX := Decimal) := 0;
		FAULT_7 : DINT (RADIX := Decimal) := 0;
		FAULT_8 : DINT (RADIX := Decimal) := 0;
		FAULT_9 : DINT (RADIX := Decimal) := 0;
		FAULT_FIRST_STEP : BOOL (RADIX := Decimal) := 0;
		FB1_Offset_LSB_Data : DINT (RADIX := Decimal) := 0;
		FB1_Offset_MSB_Data : DINT (RADIX := Decimal) := 0;
		FB1_Offset_Zero : AKD_Set_Parameter_LINT  := [1,146,0,0,[0,10000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		GETFAULT_1_SHOT : BOOL (RADIX := Decimal) := 0;
		GET_FAULT_BUSY : BOOL (RADIX := Decimal) := 0;
		GET_FAULT_COUNTER : DINT (RADIX := Decimal) := 0;
		HOME_1_SHOT : BOOL (RADIX := Decimal) := 0;
		JOG_1_SHOT : BOOL (RADIX := Decimal) := 0;
		JOG_AXIS_1 : BOOL (RADIX := Decimal) := 0;
		MOTIONSTAT_1_SHOT : BOOL (RADIX := Decimal) := 0;
		MOVE_1_SHOT : BOOL (RADIX := Decimal) := 0;
		New_Offset_Data_LSB : DINT (RADIX := Decimal) := 0;
		New_Offset_Data_MSB : DINT (RADIX := Decimal) := 0;
		Offset_State_Counter : DINT (RADIX := Decimal) := 0;
		Read_FB : AKD_Get_Parameter_LINT  := [1,295,0,0,[0,2000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
		Start_1SHT : BOOL (RADIX := Decimal) := 0;
		START_DRV_CLRFAULTS : BOOL (RADIX := Decimal) := 0;
		START_DRV_DISSOURCE : BOOL (RADIX := Decimal) := 0;
		START_DRV_MOTIONSTAT : BOOL (RADIX := Decimal) := 0;
		START_GET_FAULTS : BOOL (RADIX := Decimal) := 0;
		START_HOME_MOVE : BOOL (RADIX := Decimal) := 0;
		START_MOVE : BOOL (RADIX := Decimal) := 0;
		Start_Zero_Routine : BOOL (RADIX := Decimal) := 0;
		Step1_1SHT : BOOL (RADIX := Decimal) := 0;
		STOP_1_STOP : BOOL (RADIX := Decimal) := 0;
		Write_Net_Offset : AKD_Set_Parameter_LINT  := [1,146,0,0,[0,10000,0],0,0,0,[0,0,0,0,0,0,0,0],[0,0]];
	END_TAG

	PROGRAM MainProgram (MAIN := "MainRoutine",
	                     MODE := 0,
	                     DisableFlag := 0)
			TAG
			END_TAG

			ROUTINE MainRoutine 
					N: AKD_Drive(AKD_1,AKD_1:I,AKD_1:O,AXIS_ONE);
					N: XIC(Start_Zero_Routine)ONS(Start_1SHT)MOV(1,Offset_State_Counter);
					N: EQU(Offset_State_Counter,1)[AKD_Set_Parameter_LINT(FB1_Offset_Zero,AXIS_ONE,0,0) ,XIC(FB1_Offset_Zero.DN) MOV(2,Offset_State_Counter) ];
					N: EQU(Offset_State_Counter,2)[AKD_Get_Parameter_LINT(Read_FB,AXIS_ONE,FB1_Offset_LSB_Data,FB1_Offset_MSB_Data) ,XIC(Read_FB.DN) MOV(3,Offset_State_Counter) ];
					N: EQU(Offset_State_Counter,3)MUL(-1,FB1_Offset_LSB_Data,New_Offset_Data_LSB)MUL(-1,FB1_Offset_MSB_Data,New_Offset_Data_MSB)MOV(4,Offset_State_Counter);
					N: EQU(Offset_State_Counter,4)[EQU(FB1_Offset_MSB_Data,0) MOV(-1,New_Offset_Data_MSB) ,EQU(FB1_Offset_MSB_Data,-1) MOV(0,New_Offset_Data_MSB) ,NEQ(FB1_Offset_MSB_Data,0) NEQ(FB1_Offset_MSB_Data,-1) ADD(New_Offset_Data_MSB,-1,New_Offset_Data_MSB) ,MOV(5,Offset_State_Counter) ];
					N: EQU(Offset_State_Counter,5)[AKD_Set_Parameter_LINT(Write_Net_Offset,AXIS_ONE,New_Offset_Data_LSB,New_Offset_Data_MSB) ,XIC(Write_Net_Offset.DN) MOV(0,Offset_State_Counter) ];
					N: GRT(Offset_State_Counter,0)[EQU(Offset_State_Counter,1) XIC(FB1_Offset_Zero.ER) ,EQU(Offset_State_Counter,2) XIC(Read_FB.ER) ,EQU(Offset_State_Counter,5) XIC(Write_Net_Offset.ER) ]MOV(0,Offset_State_Counter);
			END_ROUTINE

	END_PROGRAM

	TASK MainTask (Type := CONTINUOUS,
	               Rate := 10,
	               Priority := 10,
	               Watchdog := 500,
	               DisableUpdateOutputs := No,
	               InhibitTask := No)
			MainProgram;
	END_TASK

CONFIG ASCII(XONXOFFEnable := 0,
	             DeleteMode := 0,
	             EchoMode := 0,
	             TerminationChars := 65293,
	             AppendChars := 2573,
	             BufferSize := 82) END_CONFIG

CONFIG ControllerDevice END_CONFIG

CONFIG CST(SystemTimeMasterID := 0) END_CONFIG

CONFIG DF1(DuplicateDetection := 1,
	           ErrorDetection := BCC Error,
	           EmbeddedResponseEnable := 0,
	           DF1Mode := Pt to Pt,
	           ACKTimeout := 50,
	           NAKReceiveLimit := 3,
	           ENQTransmitLimit := 3,
	           TransmitRetries := 3,
	           StationAddress := 0,
	           ReplyMessageWait := 5,
	           PollingMode := 1,
	           MasterMessageTransmit := 0,
	           NormalPollNodeFile := "<NA>",
	           NormalPollGroupSize := 0,
	           PriorityPollNodeFile := "<NA>",
	           ActiveStationFile := "<NA>",
	           SlavePollTimeout := 3000,
	           EOTSuppression := 0,
	           MaxStationAddress := 31,
	           TokenHoldFactor := 1,
	           EnableStoreFwd := 0,
	           StoreFwdFile := "<NA>") END_CONFIG

CONFIG ExtendedDevice END_CONFIG

CONFIG FaultLog END_CONFIG

CONFIG FileManager END_CONFIG

CONFIG ICP END_CONFIG

CONFIG PCCC END_CONFIG

CONFIG Redundancy END_CONFIG

CONFIG SerialPort(BaudRate := 19200,
	                  Parity := No Parity,
	                  DataBits := 8 Bits of Data,
	                  StopBits := 1 Stop Bit,
	                  ComDriverId := DF1,
	                  PendingComDriverId := DF1,
	                  RTSOffDelay := 0,
	                  RTSSendDelay := 0,
	                  ControlLine := No Handshake,
	                  PendingControlLine := No Handshake,
	                  RemoteModeChangeFlag := 0,
	                  PendingRemoteModeChangeFlag := 0,
	                  ModeChangeAttentionChar := 27,
	                  PendingModeChangeAttentionChar := 27,
	                  SystemModeCharacter := 83,
	                  PendingSystemModeCharacter := 83,
	                  UserModeCharacter := 85,
	                  PendingUserModeCharacter := 85,
	                  DCDWaitDelay := 0) END_CONFIG

CONFIG TimeSynchronize(Priority1 := 128,
	                                 Priority2 := 128,
	                                 PTPEnable := 0) END_CONFIG

CONFIG UserMemory END_CONFIG

CONFIG WallClockTime(LocalTimeAdjustment := 0,
	                     TimeZone := 0) END_CONFIG

END_CONTROLLER

