automate make process

This commit is contained in:
2019-02-13 11:03:11 +01:00
parent 5a05b7355e
commit f3c5fafe5f
6 changed files with 101 additions and 28 deletions

View File

@@ -287,32 +287,50 @@ class MXTuning(Tuning):
C=mat['ozC']
D=mat['ozD']
V=mat['V']
u=('DesPos','IqMeas','IqVolts','ActPos')
#u=('DesPos','IqMeas','ActVel','ActPos')
u=[]
for i in range(mat['ozInpName'].shape[0]):
s=str(mat['ozInpName'][i][0][0])
s=s[0].capitalize()+s[1:]
u.append(s)
y=('obsvOut',)
progSample='''double usr_servo_ctrl_{motid}(MotorData *Mptr)
{{
pshm->P[2000]=pshm->P[2000]*.9999+abs(Mptr->PosError)*0.0001; //lowpass of Position error
return pshm->ServoCtrl(Mptr);
}}'''.format(motid=motid)
#y=[]
#for i in range(mat['ozOutName'].shape[0]):
# s=str(mat['ozOutName'][i][0][0])
# s=s[0].capitalize()+s[1:]
# u.append(s)
# progSample='''double usr_servo_ctrl_{motid}(MotorData *Mptr)
#{{
# pshm->P[2000]=pshm->P[2000]*.9999+abs(Mptr->PosError)*0.0001; //lowpass of Position error
# return pshm->ServoCtrl(Mptr);
#}}'''.format(motid=motid)
prog='''double obsvr_servo_ctrl_{motid}(MotorData *Mptr)
{{
//x[n+1]=A*x[n]+B*u
//y=C*x[n]+D*x[n]
//u=[{u}].T
//y=[{y}].T
double x[{A.shape[0]}]; //new state
static double _x[{A.shape[0]}]={{0,0,0,0}}; //old state
//double {u}; // input values
double {y},iqCmd; // output values
double maxDac=Mptr->MaxDac;
static double _x[{A.shape[0]}]={{{xInit}}}; //old state
'''.format(motid=motid,A=A,xInit=','.join('0'*A.shape[0]),u=', '.join(u),y=', '.join(y))
s=' //input values\n'
for i in range(len(u)):
s+=' double {u}=Mptr->{u};\n'.format(u=u[i])
prog+=s+'''
prog+=s
prog+='''
double {y},iqCmd; // output values
double maxDac=Mptr->MaxDac; //other stuff
'''.format(u=', '.join(u),y=', '.join(y))
prog +='''
if (Mptr->ClosedLoop)
{
'''
'''
s=' //x[n+1]=A*x[n]+B*u;\n'
for i in range(A.shape[0]):
@@ -332,10 +350,14 @@ class MXTuning(Tuning):
s+=';\n'
prog+=s+'\n'
s=' //update states: oldstate=newstate\n '
s+=' '.join(map(lambda i: '_x[{i:d}]=x[{i:d}];'.format(i=i),range(A.shape[0])))
prog+=s+'\n\n'
prog+=''' iqCmd=DesPos*{V}-{y};
prog+=''' //set output
iqCmd={u}*{V}-{y};
//return iqCmd;
pshm->P[200{motid}]=iqCmd; //lowpass of Position error
pshm->P[200{motid}]=iqCmd;
return pshm->ServoCtrl(Mptr);
}}
else
@@ -343,7 +365,7 @@ class MXTuning(Tuning):
Mptr->Servo.Integrator=0.0;
return 0.0;
}}
}}'''.format(V=V[0,0],y=y[0],motid=motid)
}}'''.format(u=u[0],V=V[0,0],y=y[0],motid=motid)
hdr='''double obsvr_servo_ctrl_{motid}(MotorData *Mptr);
EXPORT_SYMBOL(obsvr_servo_ctrl_{motid});'''.format(motid=motid)
@@ -767,8 +789,10 @@ EXPORT_SYMBOL(obsvr_servo_ctrl_{motid});'''.format(motid=motid)
#after this go to: python/usr_code and call make to build the controller
#to activate the controller checkout: PBTools/pbtools/usr_servo_phase
base=os.path.dirname(__file__)
(hdr1,prog1)=self.usr_servo_gen_code('/tmp/ssc1.mat')
(hdr2,prog2)=self.usr_servo_gen_code('/tmp/ssc2.mat')
#(hdr1,prog1)=self.usr_servo_gen_code('/tmp/ssc1.mat')
#(hdr2,prog2)=self.usr_servo_gen_code('/tmp/ssc2.mat')
(hdr1,prog1)=self.usr_servo_gen_code(os.path.join(base,'../matlab/ssc1.mat'))
(hdr2,prog2)=self.usr_servo_gen_code(os.path.join(base,'../matlab/ssc2.mat'))
fn_ct=os.path.join(base,'usr_code/usrcode_template.c')
fn_ht=os.path.join(base,'usr_code/usrcode_template.h')
fnc=os.path.join(base,'usr_code/usrcode.c')
@@ -868,7 +892,7 @@ Examples:'''+''.join(map(lambda s:cmd+s, exampleCmd))+'\n '
#plt.ion()
#args.host='MOTTEST-CPPM-CRM0573'
#args.host=None
args.host=None
if args.host is None:
comm=gt=None
else:

View File

@@ -73,7 +73,11 @@ KBUILD_EXTRA_SYMBOLS := /usr/local/dtlibs/libppmac/Module.symvers
#all::
# cp -f /usr/local/usralgo/usralgomain.c $(PWD)
all:
all: usralgo.ko
usralgo.ko: usrcode.c
$(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules
# $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules V=1
@@ -108,6 +112,19 @@ tags:
Debug: all
../../matlab/ssc%.mat: ../../matlab/StateSpaceControlDesign.m ../../matlab/identifyFxFyStage.m
cd ../../matlab; /afs/psi.ch/sys/psi.x86_64_slp6/Programming/matlab/2018a/bin/matlab -nodisplay -nojvm -nosplash -nodesktop -r \
"clear;clear global;close all;\
mot=identifyFxFyStage(7);\
sscType=0;\
for k=1:2;\
[ssc]=StateSpaceControlDesign(mot{k},sscType);\
end;\
exit(0);"
usrcode.c: ../../matlab/ssc1.mat ../../matlab/ssc2.mat ../MXTuning.py
cd ..;./MXTuning.py -m512
install: all
scp usralgo.ko root@$(PPMAC):/tmp
scp /home/zamofing_t/Documents/prj/SwissFEL/PBTools/pbtools/usr_servo_phase/userservo_util root@$(PPMAC):/tmp