From 6e11f75744b14ad8876b66e0dd1c45c60a423164 Mon Sep 17 00:00:00 2001 From: Nicholas Lentz Date: Tue, 14 May 2024 15:10:55 -0700 Subject: [PATCH 1/5] Corrected bug in which PMPS state position limits would be deactivated if encoder noise projected the axis out of the fDelta range of the state for one scan. Now, the state will switch to Unknown but the limits of the last valid goal state will remain. Also updated the limit check to include the commanded position as well as the active position as part of the checks. This prevents a manual position move from being able to be commanded out of the state in the first place. Added more informative error message when it was specifically the PMPS position state limits that caused a move to error. Added error code 0x4466 to the list of error codes so that it gives a description rather than saying to contact pcds to add the error message. --- .gitmodules | 2 +- lcls-twincat-motion/Library/Library.plcproj | 3 + .../Motion/PMPS/FB_StatePMPSEnables.TcPOU | 32 +- .../Utils/F_MotionErrorCodeLookup.TcPOU | 3 +- .../Tests/FB_StatePMPSEnables_Test.TcPOU | 138 +- .../FB_MotionStageSetAndMoveHelper.TcPOU | 86 + .../Helpers/FB_TestHelperSetAndMove.TcPOU | 4 + .../NC/Axes/Axis_StatePMPSEnable_Test_1.xti | 1581 +++++++++++++++++ lcls-twincat-motion/_Config/NC/NC.xti | 1 + lcls-twincat-motion/_Config/PLC/Library.xti | 66 +- 10 files changed, 1904 insertions(+), 12 deletions(-) create mode 100644 lcls-twincat-motion/Library/Tests/Helpers/FB_MotionStageSetAndMoveHelper.TcPOU create mode 100644 lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti diff --git a/.gitmodules b/.gitmodules index d014f950..6f303e84 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "lcls-twincat-motion/Library/tc_mca_std_lib"] path = lcls-twincat-motion/Library/tc_mca_std_lib - url = ../tc_mca_std_lib.git + url = git@github.com:pcdshub/tc_mca_std_lib.git diff --git a/lcls-twincat-motion/Library/Library.plcproj b/lcls-twincat-motion/Library/Library.plcproj index 4f23ef75..97e1d91f 100644 --- a/lcls-twincat-motion/Library/Library.plcproj +++ b/lcls-twincat-motion/Library/Library.plcproj @@ -586,6 +586,9 @@ Code + + Code + Code diff --git a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU index 8a79810d..b910d3ff 100644 --- a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU +++ b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU @@ -47,6 +47,7 @@ VAR fLowerPos: LREAL; fUpperPos: LREAL; ffNoGoal: FB_FastFault; + bLockBounds: BOOL; END_VAR]]> - 0 AND nGoalStateIndex <= GeneralConstants.MAX_STATES THEN IF astPositionState[nGoalStateIndex].bValid AND astPositionState[nGoalStateIndex].bUpdated THEN bValidGoal := TRUE; + bLockBounds := TRUE; fLowerPos := astPositionState[nGoalStateIndex].fPosition - ABS(astPositionState[nGoalStateIndex].fDelta); fUpperPos := astPositionState[nGoalStateIndex].fPosition + ABS(astPositionState[nGoalStateIndex].fDelta); ELSE @@ -105,6 +111,10 @@ IF nGoalStateIndex > 0 AND nGoalStateIndex <= GeneralConstants.MAX_STATES THEN END_IF ELSE bValidGoal := FALSE; +END_IF + +IF NOT bEnable THEN + bLockBounds := FALSE; END_IF]]> @@ -129,9 +139,17 @@ ffNoGoal( This action sets bForwardEnable and bBackwardEnable based on the current position and the calculated bounds. *) -IF bValidGoal AND bEnable THEN - bForwardEnabled := stMotionStage.stAxisStatus.fActPosition < fUpperPos; - bBackwardEnabled := stMotionStage.stAxisStatus.fActPosition > fLowerPos; +IF bLockBounds THEN + // Prevent forward/backward motion if the position of the axis is outside of the upper/lower bounds respectively. + // Prevent forward/backward motion if the command to the axis is outside of the upper/lower bounds respectively. + bForwardEnabled := stMotionStage.stAxisStatus.fActPosition < fUpperPos AND stMotionStage.fPosition < fUpperPos; + bBackwardEnabled := stMotionStage.stAxisStatus.fActPosition > fLowerPos AND stMotionStage.fPosition > fLowerPos; + + IF stMotionStage.nErrorId = 16#4223 AND (NOT bForwardEnabled OR NOT bBackwardEnabled) THEN + // Cannot move forward or backward, overwrite the error with a custom error message to give more context. + stMotionStage.sCustomErrorMessage := CONCAT(CONCAT(CONCAT( + 'Limits exceeded for most recent PMPS position state: ', LREAL_TO_FMTSTR(fLowerPos,5,TRUE)), ' < pos < '), LREAL_TO_FMTSTR(fUpperPos,5,TRUE)); + END_IF ELSE // Either invalid state with a fault or FB not enabled bForwardEnabled := TRUE; diff --git a/lcls-twincat-motion/Library/POUs/Motion/Utils/F_MotionErrorCodeLookup.TcPOU b/lcls-twincat-motion/Library/POUs/Motion/Utils/F_MotionErrorCodeLookup.TcPOU index 4496017b..b79e685e 100644 --- a/lcls-twincat-motion/Library/POUs/Motion/Utils/F_MotionErrorCodeLookup.TcPOU +++ b/lcls-twincat-motion/Library/POUs/Motion/Utils/F_MotionErrorCodeLookup.TcPOU @@ -21,10 +21,11 @@ END_VAR 16#4357: msg:='Negative limit hit'; 16#4358: msg:='Positive limit hit'; 16#4395: msg:='Set velocity not allowed'; + 16#4466: msg:='Invalid I/O data for more than n continuous NC cycles (encoder)'; + 16#4467: msg:='Encoder error: invalid actual position data'; 16#4550: msg:='Stall: position lag monitoring error'; 16#4650: msg:='Drive hardware not ready to operate'; 16#4655: msg:='Invalid IO data'; - 16#4467: msg:='Encoder error: invalid actual position data'; 16#4B07: msg:='Timeout axis function block after 6 seconds'; 16#4FFF: msg:='Unknown NC error (not in manual)'; diff --git a/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU b/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU index aeeb68d1..a8f45e58 100644 --- a/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU +++ b/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU @@ -31,8 +31,7 @@ VAR END_VAR ]]> - + + + + + + nTestID THEN + RETURN; +END_IF + +// On first pass, set the goal state index to a valid state to initialize the bounds. +// Then, set the goal state index to an unknown state to ensure the bounds remain +// active. +IF NOT bInit THEN + nGoalStateIndex := nGoalState; + SetEnables(stBoundsCheckMotionStage); +ELSE + nGoalStateIndex := 0; +END_IF + + +// Run our FB which should enable the real move while within the allowable bounds. +// Once the position is set out of the bounds, the bounds should persist and prevent +// further movement away from the goal state. +fbStateEnables( + stMotionStage:=stBoundsCheckMotionStage, + astPositionState:=astPositionState, + fbFFHWO:=fbFFHWO, + bEnable:=TRUE, + nGoalStateIndex:=nGoalStateIndex, + eStatePMPSStatus:=E_StatePMPSStatus.TRANSITION, + bTransitionAuthorized:=TRUE, +); + +// Set position to be out of the goal's range, and try to move away from the goal +fbMotionStageSetAndMove( + bExecute:=bInit, + fStartPosition:=astPositionState[nGoalState].fPosition + fStartPosDelta, + fGoalPosition:=astPositionState[nGoalState].fPosition + fGoalPosDelta, + fVelocity:=1.0, + stMotionStage:=stBoundsCheckMotionStage, + fDelta:=0.01, + bResetDone=>, + bSetDone=>, + bMotionStarted=>, + bMoveDone=> +); + +bInit := TRUE; + +fbFFHWO.EvaluateOutput(); + +// If we've reached the position OR ran out of time to set the position, check the asserts +IF tonTimer.Q OR fbMotionStageSetAndMove.bMoveDone THEN + AssertTrue( + tonTimer.Q, + 'Timeout should have occurred. Move should have been unable to complete.', + ); + AssertTrue( + fbMotionStageSetAndMove.bSetDone, + 'Position was never set.', + ); + AssertTrue( + fbMotionStageSetAndMove.bMotionStarted, + 'Move was never commanded.', + ); + AssertEquals_LREAL( + Expected:=astPositionState[nGoalState].fPosition + fStartPosDelta, + Actual:=stBoundsCheckMotionStage.stAxisStatus.fActPosition, + Delta:=0.0001, + Message:='Bounds failed to persist after falling out of state', + ); + AssertFalse( + fbFFHWO.q_xFastFaultOut, + 'Fast fault should have triggered with unknown state', + ); + IF fStartPosDelta < 0 AND abs(fStartPosDelta) > astPositionState[nGoalState].fDelta THEN + AssertFalse( + fbStateEnables.bBackwardEnabled, + 'Backward should be disabled.', + ); + AssertTrue( + fbStateEnables.bForwardEnabled, + 'Forward should be enabled.', + ); + ELSIF fStartPosDelta > 0 AND abs(fStartPosDelta) > astPositionState[nGoalState].fDelta THEN + AssertTrue( + fbStateEnables.bBackwardEnabled, + 'Backward should be enabled.', + ); + AssertFalse( + fbStateEnables.bForwardEnabled, + 'Forward should be disabled.', + ); + ELSE + AssertTrue( + fbStateEnables.bForwardEnabled, + 'Forward should be enabled.', + ); + AssertTrue( + fbStateEnables.bBackwardEnabled, + 'Backward should be enabled.', + ); + END_IF + bInit := FALSE; + stBoundsCheckMotionStage.bReset := TRUE; + bOneTestDone := TRUE; + TEST_FINISHED(); +END_IF + +fbBoundsCheckMotionStage(stMotionStage:=stBoundsCheckMotionStage); ]]> diff --git a/lcls-twincat-motion/Library/Tests/Helpers/FB_MotionStageSetAndMoveHelper.TcPOU b/lcls-twincat-motion/Library/Tests/Helpers/FB_MotionStageSetAndMoveHelper.TcPOU new file mode 100644 index 00000000..1ea98942 --- /dev/null +++ b/lcls-twincat-motion/Library/Tests/Helpers/FB_MotionStageSetAndMoveHelper.TcPOU @@ -0,0 +1,86 @@ + + + + + + = fGoalPosition - fDelta; + +IF NOT bSetDone THEN + stMotionStage.bReset := TRUE; + stMotionStage.bEnable := FALSE; + IF stMotionStage.stAxisStatus.fActPosition <> fStartPosition THEN + mcSetPos( + Axis:=stMotionStage.Axis, + Execute:=NOT mcSetPos.Execute, + Position:=fStartPosition, + Mode:=FALSE, + Done=> + ); + ELSE + bSetDone := TRUE; + END_IF +ELSE + stMotionStage.bEnable := TRUE; + IF NOT bMotionStarted AND NOT stMotionStage.Axis.Status.Disabled THEN + stMotionStage.fPosition := fGoalPosition; + stMotionStage.fVelocity := fVelocity; + stMotionStage.bMoveCmd := TRUE; + bMotionStarted := TRUE; + END_IF +END_IF + +IF bMoveDone THEN + stMotionStage.bReset := TRUE; +END_IF +]]> + + + \ No newline at end of file diff --git a/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU b/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU index 42e126e1..eea64766 100644 --- a/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU +++ b/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU @@ -131,6 +131,10 @@ ELSIF fStartPosition <> fGoalPosition THEN ); bMotionStarted S= bSetDone AND fbMoveRequest.bExecute AND stMotionStage.bBusy AND stMotionStage.stAxisStatus.fActPosition <> fStartPosition; bMoveDone S= bMotionStarted AND stMotionStage.stAxisStatus.fActPosition = fGoalPosition; +ELSIF fStartPosition = fGoalPosition THEN + // if the start position matches the goal position, make sure the commanded postion is + // set to the current position. + stMotionStage.fPosition := fGoalPosition; END_IF // Set the position prior to the move but after the reset. diff --git a/lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti b/lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti new file mode 100644 index 00000000..b54a3603 --- /dev/null +++ b/lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti @@ -0,0 +1,1581 @@ + + + + + UINTARR2 + 32 + UINT + + 0 + 2 + + + [%u, %u] + [0] + [1] + + + 0x%08x [%u, %u] + . + [0] + [1] + + + 0x%08x (%u) + . + . + + + + NCENCODERSTRUCT_IN2B + 320 + + nDataIn1 + UINTARR2 + 32 + 0 + + + nDataIn2 + UINTARR2 + 32 + 32 + + + nState1 + USINT + 8 + 64 + + + nState2 + USINT + 8 + 72 + + + nState3 + USINT + 8 + 80 + + + nState4 + USINT + + 8 + 88 + + + nDataIn3 + UINTARR2 + 32 + 96 + + + nDataIn4 + UINTARR2 + 32 + 128 + + + nDataIn5 + UINTARR2 + 32 + 160 + + + nDataIn6 + UINTARR2 + 32 + 192 + + + nState5 + USINT + 8 + 224 + + + nState6 + USINT + 8 + 232 + + + nState7 + USINT + 8 + 240 + + + nState8 + USINT + 8 + 248 + + + nDcInputTime + DINT + 32 + 256 + + + nDataIn7 + UINTARR2 + + 32 + 288 + + + + NCENCODERSTRUCT_IN + + 96 + + + + + + NCENCODERSTRUCT_OUT2 + 320 + + nDataOut1 + UINTARR2 + 32 + 0 + + + nDataOut2 + UINTARR2 + 32 + 32 + + + nCtrl1 + USINT + 8 + 64 + + + nCtrl2 + USINT + 8 + 72 + + + nCtrl3 + USINT + 8 + 80 + + + nCtrl4 + USINT + 8 + 88 + + + nDataOut3 + UINTARR2 + 32 + 96 + + + nDataOut4 + UINTARR2 + 32 + 128 + + + nDataOut5 + UINTARR2 + 32 + 160 + + + nDataOut6 + UINTARR2 + 32 + 192 + + + nCtrl5 + USINT + 8 + 224 + + + nCtrl6 + USINT + 8 + 232 + + + nCtrl7 + USINT + 8 + 240 + + + nCtrl8 + USINT + 8 + 248 + + + + NCENCODERSTRUCT_OUT + + 96 + + + + + + NCDRIVESTRUCT_IN2 + 320 + + nDataIn1 + UINTARR2 + 32 + 0 + + + nDataIn2 + UINTARR2 + 32 + 32 + + + nState1 + USINT + 8 + 64 + + + nState2 + USINT + 8 + 72 + + + nState3 + USINT + 8 + 80 + + + nState4 + USINT + + 8 + 88 + + + nDataIn3 + UINTARR2 + 32 + 96 + + + nDataIn4 + UINTARR2 + 32 + 128 + + + nDataIn5 + UINTARR2 + 32 + 160 + + + nDataIn6 + UINTARR2 + 32 + 192 + + + nState5 + USINT + 8 + 224 + + + nState6 + USINT + 8 + 232 + + + nState7 + USINT + 8 + 240 + + + nState8 + USINT + + 8 + 248 + + + nDcOutputTime + DINT + 32 + 256 + + + + NCDRIVESTRUCT_IN + + 96 + + + + + + NCDRIVESTRUCT_OUT2 + 320 + + nDataOut1 + UINTARR2 + 32 + 0 + + + nDataOut2 + UINTARR2 + 32 + 32 + + + nCtrl1 + USINT + 8 + 64 + + + nCtrl2 + USINT + 8 + 72 + + + nCtrl3 + USINT + 8 + 80 + + + nCtrl4 + USINT + 8 + 88 + + + nDataOut3 + UINTARR2 + 32 + 96 + + + nDataOut4 + UINTARR2 + 32 + 128 + + + nDataOut5 + UINTARR2 + 32 + 160 + + + nDataOut6 + UINTARR2 + 32 + 192 + + + nCtrl5 + USINT + 8 + 224 + + + nCtrl6 + USINT + 8 + 232 + + + nCtrl7 + USINT + 8 + 240 + + + nCtrl8 + USINT + 8 + 248 + + + + NCDRIVESTRUCT_OUT + + 96 + + + + + + PLCTONC_AXIS_REF_CTRL + 32 + + Enable + BIT + 1 + 0 + + + FeedEnablePlus + BIT + 1 + 1 + + + FeedEnableMinus + BIT + 1 + 2 + + + HomingSensor + BIT + 1 + 5 + + + AcceptBlockedDrive + BIT + 1 + 8 + + + PlcDebugFlag + BIT + 1 + 30 + + + NcDebugFlag + BIT + 1 + 31 + + + %08x + + + 0x%08x + + + 16#%08X + + + + PLCTONC_AXIS_REF + 1024 + + ControlDWord + PLCTONC_AXIS_REF_CTRL + 32 + 0 + + + Override + UDINT + 32 + 32 + + + AxisModeRequest + UDINT + 32 + 64 + + + AxisModeDWord + UDINT + 32 + 96 + + + AxisModeLReal + LREAL + 64 + 128 + + + PositionCorrection + LREAL + 64 + 192 + + + ExtSetPos + LREAL + 64 + 256 + + + ExtSetVelo + LREAL + 64 + 320 + + + ExtSetAcc + LREAL + 64 + 384 + + + ExtSetDirection + DINT + 32 + 448 + + + ExtControllerOutput + LREAL + 64 + 512 + + + GearRatio1 + LREAL + 64 + 576 + + + GearRatio2 + LREAL + 64 + 640 + + + GearRatio3 + LREAL + 64 + 704 + + + GearRatio4 + LREAL + 64 + 768 + + + MapState + BOOL + 8 + 832 + + + PlcCycleControl + BYTE + 8 + 840 + + + PlcCycleCount + BYTE + 8 + 848 + + + ExtTorque + LREAL + 64 + 896 + + + + NcStructType + 1 + + + + + + + + + + + + + NCTOPLC_AXIS_REF_STATE + 32 + + Operational + BIT + 1 + 0 + + + Homed + BIT + 1 + 1 + + + NotMoving + BIT + 1 + 2 + + + InPositionArea + BIT + 1 + 3 + + + InTargetPosition + BIT + 1 + 4 + + + Protected + BIT + 1 + 5 + + + ErrorPropagationDelayed + BIT + 1 + 6 + + + HasBeenStopped + BIT + 1 + 7 + + + HasJob + BIT + 1 + 8 + + + PositiveDirection + BIT + 1 + 9 + + + NegativeDirection + BIT + 1 + 10 + + + HomingBusy + BIT + 1 + 11 + + + ConstantVelocity + BIT + 1 + 12 + + + Compensating + BIT + 1 + 13 + + + ExtSetPointGenEnabled + BIT + 1 + 14 + + + PhasingActive + BIT + 1 + 15 + + + ExternalLatchValid + BIT + 1 + 16 + + + NewTargetPos + BIT + 1 + 17 + + + IsDriveLimitActive + BIT + 1 + 18 + + + ContinuousMotion + BIT + 1 + 19 + + + ControlLoopClosed + BIT + 1 + 20 + + + CamTableQueued + BIT + 1 + 21 + + + CamDataQueued + BIT + 1 + 22 + + + CamScalingPending + BIT + 1 + 23 + + + CmdBuffered + BIT + 1 + 24 + + + PTPmode + BIT + 1 + 25 + + + SoftLimitMinExceeded + BIT + 1 + 26 + + + SoftLimitMaxExceeded + BIT + 1 + 27 + + + DriveDeviceError + BIT + 1 + 28 + + + MotionCommandsLocked + BIT + 1 + 29 + + + IoDataInvalid + BIT + 1 + 30 + + + Error + BIT + 1 + 31 + + + %08x + + + 0x%08x + + + 16#%08X + + + + {4C3FC5AC-D5AA-44C6-AC5A-159774BA0F6D} + + + + + NCTOPLC_AXIS_REF_OPMODE + 32 + + OpModePosAreaMonitoring + BIT + 1 + 0 + + + OpModeTargetPosMonitoring + BIT + 1 + 1 + + + OpModeLoop + BIT + 1 + 2 + + + OpModeMotionMonitoring + BIT + 1 + 3 + + + OpModePEHTimeMonitoring + BIT + 1 + 4 + + + OpModeBacklashCompensation + BIT + 1 + 5 + + + OpModeDelayedErrorReaction + BIT + 1 + 6 + + + OpModeModulo + BIT + 1 + 7 + + + OpModeSimulationAxis + BIT + 1 + 8 + + + OpModeStopMonitoring + BIT + 1 + 12 + + + OpModeOutputSmoothingFilter + BIT + 1 + 13 + + + OpModePosLagMonitoring + BIT + 1 + 16 + + + OpModeVeloLagMonitoring + BIT + 1 + 17 + + + OpModeSoftLimitMinMonitoring + BIT + 1 + 18 + + + OpModeSoftLimitMaxMonitoring + BIT + 1 + 19 + + + OpModePosCorrection + BIT + 1 + 20 + + + OpModeAllowSlaveCommands + BIT + 1 + 21 + + + OpModeAllowExtSetAxisCommands + BIT + 1 + 22 + + + ApplicationRequest + BIT + 1 + 23 + + + + NCTOPLC_AXIS_REF_STATE2_FLAGS + 32 + + AvoidingCollision + BIT + 1 + 0 + + + %08x + + + 0x%08x + + + 16#%08X + + + + NCTOPLC_AXIS_REF_STATE2 + 32 + + Value + DWORD + 32 + 0 + + + Flags + NCTOPLC_AXIS_REF_STATE2_FLAGS + 32 + 0 + + + %08x + + + 0x%08x + + + 16#%08X + + + + NCTOPLC_AXIS_REF_STATE3_FLAGS + 32 + + TouchProbe1InputState + BIT + 1 + 0 + + + TouchProbe2InputState + BIT + 1 + 1 + + + %08x + + + 0x%08x + + + 16#%08X + + + + NCTOPLC_AXIS_REF_STATE3 + 32 + + Value + DWORD + 32 + 0 + + + Flags + NCTOPLC_AXIS_REF_STATE3_FLAGS + 32 + 0 + + + %08x + + + 0x%08x + + + 16#%08X + + + + NCTOPLC_AXIS_REF_CAMCOUPLINGSTATE + 8 + + CamActivationPending + BIT + 1 + 0 + + + CamDeactivationPending + BIT + 1 + 1 + + + CamActive + BIT + 1 + 2 + + + CamDataQueued + BIT + 1 + 6 + + + CamScalingPending + BIT + 1 + 7 + + + + UINTARR8 + 128 + UINT + + 0 + 8 + + + + NCTOPLC_AXIS_REF + 2048 + + StateDWord + NCTOPLC_AXIS_REF_STATE + 32 + 0 + + + ErrorCode + UDINT + 32 + 32 + + + AxisState + UDINT + + 32 + 64 + + + AxisModeConfirmation + UDINT + 32 + 96 + + + HomingState + UDINT + + 32 + 128 + + + CoupleState + UDINT + + 32 + 160 + + + SvbEntries + UDINT + 32 + 192 + + + SafEntries + UDINT + 32 + 224 + + + AxisId + UDINT + 32 + 256 + + + OpModeDWord + NCTOPLC_AXIS_REF_OPMODE + 32 + 288 + + + ActPos + LREAL + 64 + 320 + + + ModuloActPos + LREAL + 64 + 384 + + + ActiveControlLoopIndex + UINT + 16 + 448 + + + ControlLoopIndex + UINT + 16 + 464 + + + ModuloActTurns + DINT + 32 + 480 + + + ActVelo + LREAL + 64 + 512 + + + PosDiff + LREAL + 64 + 576 + + + SetPos + LREAL + 64 + 640 + + + SetVelo + LREAL + 64 + 704 + + + SetAcc + LREAL + 64 + 768 + + + TargetPos + LREAL + 64 + 832 + + + ModuloSetPos + LREAL + 64 + 896 + + + ModuloSetTurns + DINT + 32 + 960 + + + CmdNo + UINT + 16 + 992 + + + CmdState + UINT + 16 + 1008 + + + SetJerk + LREAL + 64 + 1024 + + + SetTorque + LREAL + 64 + 1088 + + + ActTorque + LREAL + 64 + 1152 + + + StateDWord2 + NCTOPLC_AXIS_REF_STATE2 + 32 + 1216 + + + StateDWord3 + NCTOPLC_AXIS_REF_STATE3 + 32 + 1248 + + + TouchProbeState + DWORD + 32 + 1280 + + + TouchProbeCounter + DWORD + 32 + 1312 + + + CamCouplingState + NCTOPLC_AXIS_REF_CAMCOUPLINGSTATE + + 0 + 8 + + 64 + 1344 + + + CamCouplingTableID + UINTARR8 + 128 + 1408 + + + ActTorqueDerivative + LREAL + 64 + 1536 + + + SetTorqueDerivative + LREAL + 64 + 1600 + + + AbsPhasingPos + LREAL + 64 + 1664 + + + TorqueOffset + LREAL + 64 + 1728 + + + ActPosWithoutPosCorrection + LREAL + 64 + 1792 + + + ActAcc + LREAL + 64 + 1856 + + + DcTimeStamp + UDINT + 32 + 1920 + + + UserData + LREAL + 64 + 1984 + + + + NcStructType + 2 + + + + + NCAXLESTRUCT_TOPLC + + + NCAXLESTRUCT_TOPLC2 + + + NCAXLESTRUCT_TOPLC3 + + + NCAXLESTRUCT_TOPLC4 + + + + + + + + + + + + + + + + + + + + + + + + __FILENAME__ + + + + + + Inputs + + In + NCENCODERSTRUCT_IN2B + + nDataIn1 + + + nDataIn2 + + + nDataIn3 + + + nDataIn4 + + + nDataIn5 + + + nDataIn6 + + + nDataIn7 + + + + + + Outputs + + Out + NCENCODERSTRUCT_OUT2 + + nDataOut1 + + + nDataOut2 + + + nDataOut3 + + + nDataOut4 + + + nDataOut5 + + + nDataOut6 + + + + + + + + + + + Inputs + + In + NCDRIVESTRUCT_IN2 + + nDataIn1 + + + nDataIn2 + + + nDataIn3 + + + nDataIn4 + + + nDataIn5 + + + nDataIn6 + + + + + Outputs + + Out + NCDRIVESTRUCT_OUT2 + + nDataOut1 + + + nDataOut2 + + + nCtrl2 + + + + nCtrl3 + + + + nDataOut3 + + + nDataOut4 + + + nDataOut5 + + + nDataOut6 + + + + + + + + + + + Inputs + + FromPlc + PLCTONC_AXIS_REF + + + + Outputs + + ToPlc + NCTOPLC_AXIS_REF + + + + diff --git a/lcls-twincat-motion/_Config/NC/NC.xti b/lcls-twincat-motion/_Config/NC/NC.xti index 5fe0ab53..e59ef4a7 100644 --- a/lcls-twincat-motion/_Config/NC/NC.xti +++ b/lcls-twincat-motion/_Config/NC/NC.xti @@ -34,6 +34,7 @@ + diff --git a/lcls-twincat-motion/_Config/PLC/Library.xti b/lcls-twincat-motion/_Config/PLC/Library.xti index c12181bd..206ade08 100644 --- a/lcls-twincat-motion/_Config/PLC/Library.xti +++ b/lcls-twincat-motion/_Config/PLC/Library.xti @@ -983,7 +983,7 @@ External Setpoint Generation: - + Library Instance {08500001-0000-0000-F000-000000000064} @@ -2343,6 +2343,49 @@ External Setpoint Generation: PRG_TEST.fb_StatePMPSEnables_Test.fbMotionStage.fbDriveVirtual.MasterAxis.NcToPlc NCTOPLC_AXIS_REF + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.Axis.NcToPlc + NCTOPLC_AXIS_REF + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bLimitForwardEnable + + BOOL + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bLimitBackwardEnable + + BOOL + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bHome + + BOOL + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bHardwareEnable + + BOOL + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.nRawEncoderULINT + + ULINT + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.nRawEncoderUINT + + UINT + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.nRawEncoderINT + + INT + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__FBBOUNDSCHECKMOTIONSTAGE.fbDriveVirtual.MasterAxis.NcToPlc + NCTOPLC_AXIS_REF + PRG_TEST.fb_PerMotorFFOND_Test.__FB_PERMOTORFFOND_TEST__TESTBLANKCOUNT__ASTMOTIONSTAGE[1].Axis.NcToPlc NCTOPLC_AXIS_REF @@ -3797,6 +3840,23 @@ External Setpoint Generation: PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBELOW__FBFFHWO.q_xFastFaultOut BOOL + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.Axis.PlcToNc + PLCTONC_AXIS_REF + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bBrakeRelease + + BOOL + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__FBBOUNDSCHECKMOTIONSTAGE.fbDriveVirtual.MasterAxis.PlcToNc + PLCTONC_AXIS_REF + + + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__FBFFHWO.q_xFastFaultOut + BOOL + PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTDISABLED__FBFFHWO.q_xFastFaultOut BOOL @@ -4274,6 +4334,10 @@ External Setpoint Generation: + + + + From 768d8660b483186c5f28e671b26808e04d72a64b Mon Sep 17 00:00:00 2001 From: Nicholas Lentz Date: Tue, 14 May 2024 15:17:00 -0700 Subject: [PATCH 2/5] Updated readme. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0327b50..8d2e8d1a 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,8 @@ fbMotionStage(stMotionStage := stMotionStage); | Setting | Type | Usage | Default | | --- | --- | --- | --- | -| `bPowerSelf` | `BOOL` | If `FALSE` (default), then `FB_MotionStage` will expect an external PMPS function block to call `MC_Power` appropriately. You can switch this to `TRUE` to opt out of PMPS and handle motor enabling within `FB_MotionStage`. | `FALSE` | +| `bPowerSelf` | `BOOL` | If `FALSE` (default), then `FB_MotionStage` will expect an external PMPS function block to call `MC_Power` appropriately. You can switch this to `TRUE` to opt out of PMPS and handle motor enabling within `FB_MotionStage`. In version 4.1.0 of the library, this is no longer an +optional parameter and will be set automatically to `FALSE` if the PMPS enable function block is used. This is because the PMPS enable function block should never be used without `bPowerSelf` set to `FALSE`. | `FALSE` | | `nEnableMode` | `ENUM_StageEnableMode` | Automatically enable the NC Axis `ALWAYS`, `NEVER`, or only `DURING_MOTION` (default). Switch this to `ALWAYS` if you want active position correction at all times and to `NEVER` if you're doing checkout with the TwinCAT NC GUI. | `DURING_MOTION` | | `nBrakeMode` | `ENUM_StageBrakeMode` | Break disengage timing. Disengage the break `IF_ENABLED` (default), `IF_MOVING`, or never change the break state with `NO_BRAKE`. Note that this does nothing unless a brake is linked to `bBrakeRelease`. | `IF_ENABLED` | | `nHomingMode` | `ENUM_EpicsHomeCmd` | Pick which switch to home to, or not to require homing (default). | `NONE` | From cf5b529e8a852124a1e4b1d2c64b3f52c1b77431 Mon Sep 17 00:00:00 2001 From: Nicholas Lentz Date: Tue, 14 May 2024 15:31:14 -0700 Subject: [PATCH 3/5] Fixed typos. --- .../Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU | 2 +- .../Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU | 2 +- lcls-twincat-motion/_Config/PLC/Library.xti | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU index b910d3ff..c1ce4caa 100644 --- a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU +++ b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU @@ -65,7 +65,7 @@ RunFastFaults(); *) bEnabled := stMotionStage.bAllEnable; bForwardEnabled := bForwardEnabled AND stMotionStage.bAllForwardEnable; -bBackwardEnabled := bBackwardEnabled AND stMotionStage.bAllForwardEnable; +bBackwardEnabled := bBackwardEnabled AND stMotionStage.bAllBackwardEnable; CASE eStatePMPSStatus OF E_StatePMPSStatus.UNKNOWN: diff --git a/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU b/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU index eea64766..ca7516d4 100644 --- a/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU +++ b/lcls-twincat-motion/Library/Tests/Helpers/FB_TestHelperSetAndMove.TcPOU @@ -132,7 +132,7 @@ ELSIF fStartPosition <> fGoalPosition THEN bMotionStarted S= bSetDone AND fbMoveRequest.bExecute AND stMotionStage.bBusy AND stMotionStage.stAxisStatus.fActPosition <> fStartPosition; bMoveDone S= bMotionStarted AND stMotionStage.stAxisStatus.fActPosition = fGoalPosition; ELSIF fStartPosition = fGoalPosition THEN - // if the start position matches the goal position, make sure the commanded postion is + // if the start position matches the goal position, make sure the commanded position is // set to the current position. stMotionStage.fPosition := fGoalPosition; END_IF diff --git a/lcls-twincat-motion/_Config/PLC/Library.xti b/lcls-twincat-motion/_Config/PLC/Library.xti index 206ade08..4ced6990 100644 --- a/lcls-twincat-motion/_Config/PLC/Library.xti +++ b/lcls-twincat-motion/_Config/PLC/Library.xti @@ -983,7 +983,7 @@ External Setpoint Generation: - + Library Instance {08500001-0000-0000-F000-000000000064} From 805d3f3ceafeafe8e2605af5381eaecc262a911a Mon Sep 17 00:00:00 2001 From: Nicholas Lentz Date: Thu, 16 May 2024 14:28:33 -0700 Subject: [PATCH 4/5] Updated error message trigger to be more specific. Deleted extra axis. Changed PMPS position checking to use values directly from NC. --- .../Motion/PMPS/FB_StatePMPSEnables.TcPOU | 11 +- .../Tests/FB_StatePMPSEnables_Test.TcPOU | 20 +- .../NC/Axes/Axis_StatePMPSEnable_Test_1.xti | 1581 ----------------- lcls-twincat-motion/_Config/NC/NC.xti | 1 - lcls-twincat-motion/_Config/PLC/Library.xti | 62 +- 5 files changed, 18 insertions(+), 1657 deletions(-) delete mode 100644 lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti diff --git a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU index c1ce4caa..325e6ca6 100644 --- a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU +++ b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU @@ -48,6 +48,7 @@ VAR fUpperPos: LREAL; ffNoGoal: FB_FastFault; bLockBounds: BOOL; + bErrorMsg: BOOL; END_VAR]]> fLowerPos AND stMotionStage.fPosition > fLowerPos; + bForwardEnabled := stMotionStage.Axis.NcToPlc.ActPos < fUpperPos AND stMotionStage.Axis.NcToPlc.TargetPos < fUpperPos; + bBackwardEnabled := stMotionStage.Axis.NcToPlc.ActPos > fLowerPos AND stMotionStage.Axis.NcToPlc.TargetPos > fLowerPos; - IF stMotionStage.nErrorId = 16#4223 AND (NOT bForwardEnabled OR NOT bBackwardEnabled) THEN - // Cannot move forward or backward, overwrite the error with a custom error message to give more context. + IF (stMotionStage.nErrorId = 16#4223 OR stMotionStage.nErrorId = 16#4260) AND + ((stMotionStage.bAllForwardEnable AND NOT bForwardEnabled) OR + (stMotionStage.bAllBackwardEnable AND NOT bBackwardEnabled)) THEN + // Cannot move forward and not triggered by the forward limit switch, overwrite the error with a custom error message to give more context. stMotionStage.sCustomErrorMessage := CONCAT(CONCAT(CONCAT( 'Limits exceeded for most recent PMPS position state: ', LREAL_TO_FMTSTR(fLowerPos,5,TRUE)), ' < pos < '), LREAL_TO_FMTSTR(fUpperPos,5,TRUE)); END_IF diff --git a/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU b/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU index a8f45e58..3d90a6e3 100644 --- a/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU +++ b/lcls-twincat-motion/Library/Tests/FB_StatePMPSEnables_Test.TcPOU @@ -31,7 +31,8 @@ VAR END_VAR ]]> - - nTestID THEN RETURN; END_IF @@ -326,7 +326,7 @@ END_IF // active. IF NOT bInit THEN nGoalStateIndex := nGoalState; - SetEnables(stBoundsCheckMotionStage); + SetEnables(stMotionStage); ELSE nGoalStateIndex := 0; END_IF @@ -336,7 +336,7 @@ END_IF // Once the position is set out of the bounds, the bounds should persist and prevent // further movement away from the goal state. fbStateEnables( - stMotionStage:=stBoundsCheckMotionStage, + stMotionStage:=stMotionStage, astPositionState:=astPositionState, fbFFHWO:=fbFFHWO, bEnable:=TRUE, @@ -351,7 +351,7 @@ fbMotionStageSetAndMove( fStartPosition:=astPositionState[nGoalState].fPosition + fStartPosDelta, fGoalPosition:=astPositionState[nGoalState].fPosition + fGoalPosDelta, fVelocity:=1.0, - stMotionStage:=stBoundsCheckMotionStage, + stMotionStage:=stMotionStage, fDelta:=0.01, bResetDone=>, bSetDone=>, @@ -379,7 +379,7 @@ IF tonTimer.Q OR fbMotionStageSetAndMove.bMoveDone THEN ); AssertEquals_LREAL( Expected:=astPositionState[nGoalState].fPosition + fStartPosDelta, - Actual:=stBoundsCheckMotionStage.stAxisStatus.fActPosition, + Actual:=stMotionStage.stAxisStatus.fActPosition, Delta:=0.0001, Message:='Bounds failed to persist after falling out of state', ); @@ -416,12 +416,12 @@ IF tonTimer.Q OR fbMotionStageSetAndMove.bMoveDone THEN ); END_IF bInit := FALSE; - stBoundsCheckMotionStage.bReset := TRUE; + stMotionStage.bReset := TRUE; bOneTestDone := TRUE; TEST_FINISHED(); END_IF -fbBoundsCheckMotionStage(stMotionStage:=stBoundsCheckMotionStage); +fbMotionStage(stMotionStage:=stMotionStage); ]]> diff --git a/lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti b/lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti deleted file mode 100644 index b54a3603..00000000 --- a/lcls-twincat-motion/_Config/NC/Axes/Axis_StatePMPSEnable_Test_1.xti +++ /dev/null @@ -1,1581 +0,0 @@ - - - - - UINTARR2 - 32 - UINT - - 0 - 2 - - - [%u, %u] - [0] - [1] - - - 0x%08x [%u, %u] - . - [0] - [1] - - - 0x%08x (%u) - . - . - - - - NCENCODERSTRUCT_IN2B - 320 - - nDataIn1 - UINTARR2 - 32 - 0 - - - nDataIn2 - UINTARR2 - 32 - 32 - - - nState1 - USINT - 8 - 64 - - - nState2 - USINT - 8 - 72 - - - nState3 - USINT - 8 - 80 - - - nState4 - USINT - - 8 - 88 - - - nDataIn3 - UINTARR2 - 32 - 96 - - - nDataIn4 - UINTARR2 - 32 - 128 - - - nDataIn5 - UINTARR2 - 32 - 160 - - - nDataIn6 - UINTARR2 - 32 - 192 - - - nState5 - USINT - 8 - 224 - - - nState6 - USINT - 8 - 232 - - - nState7 - USINT - 8 - 240 - - - nState8 - USINT - 8 - 248 - - - nDcInputTime - DINT - 32 - 256 - - - nDataIn7 - UINTARR2 - - 32 - 288 - - - - NCENCODERSTRUCT_IN - - 96 - - - - - - NCENCODERSTRUCT_OUT2 - 320 - - nDataOut1 - UINTARR2 - 32 - 0 - - - nDataOut2 - UINTARR2 - 32 - 32 - - - nCtrl1 - USINT - 8 - 64 - - - nCtrl2 - USINT - 8 - 72 - - - nCtrl3 - USINT - 8 - 80 - - - nCtrl4 - USINT - 8 - 88 - - - nDataOut3 - UINTARR2 - 32 - 96 - - - nDataOut4 - UINTARR2 - 32 - 128 - - - nDataOut5 - UINTARR2 - 32 - 160 - - - nDataOut6 - UINTARR2 - 32 - 192 - - - nCtrl5 - USINT - 8 - 224 - - - nCtrl6 - USINT - 8 - 232 - - - nCtrl7 - USINT - 8 - 240 - - - nCtrl8 - USINT - 8 - 248 - - - - NCENCODERSTRUCT_OUT - - 96 - - - - - - NCDRIVESTRUCT_IN2 - 320 - - nDataIn1 - UINTARR2 - 32 - 0 - - - nDataIn2 - UINTARR2 - 32 - 32 - - - nState1 - USINT - 8 - 64 - - - nState2 - USINT - 8 - 72 - - - nState3 - USINT - 8 - 80 - - - nState4 - USINT - - 8 - 88 - - - nDataIn3 - UINTARR2 - 32 - 96 - - - nDataIn4 - UINTARR2 - 32 - 128 - - - nDataIn5 - UINTARR2 - 32 - 160 - - - nDataIn6 - UINTARR2 - 32 - 192 - - - nState5 - USINT - 8 - 224 - - - nState6 - USINT - 8 - 232 - - - nState7 - USINT - 8 - 240 - - - nState8 - USINT - - 8 - 248 - - - nDcOutputTime - DINT - 32 - 256 - - - - NCDRIVESTRUCT_IN - - 96 - - - - - - NCDRIVESTRUCT_OUT2 - 320 - - nDataOut1 - UINTARR2 - 32 - 0 - - - nDataOut2 - UINTARR2 - 32 - 32 - - - nCtrl1 - USINT - 8 - 64 - - - nCtrl2 - USINT - 8 - 72 - - - nCtrl3 - USINT - 8 - 80 - - - nCtrl4 - USINT - 8 - 88 - - - nDataOut3 - UINTARR2 - 32 - 96 - - - nDataOut4 - UINTARR2 - 32 - 128 - - - nDataOut5 - UINTARR2 - 32 - 160 - - - nDataOut6 - UINTARR2 - 32 - 192 - - - nCtrl5 - USINT - 8 - 224 - - - nCtrl6 - USINT - 8 - 232 - - - nCtrl7 - USINT - 8 - 240 - - - nCtrl8 - USINT - 8 - 248 - - - - NCDRIVESTRUCT_OUT - - 96 - - - - - - PLCTONC_AXIS_REF_CTRL - 32 - - Enable - BIT - 1 - 0 - - - FeedEnablePlus - BIT - 1 - 1 - - - FeedEnableMinus - BIT - 1 - 2 - - - HomingSensor - BIT - 1 - 5 - - - AcceptBlockedDrive - BIT - 1 - 8 - - - PlcDebugFlag - BIT - 1 - 30 - - - NcDebugFlag - BIT - 1 - 31 - - - %08x - - - 0x%08x - - - 16#%08X - - - - PLCTONC_AXIS_REF - 1024 - - ControlDWord - PLCTONC_AXIS_REF_CTRL - 32 - 0 - - - Override - UDINT - 32 - 32 - - - AxisModeRequest - UDINT - 32 - 64 - - - AxisModeDWord - UDINT - 32 - 96 - - - AxisModeLReal - LREAL - 64 - 128 - - - PositionCorrection - LREAL - 64 - 192 - - - ExtSetPos - LREAL - 64 - 256 - - - ExtSetVelo - LREAL - 64 - 320 - - - ExtSetAcc - LREAL - 64 - 384 - - - ExtSetDirection - DINT - 32 - 448 - - - ExtControllerOutput - LREAL - 64 - 512 - - - GearRatio1 - LREAL - 64 - 576 - - - GearRatio2 - LREAL - 64 - 640 - - - GearRatio3 - LREAL - 64 - 704 - - - GearRatio4 - LREAL - 64 - 768 - - - MapState - BOOL - 8 - 832 - - - PlcCycleControl - BYTE - 8 - 840 - - - PlcCycleCount - BYTE - 8 - 848 - - - ExtTorque - LREAL - 64 - 896 - - - - NcStructType - 1 - - - - - - - - - - - - - NCTOPLC_AXIS_REF_STATE - 32 - - Operational - BIT - 1 - 0 - - - Homed - BIT - 1 - 1 - - - NotMoving - BIT - 1 - 2 - - - InPositionArea - BIT - 1 - 3 - - - InTargetPosition - BIT - 1 - 4 - - - Protected - BIT - 1 - 5 - - - ErrorPropagationDelayed - BIT - 1 - 6 - - - HasBeenStopped - BIT - 1 - 7 - - - HasJob - BIT - 1 - 8 - - - PositiveDirection - BIT - 1 - 9 - - - NegativeDirection - BIT - 1 - 10 - - - HomingBusy - BIT - 1 - 11 - - - ConstantVelocity - BIT - 1 - 12 - - - Compensating - BIT - 1 - 13 - - - ExtSetPointGenEnabled - BIT - 1 - 14 - - - PhasingActive - BIT - 1 - 15 - - - ExternalLatchValid - BIT - 1 - 16 - - - NewTargetPos - BIT - 1 - 17 - - - IsDriveLimitActive - BIT - 1 - 18 - - - ContinuousMotion - BIT - 1 - 19 - - - ControlLoopClosed - BIT - 1 - 20 - - - CamTableQueued - BIT - 1 - 21 - - - CamDataQueued - BIT - 1 - 22 - - - CamScalingPending - BIT - 1 - 23 - - - CmdBuffered - BIT - 1 - 24 - - - PTPmode - BIT - 1 - 25 - - - SoftLimitMinExceeded - BIT - 1 - 26 - - - SoftLimitMaxExceeded - BIT - 1 - 27 - - - DriveDeviceError - BIT - 1 - 28 - - - MotionCommandsLocked - BIT - 1 - 29 - - - IoDataInvalid - BIT - 1 - 30 - - - Error - BIT - 1 - 31 - - - %08x - - - 0x%08x - - - 16#%08X - - - - {4C3FC5AC-D5AA-44C6-AC5A-159774BA0F6D} - - - - - NCTOPLC_AXIS_REF_OPMODE - 32 - - OpModePosAreaMonitoring - BIT - 1 - 0 - - - OpModeTargetPosMonitoring - BIT - 1 - 1 - - - OpModeLoop - BIT - 1 - 2 - - - OpModeMotionMonitoring - BIT - 1 - 3 - - - OpModePEHTimeMonitoring - BIT - 1 - 4 - - - OpModeBacklashCompensation - BIT - 1 - 5 - - - OpModeDelayedErrorReaction - BIT - 1 - 6 - - - OpModeModulo - BIT - 1 - 7 - - - OpModeSimulationAxis - BIT - 1 - 8 - - - OpModeStopMonitoring - BIT - 1 - 12 - - - OpModeOutputSmoothingFilter - BIT - 1 - 13 - - - OpModePosLagMonitoring - BIT - 1 - 16 - - - OpModeVeloLagMonitoring - BIT - 1 - 17 - - - OpModeSoftLimitMinMonitoring - BIT - 1 - 18 - - - OpModeSoftLimitMaxMonitoring - BIT - 1 - 19 - - - OpModePosCorrection - BIT - 1 - 20 - - - OpModeAllowSlaveCommands - BIT - 1 - 21 - - - OpModeAllowExtSetAxisCommands - BIT - 1 - 22 - - - ApplicationRequest - BIT - 1 - 23 - - - - NCTOPLC_AXIS_REF_STATE2_FLAGS - 32 - - AvoidingCollision - BIT - 1 - 0 - - - %08x - - - 0x%08x - - - 16#%08X - - - - NCTOPLC_AXIS_REF_STATE2 - 32 - - Value - DWORD - 32 - 0 - - - Flags - NCTOPLC_AXIS_REF_STATE2_FLAGS - 32 - 0 - - - %08x - - - 0x%08x - - - 16#%08X - - - - NCTOPLC_AXIS_REF_STATE3_FLAGS - 32 - - TouchProbe1InputState - BIT - 1 - 0 - - - TouchProbe2InputState - BIT - 1 - 1 - - - %08x - - - 0x%08x - - - 16#%08X - - - - NCTOPLC_AXIS_REF_STATE3 - 32 - - Value - DWORD - 32 - 0 - - - Flags - NCTOPLC_AXIS_REF_STATE3_FLAGS - 32 - 0 - - - %08x - - - 0x%08x - - - 16#%08X - - - - NCTOPLC_AXIS_REF_CAMCOUPLINGSTATE - 8 - - CamActivationPending - BIT - 1 - 0 - - - CamDeactivationPending - BIT - 1 - 1 - - - CamActive - BIT - 1 - 2 - - - CamDataQueued - BIT - 1 - 6 - - - CamScalingPending - BIT - 1 - 7 - - - - UINTARR8 - 128 - UINT - - 0 - 8 - - - - NCTOPLC_AXIS_REF - 2048 - - StateDWord - NCTOPLC_AXIS_REF_STATE - 32 - 0 - - - ErrorCode - UDINT - 32 - 32 - - - AxisState - UDINT - - 32 - 64 - - - AxisModeConfirmation - UDINT - 32 - 96 - - - HomingState - UDINT - - 32 - 128 - - - CoupleState - UDINT - - 32 - 160 - - - SvbEntries - UDINT - 32 - 192 - - - SafEntries - UDINT - 32 - 224 - - - AxisId - UDINT - 32 - 256 - - - OpModeDWord - NCTOPLC_AXIS_REF_OPMODE - 32 - 288 - - - ActPos - LREAL - 64 - 320 - - - ModuloActPos - LREAL - 64 - 384 - - - ActiveControlLoopIndex - UINT - 16 - 448 - - - ControlLoopIndex - UINT - 16 - 464 - - - ModuloActTurns - DINT - 32 - 480 - - - ActVelo - LREAL - 64 - 512 - - - PosDiff - LREAL - 64 - 576 - - - SetPos - LREAL - 64 - 640 - - - SetVelo - LREAL - 64 - 704 - - - SetAcc - LREAL - 64 - 768 - - - TargetPos - LREAL - 64 - 832 - - - ModuloSetPos - LREAL - 64 - 896 - - - ModuloSetTurns - DINT - 32 - 960 - - - CmdNo - UINT - 16 - 992 - - - CmdState - UINT - 16 - 1008 - - - SetJerk - LREAL - 64 - 1024 - - - SetTorque - LREAL - 64 - 1088 - - - ActTorque - LREAL - 64 - 1152 - - - StateDWord2 - NCTOPLC_AXIS_REF_STATE2 - 32 - 1216 - - - StateDWord3 - NCTOPLC_AXIS_REF_STATE3 - 32 - 1248 - - - TouchProbeState - DWORD - 32 - 1280 - - - TouchProbeCounter - DWORD - 32 - 1312 - - - CamCouplingState - NCTOPLC_AXIS_REF_CAMCOUPLINGSTATE - - 0 - 8 - - 64 - 1344 - - - CamCouplingTableID - UINTARR8 - 128 - 1408 - - - ActTorqueDerivative - LREAL - 64 - 1536 - - - SetTorqueDerivative - LREAL - 64 - 1600 - - - AbsPhasingPos - LREAL - 64 - 1664 - - - TorqueOffset - LREAL - 64 - 1728 - - - ActPosWithoutPosCorrection - LREAL - 64 - 1792 - - - ActAcc - LREAL - 64 - 1856 - - - DcTimeStamp - UDINT - 32 - 1920 - - - UserData - LREAL - 64 - 1984 - - - - NcStructType - 2 - - - - - NCAXLESTRUCT_TOPLC - - - NCAXLESTRUCT_TOPLC2 - - - NCAXLESTRUCT_TOPLC3 - - - NCAXLESTRUCT_TOPLC4 - - - - - - - - - - - - - - - - - - - - - - - - __FILENAME__ - - - - - - Inputs - - In - NCENCODERSTRUCT_IN2B - - nDataIn1 - - - nDataIn2 - - - nDataIn3 - - - nDataIn4 - - - nDataIn5 - - - nDataIn6 - - - nDataIn7 - - - - - - Outputs - - Out - NCENCODERSTRUCT_OUT2 - - nDataOut1 - - - nDataOut2 - - - nDataOut3 - - - nDataOut4 - - - nDataOut5 - - - nDataOut6 - - - - - - - - - - - Inputs - - In - NCDRIVESTRUCT_IN2 - - nDataIn1 - - - nDataIn2 - - - nDataIn3 - - - nDataIn4 - - - nDataIn5 - - - nDataIn6 - - - - - Outputs - - Out - NCDRIVESTRUCT_OUT2 - - nDataOut1 - - - nDataOut2 - - - nCtrl2 - - - - nCtrl3 - - - - nDataOut3 - - - nDataOut4 - - - nDataOut5 - - - nDataOut6 - - - - - - - - - - - Inputs - - FromPlc - PLCTONC_AXIS_REF - - - - Outputs - - ToPlc - NCTOPLC_AXIS_REF - - - - diff --git a/lcls-twincat-motion/_Config/NC/NC.xti b/lcls-twincat-motion/_Config/NC/NC.xti index e59ef4a7..5fe0ab53 100644 --- a/lcls-twincat-motion/_Config/NC/NC.xti +++ b/lcls-twincat-motion/_Config/NC/NC.xti @@ -34,7 +34,6 @@ - diff --git a/lcls-twincat-motion/_Config/PLC/Library.xti b/lcls-twincat-motion/_Config/PLC/Library.xti index 4ced6990..c63004d4 100644 --- a/lcls-twincat-motion/_Config/PLC/Library.xti +++ b/lcls-twincat-motion/_Config/PLC/Library.xti @@ -983,7 +983,7 @@ External Setpoint Generation: - + Library Instance {08500001-0000-0000-F000-000000000064} @@ -2343,49 +2343,6 @@ External Setpoint Generation: PRG_TEST.fb_StatePMPSEnables_Test.fbMotionStage.fbDriveVirtual.MasterAxis.NcToPlc NCTOPLC_AXIS_REF - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.Axis.NcToPlc - NCTOPLC_AXIS_REF - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bLimitForwardEnable - - BOOL - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bLimitBackwardEnable - - BOOL - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bHome - - BOOL - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bHardwareEnable - - BOOL - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.nRawEncoderULINT - - ULINT - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.nRawEncoderUINT - - UINT - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.nRawEncoderINT - - INT - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__FBBOUNDSCHECKMOTIONSTAGE.fbDriveVirtual.MasterAxis.NcToPlc - NCTOPLC_AXIS_REF - PRG_TEST.fb_PerMotorFFOND_Test.__FB_PERMOTORFFOND_TEST__TESTBLANKCOUNT__ASTMOTIONSTAGE[1].Axis.NcToPlc NCTOPLC_AXIS_REF @@ -3840,19 +3797,6 @@ External Setpoint Generation: PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBELOW__FBFFHWO.q_xFastFaultOut BOOL - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.Axis.PlcToNc - PLCTONC_AXIS_REF - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__STBOUNDSCHECKMOTIONSTAGE.bBrakeRelease - - BOOL - - - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__FBBOUNDSCHECKMOTIONSTAGE.fbDriveVirtual.MasterAxis.PlcToNc - PLCTONC_AXIS_REF - PRG_TEST.fb_StatePMPSEnables_Test.__FB_STATEPMPSENABLES_TEST__TESTBOUNDSAFTERFALLINGINTOUNKNOWNSTATE__FBFFHWO.q_xFastFaultOut BOOL @@ -4334,10 +4278,6 @@ External Setpoint Generation: - - - - From 267e9f78ad1fd38995f5ab06750d9c2c1221747c Mon Sep 17 00:00:00 2001 From: Nicholas Lentz Date: Thu, 16 May 2024 15:54:18 -0700 Subject: [PATCH 5/5] Fixed comment to be more clear. --- .../Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU index 325e6ca6..07fce42c 100644 --- a/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU +++ b/lcls-twincat-motion/Library/POUs/Motion/PMPS/FB_StatePMPSEnables.TcPOU @@ -149,7 +149,7 @@ IF bLockBounds THEN IF (stMotionStage.nErrorId = 16#4223 OR stMotionStage.nErrorId = 16#4260) AND ((stMotionStage.bAllForwardEnable AND NOT bForwardEnabled) OR (stMotionStage.bAllBackwardEnable AND NOT bBackwardEnabled)) THEN - // Cannot move forward and not triggered by the forward limit switch, overwrite the error with a custom error message to give more context. + // Cannot move forward/backward and not triggered by one of the stMotionStage disables so overwrite the error with a custom error message to give more context. stMotionStage.sCustomErrorMessage := CONCAT(CONCAT(CONCAT( 'Limits exceeded for most recent PMPS position state: ', LREAL_TO_FMTSTR(fLowerPos,5,TRUE)), ' < pos < '), LREAL_TO_FMTSTR(fUpperPos,5,TRUE)); END_IF