Changeset 787 in ETALON
- Timestamp:
- Jul 27, 2018, 11:43:24 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BPM/initialise_motors.py
r783 r787 5 5 __author__ = 'delerue' 6 6 7 8 7 from bpm_constants import * 9 from scope_functionimport *8 from read_adc import * 10 9 import numpy as np 11 10 import matplotlib.pyplot as plt 12 11 from datetime import datetime 13 12 14 13 VERBOSE_DEFAULT=0 … … 17 16 write_to_motor_dated_log = data_dir + './write_to_motor_log' 18 17 19 from writeclient import *18 #from writeclient import * 20 19 import time 21 20 … … 59 58 print('Be carful with disable vertical motor') 60 59 else : 61 move_motor_absolute(2,10000,-10000) 62 while motor_get(2, 'status') != 'READY': 63 time.sleep(1) 64 print('Say ok when motor can be put in position 0') 65 x = raw_input() 66 while not (x == 'OK' or x == 'ok' or x == 'Ok'): 67 print('Say ok when motor can be put in position 0') 68 x = raw_input() 69 move_motor_absolute(2,5000,0) 60 move_motor_absolute(2,2000,0) 70 61 while motor_get(2, 'status') != 'READY': 71 62 time.sleep(1) … … 212 203 time.sleep(1) 213 204 205 214 206 def motor_move_absolute(motor, speed, steps): 215 207 "Moves a motor with the given parameters" … … 226 218 time.sleep(1) 227 219 220 228 221 def motor_wait_for_ready(motor,verbose=VERBOSE_DEFAULT): 229 222 motor_status=motor_get(motor,'status') … … 257 250 if (x == 'NO'): 258 251 print('Please don\'t forbid to move BPM at maxima right when you look from motor side befor to shut down the motor') 259 exit() 260 252 exit() 261 253 else: 262 254 motor_enable(1) … … 277 269 if not os.path.exists(data_name_and_path) : 278 270 os.makedirs(data_name_and_path) 279 data_name_and_path = data_name_and_path+" position_vs_tension_"+bpm_name+"_"+start_time_str+"_"+str(idata)+".txt"280 while os.path.exists(data_name_and_path ) :271 data_name_and_path = data_name_and_path+"BPM-number_x-motor-step_x-motor-mm_y-motor-step_y-motor_mm_Va_Vb_Vc_Vd_Sum_X_Y_"+bpm_name+"_"+start_time_str+"_" 272 while os.path.exists(data_name_and_path+str(idata)+".txt") : 281 273 idata+=1 282 data_name_and_path = data_dir+"data/position_vs_tension_"+bpm_name+"_"+start_time_str+"_"+str(idata)+".txt" 283 return(data_name_and_path) 274 return(data_name_and_path+str(idata)+".txt") 275 276 def write_first_line(data_name_and_path, list_of_data): 277 length = len(list_of_data) 278 fichier = open(data_name_and_path, "w") 279 for index in range(length): 280 fichier.write(list_of_data[index]) 281 if index != length - 1: 282 fichier.write(" ") 283 fichier.write("\n") 284 fichier.close() 284 285 286 def horizontal_acquisition(begin, end, number_of_point, # cordinate of the the first and the last point of data taken horizontally and total number of point 287 title_bpm_name, # a string that will appear in the name of the datafile 288 statistic_number = 1, # nuber of repetition of taking data whith 1 set of parameter, as default no repetition 289 list_of_data = ["bpm_name","bpm_number","x_motor_step","x_motor_mm","y_motor_step","y_motor_mm","Va","Vb","Vc","Vd","Sum","x_libera_mm","y_libera_mm"], # list of the name of the data that the program will read, as default it read all 290 bpm_name1 = "BPM_E",bpm_name2 = "BPM_impr",bpm_name3 = "BPM_C",bpm_name4 = None): #name of the BPM used (as default, it the configuration of the BPM when this code was writen 291 292 data_name_and_path = path(title_bpm_name) #create the name of the datafile 293 write_first_line(data_name_and_path, list_of_data) # write first line of the datafile with the name of the data 294 bpm_list = initialise_bpm(bpm_name1,bpm_name2,bpm_name3,bpm_name4) # initialise BPM (program on read_adc.py) 295 y_position = 0 # set an abirtary position for y since I can't get motor step 296 motor_enable(1) 297 for x_position in np.linspace(begin,end,number_of_point): 298 move_motor_absolute(1,5000,x_position) 299 print('x_motor going to ', x_position) 300 while (motor_get(1, 'status') != 'READY') or (motor_get(2, 'status') != 'READY'): 301 time.sleep(1) 302 time.sleep(1) 303 acquisition_libera(x_position, y_position, data_name_and_path, statistic_number, list_of_data, bpm_list) # read_the data (program on read_adc.py) 304 motor_disable(1) 305 306 307 308 def vertical_acquisition(begin, end, number_of_point, # cordinate of the the first and the last point of data taken vertically and total number of point 309 title_bpm_name, # a string that will appear in the name of the datafile 310 statistic_number = 1, # nuber of repetition of taking data whith 1 set of parameter, as default no repetition 311 list_of_data = ["bpm_name","bpm_number","x_motor_step","x_motor_mm","y_motor_step","y_motor_mm","Va","Vb","Vc","Vd","Sum","x_libera_mm","y_libera_mm"], # list of the name of the data that the program will read, as default it read all 312 bpm_name1 = "BPM_E",bpm_name2 = "BPM_impr",bpm_name3 = "BPM_C",bpm_name4 = None): #name of the BPM used (as default, it the configuration of the BPM when this code was writen 285 313 286 def horizontal_acquisition(begin,end,pas,bpm_name): 287 if pas == 0: #position test 288 motor_enable(1) 289 move_motor_absolute(1,10000,begin) 290 while motor_get(1, 'status') != 'READY': 291 time.sleep(1) 292 print("position ok ?") 293 time.sleep(15) 294 move_motor_absolute(1,10000,end) 295 while motor_get(1, 'status') != 'READY': 296 time.sleep(1) 297 print("position ok ?") 298 motor_disable(1) 299 else : 300 if (end - begin)*pas < 0 : 301 pas = -pas 302 data_name_and_path = path(bpm_name) 303 motor_enable(1) 304 L = [[],[],[],[],[]] 305 for i in range(begin, end,pas): 306 move_motor_absolute(1,5000,i) 307 while motor_get(1, 'status') != 'READY': 308 time.sleep(1) 309 time.sleep(1) 310 l = read_scope_and_write(i, data_name_and_path) 311 for j in range(5): 312 L[j].append(l[j]) 313 time.sleep(1) 314 move_motor_absolute(1,5000,end) # pour assuré le dernier pas, en aller ou retour 315 while motor_get(1, 'status') != 'READY': 316 time.sleep(1) 317 time.sleep(1) 318 l = read_scope_and_write(end, data_name_and_path) 319 for j in range(5): 320 L[j].append(l[j]) 321 motor_disable(1) 322 for i in range(4): 323 plt.plot(L[0],L[i+1]) 324 plt.show() 325 326 327 328 329 def vertical_acquisition(begin,end,pas,bpm_name): 330 if pas == 0: #position test 331 motor_enable(2) 332 move_motor_absolute(2,10000,begin) 333 while motor_get(2, 'status') != 'READY': 334 time.sleep(1) 335 print("position ok ?") 336 time.sleep(15) 337 move_motor_absolute(2,10000,end) 338 while motor_get(2, 'status') != 'READY': 339 time.sleep(1) 340 print("position ok ?") 341 motor_disable(2) 342 else: 343 if (end - begin)*pas < 0 : 344 pas = -pas 345 data_name_and_path = path(bpm_name) 346 motor_enable(2) 347 L = [[],[],[],[],[]] 348 for i in range(begin,end,pas): 349 move_motor_absolute(2,5000,i) 350 while motor_get(2, 'status') != 'READY': 314 data_name_and_path = path(title_bpm_name) #create the name of the datafile 315 write_first_line(data_name_and_path, list_of_data) # write first line of the datafile with the name of the data 316 bpm_list = initialise_bpm(bpm_name1,bpm_name2,bpm_name3,bpm_name4) # initialise BPM (program on read_adc.py) 317 x_position = 0 # set an abirtary position for x since I can't get motor step 318 motor_enable(2) 319 for y_position in np.linspace(begin, end, number_of_point): 320 motor_move_absolute(2,2000,y_position) 321 print('y_moteur going to', y_position) 322 while (motor_get(1, 'status') != 'READY') or (motor_get(2, 'status') != 'READY'): 323 time.sleep(1) 324 time.sleep(1) 325 acquisition_libera(x_position, y_position, data_name_and_path, statistic_number, list_of_data, bpm_list) # read_the data (program on read_adc.py) 326 motor_disable(2) 327 328 329 def acquisition_2D(begin1,end1,number_of_point1, # cordinate of the the first and the last point of data taken horizontally and total number of point 330 begin2,end2,number_of_point2, # cordinate of the the first and the last point of data taken vertically and total number of point 331 title_bpm_name, # a string that will appear in the name of the datafile 332 statistic_number = 1,# nuber of repetition of taking data whith 1 set of parameter, as default no repetition 333 list_of_data = ["bpm_name","bpm_number","x_motor_step","x_motor_mm","y_motor_step","y_motor_mm","Va","Vb","Vc","Vd","Sum","x_libera_mm","y_libera_mm"], # list of the name of the data that the program will read, as default it read all 334 bpm_name1 = "BPM_E",bpm_name2 = "BPM_impr",bpm_name3 = "BPM_C",bpm_name4 = None):#name of the BPM used (as default, it the configuration of the BPM when this code was writen 335 336 data_name_and_path = path(title_bpm_name)#create the name of the datafile 337 write_first_line(data_name_and_path, list_of_data)# write first line of the datafile with the name of the data 338 bpm_list = initialise_bpm(bpm_name1,bpm_name2,bpm_name3,bpm_name4)# initialise BPM (program on read_adc.py) 339 motor_enable(1) 340 motor_enable(2) 341 for y_position in np.linspace(begin2, end2, number_of_point2): 342 motor_move_absolute(2,2000,y_position) 343 print('moteur going to', y_position) 344 for x_position in np.linspace(begin1,end1,number_of_point1): 345 move_motor_absolute(1,5000,x_position) 346 print('x_motor going to ', x_position) 347 while (motor_get(1, 'status') != 'READY') or (motor_get(2, 'status') != 'READY'): #waits will the motor move 351 348 time.sleep(1) 352 349 time.sleep(1) 353 l = read_scope_and_write(i, data_name_and_path) 354 for j in range(5): 355 L[j].append(l[j]) 356 time.sleep(1) 357 move_motor_absolute(2,5000,end) # pour assuré le dernier pas, en aller ou retour 358 while motor_get(2, 'status') != 'READY': 359 time.sleep(1) 360 time.sleep(1) 361 l = read_scope_and_write(end, data_name_and_path) 362 for j in range(5): 363 L[j].append(l[j]) 364 time.sleep(1) 365 for i in range(4): 366 plt.plot(L[0],L[i+1]) 367 plt.show() 368 motor_disable(2) 369 370 def acqui_column(begin, end, pas, data_path, other_position): # use in aquisition to read a column 371 if (end - begin)*pas < 0 : 372 pas = -pas 373 for i in range(begin,end,pas): 374 move_motor_absolute(2,5000,i) 375 while motor_get(2, 'status') != 'READY': 376 time.sleep(1) 377 time.sleep(1) 378 l = read_scope_and_write_2D(other_position, i, data_path) 379 time.sleep(1) 380 move_motor_absolute(2,5000,end) # pour assuré le dernier pas, en aller ou retour 381 while motor_get(2, 'status') != 'READY': 382 time.sleep(1) 383 time.sleep(1) 384 read_scope_and_write_2D(other_position, end, data_path) 385 386 def acquisition(begin1,end1,pas1,begin2,end2,pas2,bpm_name): 387 if pas1 == 0 or pas2 == 0: #position test 388 motor_enable(1) 389 motor_enable(2) 390 move_motor_absolute(1,10000,begin1) 391 move_motor_absolute(2,10000,begin2) 392 while (motor_get(1, 'status') != 'READY') or (motor_get(2, 'status') != 'READY'): 393 time.sleep(1) 394 print("position ok ?") 395 time.sleep(15) 396 move_motor_absolute(1,10000,end1) 397 move_motor_absolute(2,10000,end2) 398 while (motor_get(1, 'status') != 'READY') or (motor_get(2, 'status') != 'READY'): 399 time.sleep(1) 400 print("position ok ?") 401 motor_disable(1) 402 motor_disable(2) 403 else: 404 if (end1 - begin1)*pas1 < 0 : 405 pas1 = -pas1 406 if (end2 - begin2)*pas2 < 0 : 407 pas2 = -pas2 408 data_name_and_path = path(bpm_name) 409 motor_enable(1) 410 motor_enable(2) 411 move_motor_absolute(1,10000,begin1) 412 move_motor_absolute(2,10000,begin2) 413 while (motor_get(1, 'status') != 'READY') or (motor_get(2, 'status') != 'READY'): 414 time.sleep(1) 415 print("bagin position ok ?") 416 time.sleep(15) 417 # L = [[],[],[],[],[],[]] 418 for i in range(begin1, end1, pas1): 419 move_motor_absolute(1,5000,i) 420 while motor_get(1, 'status') != 'READY': 421 time.sleep(1) 422 acqui_column(begin2, end2, pas2, data_name_and_path, i) 423 begin2,end2 = end2,begin2 424 move_motor_absolute(1,5000,end1) # pour assuré le dernier pas, en aller ou retour 425 while motor_get(1, 'status') != 'READY': 426 time.sleep(1) 427 time.sleep(1) 428 acqui_column(begin2, end2, pas2, data_name_and_path, end1) 429 print("end position ok ?") 430 time.sleep(15) 431 motor_disable(1) 432 motor_disable(2) 433 # for j in range(6): 434 #L[j].append(l[j]) 435 # for i in range(4): 436 # plt.plot(L[0],L[i+2]) 437 # plt.show() 438 439 440 350 acquisition_libera(x_position, y_position, data_name_and_path, statistic_number, list_of_data, bpm_list) # read_the data (program on read_adc.py) 351 begin1,end1 = end1,begin1 #to 352 motor_disable(1) 353 motor_disable(2) 441 354 442 #controller_hello() 443 #move_motor_relative(1,1000,-1000) 444 #time.sleep(1) 445 #move_motor_relative(1,1000,1000) 355 #write_first_line("test.txt", ["test","de","si","ca","marche","bien","ou","pas"]) 356 357 #acquisition_2D(0,1,3,-3.1415,3.1415,2,"test_acquisition_2D") 358 #horizontal_acquisition(0,1,3,"hori") 359 #vertical_acquisition(-3.1415,3.1415,2,"test_verti")
Note: See TracChangeset
for help on using the changeset viewer.