Example #1
0
def setInitHall(init_hall=0):

    b0_hall = GetHall(dipole_pair[0])
    b1_hall = GetHall(dipole_pair[1])
    overshoot_margin = 0.001
    print("Beginning initializing dipoles...")
    while ((b0_hall - init_hall) < overshoot_margin
           or (b1_hall - init_hall) < overshoot_margin):

        diff = max(abs(b0_hall - init_hall), abs(b1_hall - init_hall))
        b0_i = GetMagnet(dipole_pair[0])

        dI = 0.02
        if (diff >= 0.001):
            dI = 0.1

        elif (diff > 0.00005):
            dI = 0.01
        # change b0 and compare
        SetMagnet(dipole_pair[0], b0_i + dI)
        #saving the new actual hall value
        sleep(3)
        b0_hall = GetHall(dipole_pair[0])
        SetMagnet(dipole_pair[1], b0_i + dI)
        b1_hall = GetHall(dipole_pair[1])

        print(f"Fields: {b0_hall:.6f}, {b1_hall:.6f}")

    time1 = CycleMagnet(dipole_pair[0])
    time2 = CycleMagnet(dipole_pair[1])
    sleep(np.max([time1, time2]) + 30)
    cont = input("Once magnets have settled, enter 'y' to continue...")

    if (cont != 'y'):
        print("Exiting...")
        exit()

    print("Magnets cycled above initial Hall values.")

    while (abs(b0_hall - init_hall) > dHall):
        diff = abs(b0_hall - init_hall)

        dI = 0.02
        #this takes too long if they're really far so I'm gona add this for now
        if (diff >= 0.001):
            dI = 0.1

        elif (diff > 0.00005):
            dI = 0.01

        b0_i = GetMagnet(dipole_pair[0])

        if (b0_hall > init_hall):
            # change b0 and compare
            SetMagnet(dipole_pair[0], b0_i - dI)
            #saving the new actual hall value
            sleep(3)
            b0_hall = GetHall(dipole_pair[0])
    print("B0 set to initial value.")
    matchHall()
#setInitHall(init_hall)

#get initial values to return two for second scan
b0_init = GetMagnet(dipole_pair[0])
b1_init = GetMagnet(dipole_pair[1])

scanDipoles(dipole_pair[0], dipole_pair[1])
print(f"Done with {dipole_pair[0]} scan.")

#reset dipoles to original currents and cycle
SetMagnet(dipole_pair[0], b0_init)
SetMagnet(dipole_pair[1], b1_init)

#cycle
time1 = CycleMagnet(dipole_pair[0])
time2 = CycleMagnet(dipole_pair[1])
sleep(np.max([time1, time2]))
print("Done cycling.")

cont = input("Once magnets have settled, enter 'y' to continue...")

if (cont != 'y'):
    print("Exiting...")
    exit()

#'''
#match Hall probe readings
matchHall()
scanDipoles(dipole_pair[1], dipole_pair[0])
print(f"Done with {dipole_pair[1]} scan.")