# fixedGapWigglerMotion.template # Template file for controlling the motion of one fixed gap wiggler ########################################################################## # OVERALL STATUS REPORTING record(bo, "$(U):MaintenanceM") { field(DESC, "Und maintenance") field(PINI, "YES") field(VAL, "0") field(ZNAM, "ACTIVE") field(ONAM, "UNDER_MAINTENANCE") info(autosaveFields, "VAL") } # Use this to disable 'Insert' or 'Extract' Moves # if wiggler is faulted record(calc, "$(U):DeviceError"){ field(DESC, "Calculation device error") field(SCAN, "1 second") field(CALC, "(A>0)||(B>0)||C||D") field(INPA, "$(MOC):$(A1):AXIS_FAULT NPP") field(INPB, "$(MOC):$(A2):AXIS_FAULT NPP") field(INPC, "$(U):MaxSkewCheck NPP") field(INPD, "$(U):MaintenanceM PP") field(HIGH, "1") field(HSV, "MAJOR") } ########################################################################## # DEVICE IDENTIFICATION # Device serial number record(stringin, "$(U):SerialNum") { field(DESC, "Serial Number") field(VAL, "WIGG SN-XXX") info(autosaveFields, VAL) } # Device mad name record(stringin, "$(U):MAD") { field(DESC, "MAD name") field(VAL, "$(MAD)") info(autosaveFields, VAL) } ########################################################################## # Enabling and Disabling Motors # Enable both motors record(seq,"$(U):EnableMotors") { field(DESC,"Enable wiggler motors") field(DOL1, "1") field(LNK1, "$(U):US:Motor.CNEN PP") field(DOL2, "1") field(LNK2, "$(U):DS:Motor.CNEN PP") } # Disable both motors record(seq,"$(U):DisableMotors") { field(DESC,"Disable wiggler motors") field(DOL1, "0") field(LNK1, "$(U):US:Motor.CNEN PP") field(DOL2, "0") field(LNK2, "$(U):DS:Motor.CNEN PP") } # Check when the motors are done moving record(calcout, "$(U):MovDone") { field(DESC, "Check motors dmov status") field(SCAN, "Passive") field(CALC, "A && B ") field(INPA, "$(U):US:Motor.DMOV CP") field(INPB, "$(U):DS:Motor.DMOV CP") field(OUT, "$(U):StopMotors.PROC") field(OOPT, "Transition To Non-zero") field(DOPT, "Use OCAL") field(OCAL, "1") } # Stop all motors and disable them record(seq,"$(U):StopMotors") { field(DESC,"Stop wiggler motors") field(DOL1, "1") field(LNK1, "$(U):US:Motor.STOP PP") field(DOL2, "1") field(LNK2, "$(U):DS:Motor.STOP PP") field(DLY3, "0.5") field(DOL3, "0") field(LNK3, "$(U):US:Motor.CNEN PP") field(DLY4, "0.5") field(DOL4, "0") field(LNK4, "$(U):DS:Motor.CNEN PP") } ########################################################################## # Control Device Insertion # Set target position when wiggler is inserted record(ao, "$(U):InsertPos") { field(DESC, "Target position wiggler inserted") field(VAL, "0.0") field(DRVL, "-30.0") field(DRVH, "1.0") field(LOPR, "-30.0") field(HOPR, "1.0") field(PREC, "4") field(EGU, "mm") info(autosaveFields, "VAL DRVL DRVH LOPR HOPR") } # Formulate the insert wiggler command and start motion record(ao, "$(U):InsertCmd") { field(DESC, "Insert wiggler command") field(DTYP, "stream") field(VAL, "0") field(OUT, "@$(PROTO) moveabs($(AXIS1),$(AXIS2)) $(PORT)") } # Trigger Insert move record(bi, "$(U):Insert") { field(DESC, "Trigger insert move") field(VAL, "0") field(ONAM, "Go") field(ZNAM, "Stby") field(SDIS, "$(U):DeviceError") field(FLNK, "$(U):InsertSq") } # Sequence record to initiate insertion move # The motors will start moving record(seq, "$(U):InsertSq") { field(DESC, "Initiate Insertion Move") # Enable the motors field(DOL1, "1") field(LNK1, "$(U):EnableMotors.PROC") # Wait a little bit for the motors to be enabled field(DLY2, "1") # Take the target position for wiggler inserted and formulate command field(DOL2, "$(U):InsertPos") field(LNK2, "$(U):InsertCmd.VAL PP") # Reset Insert flag to zero field(DOL3, "0") field(LNK3, "$(U):Insert.VAL PP") } ########################################################################## # Control Device Extraction # Extract wiggler command record(ao, "$(U):ExtractCmd") { field(DESC, "Extract wiggler command") field(DTYP, "stream") field(VAL, "-80") field(OUT, "@$(PROTO) moveabs($(AXIS1),$(AXIS2)) $(PORT)") } # Set target position when wiggler is extracted record(ao, "$(U):ExtractPos") { field(DESC, "Target position wiggler extracted") field(VAL, "-80.0") field(DRVH, "-30.0") field(DRVL, "-85.0") field(HOPR, "-30.0") field(LOPR, "-85.0") field(PREC, "4") field(EGU, "mm") info(autosaveFields, "VAL DRVL DRVH LOPR HOPR") } # Trigger Extract move record(bi, "$(U):Extract") { field(DESC, "Trigger extract move") field(VAL, "0") field(ONAM, "Go") field(ZNAM, "Stby") field(SDIS, "$(U):DeviceError") field(FLNK, "$(U):ExtractSq") } # Sequence record to initiate extraction move # The motors will start moving record(seq, "$(U):ExtractSq") { field(DESC, "Initiate Extraction Move") # Enable the motors field(DOL1, "1") field(LNK1, "$(U):EnableMotors.PROC") # Wait a little bit for the motors to be enabled field(DLY2, "1") # Take the target position for wiggler inserted and formulate command field(DOL2, "$(U):ExtractPos") field(LNK2, "$(U):ExtractCmd.VAL PP") # Reset Extract flag to zero field(DOL3, "0") field(LNK3, "$(U):Extract.VAL PP") } ########################################################################## # Control Device Skew # Calculate skew record(calc, "$(U):Skew") { field(DESC, "Wiggler calc skew value") field(CALC, "A-B") field(SCAN, ".5 second") field(INPA, "$(U):DS:Motor.RBV") field(INPB, "$(U):US:Motor.RBV") field(HIGH, "0.5") field(LOW, "-0.5") field(HIHI, "1.0") field(LOLO, "-1.0") field(HSV, "MINOR") field(LSV, "MINOR") field(HHSV, "MAJOR") field(LLSV, "MAJOR") field(PREC, "4") field(EGU, "mm") info(autosaveFields, "HIGH LOW HIHI LOLO") } # Max allowed skew record(ai, "$(U):MaxSkew") { field(DESC, "Max allowed skew") field(VAL, "1.00") field(PREC, "4") field(EGU, "mm") info(autosaveFields, "VAL") } #Set the skew threshold on the controller record(seq, "$(U):SetSkewThrSq") { field(DESC, "Set Skew Threshold on controller") # Get the value of the max skew field(DOL1, "$(U):MaxSkew") field(LNK1, "$(U):SkewThr.VAL PP") } # Calculate the difference between EPICS and controller skew record(calc, "$(U):DeltaSkew"){ field(DESC, "Delta skew btwn epics and aerotech") field(SCAN, "1 second") field(INPA, "$(U):Skew") field(INPB, "$(U):SkewRbck") field(CALC, "A-B") field(HIGH, "0.3") field(HIHI, "0.4") field(LOW, "-0.3") field(LOLO, "-0.4") field(HSV, "MINOR") field(LSV, "MINOR") field(HHSV, "MAJOR") field(LLSV, "MAJOR") field(PREC, "4") field(EGU, "mm") info(autosaveFields, "HIGH LOW HIHI LOLO") } # Process checks record(seq, "$(U):ProcSkewChecks") { field(DESC, "Process skew checks") field(SCAN, ".5 second") field(DOL1, "1") field(LNK1, "$(U):MaxSkewCheck.PROC PP") field(DOL2, "1") field(LNK2, "$(U):SkewRecoverCheck.PROC PP") } # Check if current skew is above max skew # Use this PV to disable "insert" and "extract" motions record(calc, "$(U):MaxSkewCheck") { field(DESC, "Check skew > maxSkew") field(CALC, "ABS(A)>B?1:0") field(INPA, "$(U):Skew") field(INPB, "$(U):MaxSkew PP") field(HIGH, "1") field(HSV, "MAJOR") field(FLNK, "$(U):SkewCheckMsg") } # Check if skew recovery routine needs to be initiated record(calcout, "$(U):SkewRecoverCheck") { field(DESC, "Check if skew recovey is needed") field(CALC, "A?0:1") # Input is 1 when max skew is exceeded field(INPA, "$(U):MaxSkewCheck NPP NMS") field(OOPT,"Transition To Non-zero") field(DOPT,"Use CALC") field(OUT,"$(U):SkewRecoverSq.PROC PP NMS") } # Stop and clear faults when the skew is again below the limit record(seq, "$(U):SkewRecoverSq") { field(DESC, "Recover from skew") field(DOL1, "1") field(LNK1, "$(U):StopMotors.PROC PP") field(DLY2, "0.2") field(DOL2, "1") field(LNK2, "$(MC):AEROTECH_ACKALL.PROC PP") field(DOL3, "1") field(LNK3, "$(U):DeviceRecoverMsg.PROC PP") } ########################################################################## # Formulate messages # Generate message displaying skew status record(scalcout,"$(U):SkewCheckMsg") { field(DESC,"Generates messages") field(CALC,"A?BB:AA") field(INPA,"$(U):MaxSkewCheck.VAL NPP MS") field(AA,"Skew OK") field(BB,"Max Skew Exceeded") field(OUT,"$(U):Message1.VAL PP MS") field(OOPT,"Every Time") } # Generate message displaying device recovered record(scalcout,"$(U):DeviceRecoverMsg") { field(DESC,"Generates messages") field(CALC,"AA") field(AA,"Device Recovered!") field(OUT,"$(U):Message2.VAL PP MS") field(OOPT,"Every Time") } # Generate message displaying device status record(scalcout,"$(U):DeviceErrorMsg") { field(DESC,"Generates messages") field(CALC,"A?BB:AA") field(INPA,"$(U):DeviceError.VAL CP MS") field(AA,"Device Ready to Move") field(BB,"Device Not Ready to Move!") field(OUT,"$(U):Message2.VAL PP MS") field(OOPT,"Every Time") } # Store messages record(stringout,"$(U):Message1") { field(DESC,"ID Control Status") } # Store messages record(stringout,"$(U):Message2") { field(DESC,"ID Control Status") } ########################################################################## # Read encoder offsets from the controller # Get US motor encoder offset record(ai, "$(U):US:EncOffset") { field(DESC, "Upstream encoder offset") field(DTYP, "stream") field(INP, "@$(PROTO) getEncOff($(AXIS1)) $(PORT) ") field(PINI, "YES") field(PREC, "6") } # Get DS motor encoder offset record(ai, "$(U):DS:EncOffset") { field(DESC, "Downstream encoder offset") field(DTYP, "stream") field(INP, "@$(PROTO) getEncOff($(AXIS2)) $(PORT) ") field(PINI, "YES") field(PREC, "6") }