Changeset 16853
- Timestamp:
- 06/15/13 18:11:51 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/scripts/Main.js
r16841 r16853 94 94 function doDrsCalibration(where) 95 95 { 96 console.out(" "+new Date().toUTCString()+":Starting DRS calibration ["+where+"]");96 dim.log("Starting DRS calibration ["+where+"]"); 97 97 98 98 service_feedback.voltageOff(); … … 134 134 135 135 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)); 137 137 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)); 139 139 } 140 140 … … 161 161 if (isClosed) 162 162 { 163 console.out(" "+new Date().toUTCString()+":Opening lid");163 dim.log("Opening lid"); 164 164 dim.send("LID_CONTROL/OPEN"); 165 165 } … … 167 167 168 168 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)); 170 170 } 171 171 … … 179 179 if (isOpen) 180 180 { 181 console.out(" "+new Date().toUTCString()+":Closing lid.");181 dim.log("Closing lid."); 182 182 dim.send("LID_CONTROL/CLOSE"); 183 183 } … … 185 185 186 186 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)); 188 188 } 189 189 … … 242 242 if (isOn) 243 243 { 244 console.out(" "+new Date().toUTCString()+":Switching voltage off.");244 dim.log("Switching voltage off."); 245 245 246 246 // Supress the possibility that the bias control is … … 274 274 275 275 if (isOn) 276 console.out(" "+new Date().toUTCString()+":Voltage off.");276 dim.log("Voltage off."); 277 277 } 278 278 … … 306 306 if (isOff) 307 307 { 308 console.out(" "+new Date().toUTCString()+":Switching voltage on.");308 dim.log("Switching voltage on."); 309 309 //console.out(JSON.stringify(dim.state("BIAS_CONTROL"))); 310 310 … … 321 321 if (isOff) 322 322 { 323 console.out(" "+new Date().toUTCString()+": Voltage on[cnt="+this.cnt+"]");323 dim.log("Voltage on, feedback will start ramping [cnt="+this.cnt+"]"); 324 324 325 325 this.previous = undefined; … … 347 347 return; 348 348 349 // FIXME: timeout missing350 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) 352 352 function func() 353 353 { 354 354 if (irq || 355 355 (this.cnt!=undefined && this.get().counter>this.cnt+10) || 356 (this.voltageStep && this.voltageStep<0.02 ))356 (this.voltageStep && this.voltageStep<0.022)) 357 357 return true; 358 358 } … … 363 363 364 364 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)); 366 366 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)); 368 368 } 369 369 … … 374 374 function Shutdown() 375 375 { 376 console.out(" "+new Date().toUTCString()+": Starting shutdown."); 376 dim.log("Starting shutdown."); 377 378 var now1 = new Date(); 377 379 378 380 service_feedback.voltageOff(); 379 381 CloseLid(); 382 383 var now2 = new Date(); 384 380 385 dim.send("DRIVE_CONTROL/PARK"); 381 386 … … 401 406 } 402 407 403 var now = new Date();404 408 v8.timeout(150000, func); 409 410 var now3 = new Date(); 405 411 406 412 //dim.send("FEEDBACK/STOP"); … … 427 433 console.out(" BIAS_CONTROL: "+dim.state("BIAS_CONTROL").name); 428 434 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(""); 430 437 431 438 sub.close(); … … 600 607 601 608 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)); 603 610 else 604 console.out(" "+new Date().toUTCString()+":No valid DRS calibration available.");611 dim.log("No valid DRS calibration available."); 605 612 606 613 return valid ? diff : null; … … 644 651 var n = new Date(); 645 652 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+"]"); 647 654 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+"]"); 649 656 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!"); 651 658 if (observations.length==0) 652 console.out(" "+n.toUTCString()+":No observations scheduled!");659 dim.log("No observations scheduled!"); 653 660 } 654 661 … … 656 663 // Start main loop 657 664 // ---------------------------------------------------------------- 658 console.out(" "+new Date().toUTCString()+":Entering main loop.");665 dim.log("Entering main loop."); 659 666 660 667 var run = -2; // getObservation never called 661 668 var sub; 662 669 var lastId; 670 var nextId; 663 671 var sun = Sun.horizon(-12); 664 672 var system_on; // undefined … … 686 694 if (!was_up && sun.isUp) 687 695 { 688 console.out("", " "+new Date().toUTCString()+": Sun rise detected.... automatic shutdown initiated!"); 696 console.out(""); 697 dim.log("Sun rise detected.... automatic shutdown initiated!"); 689 698 // FIXME: State check? 690 699 Shutdown(); … … 701 710 { 702 711 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+"]"); 711 713 712 714 // This is the first source, but we do not come from … … 727 729 728 730 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 } 731 747 732 748 //if (nextObs==undefined && obs[obs.length-1].task!="SHUTDOWN") … … 758 774 759 775 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]+"]"); 762 778 763 779 // FIXME: Maybe print a warning if Drive is on during day time! … … 813 829 814 830 case "STARTUP": 815 //console.out("", " "+new Date().toUTCString()+": New task [STARTUP]");816 831 CloseLid(); 817 832 … … 825 840 826 841 // 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."); 828 843 while (!irq && !takeRun("pedestal", 5000)); 829 844 … … 831 846 service_feedback.voltageOff(); 832 847 system_on = true; 833 console.out(" "+new Date().toUTCString()+": Task finished [STARTUP]", ""); 848 dim.log("Task finished [STARTUP]"); 849 console.out(""); 834 850 break; 835 851 836 852 case "SHUTDOWN": 837 //console.out(" "+new Date().toUTCString()+": New task [SHUTDOWN]", "");838 853 Shutdown(); 839 854 system_on = false; … … 841 856 // FIXME: Avoid new observations after a shutdown until 842 857 // the next startup (set run back to -2?) 843 console.out(" Waiting for next startup.", "");844 858 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.", ""); 846 862 continue; 847 863 848 864 case "DRSCALIB": 849 //console.out(" "+new Date().toUTCString()+": New task [DRSCALIB]", "");850 865 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(""); 852 868 break; 853 869 854 870 case "SINGLEPE": 855 //console.out(" "+new Date().toUTCString()+": New task [SINGLE-PE]", "");856 857 871 // The lid must be closes 858 872 CloseLid(); … … 872 886 873 887 // 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."); 875 889 while (!irq && !takeRun("pedestal", 5000)); 876 890 877 891 // It is unclear what comes next, so we better switch off the voltage 878 892 service_feedback.voltageOff(); 879 console.out(" "+new Date().toUTCString()+": Task finished [SINGLE-PE]", ""); 893 dim.log("Task finished [SINGLE-PE]"); 894 console.out(""); 880 895 break; 881 896 882 897 case "RATESCAN": 883 //console.out(" "+new Date().toUTCString()+": New task [RATESCAN]", "");884 885 898 var tm1 = new Date(); 886 899 … … 898 911 if (obs.source != undefined) 899 912 { 900 console.out(" "+new Date().toUTCString()+": Moving drive to '"+obs[cub].source+"'.");913 dim.log("Pointing telescope to '"+obs[cub].source+"'."); 901 914 dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source); 902 915 } 903 916 else 904 917 { 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); 906 919 dim.send("DRIVE_CONTROL/TRACK", obs[sub].ra, obs[sub].dec); 907 920 } … … 913 926 var tm2 = new Date(); 914 927 915 console.out(" "+new Date().toUTCString()+":Starting ratescan.");928 dim.log("Starting ratescan."); 916 929 917 930 // Start rate scan … … 929 942 //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2); 930 943 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(""); 933 947 break; // case "RATESCAN" 934 948 … … 950 964 // ------------------------------------------------------------ 951 965 952 console.out(" "+new Date().toUTCString()+":Run count "+run+" [remaining "+parseInt(remaining)+"min]");966 dim.log("Run count "+run+" [remaining "+parseInt(remaining)+"min]"); 953 967 954 968 // ----- Time since last DRS Calibration [min] ------ … … 976 990 977 991 //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+"]"); 979 993 980 994 // This is a workaround to make sure that we really catch … … 998 1012 if (!was_up && sun.isUp) 999 1013 { 1000 console.out("", " "+new Date().toUTCString()+": Sun rise detected.... automatic shutdown initiated!"); 1014 console.out(""); 1015 dim.log("Sun rise detected.... automatic shutdown initiated!"); 1001 1016 // FIXME: State check? 1002 1017 Shutdown(); … … 1027 1042 if (point) 1028 1043 { 1029 console.out(" "+new Date().toUTCString()+":Starting calibration.");1044 dim.log("Starting calibration."); 1030 1045 1031 1046 // Calibration (2% of 20') … … 1045 1060 // e.g. drive went to ERROR? Maybe we have to check all states again? 1046 1061 1047 var len = 300; 1048 while (len>15) 1062 var twilight = Sun(-16).isUp; 1063 1064 if (twilight) 1049 1065 { 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 } 1055 1080 } 1056 1081 … … 1062 1087 1063 1088 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 } 1065 1093 1066 1094 sub++; … … 1069 1097 sub_drsruns.close(); 1070 1098 1071 console.out(" "+new Date().toUTCString()+":Left main loop [irq="+irq+"]");1099 dim.log("Left main loop [irq="+irq+"]"); 1072 1100 1073 1101 if (irq.toUpperCase()=="SHUTDOWN")
Note:
See TracChangeset
for help on using the changeset viewer.