Changeset 16841
- Timestamp:
- 06/14/13 11:15:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/scripts/Main.js
r16798 r16841 90 90 // ================================================================ 91 91 92 var irq; 93 92 94 function doDrsCalibration(where) 93 95 { … … 98 100 var tm = new Date(); 99 101 100 while ( 1)102 while (!irq) 101 103 { 102 104 dim.send("FAD_CONTROL/START_DRS_CALIBRATION"); 103 if ( !takeRun("drs-pedestal", 1000)) // 40 / 20s (50Hz)105 if (irq || !takeRun("drs-pedestal", 1000)) // 40 / 20s (50Hz) 104 106 continue; 105 107 106 if ( !takeRun("drs-gain", 1000)) // 40 / 20s (50Hz)108 if (irq || !takeRun("drs-gain", 1000)) // 40 / 20s (50Hz) 107 109 continue; 108 110 109 if ( !takeRun("drs-pedestal", 1000)) // 40 / 20s (50Hz)111 if (irq || !takeRun("drs-pedestal", 1000)) // 40 / 20s (50Hz) 110 112 continue; 111 113 … … 115 117 dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2); 116 118 117 while (! takeRun("drs-pedestal", 1000)); // 40 / 20s (50Hz)118 while (! takeRun("drs-time", 1000)); // 40 / 20s (50Hz)119 120 while ( 1)119 while (!irq && !takeRun("drs-pedestal", 1000)); // 40 / 20s (50Hz) 120 while (!irq && !takeRun("drs-time", 1000)); // 40 / 20s (50Hz) 121 122 while (!irq) 121 123 { 122 124 dim.send("FAD_CONTROL/RESET_SECONDARY_DRS_BASELINE"); 123 if (takeRun("pedestal", 1000)) // 40 / 10s (80Hz)125 if (takeRun("pedestal", 1000)) // 40 / 10s (80Hz) 124 126 break; 125 127 } … … 127 129 dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2); 128 130 129 while (!takeRun("pedestal", 1000)); // 40 / 10s (80Hz) 130 131 // ----------- 132 // 4'40 / 2'00 133 134 console.out(" "+new Date().toUTCString()+": DRS calibration done [%.1f]".$((new Date()-tm)/1000)); 131 while (!irq && !takeRun("pedestal", 1000)); // 40 / 10s (80Hz) 132 // ----------- 133 // 4'40 / 2'00 134 135 if (irq) 136 console.out(" "+new Date().toUTCString()+": DRS calibration interrupted [%.1fs]".$((new Date()-tm)/1000)); 137 else 138 console.out(" "+new Date().toUTCString()+": DRS calibration done [%.1fs]".$((new Date()-tm)/1000)); 135 139 } 136 140 … … 348 352 function func() 349 353 { 350 if ((this.cnt!=undefined && this.get().counter>this.cnt+10) || 354 if (irq || 355 (this.cnt!=undefined && this.get().counter>this.cnt+10) || 351 356 (this.voltageStep && this.voltageStep<0.02)) 352 357 return true; … … 357 362 v8.timeout(4*60000, func, this); 358 363 359 console.out(" "+new Date().toUTCString()+": Voltage stable within limits [dV=%.3f, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000)); 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)); 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)); 360 368 } 361 369 … … 592 600 593 601 if (valid) 594 console.out(" "+new Date().toUTCString()+": Last DRS calib :%.1fmin ago".$(diff));602 console.out(" "+new Date().toUTCString()+": Last DRS calibration was %.1fmin ago".$(diff)); 595 603 else 596 console.out(" "+new Date().toUTCString()+": No valid drscalibration available.");604 console.out(" "+new Date().toUTCString()+": No valid DRS calibration available."); 597 605 598 606 return valid ? diff : null; 599 607 } 608 609 // ---------------------------------------------------------------- 610 // Install interrupt handler 611 // ---------------------------------------------------------------- 612 function handleIrq(cmd, args, time, user) 613 { 614 console.out("Interrupt received:"); 615 console.out(" IRQ: "+cmd); 616 console.out(" Time: "+time); 617 console.out(" User: "+user); 618 619 irq = cmd ? cmd : "stop"; 620 621 // This will end a run in progress as if it where correctly stopped 622 if (dim.state("MCP").name=="TakingData") 623 dim.send("MCP/STOP"); 624 625 // This will stop a rate scan in progress 626 if (dim.state("RATE_SCAN").name=="InProgress") 627 dim.send("RATE_SCAN/STOP"); 628 } 629 630 dimctrl.setInterruptHandler(handleIrq); 600 631 601 632 // ---------------------------------------------------------------- … … 613 644 var n = new Date(); 614 645 if (observations.length>0 && test==-1) 615 console.out( n.toUTCString()+": First observation scheduled for "+observations[0].start.toUTCString());646 console.out(" "+n.toUTCString()+": First observation scheduled for "+observations[0].start.toUTCString()); 616 647 if (test>=0 && test<observations.length) 617 console.out( n.toUTCString()+": First observation should start immediately.");648 console.out(" "+n.toUTCString()+": First observation should start immediately."); 618 649 if (observations.length>0 && observations[0].start>n+12*3600*1000) 619 console.out( n.toUTCString()+": No observations scheduled for the next 12 hours!");650 console.out(" "+n.toUTCString()+": No observations scheduled for the next 12 hours!"); 620 651 if (observations.length==0) 621 console.out( n.toUTCString()+": No observations scheduled!");652 console.out(" "+n.toUTCString()+": No observations scheduled!"); 622 653 } 623 654 … … 633 664 var system_on; // undefined 634 665 635 while ( 1)666 while (!irq) 636 667 { 637 668 // Check if observation position is still valid … … 669 700 if (lastId!=obs.id) // !Object.isEqual(obs, nextObs) 670 701 { 671 console.out("--- "+obs.id+" ---"); 672 console.out("Current time: "+new Date().toUTCString()); 673 console.out("Current observation: "+obs.start.toUTCString()); 702 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()); 674 708 if (nextObs!=undefined) 675 console.out(" Next observation:"+nextObs.start.toUTCString());709 console.out(" "+new Date().toUTCString()+": Next observation scheduled for "+nextObs.start.toUTCString()); 676 710 console.out(""); 677 711 … … 723 757 } 724 758 725 console.out("\n"+(new Date()).toUTCString()+": Current measurement: "+obs[sub]); 759 760 if (obs[sub].task!="IDLE" && obs[sub].task!="DATA") 761 console.out(" "+new Date().toUTCString()+": New task ["+obs[sub]+"]"); 726 762 727 763 // FIXME: Maybe print a warning if Drive is on during day time! … … 772 808 switch (obs[sub].task) 773 809 { 810 case "IDLE": 811 v8.sleep(5000); 812 continue; 813 774 814 case "STARTUP": 775 console.out(" "+new Date().toUTCString()+": New task [STARTUP]", "");815 //console.out("", " "+new Date().toUTCString()+": New task [STARTUP]"); 776 816 CloseLid(); 777 817 778 818 doDrsCalibration("startup"); // will switch the voltage off 819 820 if (irq) 821 break; 779 822 780 823 service_feedback.voltageOn(); … … 783 826 // Before we can switch to 3000 we have to make the right DRS calibration 784 827 console.out(" "+new Date().toUTCString()+": Taking single p.e. run."); 785 while (! takeRun("pedestal", 5000));828 while (!irq && !takeRun("pedestal", 5000)); 786 829 787 830 // It is unclear what comes next, so we better switch off the voltage … … 792 835 793 836 case "SHUTDOWN": 794 console.out(" "+new Date().toUTCString()+": New task [SHUTDOWN]", "");837 //console.out(" "+new Date().toUTCString()+": New task [SHUTDOWN]", ""); 795 838 Shutdown(); 796 839 system_on = false; … … 803 846 continue; 804 847 805 case "IDLE":806 v8.sleep(1000);807 continue;808 809 848 case "DRSCALIB": 810 console.out(" "+new Date().toUTCString()+": New task [DRSCALIB]", "");849 //console.out(" "+new Date().toUTCString()+": New task [DRSCALIB]", ""); 811 850 doDrsCalibration("drscalib"); // will switch the voltage off 812 console.out(" "+new Date().toUTCString()+": Task finished [DRSCALIB]", "");851 console.out(" "+new Date().toUTCString()+": Task finished [DRSCALIB]", ""); 813 852 break; 814 853 815 854 case "SINGLEPE": 816 console.out(" "+new Date().toUTCString()+": New task [SINGLE-PE]", "");855 //console.out(" "+new Date().toUTCString()+": New task [SINGLE-PE]", ""); 817 856 818 857 // The lid must be closes … … 822 861 var diff = getTimeSinceLastDrsCalib(); 823 862 if (diff>30 || diff==null) 863 { 824 864 doDrsCalibration("singlepe"); // will turn voltage off 865 if (irq) 866 break; 867 } 825 868 826 869 // The voltage must be on … … 830 873 // Before we can switch to 3000 we have to make the right DRS calibration 831 874 console.out(" "+new Date().toUTCString()+": Taking single p.e. run."); 832 while (! takeRun("pedestal", 5000));875 while (!irq && !takeRun("pedestal", 5000)); 833 876 834 877 // It is unclear what comes next, so we better switch off the voltage 835 878 service_feedback.voltageOff(); 836 console.out(" "+new Date().toUTCString()+": Task finished [SINGLE-PE]", "");879 console.out(" "+new Date().toUTCString()+": Task finished [SINGLE-PE]", ""); 837 880 break; 838 881 839 882 case "RATESCAN": 840 console.out(" "+new Date().toUTCString()+": New task [RATESCAN]", "");883 //console.out(" "+new Date().toUTCString()+": New task [RATESCAN]", ""); 841 884 842 885 var tm1 = new Date(); 843 886 844 887 // This is a workaround to make sure that we really catch 845 // the new stateand not the old one888 // the new OnTrack state later and not the old one 846 889 dim.send("DRIVE_CONTROL/STOP"); 847 dim.wait("DRIVE_CONTROL", "Armed", 5000);890 dim.wait("DRIVE_CONTROL", "Armed", 15000); 848 891 849 892 // The lid must be open … … 907 950 // ------------------------------------------------------------ 908 951 909 console.out(" "+new Date().toUTCString()+": Run #"+run+" (remaining "+parseInt(remaining)+"min)");952 console.out(" "+new Date().toUTCString()+": Run count "+run+" [remaining "+parseInt(remaining)+"min]"); 910 953 911 954 // ----- Time since last DRS Calibration [min] ------ … … 935 978 console.out(" "+new Date().toUTCString()+": Moving telescope to '"+obs[sub].source+"' [wobble="+wobble+"]"); 936 979 937 // var offset = observations[obs][2];938 // var wobble = observations[obs][3 + parseInt(run/4)%2];939 940 //dim.send("DRIVE_CONTROL/TRACK_SOURCE", offset, wobble, source);980 // This is a workaround to make sure that we really catch 981 // the new OnTrack state later and not the old one 982 dim.send("DRIVE_CONTROL/STOP"); 983 dim.wait("DRIVE_CONTROL", "Armed", 15000); 941 984 942 985 dim.send("DRIVE_CONTROL/TRACK_WOBBLE", wobble, obs[sub].source); … … 947 990 948 991 if (drscal) 992 { 949 993 doDrsCalibration("data"); // will turn voltage off 950 994 995 // Now we switch on the voltage and a significant amount of 996 // time has been passed, so do the check again. 997 sun = Sun.horizon(-12); 998 if (!was_up && sun.isUp) 999 { 1000 console.out("", " "+new Date().toUTCString()+": Sun rise detected.... automatic shutdown initiated!"); 1001 // FIXME: State check? 1002 Shutdown(); 1003 system_on = false; 1004 continue; 1005 } 1006 } 1007 1008 if (irq) 1009 break; 1010 951 1011 OpenLid(); 1012 952 1013 953 1014 // voltage must be switched on after the lid is open for the … … 969 1030 970 1031 // Calibration (2% of 20') 971 while ( 1)1032 while (!irq) 972 1033 { 973 if ( !takeRun("pedestal", 1000)) // 80 Hz -> 10s1034 if (irq || !takeRun("pedestal", 1000)) // 80 Hz -> 10s 974 1035 continue; 975 if ( !takeRun("light-pulser-ext", 1000)) // 80 Hz -> 10s1036 if (irq || !takeRun("light-pulser-ext", 1000)) // 80 Hz -> 10s 976 1037 continue; 977 1038 break; … … 1001 1062 1002 1063 if (nextObs!=undefined && sub==obs.length-1) 1003 console.out(" "+new Date().toUTCString()+": Waiting for next observation scheduledat "+nextObs.start.toUTCString(),"");1064 console.out(" "+new Date().toUTCString()+": Next observation will start at "+nextObs.start.toUTCString(),""); 1004 1065 1005 1066 sub++; … … 1007 1068 1008 1069 sub_drsruns.close(); 1070 1071 console.out(" "+new Date().toUTCString()+": Left main loop [irq="+irq+"]"); 1072 1073 if (irq.toUpperCase()=="SHUTDOWN") 1074 Shutdown(); 1009 1075 1010 1076 // ================================================================ … … 1014 1080 // error handline : http://www.sitepoint.com/exceptional-exception-handling-in-javascript/ 1015 1081 // classes: http://www.phpied.com/3-ways-to-define-a-javascript-class/ 1016 //1017 // Arguments: TakeFirstDrsCalib1018 // To be determined: How to stop the script without foreceful interruption?
Note:
See TracChangeset
for help on using the changeset viewer.