Go to the documentation of this file.00001 CLOSE
00002
00003 ;###################################################################
00004 ;
00005 ; Define Motion for Energy with PGM
00006 ;
00007 ; Original Author: James O'Hea
00008 ;
00009 ; Defined axes:
00010 ; X (Addr 6) = Energy in eV
00011 ;
00012 ; Macros (and example values):
00013 ; COORD = $(COORD) CS number (only works for CS 1..9), e.g. 2
00014 ; PLC = $(PLC) PLC number, should be CS number+15, e.g. 17
00015 ; BETA = $(BETA) Axis Number for Beta, e.g. 1
00016 ; THETA = $(THETA) Axis Number for Theta, e.g. 2
00017 ;
00018 ;###################################################################
00019
00020 ; Set trig calculations to be performed in degrees
00021 i15 = 0
00022
00023 ; Change to CS$(COORD)
00024 &$(COORD)
00025
00026 ; Set relevant axes to use kinematics
00027 #$(BETA)->I
00028 #$(THETA)->I
00029
00030 ; Define resolution, offset, and move flag variables
00031 ; These are set by motor_in_cs.template (from spreadsheet)
00032 #define BMOVE P(4700+$(BETA))
00033 #define BMRES P(4800+$(BETA))
00034 #define BOFF P(4900+$(BETA))
00035 #define TMOVE P(4700+$(THETA))
00036 #define TMRES P(4800+$(THETA))
00037 #define TOFF P(4900+$(THETA))
00038
00039 ; Constants
00040
00041 ; Plank's Constant (eV/s) = 4.135667749 * 10^-15
00042 ; Speed of Light is stated in mm/s as the gratings are defined in mm
00043 ; Speed of Light (mm/s) = 299792458000
00044 ; hc = Plank's Constant * Speed of Light
00045 #define HC 0.001239842 ; Plank's Constant * Speed of Light
00046 ;#define R2D 57.29577951 ; Radians to Degrees Conversion Factor
00047 ;#define D2R 0.01745329 ; Degrees to Radians Conversion Factor
00048 #define R2D 1 ; Radians to Degrees Conversion Factor
00049 #define D2R 1 ; Degrees to Radians Conversion Factor
00050
00051 ; Q1-9 Kinematic Positions (Temporary variables used in kinematic calculations by PMAC)
00052
00053 #define ENERGY Q7 ; Desired energy
00054
00055 ; Q128-199 Forward Kinematic Temporary Variables
00056
00057 ; None needed
00058
00059 ; Q228-299 Inverse Kinematic Temporary Variables
00060
00061 #define LAMBDA Q228 ; Wavelength
00062 #define SASB Q229 ; Sin(Alpha) + Sin(Beta) Calculation
00063 #define CFF2 Q230 ; Constant Fixed Focus Squared
00064 #define SIN_ALPHA Q231 ; Sin(Alpha) Calculation
00065
00066 ; Q20-70 EPICS Variables
00067
00068 #define CFF Q20 ; Fixed Focus Constant
00069 #define LINES Q21 ; Number of Grating Lines
00070 #define ORDER Q22 ; Diffraction Order (all specified as negative)
00071 #define GRT_OFFSET Q23 ; Grating Offset
00072 #define MIR_OFFSET Q24 ; Mirror Offset
00073
00074 #define BETA P$(BETA) ; Beta Calculation
00075 #define THETA P$(THETA) ; Theta Calculation
00076
00077 ; Forward Kinematics - Calculate energy from beta, theta, grating, diffraction order, and hc
00078 #define BPOS (BMRES*P$(BETA)+BOFF)
00079 #define TPOS (TMRES*P$(THETA)+TOFF)
00080
00081 OPEN FORWARD
00082 CLEAR
00083 ENERGY = ((LINES * ORDER * HC) / (sin((BPOS-GRT_OFFSET)*D2R)-sin(D2R*(2*(TPOS-MIR_OFFSET)-(BPOS-GRT_OFFSET)))))
00084 CLOSE
00085
00086 ; Inverse Kinematics - Calculate beta and theta from energy, grating, and diffraction order
00087 #define BPOS Q232
00088 #define TPOS Q233
00089
00090 OPEN INVERSE
00091 CLEAR
00092 CFF2 = (CFF * CFF)
00093 LAMBDA = (HC / ENERGY)
00094 SASB = (LINES * ORDER * LAMBDA)
00095 SIN_ALPHA = (SASB / (CFF2 - 1)) + sqrt((((SASB * CFF) / (CFF2 - 1)) * ((SASB * CFF) / (CFF2 - 1))) + 1)
00096
00097 ; Beta and Theta calculated in degress
00098 BPOS = (((asin(SIN_ALPHA + SASB)) * R2D) + GRT_OFFSET)
00099 TPOS = (((BPOS - GRT_OFFSET + ((asin(SIN_ALPHA)) * R2D)) / 2) + MIR_OFFSET)
00100
00101 ; Beta and Theta calculated in motor counts
00102 P6 = ((BPOS - BOFF) / BMRES)
00103 P2 = ((TPOS - TOFF) / TMRES)
00104 ;P6 = ((((asin(SIN_ALPHA + SASB)) * R2D) + GRT_OFFSET - BOFF) / BMRES)
00105 ;P2 = ((((BPOS - GRT_OFFSET + ((asin(SIN_ALPHA)) * R2D)) / 2) + MIR_OFFSET -TOFF) / TMRES)
00106 CLOSE
00107
00108 ; A PLC for position reporting
00109 #define ENERGY Q87 ; Desired energy
00110 #define BPOS (BMRES*(m$(BETA)62/(I$(BETA)08*32))+BOFF)
00111 #define TPOS (TMRES*(m$(THETA)62/(I$(THETA)08*32))+TOFF)
00112
00113 OPEN PLC $(PLC)
00114 CLEAR
00115 ADDRESS&$(COORD)
00116 ENERGY = ((LINES * ORDER * HC) / (sin((BPOS-GRT_OFFSET)*D2R)-sin(D2R*(2*(TPOS-MIR_OFFSET)-(BPOS-GRT_OFFSET)))))
00117 ; If beta or theta motor records did the last move, set demands = readbacks
00118 if (BMOVE = 1)
00119 or (TMOVE = 1)
00120 BMOVE = 0
00121 TMOVE = 0
00122 Q77 = Q87
00123 endif
00124 CLOSE
00125
00126 ENABLE PLC $(PLC)