From c4b5891b297bb17ff7b845dcf7afbfcbd3a2bf00 Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Fri, 21 Jul 2023 18:43:00 +0200 Subject: [PATCH] enhance generate.py --- .gitignore | 2 +- Makefile | 4 +- PPMACMotor.template | 2 +- ReadmeMCS.md | 6 + SAR-EXPMX1.subs | 27 ---- SAR-EXPMX2.subs | 30 ---- SAR-EXPMX3.subs | 30 ---- add_EXPMX1.cmd | 14 -- add_EXPMX2.cmd | 21 --- add_EXPMX3.cmd | 40 ----- add_EXPMX4.cmd | 2 - asyn.template | 3 +- generate.py | 354 +++++++++++++++++++++++++++++++------------ qt/ESB_MX_SmarAct.ui | 10 +- 14 files changed, 275 insertions(+), 270 deletions(-) delete mode 100644 SAR-EXPMX1.subs delete mode 100644 SAR-EXPMX2.subs delete mode 100644 SAR-EXPMX3.subs delete mode 100644 add_EXPMX1.cmd delete mode 100644 add_EXPMX2.cmd delete mode 100644 add_EXPMX3.cmd delete mode 100644 add_EXPMX4.cmd diff --git a/.gitignore b/.gitignore index fee4340..80eb861 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.original .cvsignore +gen/ .idea/ .tmp_versions/ gather/ @@ -45,4 +46,3 @@ src/usrServo/usrServo.sublime-workspace *Doc/*.blg - diff --git a/Makefile b/Makefile index 24f2034..99a3f42 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ include /ioc/tools/driver.makefile MODULE = $(notdir $(shell pwd)) BUILDCLASSES = Linux -ARCH_FILTER = eldk42% -EXCLUDE_VERSIONS = 3.14 7.0.6 +ARCH_FILTER = ARCH_FILTER = $(EPICS_HOST_ARCH) eldk42% +EXCLUDE_VERSIONS = 3.14 # 7.0.6 #EPICS_VERSIONS = 7.0.7 #SCRIPTS+=$(wildcard add_EXPMX*.cmd cfg/*.cfg cfg/*.py cfg/*.pbi python/*.py) diff --git a/PPMACMotor.template b/PPMACMotor.template index 08029c8..01b9845 100644 --- a/PPMACMotor.template +++ b/PPMACMotor.template @@ -2,7 +2,7 @@ record(motor,"$(P):$(M)") { field(DESC,"$(DESC)") field(DTYP,"asynMotor") - field(OUT,"@asyn($(PORT),$(ADDR))") + field(OUT,"@asyn($(PORT=PPMAC),$(ADDR))") field(DIR,"$(DIR=0)") field(VMAX,"$(VMAX=0)") field(VELO,"$(VELO)") diff --git a/ReadmeMCS.md b/ReadmeMCS.md index 1622ade..57b56c9 100644 --- a/ReadmeMCS.md +++ b/ReadmeMCS.md @@ -74,3 +74,9 @@ caput SARES30-SMX:ASYN.AOUT :GST0 caget SARES30-SMX:ASYN.TINP + + + +/home/zamofing_t/Documents/prj/SwissFEL/driver_modules_epics/motorBase/motorApp/MotorSrc/asynMotorController.h + +if the position can not be reached, the $(S):$(M).MISS is set to 1 \ No newline at end of file diff --git a/SAR-EXPMX1.subs b/SAR-EXPMX1.subs deleted file mode 100644 index 96ce2b2..0000000 --- a/SAR-EXPMX1.subs +++ /dev/null @@ -1,27 +0,0 @@ -################################################################################ -#P - prefix of the PV -#PORT - Name of the ppmac controller port created by powerPmacCreateController -#ADDR - Axis index - second parameter of powerPmacCreateAxis and powerPmacCreateVirtualAxis -################################################################################ - -#Position Units are in um - -#ms to achive speed VELO -> same as Motor[1].JogTa (if positive). Motor[1].JogTa will be set to a caculated negative number -# JAR = EGU/s^2 -> JAR = VELO/ACCL (Jog acceleration) - -#caput SAROP21-OAPU092:ASYN.AOUT '&1;#1..2p' -#caget SAROP21-OAPU092:ASYN.TINP -#caput SAROP21-OAPU092:ASYN.AOUT '&1;cpx abs;X(-900)Y(10)A(5200)B(5100)' - -file asyn.template {{P="$(P_M)1", PORT=$(PORT_M)}} - -file PPMACMotor.template { -pattern{ DESC , P , M , PORT , ADDR, DIR, VELO, HVEL, ACCL, JAR, MRES , PREC, EGU , DHLM, DLLM} - { "Sample F-Trans Y", "$(P_M)", "MOT_FY" , "$(PORT_M)", 1 , 0 , 16 , 2 , 0.1 , 20 , 0.001, 4 , "mm" , 0 , 0 } - { "Sample F-Trans X", "$(P_M)", "MOT_FX" , "$(PORT_M)", 2 , 1 , 16 , 2 , 0.1 , 20 , 0.001, 4 , "mm" , 0 , 0 } - { "Rotation Y" , "$(P_M)", "MOT_ROT_Y", "$(PORT_M)", 3 , 0 , 50 , 50 , 0.1 , 20 , 0.001, 4 , "deg", 0 , 0 } - { "Sample C-Trans X", "$(P_M)", "MOT_CX" , "$(PORT_M)", 4 , 1 , 2 , 2 , 0.1 , 20 , 0.001, 4 , "mm" , 0 , 0 } - { "Sample C-Trans Z", "$(P_M)", "MOT_CZ" , "$(PORT_M)", 5 , 1 , 2 , 2 , 0.1 , 20 , 0.001, 4 , "mm" , 0 , 0 } - { "Interfero Y" , "$(P_M)", "ENC_FY" , "$(PORT_M)", 6 , 0 , 2 , 2 , 0.1 , 20 , 0.001, 4 , "mm" , 0 , 0 } - { "Interfero X" , "$(P_M)", "ENC_FX" , "$(PORT_M)", 7 , 0 , 2 , 2 , 0.1 , 20 , 0.001, 4 , "mm" , 0 , 0 } -} diff --git a/SAR-EXPMX2.subs b/SAR-EXPMX2.subs deleted file mode 100644 index 8c1ed67..0000000 --- a/SAR-EXPMX2.subs +++ /dev/null @@ -1,30 +0,0 @@ -################################################################################ -#P - prefix of the PV -#PORT - Name of the ppmac controller port created by powerPmacCreateController -#ADDR - Axis index - second parameter of powerPmacCreateAxis and powerPmacCreateVirtualAxis -################################################################################ - -#Position Units are in um - -#ms to achive speed VELO -> same as Motor[1].JogTa (if positive). Motor[1].JogTa will be set to a caculated negative number -# JAR = EGU/s^2 -> JAR = VELO/ACCL (Jog acceleration) - -#caput SAROP21-OAPU092:ASYN.AOUT '&1;#1..2p' -#caget SAROP21-OAPU092:ASYN.TINP -#caput SAROP21-OAPU092:ASYN.AOUT '&1;cpx abs;X(-900)Y(10)A(5200)B(5100)' - -file asyn.template {{P="$(P_M)2", PORT=$(PORT_M)}} - -file PPMACMotor.template { -pattern{ DESC , P , M , PORT , ADDR, DIR, VELO, HVEL, ACCL, JAR, MRES , PREC, EGU , DHLM, DLLM} - { "Wedge 1" , "$(P_M)", "MOT_WEDGE1", "$(PORT_M)", 1 , 0 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Wedge 2" , "$(P_M)", "MOT_WEDGE2", "$(PORT_M)", 2 , 0 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Wedge 3" , "$(P_M)", "MOT_WEDGE3", "$(PORT_M)", 3 , 0 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Wedge 4" , "$(P_M)", "MOT_WEDGE4", "$(PORT_M)", 4 , 0 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Wedge X" , "$(P_M)", "MOT_WEDGEX", "$(PORT_M)", 9 , 1 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Wedge Y" , "$(P_M)", "MOT_WEDGEY", "$(PORT_M)", 10 , 0 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Wedge A" , "$(P_M)", "MOT_WEDGEA", "$(PORT_M)", 11 , 0 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Wedge B" , "$(P_M)", "MOT_WEDGEB", "$(PORT_M)", 12 , 1 , 1. , .5 , 0.1 , 20 , 0.001, 3 , "mm" , 0 , 0 } - { "Backlight", "$(P_M)", "MOT_BLGT" , "$(PORT_M)", 5 , 1 , 40E3, 20E3, 0.1 , 20 , 1 , 0 , "usr", 0 , 0 } - { "Cryojet" , "$(P_M)", "MOT_CRYO" , "$(PORT_M)", 6 , 1 , 10., 5. , 0.1 , 20 , 0.001, 3 , "mm", 0 , 0 } -} diff --git a/SAR-EXPMX3.subs b/SAR-EXPMX3.subs deleted file mode 100644 index ca5ef27..0000000 --- a/SAR-EXPMX3.subs +++ /dev/null @@ -1,30 +0,0 @@ -################################################################################ -#P - prefix of the PV -#PORT - Name of the ppmac controller port created by powerPmacCreateController -#ADDR - Axis index - second parameter of powerPmacCreateAxis and powerPmacCreateVirtualAxis -################################################################################ - -#Position Units are in um - -#ms to achive speed VELO -> same as Motor[1].JogTa (if positive). Motor[1].JogTa will be set to a caculated negative number -# JAR = EGU/s^2 -> JAR = VELO/ACCL (Jog acceleration) - -#caput SAROP21-OAPU092:ASYN.AOUT '&1;#1..2p' -#caget SAROP21-OAPU092:ASYN.TINP -#caput SAROP21-OAPU092:ASYN.AOUT '&1;cpx abs;X(-900)Y(10)A(5200)B(5100)' - -file PPMACMotor.template { -pattern -{ DESC , P , M , PORT , ADDR, DIR, VELO, MRES , PREC, EGU } -{ "Girder 1", "$(P_M)", "MOT_GIR_1", "$(PORT_M)", 1 , 0 , 40 , 0.001, 3 , "deg" } -{ "Girder 2", "$(P_M)", "MOT_GIR_2", "$(PORT_M)", 2 , 0 , 40 , 0.001, 3 , "deg" } -{ "Girder 3", "$(P_M)", "MOT_GIR_3", "$(PORT_M)", 3 , 0 , 40 , 0.001, 3 , "deg" } -{ "Girder 4", "$(P_M)", "MOT_GIR_4", "$(PORT_M)", 4 , 0 , 40 , 0.001, 3 , "deg" } -{ "Girder 5", "$(P_M)", "MOT_GIR_5", "$(PORT_M)", 5 , 0 , 40 , 0.001, 3 , "deg" } -{ "Girder X", "$(P_M)", "MOT_GIR_X", "$(PORT_M)", 9 , 0 , 40 , 0.001, 3 , "mm" } -{ "Girder Y", "$(P_M)", "MOT_GIR_Y", "$(PORT_M)", 10 , 0 , 40 , 0.001, 3 , "mm" } -{ "Girder U", "$(P_M)", "MOT_GIR_U", "$(PORT_M)", 11 , 0 , 40 , 0.001, 3 , "mrad"} -{ "Girder V", "$(P_M)", "MOT_GIR_V", "$(PORT_M)", 12 , 0 , 40 , 0.001, 3 , "mrad"} -{ "Girder W", "$(P_M)", "MOT_GIR_W", "$(PORT_M)", 13 , 0 , 40 , 0.001, 3 , "mrad"} -{ "Detector Z", "$(P_M)", "MOT_DET_Z", "$(PORT_M)", 6 , 1 , 4 , 0.001, 3 , "mm" } -} diff --git a/add_EXPMX1.cmd b/add_EXPMX1.cmd deleted file mode 100644 index d6d539e..0000000 --- a/add_EXPMX1.cmd +++ /dev/null @@ -1,14 +0,0 @@ -########################### -! $(gpasciiCommander_DIR)/gpasciiCommander --path $(ESB_MX_DIR) $(ESB_MX_DIR)/$(P)1.cfg - -powerPmacCreateAxis($(PORT), 1) -powerPmacCreateAxis($(PORT), 2) -powerPmacCreateAxis($(PORT), 3) -powerPmacCreateAxis($(PORT), 4) -powerPmacCreateAxis($(PORT), 5) -powerPmacCreateAxis($(PORT), 6) -powerPmacCreateAxis($(PORT), 7) -#powerPmacCreateAxis($(PORT), 8) - -# Load databse -dbLoadTemplate("$(ESB_MX_TEMPLATES)/$(P)1.subs", "PORT_M=$(PORT),P_M=$(P)") diff --git a/add_EXPMX2.cmd b/add_EXPMX2.cmd deleted file mode 100644 index 1724852..0000000 --- a/add_EXPMX2.cmd +++ /dev/null @@ -1,21 +0,0 @@ -########################### -! $(gpasciiCommander_DIR)/gpasciiCommander --path $(ESB_MX_DIR) $(ESB_MX_DIR)/$(P)2.cfg - -powerPmacCreateAxis($(PORT), 1) -powerPmacCreateAxis($(PORT), 2) -powerPmacCreateAxis($(PORT), 3) -powerPmacCreateAxis($(PORT), 4) -powerPmacCreateAxis($(PORT), 5) -powerPmacCreateAxis($(PORT), 6) -#powerPmacCreateAxis($(PORT), 7) -#powerPmacCreateAxis($(PORT), 8) - -#powerPmacCreateVirtualAxis(, , , ,, , , ,, , ) -powerPmacCreateController("PPMAC1", 200, 1000) +powerPmacCreateController("{port}", 200, 1000) -############################################ -#--------! Devices configuration ---------!# -############################################ -{devConf} +###### initialize axes ############ ''' - tplEVR='''\ -####### initialise EVR ############################## + tplPwrBrkAxis='''\ +powerPmacCreateAxis({PORT}, {ADDR}) +''' + + tplEVR=''' +###### initialize EVR ############ # https://git.psi.ch/epics_driver_modules/mrfioc2 require mrfioc2 runScript $(mrfioc2_DIR)/mrfioc2_evr-PCIe.cmd, "DEVICE=EVR0,EVR_SUBS=$(ESB_MX_DIR)/db/evr_PCIe-300DC.subs,EVR_DOMAIN=0x2,EVR_BUS=0x21,SYS=SAR-EXPMX" -####### initialise EVR data buffer ################## +###### initialize EVR data buffer ############ # https://git.psi.ch/epics_driver_modules/mrfioc2_regDev require mrfioc2_regDev runScript $(mrfioc2_regDev_DIR)/mrfioc2_regDev_pulseID_RX.cmd, "DEVICE=EVR0,SYS=SAR-EXPMX" ''' + pwrBrkSubsHdr='''\ +file asyn.template {{{{P={prefix}, PORT={port},R=asyn{idx}}}}} + +file PPMACMotor.template +{{ + pattern +''' + + def __init__(self): os.makedirs('gen/ioc/',exist_ok=True) #os.makedirs('gen/db/',exist_ok=True) @@ -156,26 +242,14 @@ runScript $(mrfioc2_regDev_DIR)/mrfioc2_regDev_pulseID_RX.cmd, "DEVICE=EVR0,SYS= def genIOC(self): print('### genIOC ###') - tplIOC=Generate.tplScriptPowerBrickIOC - yamlParam=Generate.yamlParam - pb_h2p=Generate.pb_host2param - tplEVR=Generate.tplEVR - fh=open('gen/ioc/Makefile','w') - fh.write('include /ioc/tools/ioc.makefile\n') - fh.close() - for host in yamlParam.keys(): - if not host in pb_h2p: - assert(host=='SARES30-CPCL-MCSSMX') - self.genSmarActIOC(host) - continue - req,devConf=pb_h2p[host] - fn='gen/ioc/{host}_startup.script'.format(host=host) - print('generate '+fn+' ...') - fh=open(fn,'w') - fh.write(tplIOC.format(host=host,req=req,devConf=devConf)) - if host=='SAR-CPPM-EXPMX1': - fh.write(tplEVR) - fh.close() + fn='gen/ioc/Makefile' + print('generate '+fn+' ...') + with open(fn,'w') as fh: + fh.write('include /ioc/tools/ioc.makefile\n') + self.genPowerBrickIOC() + self.genSmarActIOC() + + print('done.') def genLauncher(self): @@ -191,35 +265,125 @@ runScript $(mrfioc2_regDev_DIR)/mrfioc2_regDev_pulseID_RX.cmd, "DEVICE=EVR0,SYS= #'''.format(dev=dev)) # fh.close() - def genSmarActIOC(self,ioc): + def genPowerBrickIOC(self): + yamlParam=Generate.yamlParam + tplEVR=Generate.tplEVR + tplCtrl=Generate.tplPwrBrkCtrl + tplAxis=Generate.tplPwrBrkAxis + #tplAxSR=Generate.tplMcsAxisSaveRestore + subsHdr=Generate.pwrBrkSubsHdr + + for ioc,v in Generate.iocPowerBrick.items(): + # fh_ss startup script + # fh_sb substitution + # fh_sr save restore + + fmt=' '+v['fmt'] + hdr=v['motLst'][0] + if len(v['motLst'])>1: + motLst=v['motLst'][1:] + else: + motLst=tuple() + param= {k: v[k] for k in {'port','prefix','loc'}} + param['ioc']=ioc + param['idx']=ioc[-1] + param['num_ax']=len(motLst) + param['req']='require ESB_MX\n\n! $(gpasciiCommander_DIR)/gpasciiCommander --path $(ESB_MX_DIR) $(ESB_MX_DIR)/{prefix}{idx}.cfg'.format(**param) + #print(param) + + fn=f'gen/ioc/{ioc}_startup.script' + print('generate '+fn+' ...') + fh_ss=open(fn,'w') + + fn=f'gen/ioc/{ioc}_gen.subs' # with a name _* the .subs file is recognize by the 'ioc install' tool + print('generate '+fn+' ...') + fh_sb=open(fn,'w') + + #fn=f'gen/ioc/cfg/{ioc}_sr.req' + #print('generate '+fn+' ...') + #fh_sr=open(fn,'w') + + fh_ss.write(tplCtrl.format(**param)) + + fh_sb.write(subsHdr.format(**param)) + port=param['port'] + prefix=param['prefix'] + motPar=dict(zip(hdr, hdr)) + motPar['PORT']='PORT' + motPar['P']='P' + fh_sb.write(fmt.format(**motPar)) + for motPar in motLst: + motPar=dict(zip(hdr, motPar)) + motPar['PORT']=v['port'] + motPar['P']=v['prefix'] + fh_sb.write(fmt.format(**motPar)) + fh_ss.write(tplAxis.format(**motPar)) + #fh_sr.write(tplAxSR.format(prefix=prefix,m=m)) + fh_sb.write('}\n\n') + + if ioc=='SAR-CPPM-EXPMX1': + fh_ss.write(tplEVR) + fh_ss.close() + fh_sb.close() + + + + + + def genSmarActIOC(self): tplCtrl=Generate.tplMcsCtrl tplAxis=Generate.tplMcsAxis - motLst=Generate.mxSmarAct['motLst'] - subs=Generate.mcs_subs_hdr - host=Generate.mxSmarAct['host'] - prefix=Generate.mxSmarAct['prefix'] - port=Generate.mxSmarAct['port'] + #tplAxSR=Generate.tplMcsAxisSaveRestore + subsHdr=Generate.mcsSubsHdr lutSens=Generate.lutSensMcs - num_ax=len(motLst) - fn=f'gen/ioc/{ioc}_startup.script' - print('generate '+fn+' ...') - with open(fn,'w') as fh_ss: - fh_ss.write(tplCtrl.format(host=host,port=port,num_ax=num_ax)) + os.makedirs('gen/ioc/cfg/',exist_ok=True) + for ioc,v in Generate.iocSmarAct.items(): + # fh_ss startup script + # fh_sb substitution + # fh_sr save restore - fn_subs=f'gen/ioc/{ioc}_gen.subs' # with a name _* the .subs file is recognize by the 'ioc install' tool - print('generate '+fn_subs+'...') - with open(fn_subs,'w') as fh: - fh.write(subs.format(port=port,prefix=prefix)) - for d, m, a, hlm, llm, dir,sens in motLst: - sens=lutSens[sens] - param={'PORT':port,'S':prefix,'M':m,'ADDR':a,'DESC':'"'+d+'"', - 'DIR':dir,'VBAS':0,'VMAX':2,'DHLM':hlm,'DLLM':llm,'EGU':'mm','SENSOR':sens,'UDSENS':0,'RTRY':1} - fh.write(' {{{PORT:10},{S:16},{M:10},{ADDR:4},{DESC:27},{DIR:3},{VBAS:4},{VMAX:4},{DHLM:4},{DLLM:4},{EGU:3},{SENSOR:7},{UDSENS:5}{RTRY:5}}}\n'.format(**param)) - fh_ss.write(tplAxis.format(port=port,axis=a,chan=a)) - fh.write('}\n\n') + motLst=v['motLst'] + param= {k: v[k] for k in {'port','host','prefix','loc'}} + ioc_host,ioc_port=Generate.yamlParam[ioc][:2] + param['ioc']=ioc + param['ioc_host']=ioc_host + param['ioc_port']=ioc_port + param['num_ax']=len(motLst) + #print(param) + fn=f'gen/ioc/{ioc}_startup.script' + print('generate '+fn+' ...') + fh_ss=open(fn,'w') + fn=f'gen/ioc/{ioc}_gen.subs' # with a name _* the .subs file is recognize by the 'ioc install' tool + print('generate '+fn+' ...') + fh_sb=open(fn,'w') + #fn=f'gen/ioc/cfg/{ioc}_sr.req' + #print('generate '+fn+' ...') + #fh_sr=open(fn,'w') + + fh_ss.write(tplCtrl.format(**param)) + + fh_sb.write(subsHdr.format(**param)) + port=param['port'] + prefix=param['prefix'] + for d, m, a, hlm, llm, dir,egu,sens in motLst: + sens=lutSens[sens] + param={'PORT':port,'S':prefix,'M':m,'ADDR':a,'DESC':'"'+d+'"', + 'DIR':dir,'VBAS':0,'VMAX':2,'DHLM':hlm,'DLLM':llm,'EGU':egu,'SENSOR':sens,'UDSENS':0,'RTRY':1} + fh_sb.write(' {{{PORT:10},{S:16},{M:10},{ADDR:4},{DESC:27},{DIR:3},{VBAS:4},{VMAX:4},{DHLM:4},{DLLM:4},{EGU:3},{SENSOR:7},{UDSENS:5}{RTRY:5}}}\n'.format(**param)) + fh_ss.write(tplAxis.format(port=port,axis=a,chan=a)) + #fh_sr.write(tplAxSR.format(prefix=prefix,m=m)) + fh_sb.write('}\n\n') + fh_ss.close() + fh_sb.close() + #fh_sr.close() + + #fn='gen/ioc/asyn.template' + #print('generate '+fn+' ...') + #with open(fn,'w') as fh: + # fh.write(Generate.tpl_asyn) if __name__=='__main__': def parse_args(): diff --git a/qt/ESB_MX_SmarAct.ui b/qt/ESB_MX_SmarAct.ui index 78959da..3f42cfc 100644 --- a/qt/ESB_MX_SmarAct.ui +++ b/qt/ESB_MX_SmarAct.ui @@ -6,8 +6,8 @@ 0 0 - 797 - 673 + 645 + 680 @@ -60,7 +60,7 @@ 5 53 - 784 + 626 612 @@ -83,7 +83,7 @@ - 640 + 470 30 80 20 @@ -96,7 +96,7 @@ - satus bits + Relative