Skip to content

Commit

Permalink
Merge pull request #113 from nrwslac/stats-task
Browse files Browse the repository at this point in the history
SP1K1 Grating Pitch Stats Migration
  • Loading branch information
nrwslac authored Feb 2, 2024
2 parents 8bbe7b9 + 8f4e474 commit 2036925
Show file tree
Hide file tree
Showing 7 changed files with 9,232 additions and 9,108 deletions.
161 changes: 87 additions & 74 deletions lcls-plc-rixs-optics/_Config/PLC/rixs_optics.xti
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,6 @@
<BitOffs>16</BitOffs>
</SubItem>
</DataType>
<DataType>
<Name GUID="{4B0DBBA4-11EF-DC4A-BF0D-C44F27183D05}" Namespace="lcls_twincat_motion" AutoDeleteType="true">EL5042_Status</Name>
<BitSize>0</BitSize>
<BaseType GUID="{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}"/>
</DataType>
<DataType>
<Name GUID="{E7D8BF8B-2549-C401-85F6-34B274CA315B}" Namespace="lcls_twincat_motion" AutoDeleteType="true">ST_RenishawAbsEnc</Name>
<Comment><![CDATA[ Renishaw BiSS-C absolute encoder used with an EL5042]]></Comment>
<BitSize>128</BitSize>
<SubItem>
<Name>Count</Name>
<Type GUID="{18071995-0000-0000-0000-00000000000B}">ULINT</Type>
<Comment><![CDATA[ Connect to encoder "Position" input]]></Comment>
<BitSize>64</BitSize>
<BitOffs>0</BitOffs>
<Properties>
<Property>
<Name>TcAddressType</Name>
<Value>Input</Value>
</Property>
</Properties>
</SubItem>
<SubItem>
<Name>Status</Name>
<Type GUID="{4B0DBBA4-11EF-DC4A-BF0D-C44F27183D05}" Namespace="lcls_twincat_motion">EL5042_Status</Type>
<Comment><![CDATA[ Status struct placeholder]]></Comment>
<BitSize>0</BitSize>
<BitOffs>64</BitOffs>
</SubItem>
<SubItem>
<Name>Ref</Name>
<Type GUID="{18071995-0000-0000-0000-00000000000B}">ULINT</Type>
<Comment><![CDATA[ Encoder zero position (useful for aligned position with gantries)]]></Comment>
<BitSize>64</BitSize>
<BitOffs>64</BitOffs>
</SubItem>
</DataType>
<DataType>
<Name GUID="{CBC83B73-B816-4597-A9E5-2B03263CA131}" Namespace="MC" TcBaseType="true" HideType="true" IecDeclaration="DWORD;">NCTOPLC_AXIS_REF_STATE</Name>
<BitSize>32</BitSize>
Expand Down Expand Up @@ -883,6 +846,43 @@ External Setpoint Generation:
</Relation>
</Relations>
</DataType>
<DataType>
<Name GUID="{4B0DBBA4-11EF-DC4A-BF0D-C44F27183D05}" Namespace="lcls_twincat_motion" AutoDeleteType="true">EL5042_Status</Name>
<BitSize>0</BitSize>
<BaseType GUID="{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}"/>
</DataType>
<DataType>
<Name GUID="{E7D8BF8B-2549-C401-85F6-34B274CA315B}" Namespace="lcls_twincat_motion" AutoDeleteType="true">ST_RenishawAbsEnc</Name>
<Comment><![CDATA[ Renishaw BiSS-C absolute encoder used with an EL5042]]></Comment>
<BitSize>128</BitSize>
<SubItem>
<Name>Count</Name>
<Type GUID="{18071995-0000-0000-0000-00000000000B}">ULINT</Type>
<Comment><![CDATA[ Connect to encoder "Position" input]]></Comment>
<BitSize>64</BitSize>
<BitOffs>0</BitOffs>
<Properties>
<Property>
<Name>TcAddressType</Name>
<Value>Input</Value>
</Property>
</Properties>
</SubItem>
<SubItem>
<Name>Status</Name>
<Type GUID="{4B0DBBA4-11EF-DC4A-BF0D-C44F27183D05}" Namespace="lcls_twincat_motion">EL5042_Status</Type>
<Comment><![CDATA[ Status struct placeholder]]></Comment>
<BitSize>0</BitSize>
<BitOffs>64</BitOffs>
</SubItem>
<SubItem>
<Name>Ref</Name>
<Type GUID="{18071995-0000-0000-0000-00000000000B}">ULINT</Type>
<Comment><![CDATA[ Encoder zero position (useful for aligned position with gantries)]]></Comment>
<BitSize>64</BitSize>
<BitOffs>64</BitOffs>
</SubItem>
</DataType>
<DataType>
<Name GUID="{7E016B85-166E-4B4F-AAC4-ECA8DDD44F13}">ST_PMPS_Attenuator_IO</Name>
<BitSize>64</BitSize>
Expand Down Expand Up @@ -1349,7 +1349,7 @@ External Setpoint Generation:
</DataType>
</DataTypes>
<Project GUID="{85BF455D-934D-415A-B04C-6D4CDD9FF10E}" Name="rixs_optics" PrjFilePath="..\..\rixs_optics\rixs_optics.plcproj" TmcFilePath="..\..\rixs_optics\rixs_optics.tmc" ReloadTmc="true" AmsPort="851" FileArchiveSettings="#x000e" SymbolicMapping="true">
<Instance Id="#x08502000" TcSmClass="TComPlcObjDef" KeepUnrestoredLinks="2" TmcPath="rixs_optics\rixs_optics.tmc" TmcHash="{B84F8694-6679-14A7-53B9-D28E1E05082C}">
<Instance Id="#x08502000" TcSmClass="TComPlcObjDef" KeepUnrestoredLinks="2" TmcPath="rixs_optics\rixs_optics.tmc" TmcHash="{AF746F3C-18E1-BB13-C597-9DE0DD4AE3BE}">
<Name>rixs_optics Instance</Name>
<CLSID ClassFactory="TcPlc30">{08500001-0000-0000-F000-000000000064}</CLSID>
<Vars VarGrpType="1">
Expand All @@ -1368,7 +1368,18 @@ External Setpoint Generation:
<Type GUID="{64E6921B-16B3-48BF-80E0-352129E45D23}" Namespace="Tc2_SerialCom">EL6outData22B</Type>
</Var>
</Vars>
<Vars VarGrpType="1" ContextId="2" AreaNo="32">
<Vars VarGrpType="1" ContextId="1" AreaNo="16">
<Name>StatsTask Inputs</Name>
<Var>
<Name>Main.M6.Axis.NcToPlc</Name>
<Type GUID="{25521FAA-EA5F-4C7F-8864-BBCCDACD2E98}" Namespace="MC">NCTOPLC_AXIS_REF</Type>
</Var>
<Var>
<Name>Main.M7.Axis.NcToPlc</Name>
<Type GUID="{25521FAA-EA5F-4C7F-8864-BBCCDACD2E98}" Namespace="MC">NCTOPLC_AXIS_REF</Type>
</Var>
</Vars>
<Vars VarGrpType="1" ContextId="3" AreaNo="48">
<Name>DaqTask Inputs</Name>
<Var>
<Name>PRG_DAQ_ENCODER.iLatchPos</Name>
Expand All @@ -1384,7 +1395,7 @@ External Setpoint Generation:
<Type>ULINT</Type>
</Var>
</Vars>
<Vars VarGrpType="1" ContextId="3" AreaNo="48">
<Vars VarGrpType="1" ContextId="4" AreaNo="64">
<Name>PlcTask Inputs</Name>
<Var>
<Name>lcls_twincat_optics.GVL_TestStructs.TestPitch_LimitSwitches.diEncCnt</Name>
Expand Down Expand Up @@ -1933,6 +1944,16 @@ Emergency Stop for MR1K1]]></Comment>
<Name>PRG_MR4K2_KBV.bM4K2US_RTD_2_Err</Name>
<Type>BOOL</Type>
</Var>
<Var>
<Name>PRG_MR3K2_KBH.fMR3K2_Flow_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>PRG_MR3K2_KBH.fMR3K2_Press_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>PRG_MR4K2_KBV.nM4K2_Chin_Right_RTD.bError</Name>
<Type>BOOL</Type>
Expand Down Expand Up @@ -1995,6 +2016,16 @@ Emergency Stop for MR1K1]]></Comment>
<Comment><![CDATA[ M1K1 US RTDs]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>PRG_MR4K2_KBV.fMR4K2_Flow_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>PRG_MR4K2_KBV.fMR4K2_Press_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>GVL_M1K1_BENDER_RTD.nM1K1US_RTD_2</Name>
<Type>INT</Type>
Expand Down Expand Up @@ -2293,10 +2324,6 @@ Emergency Stop for MR1K1]]></Comment>
<Comment><![CDATA[ Raw encoder IO for INT (LVDT)]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>Main.M6.Axis.NcToPlc</Name>
<Type GUID="{25521FAA-EA5F-4C7F-8864-BBCCDACD2E98}" Namespace="MC">NCTOPLC_AXIS_REF</Type>
</Var>
<Var>
<Name>Main.M6.bLimitForwardEnable</Name>
<Comment><![CDATA[ NC Forward Limit Switch: TRUE if ok to move]]></Comment>
Expand Down Expand Up @@ -2332,10 +2359,6 @@ Emergency Stop for MR1K1]]></Comment>
<Comment><![CDATA[ Raw encoder IO for INT (LVDT)]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>Main.M7.Axis.NcToPlc</Name>
<Type GUID="{25521FAA-EA5F-4C7F-8864-BBCCDACD2E98}" Namespace="MC">NCTOPLC_AXIS_REF</Type>
</Var>
<Var>
<Name>Main.M7.bLimitForwardEnable</Name>
<Comment><![CDATA[ NC Forward Limit Switch: TRUE if ok to move]]></Comment>
Expand Down Expand Up @@ -3621,28 +3644,8 @@ Emergency Stop for MR1K1]]></Comment>
<Name>Main.sio_load</Name>
<Type>UINT</Type>
</Var>
<Var>
<Name>PRG_MR3K2_KBH.fMR3K2_Flow_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>PRG_MR3K2_KBH.fMR3K2_Press_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>PRG_MR4K2_KBV.fMR4K2_Flow_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>PRG_MR4K2_KBV.fMR4K2_Press_1.iRaw</Name>
<Comment><![CDATA[ Connect this input to the terminal]]></Comment>
<Type>INT</Type>
</Var>
</Vars>
<Vars VarGrpType="2" ContextId="3" AreaNo="49">
<Vars VarGrpType="2" ContextId="4" AreaNo="65">
<Name>PlcTask Outputs</Name>
<Var>
<Name>PRG_MR1K1_BEND.fbM1K1PitchControl.fbMotionStage.fbDriveVirtual.MasterAxis.PlcToNc</Name>
Expand Down Expand Up @@ -4201,7 +4204,7 @@ Emergency Stop for MR1K1]]></Comment>
<Type GUID="{96B75FEB-2D84-43BE-A3EC-D9A681F27D52}" Namespace="MC">PLCTONC_AXIS_REF</Type>
</Var>
</Vars>
<Vars VarGrpType="8" ContextId="3" AreaNo="52">
<Vars VarGrpType="8" ContextId="4" AreaNo="68">
<Name>PlcTask Retains</Name>
<Var>
<Name>PMPS_GVL.SuccessfulPreemption</Name>
Expand Down Expand Up @@ -4292,6 +4295,15 @@ Emergency Stop for MR1K1]]></Comment>
</Context>
<Context>
<Id NeedCalleeCall="true">1</Id>
<Name>StatsTask</Name>
<ManualConfig>
<OTCID>#x02010090</OTCID>
</ManualConfig>
<Priority>2</Priority>
<CycleTime>2000000</CycleTime>
</Context>
<Context>
<Id NeedCalleeCall="true">2</Id>
<Name>PiezoDriver</Name>
<ManualConfig>
<OTCID>#x02010060</OTCID>
Expand All @@ -4300,7 +4312,7 @@ Emergency Stop for MR1K1]]></Comment>
<CycleTime>1000000</CycleTime>
</Context>
<Context>
<Id NeedCalleeCall="true">2</Id>
<Id NeedCalleeCall="true">3</Id>
<Name>DaqTask</Name>
<ManualConfig>
<OTCID>#x02010080</OTCID>
Expand All @@ -4309,7 +4321,7 @@ Emergency Stop for MR1K1]]></Comment>
<CycleTime>1000000</CycleTime>
</Context>
<Context>
<Id NeedCalleeCall="true">3</Id>
<Id NeedCalleeCall="true">4</Id>
<Name>PlcTask</Name>
<ManualConfig>
<OTCID>#x02010030</OTCID>
Expand All @@ -4320,6 +4332,7 @@ Emergency Stop for MR1K1]]></Comment>
</Contexts>
<TaskPouOids>
<TaskPouOid Prio="1" OTCID="#x08502001"/>
<TaskPouOid Prio="2" OTCID="#x08502005"/>
<TaskPouOid Prio="3" OTCID="#x08502002"/>
<TaskPouOid Prio="19" OTCID="#x08502003"/>
<TaskPouOid Prio="20" OTCID="#x08502004"/>
Expand Down Expand Up @@ -4936,16 +4949,16 @@ Emergency Stop for MR1K1]]></Comment>
<Link VarA="PlcTask Outputs^Main.M9.Axis.PlcToNc" VarB="Inputs^FromPlc"/>
</OwnerB>
<OwnerB Name="TINC^NC-Task 1 SAF^Axes^g_pi">
<Link VarA="PlcTask Inputs^Main.M7.Axis.NcToPlc" VarB="Outputs^ToPlc"/>
<Link VarA="PlcTask Outputs^Main.M7.Axis.PlcToNc" VarB="Inputs^FromPlc"/>
<Link VarA="StatsTask Inputs^Main.M7.Axis.NcToPlc" VarB="Outputs^ToPlc"/>
</OwnerB>
<OwnerB Name="TINC^NC-Task 1 SAF^Axes^m_h">
<Link VarA="PlcTask Inputs^Main.M8.Axis.NcToPlc" VarB="Outputs^ToPlc"/>
<Link VarA="PlcTask Outputs^Main.M8.Axis.PlcToNc" VarB="Inputs^FromPlc"/>
</OwnerB>
<OwnerB Name="TINC^NC-Task 1 SAF^Axes^m_pi">
<Link VarA="PlcTask Inputs^Main.M6.Axis.NcToPlc" VarB="Outputs^ToPlc"/>
<Link VarA="PlcTask Outputs^Main.M6.Axis.PlcToNc" VarB="Inputs^FromPlc"/>
<Link VarA="StatsTask Inputs^Main.M6.Axis.NcToPlc" VarB="Outputs^ToPlc"/>
</OwnerB>
<OwnerB Name="TINC^NC-Task 1 SAF^Axes^s_io">
<Link VarA="PlcTask Inputs^Main.M10.Axis.NcToPlc" VarB="Outputs^ToPlc"/>
Expand Down
12 changes: 8 additions & 4 deletions lcls-plc-rixs-optics/lcls-plc-rixs-optics.tsproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
<Task Id="7" Priority="1" CycleTime="20000" AmsPort="352" AdtTasks="true">
<Name>SerialIO</Name>
</Task>
<Task Id="8" Priority="19" CycleTime="10000" AmsPort="353" Affinity="#x00000008" AdtTasks="true">
<Task Id="8" Priority="19" CycleTime="10000" AmsPort="353" Affinity="#x00000004" AdtTasks="true">
<Name>DaqTask</Name>
</Task>
<Task Id="9" Priority="2" CycleTime="20000" AmsPort="354" Affinity="#x00000008" AdtTasks="true">
<Name>StatsTask</Name>
</Task>
</Tasks>
</System>
<Motion>
Expand All @@ -48,11 +51,12 @@
</Project>
<Mappings>
<MappingInfo Identifier="{00000000-2001-0850-0020-500810000403}" Id="#x02030010"/>
<MappingInfo Identifier="{00000000-2003-0850-0220-500852000403}" Id="#x02030050"/>
<MappingInfo Identifier="{00000000-2004-0850-0320-500863000403}" Id="#x02030060"/>
<MappingInfo Identifier="{00000000-2003-0850-0320-500852000403}" Id="#x02030050"/>
<MappingInfo Identifier="{00000000-2004-0850-0420-500863000403}" Id="#x02030060"/>
<MappingInfo Identifier="{00000000-0040-0304-3000-040341000403}" Id="#x02030020"/>
<MappingInfo Identifier="{08502003-0040-0304-0020-500840000403}" Id="#x02030030" Watchdog="00000000000000000000000000000000"/>
<MappingInfo Identifier="{08502004-0040-0304-0020-500840000403}" Id="#x02030040" Watchdog="00000000000000000000000000000000"/>
<MappingInfo Identifier="{05000010-2004-0850-3000-040303205008}" Id="#x02030070" Watchdog="14000000040000000400000004000000"/>
<MappingInfo Identifier="{08502005-0010-0500-0120-500830000403}" Id="#x02030070" Watchdog="04000000040000000400000004000000"/>
<MappingInfo Identifier="{05000010-2004-0850-3000-040304205008}" Id="#x02030080" Watchdog="14000000040000000400000004000000"/>
</Mappings>
</TcSmProject>
63 changes: 2 additions & 61 deletions lcls-plc-rixs-optics/rixs_optics/POUs/PRG_SP1K1_MONO.TcPOU
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4022.18">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
<POU Name="PRG_SP1K1_MONO" Id="{397aec28-b6d3-4c1c-afed-2cc3b34939d3}" SpecialFunc="None">
<Declaration><![CDATA[PROGRAM PRG_SP1K1_MONO
VAR
Expand Down Expand Up @@ -192,28 +192,6 @@ VAR
'}
fSP1K1_Press_1_val : LREAL;
// SP1K1 Grating Mono Vibration Stats
fGpiEncoderPosDiff: LREAL;
afGpiPosDiffBuffer: ARRAY[1..1000] OF LREAL;
afGpiExtraBuffer: ARRAY[1..1000] OF LREAL;
fbGpiPosDiffCollect: FB_DataBuffer;
{attribute 'pytmc' := '
pv: SP1K1:MONO:MMS:G_PI:ENCDIFF
'}
fbGpiPosDiffStats: FB_BasicStats;
fGpiRangeMax: LREAL;
rtNewGpiMove: R_TRIG;
tonNewGpiMove: TON;
// SP1K1 Mirror Pitch Mono Vibration Stats
fMpiEncoderPosDiff: LREAL;
afMpiPosDiffBuffer: ARRAY[1..1000] OF LREAL;
afMpiExtraBuffer: ARRAY[1..1000] OF LREAL;
fbMpiPosDiffCollect: FB_DataBuffer;
{attribute 'pytmc' := '
pv: SP1K1:MONO:MMS:M_PI:ENCDIFF
'}
fbMpiPosDiffStats: FB_BasicStats;
END_VAR
]]></Declaration>
<Implementation>
Expand All @@ -232,45 +210,8 @@ fbMotionStage_g_h (stMotionStage:=M9);
fbMotionStage_s_io (stMotionStage:=M10);
fbMotionStage_s_r (stMotionStage:=M11);
fGpiEncoderPosDiff := M7.nEncoderCount - (M7.Axis.NcToPlc.SetPos - M7.stAxisParameters.fEncOffset) * 150;
fbGpiPosDiffCollect(
bExecute:=TRUE,
pInputAdr:=ADR(fGpiEncoderPosDiff),
iInputSize:=SIZEOF(fGpiEncoderPosDiff),
iElemCount:=1000,
pPartialAdr:=ADR(afGpiPosDiffBuffer),
pOutputAdr:=ADR(afGpiExtraBuffer),
);
fbGpiPosDiffStats(
aSignal:=afGpiPosDiffBuffer,
bAlwaysCalc:=TRUE,
);
rtNewGpiMove(CLK:=M7.bExecute);
tonNewGpiMove(
IN:=M7.bExecute,
PT:=T#15s,
);
IF rtNewGpiMove.Q THEN
// Reset before a move
fGpiRangeMax := 0;
ELSIF tonNewGpiMove.Q AND ABS(M7.fPosition - M7.stAxisStatus.fActPosition) > 5 THEN
// Update only during moves, not at the start or end
fGpiRangeMax := MAX(fGpiRangeMax, fbGpiPosDiffStats.fRange);
END_IF
fMpiEncoderPosDiff := M6.nEncoderCount - (M6.Axis.NcToPlc.SetPos - M6.stAxisParameters.fEncOffset) / 0.004505;
fbMpiPosDiffCollect(
bExecute:=TRUE,
pInputAdr:=ADR(fMpiEncoderPosDiff),
iInputSize:=SIZEOF(fMpiEncoderPosDiff),
iElemCount:=1000,
pPartialAdr:=ADR(afMpiPosDiffBuffer),
pOutputAdr:=ADR(afMpiExtraBuffer),
);
fbMpiPosDiffStats(
aSignal:=afMpiPosDiffBuffer,
bAlwaysCalc:=TRUE,
);
//S_R with no hardware limit switched
Expand Down
Loading

0 comments on commit 2036925

Please sign in to comment.