Changeset 16853


Ignore:
Timestamp:
06/15/13 18:11:51 (11 years ago)
Author:
tbretz
Message:
Replaced some console.out by dim.log; take only 1min runs during twilight conditions; added some code to properly print the next observation, also when it is changed in the db; improved some output.
File:
1 edited

Legend:

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

    r16841 r16853  
    9494function doDrsCalibration(where)
    9595{
    96     console.out("  "+new Date().toUTCString()+": Starting DRS calibration ["+where+"]");
     96    dim.log("Starting DRS calibration ["+where+"]");
    9797
    9898    service_feedback.voltageOff();
     
    134134
    135135    if (irq)
    136         console.out("  "+new Date().toUTCString()+": DRS calibration interrupted [%.1fs]".$((new Date()-tm)/1000));
     136        dim.log("DRS calibration interrupted [%.1fs]".$((new Date()-tm)/1000));
    137137    else
    138         console.out("  "+new Date().toUTCString()+": DRS calibration done [%.1fs]".$((new Date()-tm)/1000));
     138        dim.log("DRS calibration done [%.1fs]".$((new Date()-tm)/1000));
    139139}
    140140
     
    161161    if (isClosed)
    162162    {
    163         console.out("  "+new Date().toUTCString()+": Opening lid");
     163        dim.log("Opening lid");
    164164        dim.send("LID_CONTROL/OPEN");
    165165    }
     
    167167
    168168    if (isClosed)
    169         console.out("  "+new Date().toUTCString()+": Lid open [%.1fs]".$((new Date()-tm)/1000));
     169        dim.log("Lid open [%.1fs]".$((new Date()-tm)/1000));
    170170}
    171171
     
    179179    if (isOpen)
    180180    {
    181         console.out("  "+new Date().toUTCString()+": Closing lid.");
     181        dim.log("Closing lid.");
    182182        dim.send("LID_CONTROL/CLOSE");
    183183    }
     
    185185
    186186    if (isOpen)
    187         console.out("  "+new Date().toUTCString()+": Lid closed [%.1fs]".$((new Date()-tm)/1000));
     187        dim.log("Lid closed [%.1fs]".$((new Date()-tm)/1000));
    188188}
    189189
     
    242242    if (isOn)
    243243    {
    244         console.out("  "+new Date().toUTCString()+": Switching voltage off.");
     244        dim.log("Switching voltage off.");
    245245
    246246        // Supress the possibility that the bias control is
     
    274274
    275275    if (isOn)
    276         console.out("  "+new Date().toUTCString()+": Voltage off.");
     276        dim.log("Voltage off.");
    277277}
    278278
     
    306306    if (isOff)
    307307    {
    308         console.out("  "+new Date().toUTCString()+": Switching voltage on.");
     308        dim.log("Switching voltage on.");
    309309        //console.out(JSON.stringify(dim.state("BIAS_CONTROL")));
    310310
     
    321321    if (isOff)
    322322    {
    323         console.out("  "+new Date().toUTCString()+": Voltage on [cnt="+this.cnt+"]");
     323        dim.log("Voltage on, feedback will start ramping [cnt="+this.cnt+"]");
    324324
    325325        this.previous = undefined;
     
    347347        return;
    348348
    349     // FIXME: timeout missing
    350     console.out("  "+new Date().toUTCString()+": Waiting for voltage to be stable.");
    351 
     349    dim.log("Waiting for voltage to be stable.");
     350
     351    // 0.022 corresponds to 1 DAC count (90V/4096)
    352352    function func()
    353353    {
    354354        if (irq ||
    355355            (this.cnt!=undefined && this.get().counter>this.cnt+10) ||
    356             (this.voltageStep && this.voltageStep<0.02))
     356            (this.voltageStep && this.voltageStep<0.022))
    357357            return true;
    358358    }
     
    363363
    364364    if (irq)
    365         console.out("  "+new Date().toUTCString()+": Waiting for stable voltage interrupted [dU=%.3fV, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000));
     365        dim.log("Waiting for stable voltage interrupted [dU=%.3fV, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000));
    366366    else
    367         console.out("  "+new Date().toUTCString()+": Voltage stable within limits [dV=%.3f, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000));
     367        dim.log("Voltage stable within limits [dV=%.3f, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000));
    368368}
    369369
     
    374374function Shutdown()
    375375{
    376     console.out("  "+new Date().toUTCString()+": Starting shutdown.");
     376    dim.log("Starting shutdown.");
     377
     378    var now1 = new Date();
    377379
    378380    service_feedback.voltageOff();
    379381    CloseLid();
     382
     383    var now2 = new Date();
     384
    380385    dim.send("DRIVE_CONTROL/PARK");
    381386
     
    401406    }
    402407
    403     var now = new Date();
    404408    v8.timeout(150000, func);
     409
     410    var now3 = new Date();
    405411
    406412    //dim.send("FEEDBACK/STOP");
     
    427433    console.out("    BIAS_CONTROL:  "+dim.state("BIAS_CONTROL").name);
    428434    console.out("");
    429     console.out("Shutdown: end ["+(new Date()-now)/1000+"s]");
     435    dim.log("Shutdown: end ["+(now2-now1)/1000+"s, "+(now3-now2)/1000+"s, "+(new Date()-now3)/1000+"s]");
     436    console.out("");
    430437
    431438    sub.close();
     
    600607
    601608    if (valid)
    602         console.out("  "+new Date().toUTCString()+": Last DRS calibration was %.1fmin ago".$(diff));
     609        dim.log("Last DRS calibration was %.1fmin ago".$(diff));
    603610    else
    604         console.out("  "+new Date().toUTCString()+": No valid DRS calibration available.");
     611        dim.log("No valid DRS calibration available.");
    605612
    606613    return valid ? diff : null;
     
    644651    var n = new Date();
    645652    if (observations.length>0 && test==-1)
    646         console.out("  "+n.toUTCString()+": First observation scheduled for "+observations[0].start.toUTCString());
     653        dim.log("First observation scheduled for "+observations[0].start.toUTCString()+" [id="+observations[0].id+"]");
    647654    if (test>=0 && test<observations.length)
    648         console.out("  "+n.toUTCString()+": First observation should start immediately.");
     655        dim.log("First observation should start immediately ["+observations[test].start.toUTCString()+", id="+observations[test].id+"]");
    649656    if (observations.length>0 && observations[0].start>n+12*3600*1000)
    650         console.out("  "+n.toUTCString()+": No observations scheduled for the next 12 hours!");
     657        dim.log("No observations scheduled for the next 12 hours!");
    651658    if (observations.length==0)
    652         console.out("  "+n.toUTCString()+": No observations scheduled!");
     659        dim.log("No observations scheduled!");
    653660}
    654661
     
    656663// Start main loop
    657664// ----------------------------------------------------------------
    658 console.out("  "+new Date().toUTCString()+": Entering main loop.");
     665dim.log("Entering main loop.");
    659666
    660667var run = -2; // getObservation never called
    661668var sub;
    662669var lastId;
     670var nextId;
    663671var sun = Sun.horizon(-12);
    664672var system_on;  // undefined
     
    686694    if (!was_up && sun.isUp)
    687695    {
    688         console.out("", "  "+new Date().toUTCString()+": Sun rise detected.... automatic shutdown initiated!");
     696        console.out("");
     697        dim.log("Sun rise detected.... automatic shutdown initiated!");
    689698        // FIXME: State check?
    690699        Shutdown();
     
    701710    {
    702711        console.out("");
    703         console.out("  "+new Date().toUTCString()+": Starting new observation [id="+obs.id+"]");
    704 
    705         //console.out("--- "+obs.id+" ---");
    706         //console.out("Current time:        "+new Date().toUTCString());
    707         //console.out("Current observation: "+obs.start.toUTCString());
    708         if (nextObs!=undefined)
    709             console.out("  "+new Date().toUTCString()+": Next observation scheduled for "+nextObs.start.toUTCString());
    710         console.out("");
     712        dim.log("Starting new observation ["+obs.start.toUTCString()+", id="+obs.id+"]");
    711713
    712714        // This is the first source, but we do not come from
     
    727729
    728730        run = 0;
    729     }
    730     lastId = obs.id;
     731        lastId = obs.id;
     732    }
     733
     734    if (nextObs && nextId!=nextObs.id)
     735    {
     736        dim.log("Next observation scheduled for "+nextObs.start.toUTCString()+" [id="+nextObs.id+"]");
     737        console.out("");
     738        nextId = nextObs.id;
     739    }
     740
     741    if (!nextObs && nextId)
     742    {
     743        dim.log("No further observation scheduled.");
     744        console.out("");
     745        nextId = undefined;
     746    }
    731747
    732748    //if (nextObs==undefined && obs[obs.length-1].task!="SHUTDOWN")
     
    758774
    759775
    760     if (obs[sub].task!="IDLE" && obs[sub].task!="DATA")
    761         console.out("  "+new Date().toUTCString()+": New task ["+obs[sub]+"]");
     776    if (obs[sub].task!="IDLE" && (obs[sub].task!="DATA" && run>0))
     777        dim.log("New task ["+obs[sub]+"]");
    762778
    763779    // FIXME: Maybe print a warning if Drive is on during day time!
     
    813829
    814830    case "STARTUP":
    815         //console.out("", "  "+new Date().toUTCString()+": New task [STARTUP]");
    816831        CloseLid();
    817832
     
    825840
    826841        // Before we can switch to 3000 we have to make the right DRS calibration
    827         console.out("  "+new Date().toUTCString()+": Taking single p.e. run.");
     842        dim.log("Taking single p.e. run.");
    828843        while (!irq && !takeRun("pedestal", 5000));
    829844
     
    831846        service_feedback.voltageOff();
    832847        system_on = true;
    833         console.out("  "+new Date().toUTCString()+": Task finished [STARTUP]", "");
     848        dim.log("Task finished [STARTUP]");
     849        console.out("");
    834850        break;
    835851
    836852    case "SHUTDOWN":
    837         //console.out("  "+new Date().toUTCString()+": New task [SHUTDOWN]", "");
    838853        Shutdown();
    839854        system_on = false;
     
    841856        // FIXME: Avoid new observations after a shutdown until
    842857        //        the next startup (set run back to -2?)
    843         console.out("  Waiting for next startup.", "");
    844858        sub++;
    845         console.out("  "+new Date().toUTCString()+": Task finished [SHUTDOWN]", "");
     859        dim.log("Task finished [SHUTDOWN]");
     860        console.out("");
     861        //console.out("  Waiting for next startup.", "");
    846862        continue;
    847863
    848864    case "DRSCALIB":
    849         //console.out("  "+new Date().toUTCString()+": New task [DRSCALIB]", "");
    850865        doDrsCalibration("drscalib");  // will switch the voltage off
    851         console.out("  "+new Date().toUTCString()+": Task finished [DRSCALIB]", "");
     866        dim.log("Task finished [DRSCALIB]");
     867        console.out("");
    852868        break;
    853869
    854870    case "SINGLEPE":
    855         //console.out("  "+new Date().toUTCString()+": New task [SINGLE-PE]", "");
    856 
    857871        // The lid must be closes
    858872        CloseLid();
     
    872886
    873887        // Before we can switch to 3000 we have to make the right DRS calibration
    874         console.out("  "+new Date().toUTCString()+": Taking single p.e. run.");
     888        dim.log("Taking single p.e. run.");
    875889        while (!irq && !takeRun("pedestal", 5000));
    876890
    877891        // It is unclear what comes next, so we better switch off the voltage
    878892        service_feedback.voltageOff();
    879         console.out("  "+new Date().toUTCString()+": Task finished [SINGLE-PE]", "");
     893        dim.log("Task finished [SINGLE-PE]");
     894        console.out("");
    880895        break;
    881896
    882897    case "RATESCAN":
    883         //console.out("  "+new Date().toUTCString()+": New task [RATESCAN]", "");
    884 
    885898        var tm1 = new Date();
    886899
     
    898911        if (obs.source != undefined)
    899912        {
    900             console.out("  "+new Date().toUTCString()+": Moving drive to '"+obs[cub].source+"'.");
     913            dim.log("Pointing telescope to '"+obs[cub].source+"'.");
    901914            dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source);
    902915        }
    903916        else
    904917        {
    905             console.out("  "+new Date().toUTCString()+": Moving drive to: ra="+obs[sub].ra+" dec="+obs[sub].dec);
     918            dim.log("Pointing telescope to ra="+obs[sub].ra+" dec="+obs[sub].dec);
    906919            dim.send("DRIVE_CONTROL/TRACK", obs[sub].ra, obs[sub].dec);
    907920        }
     
    913926        var tm2 = new Date();
    914927
    915         console.out("  "+new Date().toUTCString()+": Starting ratescan.");
     928        dim.log("Starting ratescan.");
    916929
    917930        // Start rate scan
     
    929942        //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2);
    930943
    931         console.out("  "+new Date().toUTCString()+": Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
    932         console.out("  "+new Date().toUTCString()+": Task finished [RATESCAN]", "");
     944        dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
     945        dim.log("Task finished [RATESCAN]");
     946        console.out("");
    933947        break; // case "RATESCAN"
    934948
     
    950964        // ------------------------------------------------------------
    951965
    952         console.out("  "+new Date().toUTCString()+": Run count "+run+" [remaining "+parseInt(remaining)+"min]");
     966        dim.log("Run count "+run+" [remaining "+parseInt(remaining)+"min]");
    953967
    954968        // ----- Time since last DRS Calibration [min] ------
     
    976990
    977991            //console.out("  Move telescope to '"+source+"' "+offset+" "+wobble);
    978             console.out("  "+new Date().toUTCString()+": Moving telescope to '"+obs[sub].source+"' [wobble="+wobble+"]");
     992            dim.log("Pointing telescope to '"+obs[sub].source+"' [wobble="+wobble+"]");
    979993
    980994            // This is a workaround to make sure that we really catch
     
    9981012            if (!was_up && sun.isUp)
    9991013            {
    1000                 console.out("", "  "+new Date().toUTCString()+": Sun rise detected.... automatic shutdown initiated!");
     1014                console.out("");
     1015                dim.log("Sun rise detected.... automatic shutdown initiated!");
    10011016                // FIXME: State check?
    10021017                Shutdown();
     
    10271042        if (point)
    10281043        {
    1029             console.out("  "+new Date().toUTCString()+": Starting calibration.");
     1044            dim.log("Starting calibration.");
    10301045
    10311046            // Calibration (2% of 20')
     
    10451060        // e.g. drive went to ERROR? Maybe we have to check all states again?
    10461061
    1047         var len = 300;
    1048         while (len>15)
     1062        var twilight = Sun(-16).isUp;
     1063
     1064        if (twilight)
    10491065        {
    1050             var time = new Date();
    1051             if (takeRun("data", -1, len)) // Take data (5min)
    1052                 break;
    1053 
    1054             len -= parseInt((new Date()-time)/1000);
     1066            for (int i=0; i<5 && !irq; i++)
     1067                takeRun("data", -1, 60); // Take data (1min)
     1068        }
     1069        else
     1070        {
     1071            var len = 300;
     1072            while (len>15)
     1073            {
     1074                var time = new Date();
     1075                if (takeRun("data", -1, len)) // Take data (5min)
     1076                    break;
     1077
     1078                len -= parseInt((new Date()-time)/1000);
     1079            }
    10551080        }
    10561081
     
    10621087
    10631088    if (nextObs!=undefined && sub==obs.length-1)
    1064         console.out("  "+new Date().toUTCString()+": Next observation will start at "+nextObs.start.toUTCString(),"");
     1089    {
     1090        dim.log("Next observation will start at "+nextObs.start.toUTCString()+" [id="+nextObs.id+"]");
     1091        console.out("");
     1092    }
    10651093
    10661094    sub++;
     
    10691097sub_drsruns.close();
    10701098
    1071 console.out("  "+new Date().toUTCString()+": Left main loop [irq="+irq+"]");
     1099dim.log("Left main loop [irq="+irq+"]");
    10721100
    10731101if (irq.toUpperCase()=="SHUTDOWN")
Note: See TracChangeset for help on using the changeset viewer.