Changeset 17922 for trunk/FACT++/scripts


Ignore:
Timestamp:
07/22/14 13:44:52 (10 years ago)
Author:
tbretz
Message:
Added EVENT_SERVER and SQM_CONTROL; fixed a typo; close lid at startup.
Location:
trunk/FACT++/scripts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/scripts/CheckStates.js

    r16874 r17922  
    4040 *
    4141 */
    42 function checkStates(table, timeout)
     42function checkStates(table, timeout, wait)
    4343{
    4444    if (timeout===undefined)
     
    6969                    continue;
    7070
    71                 dim.log(table[i][0]+" in ["+states[i]+"] not as it ought to be ["+table[i][1]+"]");
     71                if (!wait)
     72                    dim.log(table[i][0]+" in ["+states[i]+"] not as it ought to be ["+table[i][1]+"]");
     73
    7274                rc = false;
    7375            }
    74 
    75             return rc;
     76            if (rc)
     77                return rc;
     78
     79            if (!wait)
     80                return false;
    7681        }
    7782
  • trunk/FACT++/scripts/Main.js

    r17673 r17922  
    195195
    196196// ================================================================
     197//  Interrupt data taking in case of high currents
     198// ================================================================
     199dim.onchange['FEEDBACK'] = function(state)
     200{
     201    if ((state.name=="Critical" || state.name=="OnStandby") &&
     202        (this.prev!="Critical"  && this.prev!="OnStandby"))
     203    {
     204        console.out("Feedback state changed from "+this.prev+" to "+state.name+" [Main.js]");
     205        irq = "RESCHEDULE";
     206    }
     207    this.prev=state.name;
     208}
     209
     210// ================================================================
    197211//  Code related to switching bias voltage on and off
    198212// ================================================================
     
    203217{
    204218    if (!evt.data)
     219        return;
     220
     221    if (this.ok==undefined)
    205222        return;
    206223
     
    223240    }
    224241    avg /= 320;
    225 
    226     if (this.ok==undefined)
    227         return;
    228 
    229242
    230243    this.ok = cnt<3;// || (this.last!=undefined && Math.abs(this.last-avg)<0.002);
     
    306319        ov = 1.1;
    307320
    308     if (this.ov!=ov && dim.state("FEEDBACK").name=="InProgress")
     321    if (this.ov!=ov && dim.state("FEEDBACK").name=="InProgress") // FIXME: Warning, OnStandby, Critical if (ov<this.ov)
    309322    {
    310323        dim.log("Stoping feedback.");
     
    328341
    329342        dim.send("FEEDBACK/START", ov);
     343
     344        // FIXME: We could miss "InProgress" if it immediately changes to "Warning"
     345        //        Maybe a dim.timeout state>8 ?
    330346        dim.wait("FEEDBACK", "InProgress", 45000);
    331347
     
    365381// ================================================================
    366382
    367 function Shutdown()
     383function Shutdown(singlepe)
    368384{
    369385    dim.log("Starting shutdown.");
     
    419435    }*/
    420436
    421     dim.log("Taking single-pe run.");
    422 
    423     // The voltage must be on
    424     service_feedback.voltageOn();
    425     service_feedback.waitForVoltageOn();
    426 
    427     // Before we can switch to 3000 we have to make the right DRS calibration
    428     dim.log("Taking single p.e. run.");
    429     while (!irq && !takeRun("single-pe", 10000));
     437    if (singlepe)
     438    {
     439        dim.log("Taking single-pe run.");
     440
     441        // The voltage must be on
     442        service_feedback.voltageOn();
     443        service_feedback.waitForVoltageOn();
     444
     445        // Before we can switch to 3000 we have to make the right DRS calibration
     446        dim.log("Taking single p.e. run.");
     447        while (!irq && !takeRun("single-pe", 10000));
     448    }
    430449
    431450    // It is unclear what comes next, so we better switch off the voltage
     
    528547         "FTM_CONTROL/TRIGGER_RATES",
    529548         "GPS_CONTROL/NEMA",
     549         "SQM_CONTROL/DATA",
    530550         "LID_CONTROL/DATA",
    531551         "MAGIC_LIDAR/DATA",
     
    554574
    555575    var list = obj.data.split('\n').map(map);
    556 
     576//     [A
    557577    function check(name)
    558578    {
     
    613633//console.out("Feedback init: start.");
    614634service_feedback.get(5000);
    615 
    616 //v8.timeout(3000, function() { var n = dim.state("FEEDBACK").name; if (n=="CurrentCtrlIdle" || n=="CurrentControl") return true; });
    617635
    618636// ----------------------------------------------------------------
     
    708726
    709727    if (irq.toUpperCase()=="RESCHEDULE")
    710         return true;
     728    {
     729        irq = undefined;
     730        return false;
     731    }
    711732
    712733    if (irq.toUpperCase()=="OFF")
     
    716737        return true;
    717738    }
     739
     740    /*
     741    if (irq.toUpperCase()=="STOP")
     742    {
     743        dim.send("FAD_CONTROL/CLOSE_OPEN_FILES");
     744        dim.send("MCP/STOP");
     745        return true;
     746    }*/
    718747
    719748    if (irq.toUpperCase()=="SHUTDOWN")
     
    817846    }
    818847
    819     // Check if sun is still up... only DATA and RATESCAN must be suppressed
     848    // Check if sun is still up... only DATA and */
    820849    if ((obs[sub].task=="DATA" || obs[sub].task=="RATESCAN") && sun.isUp)
    821850    {
     
    836865    // otherwise it is difficult to allow e.g. the STARTUP at the beginning of the night
    837866    var power_states = sun.isUp || !system_on ? [ "DriveOff", "SystemOn" ] : [ "SystemOn" ];
    838     var drive_states = sun.isUp || !system_on ?   undefined    : [ "Armed", "Tracking", "OnTrack" ];
     867    var drive_states = sun.isUp || !system_on ? undefined : [ "Armed", "Tracking", "OnTrack" ];
    839868
    840869    // A scheduled task was found, lets check if all servers are
     
    858887         [ "AGILENT_CONTROL_80V", [ "VoltageOn"                ] ],
    859888         [ "BIAS_CONTROL",        [ "VoltageOff", "VoltageOn", "Ramping" ] ],
    860          [ "FEEDBACK",            [ "Calibrated", "InProgress" ] ],
     889         [ "FEEDBACK",            [ "Calibrated", "InProgress", "OnStandby", "Warning", "Critical" ] ],
    861890         [ "LID_CONTROL",         [ "Open", "Closed"           ] ],
    862891         [ "DRIVE_CONTROL",       drive_states/*[ "Armed", "Tracking", "OnTrack" ]*/ ],
     
    866895         [ "RATE_CONTROL",        [ "Connected", "GlobalThresholdSet", "InProgress"  ] ],
    867896         [ "GPS_CONTROL",         [ "Locked"  ] ],
     897         [ "SQM_CONTROL",         [ "Valid"  ] ],
    868898        ];
    869899
     
    872902    {
    873903        throw new Error("Something unexpected has happened. One of the servers "+
    874                         "is in a state in which it should not be. Please,"+
     904                        "is in a state in which it should not be. Please,"+ 
    875905                        "try to find out what happened...");
    876906    }
    877907
    878     datalogger_subscriptions.check();
     908    datalogger_subscriptions.check();                                         
     909                                                                               
     910    // If this is an observation which needs the voltage to be swicthed on
     911    // skip that if the voltage is not stable                                   
     912    /*
     913    if (obs[sub].task=="DATA" || obs[sub].task=="RATESCAN")
     914    {
     915        var state = dim.state("FEEDBACK").name;
     916        if (state=="Warning" || state=="Critical" || state=="OnStandby")
     917        {
     918            v8.sleep(1000);
     919            continue;
     920        }
     921    }*/
     922
    879923
    880924    // Check if obs.task is one of the one-time-tasks
     
    909953
    910954    case "SHUTDOWN":
    911         Shutdown();
     955        Shutdown(true);
    912956        system_on = false;
    913957
     
    10371081        service_feedback.waitForVoltageOn();
    10381082
    1039         var tm2 = new Date();
    1040 
    1041         dim.log("Starting ratescan.");
    1042 
    1043         // Start rate scan
    1044         dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
    1045 
    1046         // Lets wait if the ratescan really starts... this might take a few
    1047         // seconds because RATE_SCAN configures the ftm and is waiting for
    1048         // it to be configured.
    1049         dim.wait("RATE_SCAN", "InProgress", 10000);
    1050         dim.wait("RATE_SCAN", "Connected", 2700000);
    1051 
    1052         // this line is actually some kind of hack.
    1053         // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
    1054         // So I decided to put this line here as a kind of patchwork....
    1055         //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 6);
    1056 
    1057         dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
     1083        if (!irq)
     1084        {
     1085            var tm2 = new Date();
     1086
     1087            dim.log("Starting ratescan.");
     1088
     1089            // Start rate scan
     1090            dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
     1091
     1092            // Lets wait if the ratescan really starts... this might take a few
     1093            // seconds because RATE_SCAN configures the ftm and is waiting for
     1094            // it to be configured.
     1095            dim.wait("RATE_SCAN", "InProgress", 10000);
     1096            dim.wait("RATE_SCAN", "Connected", 2700000);
     1097
     1098            // Here one could implement a watchdog for the feedback as well, but what is the difference
     1099            // whether finally one has to find out if the feedback was in the correct state
     1100            // or the ratescan was interrupted?
     1101
     1102            // this line is actually some kind of hack.
     1103            // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
     1104            // So I decided to put this line here as a kind of patchwork....
     1105            //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 6);
     1106
     1107            dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
     1108        }
     1109
    10581110        dim.log("Task finished [RATESCAN]");
    10591111        console.out("");
     
    10721124        }
    10731125    */
     1126
    10741127        // Calculate remaining time for this observation in minutes
    10751128        var remaining = nextObs==undefined ? 0 : (nextObs.start-new Date())/60000;
     
    11341187
    11351188        if (irq)
    1136             break;
     1189            continue;
    11371190
    11381191        OpenLid();
     
    11401193        // This is now th right time to wait for th drive to be stable
    11411194        dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing
     1195
     1196        // Now check the voltage... (do not start a lot of stuff just to do nothing)
     1197        var state = dim.state("FEEDBACK").name;
     1198        if (state=="Warning" || state=="Critical" || state=="OnStandby")
     1199        {
     1200            v8.sleep(60000);
     1201            continue;
     1202        }
    11421203
    11431204        // Now we are 'OnTrack', so we can ramp to nominal voltage
     
    11471208
    11481209        // If pointing had changed, do calibration
    1149         if (point)
     1210        if (!irq && point)
    11501211        {
    11511212            dim.log("Starting calibration.");
     
    11771238        {
    11781239            var len = 300;
    1179             while (len>15)
     1240            while (!irq && len>15)
    11801241            {
    11811242                var time = new Date();
  • trunk/FACT++/scripts/Startup.js

    r17673 r17922  
    9696loop.add(handleFeedbackConnected); // Feedback needs FAD to be Connected
    9797loop.add(handleRatectrlConnected);
    98 //loop.add(handleLidClosed);
     98loop.add(handleLidClosed);
    9999loop.run();
    100100
     
    194194if ((dim.state("PWR_CONTROL").index&16)==0)
    195195{
    196     console.out("Drive cabinet not power... Switching on.");
     196    console.out("Drive cabinet not powered... Switching on.");
    197197    dim.send("PWR_CONTROL/TOGGLE_DRIVE");
    198198    v8.timeout(5000, function() { if (dim.state("PWR_CONTROL").index&16) return true; });
     
    290290// ================================================================
    291291
    292 // FIXME: Check if there is a startup shceduled, if not do not force
     292// FIXME: Check if there is a startup scheduled, if not do not force
    293293// drive to be switched on
    294294
     
    300300 [ "SMART_FACT"    ],
    301301 [ "TEMPERATURE"   ],
     302 [ "EVENT_SERVER",        [ "Running", "Standby" ] ],
    302303 [ "DATA_LOGGER",         [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
    303304 [ "FSC_CONTROL",         [ "Connected"                       ] ],
     
    312313 [ "RATE_SCAN",           [ "Connected"                       ] ],
    313314 [ "RATE_CONTROL",        [ "Connected"                       ] ],
     315 [ "DRIVE_CONTROL",       [ "Armed", "Tracking", "OnTrack", "Locked" ] ],
    314316 [ "LID_CONTROL",         [ "Open", "Closed"                  ] ],
    315  [ "DRIVE_CONTROL",       [ "Armed", "Tracking", "OnTrack", "Locked" ] ],
    316317 [ "FTM_CONTROL",         [ "Valid", "TriggerOn"              ] ],
    317318 [ "FAD_CONTROL",         [ "Connected", "WritingData"        ] ],
    318319 [ "GPS_CONTROL",         [ "Locked" ] ],
     320 [ "SQM_CONTROL",         [ "Valid" ] ],
    319321];
     322
     323
    320324
    321325if (!checkStates(table))
  • trunk/FACT++/scripts/takeRun.js

    r17352 r17922  
    173173    //}
    174174
     175    // ================================================================
     176    //  Function for Critical voltage
     177    // ================================================================
     178
     179    // INSTALL a watchdog... send FAD_CONTROL/CLOSE_OPEN_FILES
     180    // could send MCP/RESET as well but would result in a timeout
     181    var callback = dim.onchange['FEEDBACK'];
     182    dim.onchange['FEEDBACK'] = function(state)
     183    {
     184        if (callback)
     185            callback.call(this, state);
     186
     187        if ((state.name=="Critical" || state.name=="OnStandby") &&
     188            (this.last!="Critical"  && this.last!="OnStandby"))
     189        {
     190            console.out("Feedback state changed from "+this.last+" to "+state.name+" [takeRun.js]");
     191
     192            // Includes FAD_CONTROL/CLOSE_ALL_OPEN_FILES
     193            dim.send("MCP/STOP");
     194        }
     195
     196        this.last=state.name;
     197    }
     198
    175199    // Here we could check and handle fad losses
    176200
     
    241265    }
    242266
     267    // This is to check if we have missed the event. This can happen as
     268    // a race condition when the MCP/STOP is sent by the event handler
     269    // but the run was not yet fully configured.
     270    var statefb = dim.state("FEEDBACK").name;
     271    if (statefb=="Critical" || statefb=="OnStandby")
     272    {
     273        console.out("Run started by FEEDBACK in state "+statefb);
     274        dim.send("MCP/STOP"); // Includes FAD_CONTROL/CLOSE_ALL_OPEN_FILES
     275
     276        dim.onchange['FEEDBACK'] = callback;
     277
     278        return true;
     279    }
     280
    243281    dim.wait("MCP", "Idle", time>0 ? time*1250 : undefined); // run time plus 25%
     282
     283    // REMOVE watchdog
     284    dim.onchange['FEEDBACK'] = callback;
    244285
    245286    if (incomplete)
Note: See TracChangeset for help on using the changeset viewer.