Changeset 18085
- Timestamp:
- 01/04/15 05:57:20 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/scripts/Main.js
r17924 r18085 195 195 196 196 // ================================================================ 197 // Interrupt data taking in case of high currents 198 // ================================================================ 199 dim.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 // ================================================================ 197 211 // Code related to switching bias voltage on and off 198 212 // ================================================================ … … 203 217 { 204 218 if (!evt.data) 219 return; 220 221 if (this.ok==undefined) 205 222 return; 206 223 … … 223 240 } 224 241 avg /= 320; 225 226 if (this.ok==undefined)227 return;228 229 242 230 243 this.ok = cnt<3;// || (this.last!=undefined && Math.abs(this.last-avg)<0.002); … … 306 319 ov = 1.1; 307 320 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) 309 322 { 310 323 dim.log("Stoping feedback."); … … 328 341 329 342 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 ? 330 346 dim.wait("FEEDBACK", "InProgress", 45000); 331 347 … … 365 381 // ================================================================ 366 382 367 function Shutdown( )383 function Shutdown(singlepe) 368 384 { 369 385 dim.log("Starting shutdown."); … … 419 435 }*/ 420 436 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 } 430 449 431 450 // It is unclear what comes next, so we better switch off the voltage … … 528 547 "FTM_CONTROL/TRIGGER_RATES", 529 548 "GPS_CONTROL/NEMA", 549 "SQM_CONTROL/DATA", 530 550 "LID_CONTROL/DATA", 531 551 "MAGIC_LIDAR/DATA", … … 554 574 555 575 var list = obj.data.split('\n').map(map); 556 576 // [A 557 577 function check(name) 558 578 { … … 613 633 //console.out("Feedback init: start."); 614 634 service_feedback.get(5000); 615 616 //v8.timeout(3000, function() { var n = dim.state("FEEDBACK").name; if (n=="CurrentCtrlIdle" || n=="CurrentControl") return true; });617 635 618 636 // ---------------------------------------------------------------- … … 708 726 709 727 if (irq.toUpperCase()=="RESCHEDULE") 710 return true; 728 { 729 irq = undefined; 730 return false; 731 } 711 732 712 733 if (irq.toUpperCase()=="OFF") … … 716 737 return true; 717 738 } 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 }*/ 718 747 719 748 if (irq.toUpperCase()=="SHUTDOWN") … … 786 815 } 787 816 817 //dim.log("DEBUG: Next observation scheduled for "+nextObs.start.toUTCString()+" [id="+nextObs.id+"]"); 788 818 if (nextObs && nextId!=nextObs.id) 789 819 { … … 817 847 } 818 848 819 // Check if sun is still up... only DATA and RATESCAN must be suppressed820 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) 821 851 { 822 852 var now = new Date(); … … 836 866 // otherwise it is difficult to allow e.g. the STARTUP at the beginning of the night 837 867 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" ]; 839 869 840 870 // A scheduled task was found, lets check if all servers are … … 858 888 [ "AGILENT_CONTROL_80V", [ "VoltageOn" ] ], 859 889 [ "BIAS_CONTROL", [ "VoltageOff", "VoltageOn", "Ramping" ] ], 860 [ "FEEDBACK", [ "Calibrated", "InProgress" ] ],890 [ "FEEDBACK", [ "Calibrated", "InProgress", "OnStandby", "Warning", "Critical" ] ], 861 891 [ "LID_CONTROL", [ "Open", "Closed" ] ], 862 892 [ "DRIVE_CONTROL", drive_states/*[ "Armed", "Tracking", "OnTrack" ]*/ ], … … 866 896 [ "RATE_CONTROL", [ "Connected", "GlobalThresholdSet", "InProgress" ] ], 867 897 [ "GPS_CONTROL", [ "Locked" ] ], 898 [ "SQM_CONTROL", [ "Disconnected", "Connected", "Valid" ] ], 868 899 ]; 869 900 … … 872 903 { 873 904 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,"+ 875 906 "try to find out what happened..."); 876 907 } 877 908 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 879 924 880 925 // Check if obs.task is one of the one-time-tasks … … 909 954 910 955 case "SHUTDOWN": 911 Shutdown( );956 Shutdown(true); 912 957 system_on = false; 913 958 … … 1019 1064 service_feedback.voltageOn(0); 1020 1065 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+"'."); 1024 1069 dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source); 1025 1070 } … … 1037 1082 service_feedback.waitForVoltageOn(); 1038 1083 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 1058 1111 dim.log("Task finished [RATESCAN]"); 1059 1112 console.out(""); 1060 1113 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" 1061 1224 1062 1225 case "DATA": … … 1072 1235 } 1073 1236 */ 1237 1074 1238 // Calculate remaining time for this observation in minutes 1075 1239 var remaining = nextObs==undefined ? 0 : (nextObs.start-new Date())/60000; 1240 //dim.log("DEBUG: remaining: "+remaining+" nextObs="+nextObs+" start="+nextObs.start); 1076 1241 1077 1242 // ------------------------------------------------------------ … … 1095 1260 // ...no drs calibration was done yet 1096 1261 var drscal = (run%4==0 && (remaining>15 && diff>70)) || diff==null; 1097 1262 1098 1263 if (point) 1099 1264 { … … 1134 1299 1135 1300 if (irq) 1136 break;1301 continue; 1137 1302 1138 1303 OpenLid(); … … 1140 1305 // This is now th right time to wait for th drive to be stable 1141 1306 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 } 1142 1315 1143 1316 // Now we are 'OnTrack', so we can ramp to nominal voltage … … 1147 1320 1148 1321 // If pointing had changed, do calibration 1149 if ( point)1322 if (!irq && point) 1150 1323 { 1151 1324 dim.log("Starting calibration."); … … 1177 1350 { 1178 1351 var len = 300; 1179 while ( len>15)1352 while (!irq && len>15) 1180 1353 { 1181 1354 var time = new Date();
Note:
See TracChangeset
for help on using the changeset viewer.