Changeset 628 in ETALON


Ignore:
Timestamp:
Dec 7, 2016, 11:05:28 AM (8 years ago)
Author:
delerue
Message:

CLIO control code updated

Location:
CLIO/control
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • CLIO/control/clio_constants.py

    r627 r628  
    22
    33global data_dir
    4 data_dir='/Users/delerue/travail/smith-purcell/SPARC/data/201507/'
     4#data_dir="C:\\CLIO\\data\\20161201\\"
     5data_dir="/Users/delerue/Downloads/CLIO/"
    56
    6 #SCOPE_IP='192.168.197.145'
    7 SCOPE_IP='10.0.1.112'
     7SCOPE1_IP='129.175.202.193'
     8SCOPE2_IP='129.175.202.14'
    89
    910global motor_controller_IP
    1011global motor_controller_port
    11 motor_controller_IP='10.0.1.160'
     12motor_controller_IP='129.175.202.187'
    1213motor_controller_port=30000
    1314
     
    2223
    2324
    24 CAMERA_1_PORT='10.0.1.130:80'
    25 CAMERA_2_PORT='10.0.1.132:80'
     25CAMERA_1_PORT='129.175.202.189:80'
     26CAMERA_2_PORT='129.175.202.190:80'
    2627CAMERAS_PORT=[CAMERA_1_PORT, CAMERA_2_PORT]
    2728
  • CLIO/control/initialise_motors.py

    r627 r628  
    2828    "Writes a formatted message to a motor"
    2929    if (len(message) <= 12):
    30         print 'Message length ', len(message), ' >', message, '<'
     30        print('Message length ', len(message), ' >', message, '<')
    3131    while len(message) < 12:
    3232        message += '0'
     
    3535    else:
    3636        if verbose == 1:
    37             print 'Command too long'
     37            print('Command too long')
    3838        return 'Command too long'
    3939
     
    112112    if (param == 'velocity'):
    113113        velocity = motor_send(motor + 'QV')
     114        print(velocity)
    114115        velo=float(velocity[3:12])
    115         print velo
     116        print(velo)
    116117        return velo
    117118    elif (param == 'acceleration'):
     
    212213
    213214def controller_hello():
    214     "Sends ça_va query to the motor and display reply"
     215    "Sends ca_va query to the motor and display reply"
    215216    #    write_to_motor("ça_va?",1)
    216217    ret=write_to_motor(chr(231) + "a_va?", 1)
  • CLIO/control/motor_function.py

    r627 r628  
    3232    motor_get(2,"actual_position")
    3333    lim=motor_get(2,"limit")
    34     print lim
     34    print(lim)
    3535    return lim
    3636
     
    3838def table_to_mm_from_back(pos):
    3939    motor_enable(2)
    40     print "BACK_LIMIT ", BACK_LIMIT
     40    print("BACK_LIMIT ", BACK_LIMIT)
    4141    target_pos=(pos*STEPS_TO_MM)+BACK_LIMIT
    42     print target_pos
     42    print(target_pos)
    4343    move_motor_absolute(2,2000,target_pos)
    4444    motor_wait_for_ready(2)
     
    7272    get_out_of_limit()
    7373    BACK_LIMIT=motor_get(2,"actual_position")
    74     print "BACK_LIMIT ", BACK_LIMIT
     74    print("BACK_LIMIT ", BACK_LIMIT)
    7575    table_to_mm_from_back(1)
    7676
     
    8080    for icam in range(3):
    8181        if (CAMERAS_ON[icam]==1):
    82             print icam,CAMERAS_ON[icam],CAMERAS_PORT[icam]
     82            print(icam,CAMERAS_ON[icam],CAMERAS_PORT[icam])
    8383            image_name_and_path=data_dir+"camera_image_"+start_time_str+"_"+str(icam)+".png"
    8484            camera_image_url="http://"+CAMERAS_PORT[icam]+"/jpg/image.jpg"
    85             print "camera_image_url ",camera_image_url," ",image_name_and_path
     85            print("camera_image_url ",camera_image_url," ",image_name_and_path)
    8686            urllib.urlretrieve(camera_image_url,image_name_and_path)
    8787            if (show==1):
  • CLIO/control/scope_function.py

    r627 r628  
    55import time
    66import urllib
     7import sys
    78from datetime import datetime
    89from clio_constants import *
    910from writeclient import writeclient
    1011
    11 scope_image_url="http://"+SCOPE_IP+"/crt_print.png"
     12scope1_image_url="http://"+SCOPE1_IP+"/crt_print.png"
     13scope1_ch1_url="http://"+SCOPE1_IP+"/scpi_response.txt?lang=en&request=CHAN1:STAT ON"
     14scope1_ch2_url="http://"+SCOPE1_IP+"/scpi_response.txt?lang=en&request=CHAN2:STAT ON"
     15scope1_ch3_url="http://"+SCOPE1_IP+"/scpi_response.txt?lang=en&request=CHAN3:STAT ON"
     16scope1_ch4_url="http://"+SCOPE1_IP+"/scpi_response.txt?lang=en&request=CHAN4:STAT ON"
     17scope1_data_url="http://"+SCOPE1_IP+"/chaninfo.txt?lang=en&trace=0&source=0&format=1&points=0&button=save"
     18
     19scope2_image_url="http://"+SCOPE2_IP+"/Image.png"
     20scope2_data_ch1_url="http://"+SCOPE2_IP+"/data/comm.html?command=select%3Acontrol+ch1&command=save%3Awaveform%3Afileformat%20spreadsheet&wfmsend=GET"
     21scope2_data_ch2_url="http://"+SCOPE2_IP+"/data/comm.html?command=select%3Acontrol+ch2&command=save%3Awaveform%3Afileformat%20spreadsheet&wfmsend=GET"
     22scope2_data_ch3_url="http://"+SCOPE2_IP+"/data/comm.html?command=select%3Acontrol+ch3&command=save%3Awaveform%3Afileformat%20spreadsheet&wfmsend=GET"
     23scope2_data_ch4_url="http://"+SCOPE2_IP+"/data/comm.html?command=select%3Acontrol+ch4&command=save%3Awaveform%3Afileformat%20spreadsheet&wfmsend=GET"
     24
    1225
    1326
    1427def read_images_from_scope(nimages):
     28    print(" Acquiring images...")
     29    for iimage in range(nimages):
     30        read_images_from_scope1(1)
     31        read_images_from_scope2(1)
     32
     33
     34def read_images_from_scope1(nimages):
    1535    iimage=1
    1636    subproc=0
    1737    start_time_str=datetime.now().strftime("%Y%m%d_%H%M%S")
    1838    for iimage in range(nimages):
    19         image_name_and_path=data_dir+"scope_image_"+start_time_str+"_"+str(iimage)+".png"
    20         urllib.urlretrieve(scope_image_url,image_name_and_path)
    21         if (subproc !=0):
    22             subproc.kill()
    23         subproc = subprocess.Popen(["display",image_name_and_path])
    24         time.sleep(2)
    25     time.sleep(10)
    26     if (subproc !=0):
    27         subproc.kill()
     39        image_name_and_path=data_dir+"scope1_image_"+start_time_str+"_"+str(iimage)+".png"
     40        print(' image:' , image_name_and_path)
     41        urllib.urlretrieve(scope1_image_url,image_name_and_path)
     42       
     43        data_name_ch1_and_path=data_dir+"scope1_data_ch1_"+start_time_str+"_"+str(iimage)+".csv"
     44        print(scope1_ch1_url)
     45        txt=urllib.urlopen(scope1_ch1_url)
     46        print(scope1_data_url)
     47        urllib.urlretrieve(scope1_data_url,data_name_ch1_and_path)
     48
     49        data_name_ch2_and_path=data_dir+"scope1_data_ch2_"+start_time_str+"_"+str(iimage)+".csv"
     50        print(scope1_ch2_url)
     51        txt=urllib.urlopen(scope1_ch2_url)
     52        print(scope1_data_url)
     53        urllib.urlretrieve(scope1_data_url,data_name_ch2_and_path)
     54
     55        data_name_ch3_and_path=data_dir+"scope1_data_ch3_"+start_time_str+"_"+str(iimage)+".csv"
     56        print(scope1_ch3_url)
     57        txt=urllib.urlopen(scope1_ch3_url)
     58        print(scope1_data_url)
     59        urllib.urlretrieve(scope1_data_url,data_name_ch3_and_path)
     60
     61        data_name_ch4_and_path=data_dir+"scope1_data_ch4_"+start_time_str+"_"+str(iimage)+".csv"
     62        print(scope1_ch4_url)
     63        txt=urllib.urlopen(scope1_ch4_url)
     64        print(scope1_data_url)
     65        urllib.urlretrieve(scope1_data_url,data_name_ch4_and_path)
     66#        if (subproc !=0):
     67#            subproc.kill()
     68        #subproc = subprocess.Popen(["display",image_name_and_path])
     69        time.sleep(5)
     70    time.sleep(1)
     71#    if (subproc !=0):
     72#        subproc.kill()
    2873
    2974
    30 def scpi_command(command):
    31     reply=writeclient(SCOPE_IP,5025,command+chr(10),1)
    32     print "SCPI: ",command," => ", reply
     75def read_images_from_scope2(nimages):
     76    iimage=1
     77    subproc=0
     78    start_time_str=datetime.now().strftime("%Y%m%d_%H%M%S")
     79    for iimage in range(nimages):
     80        image_name_and_path=data_dir+"scope2_image_"+start_time_str+"_"+str(iimage)+".png"
     81        print(' image:' , image_name_and_path)
     82        try:
     83            urllib.urlretrieve(scope2_image_url,image_name_and_path)
     84        except:
     85            print(" Error: ",sys.exc_info()[0])
     86#        if (subproc !=0):
     87#            subproc.kill()
     88        #subproc = subprocess.Popen(["display",image_name_and_path])
     89        time.sleep(2)
     90        try:
     91            data_name_ch1_and_path=data_dir+"scope2_data_ch1_"+start_time_str+"_"+str(iimage)+".csv"
     92            print(scope2_data_ch1_url)
     93            urllib.urlretrieve(scope2_data_ch1_url,data_name_ch1_and_path)
     94        except:
     95            print(" Error: ",sys.exc_info()[0])
     96        time.sleep(2)
     97
     98        try:
     99            data_name_ch2_and_path=data_dir+"scope2_data_ch2_"+start_time_str+"_"+str(iimage)+".csv"
     100            print(scope2_data_ch2_url)
     101            urllib.urlretrieve(scope2_data_ch1_url,data_name_ch2_and_path)
     102        except:
     103            print(" Error: ",sys.exc_info()[0])
     104        time.sleep(2)
     105       
     106        try:
     107            data_name_ch3_and_path=data_dir+"scope2_data_ch3_"+start_time_str+"_"+str(iimage)+".csv"
     108            print(scope2_data_ch3_url)           
     109            urllib.urlretrieve(scope2_data_ch3_url,data_name_ch3_and_path)
     110        except:
     111            print(" Error: ",sys.exc_info()[0])
     112        time.sleep(2)
     113       
     114        try:
     115            data_name_ch4_and_path=data_dir+"scope2_data_ch4_"+start_time_str+"_"+str(iimage)+".csv"
     116            print(scope2_data_ch4_url)           
     117            urllib.urlretrieve(scope2_data_ch4_url,data_name_ch4_and_path)
     118        except:
     119            print(" Error: ",sys.exc_info()[0])
     120        time.sleep(2)
     121
     122    time.sleep(1)
     123#    if (subproc !=0):
     124#        subproc.kill()
     125
     126
     127def scpi_command1(command):
     128    reply=writeclient(SCOPE1_IP,5025,command+chr(10),1)
     129    print("SCPI: ",command," => ", reply)
     130
     131def scpi_command2(command):
     132    reply=writeclient(SCOPE2_IP,5025,command+chr(10),1)
     133    print("SCPI: ",command," => ", reply)
  • CLIO/control/test.py

    r627 r628  
    11__author__ = 'delerue'
    22
    3 
     3import sys
    44from clio_constants import *
    55from motor_function import *
    66from scope_function import *
    77
    8 
    9 controller_hello()
    10 
    11 motor_reset(1)
    12 motor_enable(1)
    13 motor_move_absolute(1,20,000)
    14 motor_wait_for_ready(1)
    15 read_images_from_scope(5)
    16 
    17 motor_move_absolute(1,20,-50)
    18 motor_wait_for_ready(1)
    19 read_images_from_scope(5)
    20 
    21 motor_move_absolute(1,20,000)
    22 motor_wait_for_ready(1)
    23 read_images_from_scope(5)
    24 
    25 motor_disable(1)
    26 
    27 read_images_from_scope(5)
     8read_images_from_scope(2)
    289
    2910
    30 scpi_command("*IDN?")
    31 scpi_command("TIMEbase:SCALE?")
     11#motor_set(1,' velocity', 5000)
     12#motor_wait_for_ready(1)
     13#read_images_from_scope(5)
     14
     15#motor_move_absolute(1,20,-50)
     16#read_images_from_scope(5)
     17
     18#motor_move_absolute(1,20,000)
     19#motor_wait_for_ready(1)
     20#read_images_from_scope(5)
    3221
    3322
    34 #motor_disable(1)
    35 #tranlation_in_mm(-1)
    36 
    37 #motor_reset(1)
    38 #motor_enable(1)
    39 #motor_move_relative(1,2000,50000)
    40 #motor_wait_for_ready(1)
    41 #motor_move_absolute(1,20,000)
    42 #motor_wait_for_ready(1)
    43 #motor_move_absolute(1,20,500)
    44 #motor_wait_for_ready(1)
    45 #motor_disable(1)
    46 
    47 #get_out_of_limit()
    48 
    49 get_camera_images(show=1)
    50 
    51 #table_to_mm_from_back(1)
    52 #grating_big_p05()
    53 #time.sleep(20)
    54 #grating_big_blank()
    55 #time.sleep(20)
    56 #grating_small_p1()
    57 #time.sleep(20)
    58 #grating_small_blank()
    59 #time.sleep(20)
    60 #grating_small_p1()
    61 
    62 
    63 #read_image("/Users/delerue/Downloads/test.png")
    64 #read_images_from_scope(3)
    65 
    66 
    67 #read_encoder()
    68 #init_encoder_ref_pos()
    69 #check_encoder_constistency()
    70 #monitor_encoder_consistency()
     23#read_images_from_scope(1)
    7124
    7225
    7326#scpi_command("*IDN?")
     27#scpi_command("TIMEbase:SCALE 1e-6")
    7428#scpi_command("TIMEbase:SCALE?")
    7529
    76 #writeclient('192.168.0.21',80,'GET /'+chr(10),1)
    77 #writeclient('192.168.0.22',5025,'*IDN?'+chr(10),1)
    78 #writeclient(SCOPE_IP,5025,'*IDN?'+chr(10),1)
  • CLIO/control/writeclient.py

    r627 r628  
    1212    s.connect((HOST, PORT))
    1313    if (verbose==1):
    14         print 'Sending message ', msg, ' to host ', HOST, ' on port ', PORT
     14        print('Sending message ', msg, ' to host ', HOST, ' on port ', PORT)
    1515    if (datedlog!=''):
    1616        date_str=datetime.now().strftime("_%Y%m%d")
     
    2929        f.close()
    3030    if (verbose==1):
    31         print 'Received', repr(data)
     31        print('Received', repr(data))
    3232    return data
    3333
Note: See TracChangeset for help on using the changeset viewer.