Changeset 15098
- Timestamp:
- 03/18/13 14:52:05 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/scripts/Main.js
r15030 r15098 6 6 7 7 //this is just the class implementation of 'Observation' 8 include('scripts/Observation_class.js'); 8 include('scripts/Observation_class.js'); 9 9 10 10 dimctrl.defineState(37, "TimeOutBeforeTakingData", "MCP took more than 5minutes to start TakingData"); … … 12 12 13 13 // error handline : http://www.sitepoint.com/exceptional-exception-handling-in-javascript/ 14 // clas es: http://www.phpied.com/3-ways-to-define-a-javascript-class/14 // classes: http://www.phpied.com/3-ways-to-define-a-javascript-class/ 15 15 // 16 16 // Arguments: TakeFirstDrsCalib 17 17 // To be determined: How to stop the script without foreceful interruption? 18 19 // adapt states of drivectrl20 18 21 19 // … … 82 80 // fad_connections.reconnect() is not really good, but at least it has FAD in it. 83 81 var service_con = new Subscription("FAD_CONTROL/CONNECTIONS"); 82 84 83 /** 85 84 * call-back function of FAD_CONTROL/CONNECTIONS … … 102 101 return; 103 102 104 dim.alarm("FAD board loss detected...");103 //m.alarm("FAD board loss detected..."); 105 104 dim.send("MCP/RESET"); 106 105 dim.send("FAD_CONTROL/CLOSE_OPEN_FILES"); … … 157 156 time = -1; 158 157 159 console.out(" Take run N="+count+" T="+time+"s ["+type+"]"); 160 // change rats for cal runs1!!! 158 console.out(" Take run: N="+count+" T="+time+"s ["+type+"]"); 161 159 162 160 dim.send("MCP/START", time?time:-1, count?count:-1, type); 163 164 165 161 166 162 // What could be a reasonable timeout here? … … 263 259 while (Sun.horizon( horizon_parameter ).isUp) 264 260 { 265 var minutes_until_sunset = (Sun.horizon( horizon_parameter ).set - new Date())/60000; 266 console.out("Open Lid - Info: "); 267 console.out(" Sun is above FACT-horizon, lid cannot be opened."); 268 console.out(" sleeping " + minutes_until_sunset + "minutes ..."); 269 v8.sleep(60000); 270 } 271 272 console.out("Open lid: start"); 261 var now = new Date(); 262 var minutes_until_sunset = (Sun.horizon( horizon_parameter ).set - now)/60000; 263 console.out(now.toUTCString()+": Sun above FACT-horizon, lid cannot be opened: sleeping 1min, remaining %.1fmin".$(minutes_until_sunset)); 264 v8.sleep(60000); 265 } 266 267 var isClosed = dim.state("LID_CONTROL").name=="Closed"; 273 268 274 269 // Wait for lid to be open 275 if (dim.state("LID_CONTROL").name=="Closed") 270 if (isClosed) 271 { 272 console.out(" Open lid: start"); 276 273 dim.send("LID_CONTROL/OPEN"); 274 } 277 275 dim.wait("LID_CONTROL", "Open", 30000); 278 console.out("Open lid: done"); 276 277 if (isClosed) 278 console.out(" Open lid: done"); 279 279 } 280 280 281 281 function CloseLid() 282 282 { 283 console.out("Close lid: start");283 var isOpen = dim.state("LID_CONTROL").name=="Open"; 284 284 285 285 // Wait for lid to be open 286 if (dim.state("LID_CONTROL").name=="Open") 286 if (isOpen) 287 { 288 console.out(" Close lid: start"); 287 289 dim.send("LID_CONTROL/CLOSE"); 290 } 288 291 dim.wait("LID_CONTROL", "Closed", 30000); 289 292 290 console.out("Close lid: end"); 293 if (isOpen) 294 console.out(" Close lid: end"); 291 295 } 292 296 … … 303 307 service_feedback.voltageOff = function() 304 308 { 305 console.out(" Voltage off: start");306 307 var isOn = dim.state("BIAS_CONTROL").name=="VoltageOn";308 309 var state = dim.state("BIAS_CONTROL").name; 310 311 // check of feedback has to be switched on 312 var isOn = state=="VoltageOn" || state=="Ramping"; 309 313 if (isOn) 310 314 { 315 console.out(" Voltage off: start"); 316 317 // Supress the possibility that the bias control is 318 // ramping and will reject the command to switch the 319 // voltage off 320 var isControl = dim.state("FEEDBACK").name=="CurrentControl"; 321 if (isControl) 322 { 323 console.out(" Suspending feedback."); 324 dim.send("FEEDBACK/ENABLE_OUTPUT", false); 325 dim.wait("FEEDBACK", "CurrentCtrlIdle", 3000); 326 } 327 328 // Switch voltage off 311 329 console.out(" Voltage on: switch off"); 312 330 dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE"); 331 332 // If the feedback was enabled, re-enable it 333 if (isControl) 334 { 335 console.out(" Resuming feedback."); 336 dim.send("FEEDBACK/ENABLE_OUTPUT", true); 337 dim.wait("FEEDBACK", "CurrentControl", 3000); 338 } 313 339 } 314 340 … … 318 344 // dim.wait("FEEDBACK", "CurrentCtrlIdle", 1000); 319 345 320 console.out(" Voltage off: end"); 346 if (isOn) 347 console.out(" Voltage off: end"); 321 348 } 322 349 … … 347 374 // throw new Error("Sun is above FACT-horizon, voltage cannot be switched on."); 348 375 349 console.out(" Voltage on: start");350 351 376 var isOff = dim.state("BIAS_CONTROL").name=="VoltageOff"; 352 353 377 if (isOff) 354 378 { 355 379 console.out(" Voltage on: switch on"); 356 //console.out(JSON.stringify(dim.state("BIAS_CONTROL")));380 //console.out(JSON.stringify(dim.state("BIAS_CONTROL"))); 357 381 358 382 dim.send("BIAS_CONTROL/SET_GLOBAL_DAC", 1); … … 371 395 console.out(" Voltage on: cnt="+this.cnt); 372 396 } 373 374 console.out(" Voltage on: end"); 375 } 376 377 397 } 378 398 379 399 service_feedback.waitForVoltageOn = function() … … 390 410 // So we want one recent temperature update 391 411 // and three recent current updates 392 console.out(" Voltage wait: start"); 412 413 // Avoid output if condition is already fulfilled 414 if (this.cnt && this.get().counter>this.cnt+2) 415 return; 416 417 // FIXME: timeout missing 418 console.out(" Feedback wait: start"); 419 420 var now = new Date(); 393 421 while (this.cnt==undefined || this.get().counter<=this.cnt+2) 394 422 v8.sleep(); 395 console.out(" Voltage wait: end [cnt="+this.get().counter+"]"); 423 424 console.out(" Feedback wait: end [cnt=%d, %.2fs]".$(this.get().counter, (new Date()-now)/1000)); 396 425 } 397 426 … … 460 489 // this file just contains the definition of 461 490 // the variable observations, which builds our nightly schedule, hence the filename 462 include('scripts/schedule.js'); 463 491 include('scripts/schedule.js'); 492 464 493 // make Observation objects from user input and check if 'date' is increasing. 465 494 for (var i=0; i<observations.length; i++) 466 495 { 467 496 observations[i] = new Observation(observations[i]); 468 497 469 498 // check if the start date given by the user is increasing. 470 499 if (i>0 && observations[i].start <= observations[i-1].start) … … 474 503 } 475 504 } 476 477 478 505 479 506 // ---------------------------------------------------------------- … … 486 513 // also Startup needs DRS_RUNS 487 514 var service_drs = new Subscription("FAD_CONTROL/DRS_RUNS"); 488 service_drs.get(5000 , false);515 service_drs.get(5000); 489 516 490 517 console.out("Drs runs init: end."); … … 511 538 //console.out(" => [SHUTDOWN] called."); 512 539 console.out("Shutdown: start"); 540 541 dim.send("FTM_CONTROL/STOP_TRIGGER"); 513 542 service_feedback.voltageOff(); 514 543 CloseLid(); 515 544 dim.send("DRIVE_CONTROL/PARK"); 545 546 console.out("Waiting for telescope to park. This may take a while."); 547 548 // FIXME: This might not work is the drive is already close to park position 516 549 dim.wait("DRIVE_CONTROL", "Moving", 3000); 517 dim.wait("DRIVE_CONTROL", "Armed", 120000); 550 dim.wait("DRIVE_CONTROL", "Armed", 120000); 551 552 // dim.wait("DRIVE_CONTROL", "Locked", 3000); 553 554 var sub = new Subscription("DRIVE_CONTROL/POINTING_POSITION"); 555 sub.get(5000); // FIXME: Proper error message in case of failure 556 557 function func() 558 { 559 var report = sub.get(); 560 561 var zd = report.obj['Zd']; 562 var az = report.obj['Az']; 563 564 if (zd>100 && Math.abs(az)<1) 565 return true; 566 567 return undefined; 568 } 569 570 v8.timeout(150000, func); 571 572 // FIXME: Add a check for the position here! 573 518 574 console.out("Shutdown: end"); 519 575 } … … 525 581 if (now==undefined) 526 582 now = new Date(); 527 583 528 584 if (isNaN(now.valueOf())) 529 585 throw new Error("Date argument in getObservation invalid."); … … 541 597 // the reader at this point has no idea why run is -2 ... this is the first time she 542 598 // reads about this variable and there is not a word of explanation found. 543 var run = -2; 599 var run = -2; // getObservation never called 600 var sub; 544 601 var lastObs; 545 602 546 603 var test = getObservation(); 547 if (test!=undefined && test<observations.length) 548 { 549 var t = observations[test].start; 604 if (test!=undefined) 605 { 550 606 var n = new Date(); 551 if (t >n)552 console.out(n.toUTCString()+": First observation scheduled for "+ t.toUTCString());553 else607 if (test==-1) 608 console.out(n.toUTCString()+": First observation scheduled for "+observations[0].start.toUTCString()); 609 if (test>=0 && test<observations.length) 554 610 console.out(n.toUTCString()+": First observation should start immediately."); 555 if ( t>n+12*3600*1000)611 if (observations[0].start>n+12*3600*1000) 556 612 console.out(n.toUTCString()+": No observations scheduled for the next 12 hours!"); 557 613 } … … 565 621 exit(); 566 622 623 // we are still waiting for the first observation in the schedule 567 624 if (idxObs==-1) 568 625 { 626 // flag that the first observation will be in the future 627 run = -1; 569 628 v8.sleep(1000); 570 629 continue; … … 575 634 576 635 // Check if observation target has changed 577 if (lastObs!=idxObs) 636 if (lastObs!=idxObs) // !Object.isEqual(obs, nextObs) 578 637 { 579 638 console.out("--- "+idxObs+" ---"); 580 console.out("Current time: "+new Date()); 581 console.out("Current observation: "+obs); 582 console.out("Next observation: "+nextObs); 639 console.out("Current time: "+new Date().toUTCString()); 640 console.out("Current observation: "+obs.start.toUTCString()); 641 if (nextObs!=undefined) 642 console.out("Next observation: "+nextObs.start.toUTCString()); 583 643 console.out(""); 584 644 … … 586 646 // a scheduled 'START', so we have to check if the 587 647 // telescop is operational already 588 if (run==-2) 648 sub = 0; 649 if (run<0) 589 650 { 590 651 Startup(); // -> Bias On/Off?, Lid open/closed? … … 592 653 } 593 654 655 // The first observation had a start-time in the past... 656 // In this particular case start with the last entry 657 // in the list of measurements 658 if (run==-2) 659 sub = obs.length-1; 660 594 661 run = 0; 595 662 } 596 663 lastObs = idxObs; 597 664 598 // We have performed startup or shutdown... wait for next observation 599 if (run==-1) 665 if (nextObs==undefined && obs[obs.length-1].task!="SHUTDOWN") 666 throw Error("Last scheduled measurement must be a shutdown."); 667 668 // We are done with all measurement slots for this 669 // observation... wait for next observation 670 if (sub>=obs.length) 600 671 { 601 672 v8.sleep(1000); 602 673 continue; 603 674 } 675 // add time 676 console.out("\n"+(new Date()).toUTCString()+": Current measurement: "+obs[sub]); 604 677 605 678 // Check if obs.task is one of the one-time-tasks 606 switch (obs .task)679 switch (obs[sub].task) 607 680 { 608 681 case "STARTUP": … … 627 700 628 701 console.out(" Waiting for first scheduled observation.",""); 629 run = -1;702 sub++; 630 703 continue; 631 704 … … 635 708 636 709 console.out(" Waiting for next startup.", ""); 637 run = -1; 710 sub++; 711 continue; 712 713 case "IDLE": 714 // FIXME: Checks missing whether a shutdown is needed... 715 v8.sleep(1000); 638 716 continue; 639 717 … … 641 719 console.out(" RATESCAN "); 642 720 721 if (dim.state("FTM_CONTROL").name=="TriggerOn") 722 { 723 dim.send("FTM_CONTROL/STOP_TRIGGER"); 724 dim.wait("FTM_CONTROL", "Idle", 3000); 725 } 726 643 727 dim.send("DRIVE_CONTROL/STOP"); 644 728 dim.wait("DRIVE_CONTROL", "Armed", 5000); 645 729 730 OpenLid(); 731 732 service_feedback.voltageOn(); 733 646 734 if (obs.source != undefined) 647 dim.send("DRIVE_CONTROL/TRACK_ON", obs .source);735 dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source); 648 736 else 649 dim.send("DRIVE_CONTROL/TRACK", obs.ra, obs.dec); 650 651 //OpenLid(); 652 dim.wait("DRIVE_CONTROL", "OnTrack", 300000); 653 654 OpenLid(); 655 656 service_feedback.voltageOn(); 737 dim.send("DRIVE_CONTROL/TRACK", obs[sub].ra, obs[sub].dec); 738 739 dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing 740 657 741 service_feedback.waitForVoltageOn(); 658 742 … … 702 786 703 787 console.out("Ratescan done."); 704 run = -1;788 sub++; 705 789 continue; 706 790 } 791 792 // ========================== case "DATA" ============================ 707 793 /* 708 794 if (Sun.horizon("FACT").isUp) … … 715 801 */ 716 802 // Calculate remaining time for this observation in minutes 717 var remaining = (nextObs.start-new Date())/60000;803 var remaining = nextObs==undefined ? 0 : (nextObs.start-new Date())/60000; 718 804 719 805 // ------------------------------------------------------------ … … 755 841 } 756 842 757 console.out(" Checking states: end.");758 759 843 // ------------------------------------------------------------ 760 844 761 console.out(" Run #"+run+" ( "+parseInt(remaining)+"min)");845 console.out(" Run #"+run+" (remaining "+parseInt(remaining)+"min)"); 762 846 763 847 // ----- Time since last DRS Calibration [min] ------ 764 var runs = service_drs.get(0 , false);848 var runs = service_drs.get(0); 765 849 var diff = (new Date()-runs.time)/60000; 766 850 767 851 // Warning: 'roi=300' is a number which is not intrisically fixed 768 852 // but can change depending on the taste of the observers 769 var valid = runs. data[1][2]>0 && runs.data[0]==300;853 var valid = runs.obj['run'][2]>0 && runs.obj['roi']==300; 770 854 771 855 if (valid) … … 795 879 796 880 //console.out(" Move telescope to '"+source+"' "+offset+" "+wobble); 797 console.out(" Move telescope to '"+obs .source+"' ["+wobble+"]");881 console.out(" Move telescope to '"+obs[sub].source+"' ["+wobble+"]"); 798 882 799 883 //var offset = observations[obs][2]; … … 802 886 //dim.send("DRIVE_CONTROL/TRACK_SOURCE", offset, wobble, source); 803 887 804 dim.send("DRIVE_CONTROL/TRACK_WOBBLE", wobble+1, obs .source);888 dim.send("DRIVE_CONTROL/TRACK_WOBBLE", wobble+1, obs[sub].source); 805 889 806 890 // Do we have to check if the telescope is really moving? … … 856 940 } 857 941 858 //v8.sleep(360000);859 942 console.out(" Taking data: done"); 860 861 943 run++; 862 944 }
Note:
See TracChangeset
for help on using the changeset viewer.