Changeset 777 in ETALON


Ignore:
Timestamp:
Jun 14, 2018, 11:25:20 AM (6 years ago)
Author:
moutardier
Message:

add program to initilase_motor.py to generat data_path and add exeception to acquisition's program to test position

Location:
BPM
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • BPM/initialise_motors.py

    r776 r777  
    5858        if (x == 'no' or x == 'n' or  x == 'NO' or x == 'N'):
    5959            print('Be carful with disable vertical motor')
    60             exit()
    61     msg = str(motor) + 'CD'
    62     motor_send(msg, verbose)
     60        else :
     61            msg = str(motor) + 'CD'
     62            motor_send(msg, verbose)
     63    else :
     64        msg = str(motor) + 'CD'
     65        motor_send(msg, verbose)
    6366
    6467
     
    254257    motor_disable(1)
    255258
    256 def horizontal_aquisition(begin,end,pas,bpm_name):
     259def path(bpm_name): # create the path of the file what will contain data
    257260    idata = 0
    258     start_time_str=datetime.now().strftime("%Y%m%d_%H%M%S")
    259     data_name_and_path = data_dir+"data/position_vs_tension_"+bpm_name+"_"+start_time_str+"_"+str(idata)+".txt"
     261    start_time_str=datetime.now().strftime("%Y%m%d")
     262    data_name_and_path = data_dir+"data/"
     263    if not os.path.exists(data_name_and_path) :
     264        os.makedirs(data_name_and_path)
     265    data_name_and_path = data_name_and_path+"position_vs_tension_"+bpm_name+"_"+start_time_str+"_"+str(idata)+".txt"
    260266    while os.path.exists(data_name_and_path) :
    261267        idata+=1
    262268        data_name_and_path = data_dir+"position_vs_tension_"+bpm_name+start_time_str+"_"+str(idata)+".txt"
    263     fichier  = open(data_name_and_path, "w")
    264     motor_enable(1)
    265     L = [[],[],[],[],[]]
    266     for i in range(begin, end,pas):
    267         move_motor_absolute(1,5000,i)
     269    return(data_name_and_path)
     270   
     271   
     272def horizontal_aquisition(begin,end,pas,bpm_name):
     273    if pas == 0: #position test
     274        motor_enable(1)
     275        move_motor_absolute(1,10000,begin)
    268276        while motor_get(1, 'status') != 'READY':
    269277                time.sleep(1)
    270         time.sleep(1)
    271         l = read_scope_and_write(i, fichier)
     278        print("position ok ?")
     279        time.sleep(15)
     280        move_motor_absolute(1,10000,end)
     281        while motor_get(1, 'status') != 'READY':
     282            time.sleep(1)
     283        print("position ok ?")
     284        motor_disable(1)
     285    else :
     286        if (end - begin)*pas < 0 :
     287            pas = -pas
     288        data_name_and_path = path(bpm_name)
     289        motor_enable(1)
     290        L = [[],[],[],[],[]]
     291        for i in range(begin, end,pas):
     292            move_motor_absolute(1,5000,i)
     293            while motor_get(1, 'status') != 'READY':
     294                time.sleep(1)
     295            time.sleep(1)
     296            l = read_scope_and_write(i, data_name_and_path)
     297            for j in range(5):
     298                L[j].append(l[j])
     299        time.sleep(1)
     300        move_motor_absolute(1,5000,end) # pour assuré le dernier pas, en aller ou retour
     301        while motor_get(1, 'status') != 'READY':
     302            time.sleep(1)
     303        time.sleep(1)
     304        l = read_scope_and_write(end, data_name_and_path)
    272305        for j in range(5):
    273306            L[j].append(l[j])
    274     time.sleep(1)
    275    
    276     move_motor_absolute(1,5000,end) # pour assuré le dernier pas, en aller ou retour
    277     while motor_get(1, 'status') != 'READY':
    278         time.sleep(1)
    279     time.sleep(1)
    280     l = read_scope_and_write(end, fichier)
    281     for j in range(5):
    282         L[j].append(l[j])
    283     time.sleep(1)
    284     motor_disable(1)
    285     fichier.close()
    286 #    for i in range(4):
    287 #         plt.plot(L[0],L[i+1])
    288 #    plt.show()
     307        motor_disable(1)
     308        for i in range(4):
     309            plt.plot(L[0],L[i+1])
     310        plt.show()
    289311
    290312
     
    292314
    293315def vertical_aquisition(begin,end,pas,bpm_name):
    294     idata = 0
    295     start_time_str=datetime.now().strftime("%Y%m%d_%H%M%S")
    296     data_name_and_path = data_dir+"data/position_vs_tension_"+bpm_name+"_"+start_time_str+"_"+str(idata)+".txt"
    297     while os.path.exists(data_name_and_path) :
    298         idata+=1
    299         data_name_and_path = data_dir+"position_vs_tension_"+bpm_name+start_time_str+"_"+str(idata)+".txt"
    300     fichier  = open(data_name_and_path, "w")
    301     motor_enable(2)
    302     L = [[],[],[],[],[]]
    303     for i in range(begin, end,pas):
    304         move_motor_absolute(1,5000,i)
     316    if pas == 0: #position test
     317        motor_enable(2)
     318        move_motor_absolute(2,10000,begin)
     319        while motor_get(2, 'status') != 'READY':
     320            time.sleep(1)
     321        print("position ok ?")
     322        time.sleep(15)
     323        move_motor_absolute(2,10000,end)
    305324        while motor_get(2, 'status') != 'READY':
    306325                time.sleep(1)
    307         time.sleep(1)
    308         l = read_scope_and_write(i, fichier)
     326        print("position ok ?")
     327        motor_disable(2)
     328    else:
     329        if (end - begin)*pas < 0 :
     330            pas = -pas
     331        data_name_and_path = path(bpm_name)
     332        motor_enable(2)
     333        L = [[],[],[],[],[]]
     334        for i in range(begin,end,pas):
     335            move_motor_absolute(2,5000,i)
     336            while motor_get(2, 'status') != 'READY':
     337                time.sleep(1)
     338            time.sleep(1)
     339            l = read_scope_and_write(i, data_name_and_path)
     340            for j in range(5):
     341                L[j].append(l[j])
     342        time.sleep(1)
     343        move_motor_absolute(2,5000,end) # pour assuré le dernier pas, en aller ou retour
     344        while motor_get(2, 'status') != 'READY':
     345            time.sleep(1)
     346        time.sleep(1)
     347        l = read_scope_and_write(end, data_name_and_path)
    309348        for j in range(5):
    310349            L[j].append(l[j])
    311     time.sleep(1)
    312    
    313     move_motor_absolute(2,5000,end) # pour assuré le dernier pas, en aller ou retour
    314     while motor_get(2, 'status') != 'READY':
    315         time.sleep(1)
    316     time.sleep(1)
    317     l = read_scope_and_write(end, fichier)
    318     for j in range(5):
    319         L[j].append(l[j])
    320     time.sleep(1)
    321 #    for i in range(4):
    322 #         plt.plot(L[0],L[i+1])
    323 #    plt.show()
    324     motor_disable(2)
    325     fichier.close()
    326 
    327 
    328 """
    329 def aquisition(begin1,end1,begin2,end2,pas1,pas2,bpm_name):
    330     idata = 0
    331     start_time_str=datetime.now().strftime("%Y%m%d_%H%M%S")
    332     data_name_and_path = data_dir+"data/position_vs_tension_"+bpm_name+"_"+start_time_str+"_"+str(idata)+".txt"
    333     while os.path.exists(data_name_and_path) :
    334         idata+=1
    335         data_name_and_path = data_dir+"position_vs_tension_"+bpm_name+start_time_str+"_"+str(idata)+".txt"
    336     fichier  = open(data_name_and_path, "w")
    337     motor_enable(1)
    338     motor_enable(2)
    339     L = [[],[],[],[],[]]
    340     for i in range(begin1, end1,pas1):
    341         move_motor_absolute(1,5000,i)
    342         while motor_get(1, 'status') != 'READY':
     350        time.sleep(1)
     351        for i in range(4):
     352            plt.plot(L[0],L[i+1])
     353        plt.show()
     354        motor_disable(2)
     355
     356
     357
     358
     359def aquisition(begin1,end1,pas2,begin2,end2,pas1,bpm_name):
     360    if pas == 0: #position test
     361        motor_enable(1)
     362        motor_enable(2)
     363        move_motor_absolute(1,10000,begin1)
     364        move_motor_absolute(2,10000,begin2)
     365        while (motor_get(1, 'status') != 'READY') and (motor_get(2, 'status') != 'READY'):
     366            time.sleep(1)
     367        print("position ok ?")
     368        time.sleep(15)
     369        move_motor_absolute(1,10000,end1)
     370        move_motor_absolute(2,10000,end2)
     371        while (motor_get(1, 'status') != 'READY') and (motor_get(2, 'status') != 'READY'):
     372            time.sleep(1)
     373        print("position ok ?")
     374        motor_disable(1)
     375        motor_disable(2)
     376    else:
     377        if (end - begin)*pas < 0 :
     378            pas = -pas
     379        data_name_and_path = path(bpm_name)
     380        motor_enable(1)
     381        motor_enable(2)
     382        L = [[],[],[],[],[]]
     383        for i in range(begin1, end1,pas1):
     384            move_motor_absolute(1,5000,i)
     385            while motor_get(1, 'status') != 'READY':
    343386                time.sleep(1)
    344         time.sleep(1)
    345         for j in range(begin2, end2,pas2):
    346             move_motor_absolute(2,5000,i)
    347             while motor_get(2, 'status') != 'READY':
    348                 time.sleep(1)
    349             time.sleep(1)
    350             l = read_scope_and_write(i, fichier)
    351             for k in range(5):
    352                 L[k].append(l[k])
    353             time.sleep(1)
    354     move_motor_absolute(1,5000,end1)   
    355     move_motor_absolute(2,5000,end2) # pour assuré le dernier pas, en aller ou retour
    356     while (motor_get(1, 'status') != 'READY') & (motor_get(2, 'status') != 'READY'):
    357         time.sleep(1)
    358     time.sleep(1)
    359     l = read_scope_and_write(end, fichier)
    360     for j in range(5):
    361         L[j].append(l[j])
    362     time.sleep(1)
    363     for i in range(4):
    364          plt.plot(L[0],L[i+1])
    365     plt.show()
    366     fichier.close()
    367 """
     387            time.sleep(1)
     388            for j in range(begin2, end2,pas2):
     389                move_motor_absolute(2,5000,i)
     390                while motor_get(2, 'status') != 'READY':
     391                    time.sleep(1)
     392                time.sleep(1)
     393                l = read_scope_and_write_2D(i, data_name_and_path)
     394                for k in range(5):
     395                    L[k].append(l[k])
     396                time.sleep(1)
     397        move_motor_absolute(1,5000,end1)   
     398        move_motor_absolute(2,5000,end2) # pour assuré le dernier pas, en aller ou retour
     399        while (motor_get(1, 'status') != 'READY') & (motor_get(2, 'status') != 'READY'):
     400            time.sleep(1)
     401        time.sleep(1)
     402        l = read_scope_and_write_2D(end, data_name_and_path)
     403        for j in range(5):
     404            L[j].append(l[j])
     405        time.sleep(1)
     406        for i in range(4):
     407            plt.plot(L[0],L[i+1])
     408        plt.show()
     409
    368410
    369411
  • BPM/motor_control.py

    r776 r777  
    1515    time.sleep(1)
    1616time.sleep(5)
    17    
     17"""
    1818move_motor_absolute(2,5000,0)
    1919while motor_get(1, 'status') != 'READY':
    2020    time.sleep(1)
    21 
     21"""
    2222#controller_hello()
    2323#move_motor_relative(1,1000,-1000)
     
    3434
    3535
    36 turn_on()
     36#turn_on()
    3737
    3838vertical_aquisition(-110000,90000,4000,"ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition")
    3939
    40 vertical_aquisition(90000,-110000,-4000,"ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition")
     40#vertical_aquisition(90000,-110000,4000,"ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition")
    4141
    42 #vertical_aquisition(0,4000,2000,"test")
     42#vertical_aquisition(0,-4000,2000,"test")
     43#vertical_aquisition(4000,0,2000,"test2")
    4344
    4445#horizontal_aquisition(400000,0,-4000,"ch1-3_bpm_ref_ch2-4_bpm_impr")   
    4546
    46 turn_off()
     47#turn_off()
    4748
    4849#fichier = open("24-05-2018_aquisition_from_0_to_400000_step_of_1000.txt", "r")
  • BPM/print_datas.py

    r776 r777  
    88        L.append(float(i))
    99    return(L)
     10
     11def product_list(L,x):
     12    Lx = []
     13    for i in L:
     14        Lx.append(i*x)
     15    return(Lx)
     16
    1017
    1118def print_data(fichier):
     
    4249    for i in range(5):
    4350        L[i] = float_list(L[i])
     51    L[0] = product_list(L[0],10**-6)
     52    for i in range(1,5):
     53        L[i] = product_list(L[i],1000)
    4454    print_graph(L)
    4555
     
    6676   
    6777    plt.legend()
    68     plt.xlabel("length in motor step")
    69     plt.ylabel("tension in V")
     78    plt.xlabel("length in million motor step")
     79    plt.ylabel("tension in mV")
    7080    plt.show()
    7181
     
    8090
    8191
    82 print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt")
    83 print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_163036_0.txt")
     92#print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_160153_0.txt")
     93#print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_20180611_163036_0.txt")
     94
     95#print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition_20180612_0.txt")
     96print_data("data/position_vs_tension_ch1-3_bpm_ref_ch2-4_bpm_impr_vertical_acquisition_20180612_0.txt")
  • BPM/scope_function.py

    r771 r777  
    6868    return(L)
    6969   
    70 def read_scope_and_write(position, fichier):
     70def read_scope_and_write(position, path):
     71    fichier  = open(path, "a")
    7172    fichier.write(str(position)+' ')
    7273    L = [position]
     
    7879        fichier.write(valeur+' ')
    7980    fichier.write('\n')
     81    fichier.close()
    8082    return(L)
    8183       
Note: See TracChangeset for help on using the changeset viewer.