Exemplo n.º 1
0
def run_single_bumps(pvmaps):
    for pvm in pvmaps:
        if ap.caget(pvm["cmd"]) == 0: continue
        ap.caput(pvm["cmddone"], 0)
        ename = pvm["idname"]
        if not ename: continue
        if ap.caget(pvm["op"]) == 0: continue
        xc, xangle = ap.caget([pvm["offset"], pvm["angle"]])
        plane = pvm["XY"].lower()
        print ename, xc, xangle, plane
        norm0, norm1, norm2, corvals = ap.setIdBump(
            ename, xc, xangle, plane=plane, check=False, ncor=6, dImax=0.5)
        print "Norm:", norm0, norm1, norm2
        print corvals
        ap.caput(pvm["cmddone"], 1)
        ap.caput(pvm["cmd"], 0)
        cothread.Yield(0.1)
Exemplo n.º 2
0
    def _aplocalbumpcreation(self, plane, ename, source, bumpsettings):
        """
        plane: 0: X plane, 1: Y plane;
        ename: selected insertion device element name;
        source: s position at source position
        bumpsettings: local bump settings: [shift, angle]

        return: delta correctors [H, V]
        """

        if plane == 0:
            fld = 'x'
            #xc = ((self.idobj.se - self.idobj.sb) / 2.0 - self.sourceposition) * \
            #    bumpsettings[1] + bumpsettings[0]
            #thetac = bumpsettings[1]
        elif plane == 1:
            fld = 'y'
        xc = ((self.idobj.se - self.idobj.sb) / 2.0 - self.sourceposition) * \
            bumpsettings[1] + bumpsettings[0]
        thetac = bumpsettings[1]

        if self.previoush is None:
            self.previoush = [0.0] * self.corscount
        for i, cor in enumerate(self.cors):
            self.previoush[i] = cor.get(fld, unitsys=None, handle="setpoint")

        niter = 10
        for i in range(niter):
            cothread.Yield(0.10)
            norm0, norm1, norm2, corvals = \
                ap.setIdBump(ename, xc, thetac, plane=fld)
            angle, position, _, _ = self._getliveangleandpos(self.bpms[self.bpmcounts/2-1], self.bpms[self.bpmcounts/2])
            # if the achieved angle and offset are very close to desired values, break
            # can not distinguish 10urad and 5um.
            if np.abs(angle - thetac) < 1e-2 and np.abs(xc - position) < 5e-3:
                break
            if corvals is None:
                msg = "{0}/{1} Minimum chi^2 achieved: {2} (predicted: {3})".format(i,niter,norm0, norm1)
            else:
                msg = "{0}/{1} chi^2 decreased {2} from {3} (predicted: {4})".format(
                    i, niter, norm2-norm0, norm0, norm1)
            ca.caput(self.pvmapping.__status__, msg[:255], datatype=DBR_CHAR_STR)

        delta = ap.fget(self.cors, fld, unitsys=None, handle="setpoint") - np.array(self.previoush, 'd')
        return delta
Exemplo n.º 3
0
def run_single_bumps(pvmaps):
    for pvm in pvmaps:
        if ap.caget(pvm["cmd"]) == 0: continue
        ap.caput(pvm["cmddone"], 0)
        ename = pvm["idname"]
        if not ename: continue
        if ap.caget(pvm["op"]) == 0: continue
        xc, xangle = ap.caget([pvm["offset"], pvm["angle"]])
        plane = pvm["XY"].lower()
        print ename, xc, xangle, plane
        dImax = ap.caget("SR:APHLA:SOFB{BUMP:ALL}Single-dImax-I")
        norm0, norm1, norm2, corvals = ap.setIdBump(
            ename, xc, xangle, plane=plane, check=False, ncor=4, dImax=dImax,
            bbpms=[pvm["bpm1"], pvm["bpm2"]])
        #norm0, norm1, norm2, corvals = ap.setIdBump(
        #    ename, xc, xangle, plane=plane, check=False, ncor=6, dImax=0.5)
        print "Norm:", norm0, norm1, norm2
        print corvals
        ap.caput(pvm["cmddone"], 1)
        ap.caput(pvm["cmd"], 0)
        cothread.Yield(0.1)
Exemplo n.º 4
0
    print "Start checking IDLocalBump command ..."
    while True:
        run_single_bumps(pvmaps)
        if ap.caget(_pvcmd) == 0:
            time.sleep(1)
            continue
        #obt = ap.getOrbit(spos=True)
        #print "BPMS:", len(ap.getElements("BPM")),
        #print np.average(obt[:,0]), np.std(obt[:,0])
        for pvm in pvmaps:
            ap.caput(pvm["cmddone"], 0)
        for pvm in pvmaps:
            ename = pvm["idname"]
            if not ename: continue
            if ap.caget(pvm["op"]) == 0: continue
            xc, xangle = ap.caget([pvm["offset"], pvm["angle"]])
            plane = pvm["XY"].lower()
            print ename, xc, xangle, plane
            dImax = ap.caget("SR:APHLA:SOFB{BUMP:ALL}dImax-I")
            norm0, norm1, norm2, corvals = ap.setIdBump(
                ename, xc, xangle, plane=plane, check=False, ncor=6, dImax=dImax,
                bbpms=[pvm["bpm1"], pvm["bpm2"]])
            #norm0, norm1, norm2, corvals = ap.setIdBump(
            #    ename, xc, xangle, plane=plane, check=False, ncor=6, dImax=0.5)
            print "Norm:", norm0, norm1, norm2
            print corvals
            ap.caput(pvm["cmddone"], 1)
            cothread.Yield(0.1)
        time.sleep(1)
        ap.caput(_pvcmd, 0) 
Exemplo n.º 5
0
        pvmaps.append(pvdict)

    #for b in ap.getElements("UBPM"):
    #    print b.name, b.pv(field="x")
    print "Start checking IDLocalBump command ..."
    while True:
        run_single_bumps(pvmaps)
        if ap.caget(_pvcmd) == 0:
            time.sleep(1)
            continue
        #obt = ap.getOrbit(spos=True)
        #print "BPMS:", len(ap.getElements("BPM")),
        #print np.average(obt[:,0]), np.std(obt[:,0])
        for pvm in pvmaps:
            ap.caput(pvm["cmddone"], 0)
        for pvm in pvmaps:
            ename = pvm["idname"]
            if not ename: continue
            if ap.caget(pvm["op"]) == 0: continue
            xc, xangle = ap.caget([pvm["offset"], pvm["angle"]])
            plane = pvm["XY"].lower()
            print ename, xc, xangle, plane
            norm0, norm1, norm2, corvals = ap.setIdBump(
                ename, xc, xangle, plane=plane, check=False, ncor=6, dImax=0.5)
            print "Norm:", norm0, norm1, norm2
            print corvals
            ap.caput(pvm["cmddone"], 1)
            cothread.Yield(0.1)
        time.sleep(1)
        ap.caput(_pvcmd, 0)