Changeset 13812 for fact


Ignore:
Timestamp:
05/22/12 10:09:31 (13 years ago)
Author:
neise
Message:
Evolving
Location:
fact/tools/PyDimCtrl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/PyDimCtrl/factdimserver.py

    r13809 r13812  
    2929        self.reg_msg_cb()
    3030        self.user_func = None
     31        self.__delay_between_cmds = 1.0
     32        seld.__delay_between_services = 1.0
     33        self.__last_cmd_send = -1*float('inf')
     34        self.__last_service_got = -1*float('inf')
    3135
    3236    def _cmd(self, cmdstr, *args):
     
    4246            desc = 'I'
    4347            args=(1,)
     48        while not time.time() - self.__last_cmd_send > self.__delay_between_cmds:
     49            time.sleep(0.5)
     50        self.__last_cmd_send = time.time()
    4451        pydim.dic_sync_cmnd_service(cmdstr, args, desc, timeout=None)
     52       
    4553
    4654
     
    5058        full_srv_name = self.name+'/'+service.upper()
    5159        desc = services[self.name][full_srv_name][0]
     60
     61        while not time.time() - self.__last_service_got > self.__delay_between_services:
     62            time.sleep(0.5)
     63        self.__last_service_got = time.time()
     64
    5265        return pydim.dic_sync_info_service(full_srv_name, desc)
    5366
  • fact/tools/PyDimCtrl/pyfactctrl.py

    r13810 r13812  
    11#!/usr/bin/python -tti
    22from factdimserver import *
     3
     4# List of Wobble Positions
     5source_list = { '1ES 1218+304' : [( 0.6, -5), (0.6, 175)] ,\
     6    'Crab' : [(0.6, 50), (0.6, -130)], \
     7    'Mrk 421' : [(0.6, 90),(0.6, -90)] \
     8    'Mrk 501' : [(0.6, 90),(0.6, -90)] }
     9
     10def TakeFullSet( source = 'Crab', verbose = True):
     11    msg = MSG( verbose )
     12    drs_calib_done = False      # Drs Calib is only done in the 1st wobble pos
     13   
     14    if not source in source_list:
     15        raise ValueError('source not in source_list')
     16        msg("Possible sources are:")
     17        for src in source_list.keys():
     18            msg(src)
     19        return False
     20   
     21   
     22    # set is a list of wobble positions, stored as 2-tuple
     23    for set in source_list(source):
     24        # wobble is a 2-tuple: (Shift, Angle)
     25        for wobble in set:
     26            TrackSource( source, wobble[0] , wobble[1] , CalmDownTime=45)
     27
     28            if not drs_calib_done:
     29                TakeDrsAmplitudeCalibration( roi=1024 )
     30                TakeDrsTimeCalibration( mode='upshifted' )
     31                AddDrsAmplitudeCalibration( roi=300 )
     32                drs_calib_done = True
     33
     34            VoltageOn( mode='current' )
     35            for i in range(4):
     36                msg("Taking Data Run "+str(i+1)+" of 4")
     37                TakeDataRun()
     38            VoltageOff()
     39
     40    StopTracking()
     41    return True
     42
     43#=========== TRACKING =========================================================
     44def TrackSource( Shift=0.6, Angle=50, SrcName='Crab', CalmDownTime = None, verbose=True):
     45    drive = drive_control
     46    msg = MSG( verbose )
     47    SrcName += '\0'
     48
     49    if not StopTracking( timeout = 5, verbose = False ):
     50        msg.fail('Cannot start Tracking, because I cannot Stop the Drive')
     51        return False
     52   
     53    drive.track_source( Shift, Angle, SrcName)
     54
     55    if CalmDownTime != None:
     56        if not WaitToCalmDown( CalmDownTime, verbose = True):
     57            msg.fail("a problem in WaitToCalmDown(). drive state: "+drive.sts)
     58            return False:
     59   
     60    msg.ok('Tracking Source '+SrcName + ' Angle:'+str(Angle)+' Shift:'+str(Shift))
     61    return True
     62
     63def WaitToCalmDown( CalmDownTime = 45, time_until_moving = 10, time_until_tracking = 40, verbose = True):
     64    """ before calling this function, one should call TrackSource()
     65        this function waits until Drive is in state 'Tracking'
     66        and then sleeps *CalmDownTime* seconds in order to give
     67        the Drive time to calm down.
     68       
     69    """
     70    drive = drive_control
     71    msg = MSG(verbose)
     72
     73    starttime = time.time()
     74    while not drive.stn == 6: #Moving
     75        if time.time() - starttime > time_until_moving:
     76            msg.fail("DRIVE not in Moving after "+str(time_until_moving))
     77            return False
     78        time.sleep(0.5)
     79    msg.ok("Drive is Moving, waiting for Tracking")
     80       
     81    starttime = time.time()
     82    while not drive.stn == 7: #Tracking
     83        if time.time() - starttime > time_until_tracking:
     84            msg.fail("DRIVE not in Tracking after "+str(time_until_tracking))
     85            return False
     86        time.sleep(0.5)
     87    msg.ok("Drive is Tracking, waiting to calm down...")
     88   
     89    time.sleep(CalmDownTime)
     90    msg.ok("Drive hopefully has calmed down")
     91    return True
     92
     93def StopTracking( timeout = 3, verbose = True ):
     94    msg = MSG(verbose)
     95    drive = drive_control
     96    starttime = time.time()
     97    while not drive.stn == 5:
     98        if time.time() - starttime > timeout:
     99            msg.fail('Did not get DRIVE into Armed state within '+str(timeout)+' seconds')
     100            return False
     101
     102        if drive.stn < 5:
     103            msg.fail('DRIVE in state'+drive.sts+" I don't know how to STOP")
     104        if drive.stn >= 256:
     105            msg.fail('DRIVE in state'+drive.sts+" I don't know how to STOP")
     106
     107        if drive.stn in [6,7]:
     108            drive.stop()
     109            time.sleep(0.5)
     110
     111    msg.ok('DRIVE Stopped: current state:'+drive.sts)
     112    return True
     113
     114#=========== DRS CALIBRATION ==================================================
     115def TakeDrsAmplitudeCalibration( roi = None, verbose = True):
     116    """ Takes DRS Amplitude Calibration
     117        *roy* integer: 300, 1024 or
     118        *roy* string : 'both'
     119        in case of both, the roi=300 calibration is done last.
     120       
     121        after each complete AmpliteCalibration a 4th pedestal run of the same
     122        roi is taken, for crosschecking.
     123        """
     124    msg = MSG( verbose )
     125    bias = bias_control
     126    fad = fad_control
     127    if not roi in [300,1024,'both']:
     128        raise ValueError("roi must be 300,1024 or the string 'both'")
     129
     130
     131    bias.set_zero_voltage()
     132    if not bias.wait(7, 10):
     133        msg.warn("bias has not switched of after 10sec")
     134        return False
     135
     136    fad.start_drs_calibration()
     137    Take( -1, 1000, 'drs-pedestal')
     138    Take( -1, 1000, 'drs-gain')
     139    if roi == 300:
     140        Take( -1, 1000, 'pedestal')
     141        fad.set_file_format(2)
     142        Take( -1, 1000, 'pedestal')
     143    elif roi == 1024:
     144        Take( -1, 1000, 'drs-pedestal')
     145        fad.set_file_format(2)
     146        Take( -1, 1000, 'drs-pedestal')
     147    elif roi == 'both':
     148        Take( -1, 1000, 'drs-pedestal')
     149        fad.set_file_format(2)
     150        Take( -1, 1000, 'drs-pedestal')
     151        fad.reset_secondary_drs_baseline()
     152        Take( -1, 1000, 'pedestal')
     153        fad.set_file_format(2)
     154        Take( -1, 1000, 'pedestal')
     155
     156
     157def TakeDrsTimeCalibration( mode = 'upshifted', verbose = True):
     158    """ Takes DRS Time Calibration
     159        *mode* can be 'upshifted', 'old' or 'both'
     160    """
     161    msg = MSG( verbose )
     162    bias = bias_control
     163    fad = fad_control
     164    if not mode in ['upshifted', 'old', 'both']:
     165        raise ValueError("mode must be: 'upshifted','old' or 'both'")
     166
     167    bias.set_zero_voltage()
     168    if not bias.wait(7, 10):
     169        msg.warn("bias has not switched of after 10sec")
     170        return False
     171
     172    fad.set_file_format(2)
     173    if mode == 'old':
     174        Take(-1, 1000, 'drs-time')
     175    if mode == 'upshifted':
     176        Take(-1, 1000, 'drs-time-upshifted')
     177    if mode == 'both':
     178        Take(-1, 1000, 'drs-time')
     179        Take(-1, 1000, 'drs-time-upshifted')
     180
     181
     182
     183def AddDrsAmplitudeCalibration( roi = None, verbose = True):
     184    """ Adds a DRS Amplitude Calibration,
     185        do not call, in case you did not *Take* one before
     186        *roy* integer: 300, 1024
     187       
     188        after each complete AmpliteCalibration a 4th pedestal run of the same
     189        roi is taken, for crosschecking.
     190        """
     191    msg = MSG( verbose )
     192    bias = bias_control
     193    fad = fad_control
     194    if not roi in [300,1024]:
     195        raise ValueError("roi must be 300,1024")
     196
     197    if not bias.stn == 'VoltageOff':
     198        msg.fail('a DRS amplitude calibration should not be taken with Voltage On')
     199        return False
     200
     201    fad.reset_secondary_drs_baseline()
     202    if roi == 300
     203        Take( -1, 1000, 'pedestal')
     204        fad.set_file_format(2)
     205        Take( -1, 1000, 'pedestal')
     206    elif roi == 1024:
     207        Take( -1, 1000, 'drs-pedestal')
     208        fad.set_file_format(2)
     209        Take( -1, 1000, 'drs-pedestal')
     210       
     211    return True
     212
     213
     214#============ BIAS VOLTAGE ====================================================
     215def VoltageOn( mode = None, Watchdog = None, verbose = True):
     216    """ High Level Method for switching on the bias Voltage
     217        can be called, in whatever state the bias and the feedback might be.
     218        In case the voltage is on and the feedback is already in the mode
     219        requested, nothing happens.
     220        In all other cases, the method will perform the needed steps to switch
     221        on the bias voltage, the way the user requested
     222    """
     223    msg = MSG( verbose )
     224    bias = bias_control
     225    fb = feedback
     226
     227    if not mode in ['temperature', 'current', 'feedback']:
     228        raise ValueError("mode must be 'temperature', 'current' or 'feedback'")
     229
     230   
     231   
     232    bias.set_global_dac(1)
     233    if not bias.wait(9, 10):
     234        msg.warn("bias not in Voltage ON after 10sec")
     235        return False
     236    if not bias.wait(5, 10):
     237        msg.warn("bias not Ramping after 10sec")
     238        return False
     239    if not bias.wait(9, 30):
     240        msg.warn("bias not fully ramped up after 30sec")
     241        return False
     242
     243    msg("waiting 45sec...")   
     244    time.sleep(45)
     245    return True
     246
     247
    3248
    4249def IsReadyForDataTaking( verbose = True ):
     
    41286
    42287    return ok
    43 
    44 def StopTracking( verbose = True ):
    45     msg = MSG()
    46     msg.output = verbose
    47 
    48     # defining a shortcut
    49     drive = drive_control
    50 
    51     drive.stop()
    52     if not drive.wait(5, 10):
    53         msg.warn("drive did not reach state 5 after 10 seconds")
    54         msg.warn( drive.state()[0].rstrip('\x00') )
    55         return False
    56 
    57     return True
    58288
    59289def TakeDataRun( verbose = True ):
     
    73303        msg.warn("FAD did not return to Connected, after 330 seconds")
    74304        return False
    75     return True
    76 
    77 def TrackSource( Shift=0.6, Angle=50, SrcName='Crab', verbose=True):
    78     drive = drive_control
    79     msg = MSG( verbose )
    80     SrcName += '\0'
    81 
    82     timeout  = 3
    83     starttime = time.time()
    84     while not drive.stn == 5:
    85         if time.time() - starttime > timeout:
    86             msg.fail('Did not get DRIVE into Armed state')
    87             return False
    88 
    89         if drive.stn < 5:
    90             msg.fail('DRIVE in state'+drive.sts+" I don't what to do.")
    91         if drive.stn >= 256:
    92             msg.fail('DRIVE in state'+drive.sts+" I don't what to do.")
    93 
    94         if drive.stn in [6,7]:
    95             drive.stop()
    96             time.sleep(0.5)
    97 
    98     drive.track_source( Shift, Angle, SrcName)
    99     return True
    100 
    101 def WaitForTracking( CalmDownTime = 30, verbose = True):
    102     drive = drive_control
    103     msg = MSG(verbose)
    104 
    105     starttime = time.time()
    106     time_out = 10
    107 
    108     while not drive.stn == 7: #Tracking
    109         if time.time() - starttime > time_out:
    110             msg.fail("DRIVE not in Tracking after Timeout")
    111             return False
    112 
    113     msg.ok("Drive is Tracking, waiting to calm down...")
    114     time.sleep(CalmDownTime)
    115305    return True
    116306
     
    178368    return True
    179369
    180 def Take1218( verbose = True):
    181 
    182     TrackSource( Shift=0.6, Angle=-5, SrcName='1ES 1218+304')
    183     WaitForTracking( CalmDownTime = 45, verbose = True)
    184 
    185     TakeDrsAmplitudeCalibration( roi=1024 )
    186     TakeDrsTimeCalibration( mode='upshifted' )
    187     TakeDrsAmplitudeCalibration( roi=300 )
    188 
    189     VoltageOn( mode='current' )
    190     for i in range(4):
    191         msg("Taking Data Run "+str(i+1)+" of 4")
    192         TakeDataRun()
    193     VoltageOff()
    194 
    195     TrackSource( Shift=0.6, Angle=175, SrcName='1ES 1218+304')
    196     WaitForTracking( CalmDownTime = 45, verbose = True)
    197 
    198     VoltageOn( mode='current' )
    199     for i in range(4):
    200         msg("Taking Data Run "+str(i+1)+" of 4")
    201         TakeDataRun()
    202     VoltageOff()
    203 
    204     drive_control.stop()
    205370
    206371def BlinkenLights(verbose = True):
     
    473638
    474639#==============================================================================
    475 def TakeDrsAmplitudeCalibration( roi = None, verbose = True):
    476     """ Takes DRS Amplitude Calibration
    477         *roy* integer: 300, 1024 or
    478         *roy* string : 'both'
    479         in case of both, the roi=300 calibration is done last.
    480        
    481         after each complete AmpliteCalibration a 4th pedestal run of the same
    482         roi is taken, for crosschecking.
    483         """
    484     msg = MSG( verbose )
    485     bias = bias_control
    486     fad = fad_control
    487     if not roi in [300,1024,'both']:
    488         raise ValueError("roi must be 300,1024 or the string 'both'")
    489 
    490 
    491     bias.set_zero_voltage()
    492     if not bias.wait(7, 10):
    493         msg.warn("bias has not switched of after 10sec")
    494         return False
    495 
    496     fad.start_drs_calibration()
    497     Take( -1, 1000, 'drs-pedestal')
    498     Take( -1, 1000, 'drs-gain')
    499     if roi == 300:
    500         Take( -1, 1000, 'pedestal')
    501         fad.set_file_format(2)
    502         Take( -1, 1000, 'pedestal')
    503     elif roi == 1024:
    504         Take( -1, 1000, 'drs-pedestal')
    505         fad.set_file_format(2)
    506         Take( -1, 1000, 'drs-pedestal')
    507     elif roi == 'both':
    508         Take( -1, 1000, 'drs-pedestal')
    509         fad.set_file_format(2)
    510         Take( -1, 1000, 'drs-pedestal')
    511         fad.reset_secondary_drs_baseline()
    512         Take( -1, 1000, 'pedestal')
    513         fad.set_file_format(2)
    514         Take( -1, 1000, 'pedestal')
    515 
    516 
    517 def TakeDrsTimeCalibration( mode = None, verbose = True):
    518     """ Takes DRS Time Calibration
    519         *mode* can be 'upshifted', 'old' or 'both'
    520     """
    521     msg = MSG( verbose )
    522     bias = bias_control
    523     fad = fad_control
    524     if not mode in ['upshifted', 'old', 'both']:
    525         raise ValueError("mode must be: 'upshifted','old' or 'both'")
    526 
    527     bias.set_zero_voltage()
    528     if not bias.wait(7, 10):
    529         msg.warn("bias has not switched of after 10sec")
    530         return False
    531 
    532     fad.set_file_format(2)
    533     if mode == 'old':
    534         Take(-1, 1000, 'drs-time')
    535     if mode == 'upshifted':
    536         Take(-1, 1000, 'drs-time-upshifted')
    537     if mode == 'both':
    538         Take(-1, 1000, 'drs-time')
    539         Take(-1, 1000, 'drs-time-upshifted')
    540 
    541 
    542 def VoltageOn( mode = None, Watchdog = None, verbose = True):
    543     msg = MSG( verbose )
    544     bias = bias_control
    545     fb = feedback
    546 
    547     if not mode in ['temperature', 'current', 'feedback']:
    548         raise ValueError("mode must be 'temperature', 'current' or 'feedback'")
    549    
    550    
    551     bias.set_global_dac(1)
    552     if not bias.wait(9, 10):
    553         msg.warn("bias not in Voltage ON after 10sec")
    554         return False
    555     if not bias.wait(5, 10):
    556         msg.warn("bias not Ramping after 10sec")
    557         return False
    558     if not bias.wait(9, 30):
    559         msg.warn("bias not fully ramped up after 30sec")
    560         return False
    561 
    562     msg("waiting 45sec...")   
    563     time.sleep(45)
    564     return True
    565 
    566640# standard watchdog:
    567641def std_bias_watchdog( state, verbose=True ):
Note: See TracChangeset for help on using the changeset viewer.