Changeset 18085


Ignore:
Timestamp:
01/04/15 05:57:20 (10 years ago)
Author:
Daniela Dorner
Message:
implemented new ratescan types
File:
1 edited

Legend:

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

    r17924 r18085  
    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")
     
    786815    }
    787816
     817    //dim.log("DEBUG: Next observation scheduled for "+nextObs.start.toUTCString()+" [id="+nextObs.id+"]");
    788818    if (nextObs && nextId!=nextObs.id)
    789819    {
     
    817847    }
    818848
    819     // Check if sun is still up... only DATA and RATESCAN must be suppressed
    820     if ((obs[sub].task=="DATA" || obs[sub].task=="RATESCAN") && sun.isUp)
     849    // Check if sun is still up... only DATA and */
     850    if ((obs[sub].task=="DATA" || obs[sub].task=="RATESCAN" || obs[sub].task=="RATESCAN2" ) && sun.isUp)
    821851    {
    822852        var now = new Date();
     
    836866    // otherwise it is difficult to allow e.g. the STARTUP at the beginning of the night
    837867    var power_states = sun.isUp || !system_on ? [ "DriveOff", "SystemOn" ] : [ "SystemOn" ];
    838     var drive_states = sun.isUp || !system_on ?   undefined    : [ "Armed", "Tracking", "OnTrack" ];
     868    var drive_states = sun.isUp || !system_on ? undefined : [ "Armed", "Tracking", "OnTrack" ];
    839869
    840870    // A scheduled task was found, lets check if all servers are
     
    858888         [ "AGILENT_CONTROL_80V", [ "VoltageOn"                ] ],
    859889         [ "BIAS_CONTROL",        [ "VoltageOff", "VoltageOn", "Ramping" ] ],
    860          [ "FEEDBACK",            [ "Calibrated", "InProgress" ] ],
     890         [ "FEEDBACK",            [ "Calibrated", "InProgress", "OnStandby", "Warning", "Critical" ] ],
    861891         [ "LID_CONTROL",         [ "Open", "Closed"           ] ],
    862892         [ "DRIVE_CONTROL",       drive_states/*[ "Armed", "Tracking", "OnTrack" ]*/ ],
     
    866896         [ "RATE_CONTROL",        [ "Connected", "GlobalThresholdSet", "InProgress"  ] ],
    867897         [ "GPS_CONTROL",         [ "Locked"  ] ],
     898         [ "SQM_CONTROL",         [ "Disconnected", "Connected", "Valid" ] ],
    868899        ];
    869900
     
    872903    {
    873904        throw new Error("Something unexpected has happened. One of the servers "+
    874                         "is in a state in which it should not be. Please,"+
     905                        "is in a state in which it should not be. Please,"+ 
    875906                        "try to find out what happened...");
    876907    }
    877908
    878     datalogger_subscriptions.check();
     909    datalogger_subscriptions.check();                                         
     910                                                                               
     911    // If this is an observation which needs the voltage to be swicthed on
     912    // skip that if the voltage is not stable                                   
     913    /*
     914    if (obs[sub].task=="DATA" || obs[sub].task=="RATESCAN")
     915    {
     916        var state = dim.state("FEEDBACK").name;
     917        if (state=="Warning" || state=="Critical" || state=="OnStandby")
     918        {
     919            v8.sleep(1000);
     920            continue;
     921        }
     922    }*/
     923
    879924
    880925    // Check if obs.task is one of the one-time-tasks
     
    909954
    910955    case "SHUTDOWN":
    911         Shutdown();
     956        Shutdown(true);
    912957        system_on = false;
    913958
     
    10191064        service_feedback.voltageOn(0);
    10201065
    1021         if (obs.source != undefined)
    1022         {
    1023             dim.log("Pointing telescope to '"+obs[cub].source+"'.");
     1066        if (obs[sub].source != undefined)
     1067        {
     1068            dim.log("Pointing telescope to '"+obs[sub].source+"'.");
    10241069            dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source);
    10251070        }
     
    10371082        service_feedback.waitForVoltageOn();
    10381083
    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));
     1084        if (!irq)
     1085        {
     1086            var tm2 = new Date();
     1087
     1088            dim.log("Starting ratescan.");
     1089
     1090            // Start rate scan
     1091            dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10, "default");
     1092
     1093            // Lets wait if the ratescan really starts... this might take a few
     1094            // seconds because RATE_SCAN configures the ftm and is waiting for
     1095            // it to be configured.
     1096            dim.wait("RATE_SCAN", "InProgress", 10000);
     1097            dim.wait("RATE_SCAN", "Connected", 2700000);
     1098
     1099            // Here one could implement a watchdog for the feedback as well, but what is the difference
     1100            // whether finally one has to find out if the feedback was in the correct state
     1101            // or the ratescan was interrupted?
     1102
     1103            // this line is actually some kind of hack.
     1104            // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
     1105            // So I decided to put this line here as a kind of patchwork....
     1106            //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 6);
     1107
     1108            dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
     1109        }
     1110
    10581111        dim.log("Task finished [RATESCAN]");
    10591112        console.out("");
    10601113        break; // case "RATESCAN"
     1114
     1115    case "RATESCAN2":
     1116        var tm1 = new Date();
     1117
     1118        // This is a workaround to make sure that we really catch
     1119        // the new OnTrack state later and not the old one
     1120        dim.send("DRIVE_CONTROL/STOP");
     1121        dim.wait("DRIVE_CONTROL", "Armed", 15000);
     1122
     1123        // Open the lid if required
     1124        if (!obs[sub].lidclosed)
     1125            OpenLid();
     1126        else
     1127            CloseLid();
     1128
     1129        // Switch the voltage to a reduced level (Ubd)
     1130        service_feedback.voltageOn(0);
     1131
     1132        // track source/position or move to position
     1133        if (obs[sub].lidclosed)
     1134        {
     1135            dim.log("Moving telescope to zd="+obs[sub].zd+" az="+obs[sub].az);
     1136            dim.send("DRIVE_CONTROL/MOVE_TO", obs[sub].zd, obs[sub].az);
     1137            v8.sleep(1000);
     1138            dim.wait("DRIVE_CONTROL", "Armed", 150000); // 110s for turning and 30s for stabilizing
     1139        }
     1140        else
     1141        {
     1142            if (obs[sub].source != undefined)
     1143            {
     1144                dim.log("Pointing telescope to '"+obs[sub].source+"'.");
     1145                dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source);
     1146            }
     1147            else
     1148            {
     1149                dim.log("Pointing telescope to ra="+obs[sub].ra+" dec="+obs[sub].dec);
     1150                dim.send("DRIVE_CONTROL/TRACK", obs[sub].ra, obs[sub].dec);
     1151            }
     1152
     1153            dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing
     1154        }
     1155
     1156        // Now tracking stable, switch voltage to nominal level and wait
     1157        // for stability.
     1158        if (obs[sub].rstype=="dark-bias-off")
     1159            service_feedback.voltageOff();
     1160        else
     1161        {
     1162            service_feedback.voltageOn();
     1163            service_feedback.waitForVoltageOn();
     1164        }
     1165        dim.log("rs-type: "+obs[sub].rstype);
     1166
     1167        if (!irq)
     1168        {
     1169            var tm2 = new Date();
     1170
     1171            dim.log("Starting ratescan 2/1");
     1172
     1173            // Start rate scan
     1174            dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 300, 20, obs[sub].rstype);
     1175
     1176            // Lets wait if the ratescan really starts... this might take a few
     1177            // seconds because RATE_SCAN configures the ftm and is waiting for
     1178            // it to be configured.
     1179            dim.wait("RATE_SCAN", "InProgress", 10000);
     1180            dim.wait("RATE_SCAN", "Connected", 2700000);
     1181
     1182            // Here one could implement a watchdog for the feedback as well, but what is the difference
     1183            // whether finally one has to find out if the feedback was in the correct state
     1184            // or the ratescan was interrupted?
     1185
     1186            // this line is actually some kind of hack.
     1187            // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
     1188            // So I decided to put this line here as a kind of patchwork....
     1189            //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 6);
     1190
     1191            dim.log("Ratescan 2/1 done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
     1192        }
     1193
     1194        if (!irq)
     1195        {
     1196            var tm2 = new Date();
     1197
     1198            dim.log("Starting ratescan 2/2");
     1199
     1200            // Start rate scan
     1201            dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 300, 1000, 100, obs[sub].rstype);
     1202
     1203            // Lets wait if the ratescan really starts... this might take a few
     1204            // seconds because RATE_SCAN configures the ftm and is waiting for
     1205            // it to be configured.
     1206            dim.wait("RATE_SCAN", "InProgress", 10000);
     1207            dim.wait("RATE_SCAN", "Connected", 2700000);
     1208
     1209            // Here one could implement a watchdog for the feedback as well, but what is the difference
     1210            // whether finally one has to find out if the feedback was in the correct state
     1211            // or the ratescan was interrupted?
     1212
     1213            // this line is actually some kind of hack.
     1214            // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
     1215            // So I decided to put this line here as a kind of patchwork....
     1216            //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 6);
     1217
     1218            dim.log("Ratescan 2/2 done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
     1219        }
     1220
     1221        dim.log("Task finished [RATESCAN2]");
     1222        console.out("");
     1223        break; // case "RATESCAN2"
    10611224
    10621225    case "DATA":
     
    10721235        }
    10731236    */
     1237
    10741238        // Calculate remaining time for this observation in minutes
    10751239        var remaining = nextObs==undefined ? 0 : (nextObs.start-new Date())/60000;
     1240        //dim.log("DEBUG: remaining: "+remaining+" nextObs="+nextObs+" start="+nextObs.start);
    10761241
    10771242        // ------------------------------------------------------------
     
    10951260        //  ...no drs calibration was done yet
    10961261        var drscal = (run%4==0 && (remaining>15 && diff>70)) || diff==null;
    1097 
     1262   
    10981263        if (point)
    10991264        {
     
    11341299
    11351300        if (irq)
    1136             break;
     1301            continue;
    11371302
    11381303        OpenLid();
     
    11401305        // This is now th right time to wait for th drive to be stable
    11411306        dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing
     1307
     1308        // Now check the voltage... (do not start a lot of stuff just to do nothing)
     1309        var state = dim.state("FEEDBACK").name;
     1310        if (state=="Warning" || state=="Critical" || state=="OnStandby")
     1311        {
     1312            v8.sleep(60000);
     1313            continue;
     1314        }
    11421315
    11431316        // Now we are 'OnTrack', so we can ramp to nominal voltage
     
    11471320
    11481321        // If pointing had changed, do calibration
    1149         if (point)
     1322        if (!irq && point)
    11501323        {
    11511324            dim.log("Starting calibration.");
     
    11771350        {
    11781351            var len = 300;
    1179             while (len>15)
     1352            while (!irq && len>15)
    11801353            {
    11811354                var time = new Date();
Note: See TracChangeset for help on using the changeset viewer.