source: trunk/MagicSoft/Cosy/main/MStarguider.cc@ 5612

Last change on this file since 5612 was 4888, checked in by rwagner, 20 years ago
*** empty log message ***
File size: 45.9 KB
Line 
1#define EXPERT
2
3#include "MStarguider.h"
4
5#include <fstream.h> // ifstream
6#include <iostream.h> // cout
7#include <iomanip.h> // cout
8
9#include <TH2F.h>
10#include <TGraph.h>
11#include <TTimer.h>
12#include <TSystem.h>
13#include <TFile.h> // temp writeout of histos
14#include "MAstro.h"
15#include "MString.h"
16
17#include <TGMenu.h>
18#include <TGLabel.h>
19#include <TGButton.h>
20#include <TGSplitter.h> // TGHorizontal3DLine
21#include <TGTextEntry.h>
22#include <TGLayout.h>
23#include "MString.h"
24
25#include "MCosy.h"
26#include "MCaos.h"
27// #include "MStargLeds.h"
28#include "MStargHistograms.h"
29#include "MDriveCom.h"
30
31#include "MGStarg.h"
32#include "TGFrame.h"
33
34#include "MGImage.h"
35#include "MGCoordinates.h"
36
37#include "coord.h"
38
39#include "Camera.h"
40#include "PngReader.h"
41
42#include "Led.h"
43#include "Writer.h"
44#include "FilterLed.h"
45#include "MStarList.h"
46#include "CaosFilter.h"
47#include "StarCatalog.h"
48#include "MGeomCamMagic.h"
49#include "MAstroCamera.h"
50
51#include "MGMenu.h"
52#include "MGCosy.h"
53
54ClassImp(MStarguider);
55
56enum {
57 IDM_kFilter,
58 IDM_kFindStar,
59 IDM_kCaosFilter,
60 IDM_kCatalog,
61 IDM_kStarguider,
62 IDM_kStart,
63 IDM_kStop,
64 IDM_kFileType,
65 IDM_kPPM,
66 IDM_kPNG,
67 IDM_kOnce,
68 IDM_kStretch,
69 IDM_kInput,
70 IDM_kChannel1,
71 IDM_kChannel2,
72 IDM_kContinous,
73 IDM_kRate25ps,
74 IDM_kRate5ps,
75 IDM_kRate1s,
76 IDM_kRate5s,
77 IDM_kRate30s,
78 IDM_kRate1m,
79 IDM_kRate5m,
80 IDM_kSetup,
81 IDM_kLimMag3,
82 IDM_kLimMag4,
83 IDM_kLimMag5,
84 IDM_kLimMag6,
85 IDM_kLimMag7,
86 IDM_kLimMag8,
87 IDM_kLimMag9,
88 IDM_kPixSize,
89 IDM_kAngle,
90 IDM_kInterpol250,
91 IDM_kInterpol125,
92 IDM_kInterpol50,
93 IDM_kInterpol25,
94 IDM_kInterpol10,
95 IDM_kInterpol5,
96 IDM_kInterpol2,
97 IDM_kInterpol1,
98 IDM_kCaosPrintRings,
99 IDM_kCaosPrintLeds,
100 IDM_kCaosAnalStart,
101 IDM_kCaosAnalStop,
102 IDM_kCaosWriteStart,
103 IDM_kCaosWriteStop,
104 IDM_kResetHistograms,
105 IDM_kStargHistograms,
106 IDM_kStargAnalysis,
107 IDM_kStargCaosFilter,
108 IDM_kStargLEDFilter,
109 IDM_kStargFindStar
110
111};
112
113Bool_t MStarguider::HandleTimer(TTimer *t)
114{
115 if (IsMapped())
116 {
117 fImage->DoRedraw();
118 fZoomImage->DoRedraw();
119 }
120
121 if (fCosy && fCosy->GetWin()->IsMapped())
122 fCosy->GetWin()->GetImage()->DoRedraw();
123
124 fGStarg->Update(fPos, fD);
125
126 return kTRUE;
127}
128
129#define kZOOM 96
130
131XY MStarguider::GetCoordinates() const
132{
133 return fPZdAz->GetCoordinates();
134}
135
136void MStarguider::InitGui(Int_t channel)
137{
138 fList = new MGList;
139
140 const TGWindow *p=gClient->GetRoot();
141
142 fChannel = new MGPopupMenu(p);
143 fChannel->AddEntry("Starfield Camera", IDM_kChannel1);
144 fChannel->AddEntry("TPoint Camera", IDM_kChannel2);
145 fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
146 fChannel->Associate(this);
147 fList->Add(fChannel);
148
149 //
150 // Create Menu for MStarguider Display
151 //
152 fDisplay = new MGPopupMenu(p);
153 fDisplay->AddEntry("&Filter", IDM_kFilter);
154 fDisplay->AddEntry("Find &Star", IDM_kFindStar);
155 fDisplay->AddEntry("C&aos Filter", IDM_kCaosFilter);
156 fDisplay->AddEntry("SAO &Catalog", IDM_kCatalog);
157 fDisplay->AddEntry("Stretch", IDM_kStretch);
158 fDisplay->AddSeparator();
159 fDisplay->AddEntry("Starguider", IDM_kStarguider);
160 fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter);
161 fDisplay->AddEntry("Starguider Find Star", IDM_kStargFindStar);
162 fDisplay->AddEntry("Starguider Analysis", IDM_kStargAnalysis);
163 fDisplay->AddSeparator();
164 if (channel>=0)
165 fDisplay->AddPopup("&Input", fChannel);
166 fDisplay->DisableEntry(IDM_kStargAnalysis);
167 fDisplay->DisableEntry(IDM_kStargFindStar);
168 fDisplay->CheckEntry(IDM_kStretch);
169 fDisplay->Associate(this);
170 fList->Add(fDisplay);
171
172 fFileType = new MGPopupMenu(p);
173 fFileType->AddEntry("PP&M", IDM_kPPM);
174 fFileType->AddEntry("&PNG", IDM_kPNG);
175 fFileType->CheckEntry(IDM_kPNG);
176 fFileType->Associate(this);
177 fList->Add(fFileType);
178
179 fWriteType = new MGPopupMenu(p);
180 fWriteType->AddEntry("&Once", IDM_kOnce);
181 fWriteType->AddEntry("&Continous", IDM_kContinous);
182 fWriteType->CheckEntry(IDM_kOnce);
183 fWriteType->Associate(this);
184 fList->Add(fWriteType);
185
186 fWriteRate = new MGPopupMenu(p);
187 fWriteRate->AddEntry("25/s", IDM_kRate25ps);
188 fWriteRate->AddEntry("5/s", IDM_kRate5ps);
189 fWriteRate->AddEntry("1s", IDM_kRate1s);
190 fWriteRate->AddEntry("5s", IDM_kRate5s);
191 fWriteRate->AddEntry("30s", IDM_kRate30s);
192 fWriteRate->AddEntry("1min", IDM_kRate1m);
193 fWriteRate->AddEntry("5min", IDM_kRate5m);
194 fWriteRate->CheckEntry(IDM_kRate1m);
195 fWriteRate->Associate(this);
196 fList->Add(fWriteRate);
197
198 fWrtRate = 25*60;
199
200 fWritePictures = new MGPopupMenu(p);
201 fWritePictures->AddEntry("&Start", IDM_kStart);
202 fWritePictures->AddEntry("Sto&p", IDM_kStop);
203 fWritePictures->AddSeparator();
204 fWritePictures->AddPopup("File &Type", fFileType);
205 fWritePictures->AddPopup("&Write Type", fWriteType);
206 fWritePictures->AddPopup("Write &Rate", fWriteRate);
207 fWritePictures->DisableEntry(IDM_kStop);
208 fWritePictures->Associate(this);
209 fList->Add(fWritePictures);
210
211 fLimMag = new MGPopupMenu(p);
212 fLimMag->AddEntry("3", IDM_kLimMag3);
213 fLimMag->AddEntry("4", IDM_kLimMag4);
214 fLimMag->AddEntry("5", IDM_kLimMag5);
215 fLimMag->AddEntry("6", IDM_kLimMag6);
216 fLimMag->AddEntry("7", IDM_kLimMag7);
217 fLimMag->AddEntry("8", IDM_kLimMag8);
218 fLimMag->AddEntry("9", IDM_kLimMag9);
219 fLimMag->CheckEntry(IDM_kLimMag8);
220 fLimMag->Associate(this);
221 fList->Add(fLimMag);
222
223 fSao->SetLimitMag(7.0);
224
225 fInterpol = new MGPopupMenu(p);
226 fInterpol->AddEntry("250", IDM_kInterpol250);
227 fInterpol->AddEntry("125", IDM_kInterpol125);
228 fInterpol->AddEntry("50", IDM_kInterpol50);
229 fInterpol->AddEntry("25", IDM_kInterpol25);
230 fInterpol->AddEntry("10", IDM_kInterpol10);
231 fInterpol->AddEntry("5", IDM_kInterpol5);
232 fInterpol->AddEntry("2", IDM_kInterpol2);
233 fInterpol->AddEntry("Off", IDM_kInterpol1);
234 fInterpol->Associate(this);
235 fList->Add(fInterpol);
236
237 TString disp=gVirtualX->DisplayName();
238 cout << "Display: " << disp << endl;
239 if (disp.First(':')>=0)
240 disp=disp(0, disp.First(':'));
241
242 if (disp.IsNull() || disp==(TString)"localhost")
243 {
244 fInterpol->CheckEntry(IDM_kInterpol5);
245 fIntRate = 50;
246 }
247 else
248 {
249 fInterpol->CheckEntry(IDM_kInterpol125);
250 fIntRate = 125;
251 }
252
253 fSetup = new MGPopupMenu(p);
254 fSetup->AddPopup("Lim. &Magnitude", fLimMag);
255 fSetup->AddPopup("Disp. &Interpolation", fInterpol);
256 //fSetup->AddEntry("Use Ra/Dec from file", IDM_kUseFileRaDec);
257 fSetup->Associate(this);
258 fList->Add(fSetup);
259
260 fCaosPrint = new MGPopupMenu(p);
261 fCaosPrint->AddEntry("&Leds", IDM_kCaosPrintLeds);
262 fCaosPrint->AddEntry("&Rings", IDM_kCaosPrintRings);
263 fCaosPrint->Associate(this);
264 fList->Add(fCaosPrint);
265
266 fCaosWrite = new MGPopupMenu(p);
267 fCaosWrite->AddEntry("&Start", IDM_kCaosWriteStart);
268 fCaosWrite->AddEntry("Sto&p", IDM_kCaosWriteStop);
269 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
270 fCaosWrite->Associate(this);
271 fList->Add(fCaosWrite);
272
273 fCaosAnalyse = new MGPopupMenu(p);
274 fCaosAnalyse->AddEntry("S&tart Analysis", IDM_kCaosAnalStart);
275 fCaosAnalyse->AddEntry("St&op Analysis", IDM_kCaosAnalStop);
276 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
277 // fCaosAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
278 // fCaosAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
279 fCaosAnalyse->Associate(this);
280 fList->Add(fCaosAnalyse);
281
282 fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
283 fMenu->AddPopup("&Display", fDisplay, NULL);
284 fMenu->AddPopup("&WritePics", fWritePictures, NULL);
285 fMenu->AddPopup("&Setup", fSetup, NULL);
286 fMenu->Resize(fMenu->GetDefaultSize());
287 fMenu->BindKeys(this);
288 AddFrame(fMenu);
289 fList->Add(fMenu);
290
291 fCaOs = new MGPopupMenu(p);
292 fCaOs->AddPopup("&Write", fCaosWrite);
293 fCaOs->AddPopup("&Print", fCaosPrint);
294 fCaOs->AddPopup("&Analyse", fCaosAnalyse);
295 fCaOs->Associate(this);
296 fCaOs->BindKeys(fMenu, this);
297 fList->Add(fCaOs);
298
299 TGLayoutHints *hints2a =
300 new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|
301 kLHintsExpandX|kLHintsExpandY,1,1);
302 fList->Add(hints2a);
303
304 fGStarg = new MGStarg(this, 235);
305 fGStarg->Move(530,596+5);
306 fList->Add(fGStarg);
307
308 fCRaDec = new MGCoordinates(this, kETypeRaDec);
309 fCRaDec->Move(4, fMenu->GetDefaultHeight()+584);
310 AddFrame(fCRaDec);
311 fList->Add(fCRaDec);
312
313 fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
314 fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+581+12);
315 AddFrame(fCZdAz);
316 fList->Add(fCZdAz);
317
318 fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
319 fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+627+2*12);
320 AddFrame(fPZdAz);
321 fList->Add(fPZdAz);
322
323 fDZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
324 fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+673+3*12);
325 AddFrame(fDZdAz);
326 fList->Add(fDZdAz);
327
328 fSZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
329 fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+719+4*12);
330 AddFrame(fSZdAz);
331 fList->Add(fSZdAz);
332
333 fTPoint = new TGTextButton(this, "TPoint");
334 fTPoint->Move(4, fMenu->GetDefaultHeight()+722+3*12+25);
335 fTPoint->AllowStayDown(kTRUE);
336 AddFrame(fTPoint);
337 fList->Add(fTPoint);
338
339 fFps = new TGLabel(this, "---fps");
340 fFps->SetTextJustify(kTextRight);
341 fFps->Move(650-440, fMenu->GetDefaultHeight()+619+13+60+20);
342 AddFrame(fFps);
343 fList->Add(fFps);
344
345 fPosZoom = new TGLabel(this, "----.--d/----.--d (----, ----)");
346 fPosZoom->SetTextJustify(kTextRight);
347 fPosZoom->Move(4, fMenu->GetDefaultHeight()+765);
348 AddFrame(fPosZoom);
349 fList->Add(fPosZoom);
350
351 fSkyBright = new TGLabel(this, "Sky Brightness: --- ");
352 fSkyBright->SetTextJustify(kTextLeft);
353 fSkyBright->Move(4, fMenu->GetDefaultHeight()+785);
354 AddFrame(fSkyBright);
355 fList->Add(fSkyBright);
356
357 TGLabel *l = new TGLabel(this, "arcsec/pix");
358 l->SetTextJustify(kTextLeft);
359 l->Move(605-400, fMenu->GetDefaultHeight()+619+13+60);
360 AddFrame(l);
361 fList->Add(l);
362
363 l = new TGLabel(this, "deg");
364 l->SetTextJustify(kTextLeft);
365 l->Move(605-410, fMenu->GetDefaultHeight()+619-10+60);
366 AddFrame(l);
367 fList->Add(l);
368
369 l = new TGLabel(this, "Telescope pointing at");
370 l->SetTextJustify(kTextLeft);
371 l->Move(240+12+20, fMenu->GetDefaultHeight()+584-5);
372 AddFrame(l);
373 fList->Add(l);
374
375 l = new TGLabel(this, "Starguider position");
376 l->SetTextJustify(kTextLeft);
377 l->Move(240+12+20, fMenu->GetDefaultHeight()+630+12-5);
378 AddFrame(l);
379 fList->Add(l);
380
381 l = new TGLabel(this, "Misspointing");
382 l->SetTextJustify(kTextLeft);
383 l->Move(240+12+20, fMenu->GetDefaultHeight()+676+2*12-5);
384 AddFrame(l);
385 fList->Add(l);
386
387#ifdef EXPERT
388 l = new TGLabel(this, "Misspointing/FindStar (Experts Only!)");
389 l->SetTextJustify(kTextLeft);
390 l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*12-5);
391 AddFrame(l);
392 fList->Add(l);
393#endif
394
395 const Double_t pixsize = 48.8; // used to be 23.4
396
397 fSao->SetPixSize(pixsize);
398 fSao->SetRotationAngle(0);
399
400 TString txt;
401 txt += pixsize;
402
403 fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
404 fPixSize->SetAlignment(kTextCenterX);
405 fPixSize->Move(547-410, fMenu->GetDefaultHeight()+617+13+60);
406 AddFrame(fPixSize);
407 fList->Add(fPixSize);
408
409 fAngle = new TGTextEntry(this, " 0", IDM_kAngle);
410 fAngle->SetAlignment(kTextCenterX);
411 fAngle->Move(547-410, fMenu->GetDefaultHeight()+617-10+60);
412 AddFrame(fAngle);
413 fList->Add(fAngle);
414
415 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
416 // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
417 // fList->Add(fLineSep);
418
419 //
420 // Create Image Display
421 //
422 fZoomImage = new MGImage(this, kZOOM, kZOOM);
423 // fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
424 fZoomImage->Move(4, 700-kZOOM-2+85);
425 AddFrame(fZoomImage);
426 fList->Add(fZoomImage);
427
428 fImage = new MGImage(this, 768, 576);
429 fImage->Move(0, fMenu->GetDefaultHeight());
430 AddFrame(fImage);
431 fList->Add(fImage);
432
433 //
434 // Make everything visible
435 //
436 SetWindowName("MStarguider Main Window");
437 SetIconName("MStarguider");
438
439 MapSubwindows();
440 fTPoint->UnmapWindow();
441 fGStarg->UnmapWindow();
442 fPZdAz->UnmapWindow();
443 fDZdAz->UnmapWindow();
444 fSZdAz->UnmapWindow();
445 fSkyBright->UnmapWindow();
446 MapWindow();
447
448
449 //IconifyWindow();
450
451 //------------------------------------------------------------
452 // XY xy(3.819444, 24.05333);
453 // fCRaDec->SetCoordinates(xy);
454 // fRaDec->Set(xy.X()*360/24, xy.Y());
455 //------------------------------------------------------------
456}
457
458MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel)
459 : TGMainFrame(gClient->GetRoot(), 768, 840), fCosy(NULL), fOutTp(0), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2), fStatus(MDriveCom::kStandby)
460{
461
462 cout << " #### FIXME: Make MCaos Thread safe!" << endl;
463
464 fSao = new StarCatalog(obs);
465 fRaDec = new RaDec(180, 40);
466
467 // fStargLeds = new MStargLeds;
468 // fStargLeds->ReadResources();
469
470 fCaos = new MCaos;
471 fCaos->ReadResources();
472
473 fStargCaos = new MCaos;
474 fStargCaos->ReadResources("stargleds.txt");
475 fStargCaos->SetMinNumberRings(2);
476 fStargCaos->SetRadii(158,164);
477
478 fStargHistograms = new MStargHistograms();
479
480 InitGui(channel);
481
482 fTimer=new TTimer(this, 1000/25); // 40ms
483 fTimer->TurnOn();
484
485 fTime.Now();
486
487 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
488
489 if (channel<0)
490 fGetter=new PngReader(*this);
491 else
492 {
493 fGetter = new Camera(*this, channel);
494 ((Camera*)fGetter)->Loop(0);
495 }
496}
497
498MStarguider::~MStarguider()
499{
500 fGetter->ExitLoop();
501 delete fGetter;
502
503 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
504
505 fTimer->TurnOff();
506 delete fTimer;
507
508 delete fList;
509
510 delete fCaos;
511 delete fStargCaos;
512 // delete fStargLeds;
513 delete fStargHistograms;
514 delete fSao;
515 delete fRaDec;
516
517 if (fOutTp)
518 delete fOutTp;
519
520 cout << "Camera Display destroyed." << endl;
521}
522
523void MStarguider::Layout()
524{
525 // Resize(GetDefaultSize());
526}
527
528void MStarguider::CloseWindow()
529{
530 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
531
532 //fClient.ExitLoop();
533 // cout << "FIXME: ExitLoop not called!!!!!!" << endl;
534 gSystem->ExitLoop();
535}
536
537void MStarguider::Toggle(MGPopupMenu *p, UInt_t id)
538{
539 if (p->IsEntryChecked(id))
540 p->UnCheckEntry(id);
541 else
542 p->CheckEntry(id);
543}
544
545Bool_t MStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
546{
547 switch (GET_MSG(msg))
548 {
549 case kC_TEXTENTRY:
550 if (GET_SUBMSG(msg)==kTE_ENTER)
551 switch (mp1)
552 {
553 case IDM_kPixSize:
554 {
555 const Float_t pixsize = atof(fPixSize->GetText());
556 cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl;
557 fSao->SetPixSize(pixsize);
558 return kTRUE;
559 }
560 case IDM_kAngle:
561 {
562 const Float_t angle = atof(fAngle->GetText());
563 cout << "Rotation Angle changed to " << angle << "deg" << endl;
564 fSao->SetRotationAngle(angle);
565 return kTRUE;
566 }
567 }
568 return kTRUE;
569
570 case kC_COMMAND:
571 switch (GET_SUBMSG(msg))
572 {
573 case kCM_MENU:
574 switch (mp1)
575 {
576 case IDM_kCatalog:
577 Toggle(fDisplay, IDM_kCatalog);
578// if (!fDisplay->IsEntryChecked(IDM_kCatalog))
579// {
580// fDisplay->UnCheckEntry(IDM_kStarguider);
581// fDisplay->DisableEntry(IDM_kStarguider);
582// } else {
583// fDisplay->EnableEntry(IDM_kStarguider);
584// }
585 return kTRUE;
586
587 case IDM_kStargFindStar:
588 Toggle(fDisplay, IDM_kStargFindStar);
589 if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) {
590 fSZdAz->MapWindow();
591 } else {
592 fSZdAz->UnmapWindow();
593 }
594 return kTRUE;
595
596 case IDM_kStarguider:
597 Toggle(fDisplay, IDM_kStarguider);
598
599 if (fDisplay->IsEntryChecked(IDM_kStarguider)) {
600
601 fLastBright = 0xff;
602
603 fDisplay->DisableEntry(IDM_kFindStar);
604 fDisplay->EnableEntry(IDM_kStargAnalysis);
605
606 fPZdAz->MapWindow();
607 fDZdAz->MapWindow();
608 fSkyBright->MapWindow();
609
610 fSao->SetLimitMag(8.3);
611 fIntRate = 125;
612
613 fDisplay->CheckEntry(IDM_kCatalog);
614 fGStarg->MapWindow();
615
616 const Int_t ch0 =
617 fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
618 const Int_t ch1 = 0;
619
620 if (ch0!=ch1)
621 {
622
623 delete fGetter;
624 usleep(150000); // FIX: Device or resource busy.
625 fGetter = new Camera(*this, ch1);
626 ((Camera*)fGetter)->Loop(0);
627 }
628
629 fChannel->CheckEntry(IDM_kChannel1);
630 fChannel->UnCheckEntry(IDM_kChannel2);
631 fChannel->DisableEntry(IDM_kChannel2);
632
633 } else {
634
635 fStatus = MDriveCom::kStandby;
636
637 fPZdAz->UnmapWindow();
638 fDZdAz->UnmapWindow();
639 fSkyBright->UnmapWindow();
640 fGStarg->UnmapWindow();
641 fChannel->EnableEntry(IDM_kChannel2);
642 fDisplay->EnableEntry(IDM_kFindStar);
643 fDisplay->DisableEntry(IDM_kStargAnalysis);
644 }
645
646 gSystem->Unlink("tracking_error.txt");
647
648 return kTRUE;
649
650 case IDM_kStargAnalysis:
651 Toggle(fDisplay, IDM_kStargAnalysis);
652 if (fDisplay->IsEntryChecked(IDM_kStargAnalysis)) {
653 fStargHistograms->OpenFile();
654 } else {
655 fStargHistograms->CloseFile();
656 }
657
658 return kTRUE;
659
660 case IDM_kStargHistograms:
661 Toggle(fDisplay, IDM_kStargHistograms);
662 return kTRUE;
663
664 case IDM_kStargLEDFilter:
665 Toggle(fDisplay, IDM_kStargLEDFilter);
666 return kTRUE;
667
668 case IDM_kFilter:
669 Toggle(fDisplay, IDM_kFilter);
670 return kTRUE;
671
672// case IDM_kFilterStarg:
673// Toggle(fDisplay, IDM_kFilterStarg);
674// if (fDisplay->IsEntryChecked(IDM_kFilterStarg))
675// fDisplay->EnableEntry(IDM_kStarguider);
676// else
677// {
678// fDisplay->UnCheckEntry(IDM_kStarguider);
679// fDisplay->DisableEntry(IDM_kStarguider);
680// }
681// return kTRUE;
682
683 case IDM_kFindStar:
684 Toggle(fDisplay, IDM_kFindStar);
685 if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
686 fTPoint->MapWindow();
687 else
688 {
689 fTPoint->UnmapWindow();
690 fTPoint->SetDown(kFALSE);
691 }
692 return kTRUE;
693
694 case IDM_kStretch:
695 Toggle(fDisplay, IDM_kStretch);
696 return kTRUE;
697
698 case IDM_kCaosFilter:
699 //if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
700 // fCaos->OpenFile();
701 Toggle(fDisplay, IDM_kCaosFilter);
702 if (fDisplay->IsEntryChecked(IDM_kCaosFilter)) {
703 fMenu->AddPopup("&CaOs", fCaOs, NULL);
704 }
705 else
706 {
707 if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintLeds))
708 fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds);
709 if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintRings))
710 fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings);
711 if(fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop))
712 {
713 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
714 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
715 fCaos->DeleteHistograms();
716 }
717 if(fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop))
718 {
719 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
720 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
721 fCaos->CloseFile();
722 }
723 fMenu->RemovePopup("CaOs");
724 }
725 fMenu->Resize(fMenu->GetDefaultSize());
726 MapSubwindows(); // maps everything, but we don't want that
727 fTPoint->UnmapWindow();
728 fGStarg->UnmapWindow();
729 fPZdAz->UnmapWindow();
730 fDZdAz->UnmapWindow();
731 fSZdAz->UnmapWindow();
732 fSkyBright->UnmapWindow();
733 MapWindow();
734 return kTRUE;
735
736 case IDM_kStargCaosFilter:
737 Toggle(fDisplay, IDM_kStargCaosFilter);
738 if (fDisplay->IsEntryEnabled(IDM_kStargCaosFilter)) {
739 fDisplay->EnableEntry(IDM_kStargFindStar);
740 } else {
741 fDisplay->DisableEntry(IDM_kStargFindStar);
742 }
743 return kTRUE;
744
745 case IDM_kCaosPrintLeds:
746 case IDM_kCaosPrintRings:
747 Toggle(fCaosPrint, mp1);
748 return kTRUE;
749
750 case IDM_kCaosAnalStart:
751 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStart);
752 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStop);
753 fCaos->InitHistograms();
754 return kTRUE;
755
756 case IDM_kCaosAnalStop:
757 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
758 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
759 fCaos->ShowHistograms();
760 fCaos->DeleteHistograms();
761 return kTRUE;
762
763 case IDM_kCaosWriteStart:
764 fCaosWrite->DisableEntry(IDM_kCaosWriteStart);
765 fCaosWrite->EnableEntry(IDM_kCaosWriteStop);
766 fCaos->OpenFile();
767 return kTRUE;
768
769 case IDM_kCaosWriteStop:
770 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
771 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
772 fCaos->CloseFile();
773 return kTRUE;
774
775 case IDM_kStart:
776 fWritePictures->DisableEntry(IDM_kStart);
777 fWritePictures->EnableEntry(IDM_kStop);
778 return kTRUE;
779
780 case IDM_kStop:
781 fWritePictures->DisableEntry(IDM_kStop);
782 fWritePictures->EnableEntry(IDM_kStart);
783 return kTRUE;
784
785 case IDM_kPNG:
786 fFileType->CheckEntry(IDM_kPNG);
787 fFileType->UnCheckEntry(IDM_kPPM);
788 return kTRUE;
789
790 case IDM_kPPM:
791 fFileType->CheckEntry(IDM_kPPM);
792 fFileType->UnCheckEntry(IDM_kPNG);
793 return kTRUE;
794
795 case IDM_kOnce:
796 fWriteType->CheckEntry(IDM_kOnce);
797 fWriteType->UnCheckEntry(IDM_kContinous);
798 return kTRUE;
799
800 case IDM_kContinous:
801 fWriteType->CheckEntry(IDM_kContinous);
802 fWriteType->UnCheckEntry(IDM_kOnce);
803 return kTRUE;
804
805 case IDM_kRate25ps:
806 case IDM_kRate5ps:
807 case IDM_kRate1s:
808 case IDM_kRate5s:
809 case IDM_kRate30s:
810 case IDM_kRate1m:
811 case IDM_kRate5m:
812 for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
813 if (mp1==i)
814 fWriteRate->CheckEntry(i);
815 else
816 fWriteRate->UnCheckEntry(i);
817 switch (mp1)
818 {
819 case IDM_kRate25ps:
820 fWrtRate = 1;
821 return kTRUE;
822 case IDM_kRate5ps:
823 fWrtRate = 5;
824 return kTRUE;
825 case IDM_kRate1s:
826 fWrtRate = 25;
827 return kTRUE;
828 case IDM_kRate5s:
829 fWrtRate = 5*25;
830 return kTRUE;
831 case IDM_kRate30s:
832 fWrtRate = 30*25;
833 return kTRUE;
834 case IDM_kRate1m:
835 fWrtRate = 60*25;
836 return kTRUE;
837 case IDM_kRate5m:
838 fWrtRate = 5*60*25;
839 return kTRUE;
840 }
841 return kTRUE;
842
843 case IDM_kChannel1:
844 case IDM_kChannel2:
845 {
846 const Int_t ch0 = fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
847 const Int_t ch1 = mp1==IDM_kChannel1 ? 0 : 1;
848
849 if (ch0==ch1)
850 return kTRUE;
851
852 fChannel->CheckEntry (ch1==0?IDM_kChannel1:IDM_kChannel2);
853 fChannel->UnCheckEntry(ch1==1?IDM_kChannel1:IDM_kChannel2);
854 delete fGetter;
855 usleep(150000); // FIX: Device or resource busy.
856 fGetter = new Camera(*this, ch1);
857 ((Camera*)fGetter)->Loop(0);
858 }
859 return kTRUE;
860
861 case IDM_kInterpol250:
862 case IDM_kInterpol125:
863 case IDM_kInterpol50:
864 case IDM_kInterpol25:
865 case IDM_kInterpol10:
866 case IDM_kInterpol5:
867 case IDM_kInterpol2:
868 case IDM_kInterpol1:
869 for (int i=IDM_kInterpol250; i<=IDM_kInterpol1; i++)
870 if (mp1==i)
871 fInterpol->CheckEntry(i);
872 else
873 fInterpol->UnCheckEntry(i);
874 switch (mp1)
875 {
876 case IDM_kInterpol1:
877 fIntRate = 1;
878 return kTRUE;
879 case IDM_kInterpol2:
880 fIntRate = 2;
881 return kTRUE;
882 case IDM_kInterpol5:
883 fIntRate = 5;
884 return kTRUE;
885 case IDM_kInterpol10:
886 fIntRate = 10;
887 return kTRUE;
888 case IDM_kInterpol25:
889 fIntRate = 25;
890 return kTRUE;
891 case IDM_kInterpol50:
892 fIntRate = 50;
893 return kTRUE;
894 case IDM_kInterpol125:
895 fIntRate = 125;
896 return kTRUE;
897 case IDM_kInterpol250:
898 fIntRate = 250;
899 return kTRUE;
900 }
901 return kTRUE;
902
903 case IDM_kLimMag3:
904 case IDM_kLimMag4:
905 case IDM_kLimMag5:
906 case IDM_kLimMag6:
907 case IDM_kLimMag7:
908 case IDM_kLimMag8:
909 case IDM_kLimMag9:
910 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
911 if (mp1==i)
912 fLimMag->CheckEntry(i);
913 else
914 fLimMag->UnCheckEntry(i);
915
916 fSao->SetLimitMag(mp1-IDM_kLimMag3+3);
917 return kTRUE;
918 }
919 break;
920 }
921 break;
922 }
923
924 return kTRUE;
925}
926
927void MStarguider::SetPointingPosition(RaDec rd)
928{
929 rd.Ra(rd.Ra()*24/360);
930 fCRaDec->SetCoordinates(rd);
931}
932
933ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag) const
934{
935 //
936 // Viewable area (FIXME: AZ)
937 //
938 // TH2F h("Hist", "dX/dY", 77, -768/2-.5, 768/2+.5, 58, -576/2-.5, 576/2+.5); // 3
939 // chose a bit coarser binning to enhance excess
940 // important: chose binning symmetrical around (0|0)!
941 TH2F h("Hist", "dX/dY", 49, -768/2-8, 768/2+8, 37, -576/2-8, 576/2+8); // 3
942
943// TH1F hmag("HistMag", "Mag", 19, 0, 100);
944// for (int i=0; i<mag.GetSize(); i++)
945// hmag.Fill(mag[i]);
946
947 //
948 // Search for matching Magnitudes
949 //
950 for (int i=0; i<mag.GetSize(); i++)
951 {
952 if (mag[i]>48-15 && mag[i]<48+15)
953 h.Fill(x[i], y[i]);
954 }
955
956 //
957 // Search for an excess in the histogram
958 //
959 Int_t mx, my, dummy;
960 h.GetMaximumBin(mx, my, dummy);
961
962 const double xmax = h.GetXaxis()->GetBinCenter(mx);
963 const double dx = h.GetXaxis()->GetBinWidth(mx);
964
965 const double ymax = h.GetYaxis()->GetBinCenter(my);
966 const double dy = h.GetYaxis()->GetBinWidth(my);
967
968#ifdef EXPERT
969 cout << setprecision(3);
970 cout << "Cut-XY: " << xmax << " +- " << dx << " / " << ymax << " +- " << dy << endl;
971#endif
972
973 TGraph g;
974 for (int i=0; i<mag.GetSize(); i++)
975 {
976 if (!(x[i]>xmax-dx && x[i]<xmax+dx &&
977 y[i]>ymax-dy && y[i]<ymax+dy /*&&
978 mag[i]>48-15 && mag[i]<48+15*/))
979 continue;
980
981 g.SetPoint(g.GetN(), x[i], y[i]);
982 }
983
984#ifdef EXPERT
985 cout << "Offset-XY: " << g.GetMean(1) << " +- " << g.GetRMS(1) << " / ";
986 cout << g.GetMean(2) << " +- " << g.GetRMS(2) << endl;
987#endif
988
989 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg;
990 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+g.GetMean(1), 576/2+g.GetMean(2))*kRad2Deg;
991
992 ofstream fout1("pointingpos.txt");
993 fout1 << setprecision(10) << fSao->GetMjd()-52000 << " ";
994 if (fCosy)
995 fout1 << fCosy->GetPointingPos() << " ";
996 fout1 << -pos1.Alt() << " " << pos1.Az() << endl;
997
998 pos1 -= pos0;
999
1000 ofstream fout2("tracking_error.txt", ios::app);
1001 fout2 << setprecision(10) << fSao->GetMjd()-52000 << " ";
1002 if (fCosy)
1003 fout2 << fCosy->GetPointingPos() << " ";
1004 fout2 << -pos1.Alt() << " " << pos1.Az() << endl;
1005
1006// if (g.GetMean(1)>9 || g.GetMean(2)>9) {
1007// TFile f1("sguider-highoffset.root","UPDATE");
1008// h.Write();
1009// hmag.Write();
1010// g.Write();
1011// f1.Close();
1012// } else {
1013// TFile f1("sguider-niceoffset.root","UPDATE");
1014// h.Write();
1015// hmag.Write();
1016// g.Write();
1017 // f1.Close();
1018
1019
1020// }
1021
1022 return ZdAz(-pos1.Alt(), pos1.Az());
1023}
1024
1025bool MStarguider::CalcTrackingError(Leds &leds, MStarList &stars, ZdAz &d, MTime &t)
1026{
1027 const Int_t max = leds.GetEntries();
1028 if (stars.GetRealEntries() < 3)
1029 {
1030 cout << "Sorry, less than 3 stars in FOV!" << endl;
1031 return kFALSE;
1032 }
1033 if (max < 3) //was 1
1034 {
1035 cout << "Sorry, less than 3 detected spot in FOV!" << endl;
1036 return kFALSE;
1037 }
1038
1039 stars.Sort(); // Sort by magnitude
1040
1041#ifdef EXPERT
1042 TString str = "data/tracking_";
1043 str += fSao->GetMjd();
1044 str += ".txt";
1045
1046 ofstream fout(str);
1047#endif
1048
1049 TArrayF x, y, mag;
1050
1051 Int_t num = 0;
1052
1053 // FIXME: Is predefined value 3 a good idea?
1054
1055 MStar *star;
1056 MStarListIter NextStar(&stars);
1057 while ((star=NextStar()) && num++<max+3)
1058 {
1059 TIter NextSp(&leds);
1060 Led *spot=NULL;
1061 while ((spot=(Led*)NextSp()))
1062 {
1063 const XY dpos(spot->GetX()-(768-star->GetX()), spot->GetY()-star->GetY());
1064
1065 const Int_t idx = x.GetSize();
1066
1067 x.Set(idx+1);
1068 y.Set(idx+1);
1069 mag.Set(idx+1);
1070
1071 x.AddAt(dpos.X(), idx);
1072 y.AddAt(dpos.Y(), idx);
1073 mag.AddAt(spot->GetMag()/star->GetMag(), idx);
1074#ifdef EXPERT
1075 if (fout) {
1076 fout << spot->GetX() << " "
1077 << spot->GetY() << " "
1078 << spot->GetMag() << " "
1079 << star->GetX() << " "
1080 << star->GetY() << " "
1081 << star->GetMag() << " ";
1082 fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
1083 }
1084#endif
1085 }
1086 }
1087
1088 d = TrackingError(x, y, mag);
1089 fDZdAz->SetCoordinates(d);
1090
1091 //
1092 // Calculated offsets
1093 //
1094
1095#ifdef EXPERT
1096 // round= floor(x+.5)
1097 cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
1098 cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
1099#endif
1100
1101 //
1102 // Current Pointing position
1103 //
1104 ZdAz cpos = fSao->GetZdAz()-d;
1105 fPZdAz->SetCoordinates(cpos);
1106
1107 return kTRUE;
1108
1109}
1110
1111ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)
1112{
1113 // Set search Paremeters (FIXME: Get them from user input!)
1114 f.SetCut(cut); // 3.5
1115 f.SetBox(box); // 70
1116
1117 // Try to find Led in this area
1118 Leds leds;
1119 f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
1120
1121 // Check whether star found
1122 Led *star = (Led*)leds.At(0);
1123 if (!star || leds.GetEntries()<1)
1124 return ZdAz(.0,.0);
1125
1126 cout << "Found star @ " << flush;
1127 star->Print();
1128 f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
1129
1130 // Initialize Star Catalog on th camera plane
1131 MGeomCamMagic geom;
1132 MAstroCamera ac;
1133 ac.SetGeom(geom);
1134 ac.SetRadiusFOV(3);
1135 ac.SetObservatory(*fSao);
1136 ac.SetTime(t);
1137
1138 // Get tracking coordinates
1139 const XY xy = fCRaDec->GetCoordinates();
1140 const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
1141
1142 ac.SetRaDec(rd.Ra(), rd.Dec());
1143
1144 // Adapt coordinate system (GUIs and humans are counting Y in different directions)
1145 Double_t x = star->GetX()-center.GetX();
1146 Double_t y = center.GetY()-star->GetY();
1147
1148 cout << "STAR-Offset: " << MTime(-1) << " dx=" << x << "pix dy=" << y << "pix" << endl;
1149
1150 // Convert from Pixel to millimeter (1pix=2.9mm)
1151 x *= (2.58427 * scalefactor);
1152 y *= (2.58427 * scalefactor);
1153
1154 // Correct for abberation.
1155 x /= 1.0713;
1156 y /= 1.0713;
1157
1158 // Calculate Offset
1159 Double_t dzd, daz;
1160 ac.GetDiffZdAz(x, y, dzd, daz);
1161
1162 cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d dAz=" << daz << "d" << endl;
1163
1164 ZdAz zdaz(dzd,daz);
1165
1166 // Check TPoint data set request
1167 if (!fTPoint->IsDown())
1168 return zdaz;
1169 fTPoint->SetDown(kFALSE);
1170
1171 // If no file open: open new file
1172 if (!fOutTp)
1173 {
1174 //
1175 // open tpoint file
1176 //
1177 const TString name = MCosy::GetFileName("tpoint/starg_%s.txt");
1178 cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
1179
1180 fOutTp = new ofstream(name);
1181 *fOutTp << "Magic Model TPOINT data file" << endl;
1182 *fOutTp << ": ALTAZ" << endl;
1183 *fOutTp << "49 48 0 ";
1184 *fOutTp << t << endl;
1185 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
1186 }
1187
1188 // Output Ra/Dec the drive system thinks that it is currently tracking
1189 cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;
1190
1191 // From the star position in the camera we calculate the Alt/Az
1192 // position we are currently tracking (real pointing position)
1193 fSao->SetMjd(t.GetMjd());
1194 AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
1195
1196 //ZdAz za0 = fSao->GetZdAz();
1197 za0 -= AltAz(-dzd, daz);
1198
1199 // From the Shaftencoders we get the current 'pointing' position
1200 // as it is seen by the drive system (system pointing position)
1201 const ZdAz za1 = fCosy->GetTrackingPosRaw();
1202
1203 // Write real pointing position
1204 cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
1205 *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
1206
1207 // Write system pointing position
1208 cout << " SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
1209 *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd();
1210
1211 *fOutTp << " " << xy.X() << " " << xy.Y();
1212 *fOutTp << " " << -dzd << " " << -daz;
1213 *fOutTp << " " << setprecision(11) << t.GetMjd();
1214 *fOutTp << " " << setprecision(4) << center.GetMag();
1215 *fOutTp << " " << star->GetMag();
1216 *fOutTp << endl;
1217
1218 MLog &outrep = *fCosy->GetOutRep();
1219 if (outrep.Lock("MStarguider::FindStar"))
1220 {
1221 outrep << "FINDSTAR-REPORT " << MTime(-1) << " " << setprecision(7);
1222 outrep << 90-za0.Alt() << " " << za0.Az() << " ";
1223 outrep << za1.Zd() << " " << za1.Az() << " ";
1224 outrep << xy.X() << " " << xy.Y() << " ";
1225 outrep << -dzd << " " << -daz << " ";
1226 outrep << star->GetX() << " " << star->GetY() << " ";
1227 outrep << center.GetX() << " " << center.GetY() << " ";
1228 outrep << x*1.0713/2.58427 << " " << y*1.0713/2.58427 << " " << star->GetMag();
1229 outrep << setprecision(11) << t.GetMjd() << endl;
1230 outrep.UnLock("MStarguider::FindStar");
1231 }
1232
1233 return zdaz;
1234}
1235
1236bool MStarguider::Interpolate(const unsigned long n, byte *img) const
1237{
1238 if (fIntRate<=1)
1239 return true;
1240
1241 static unsigned short myimg[768*576];
1242
1243 unsigned short *f = myimg;
1244 byte *i = img;
1245 byte *e = img+768*576;
1246
1247 while (i<e)
1248 *f++ += *i++;
1249
1250 if (n%fIntRate)
1251 return false;
1252
1253 f = myimg;
1254 i = img;
1255 e = img+768*576;
1256
1257 while (i<e)
1258 *i++ = (byte)(*f++/fIntRate);
1259
1260 memset(myimg, 0, sizeof(myimg));
1261
1262 return true;
1263}
1264
1265void MStarguider::ProcessFrame(const unsigned long n, byte *img,
1266 struct timeval *tm)
1267{
1268 static unsigned long n0 = n;
1269
1270 MTime t(*tm);
1271
1272 const Double_t d = t-fTime;
1273 if (d>1)
1274 {
1275 MString txt;
1276 txt.Print("%dfps", (int)((n-n0)/d+.5));
1277 fFps->SetText(txt);
1278 fTime = t;
1279 n0 = n;
1280 }
1281
1282 if (!Interpolate(n, img))
1283 return;
1284
1285 byte cimg[768*576];
1286 memset(cimg, 0, 768*576);
1287
1288 FilterLed f(img, 768, 576, 2.5); // 2.5
1289 FilterLed f2(cimg, 768, 576); // former color 0xb0
1290
1291 if (fDisplay->IsEntryChecked(IDM_kStretch))
1292 f.Stretch();
1293
1294 if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
1295 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
1296 {
1297
1298 if (fFileType->IsEntryChecked(IDM_kPNG))
1299 Writer::Png("pix/file", img, tm, fCRaDec->GetCoordinates());
1300
1301 if (fFileType->IsEntryChecked(IDM_kPPM))
1302 Writer::Ppm("pix/file", img, tm, fCRaDec->GetCoordinates());
1303
1304 if (fWriteType->IsEntryChecked(IDM_kOnce))
1305 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
1306 }
1307
1308 // Visual Filter, whole FOV
1309 if (fDisplay->IsEntryChecked(IDM_kFilter))
1310 f.Execute();
1311
1312 /* ----------------------------------
1313 // Visual StarFilter for Starguider
1314 if (fDisplay->IsEntryChecked(IDM_kFilterStarg) && !fDisplay->IsEntryChecked(IDM_kStarguider)) {
1315 f.SetBox(230);
1316 f.AddIgnoreRegion(295,112,384,204);
1317 f.Execute(530, 292);
1318 }
1319 ------------------------------------- */
1320
1321 // Find Center of Camera for Caos and Tpoints
1322 Ring center(768/2, 576/2);
1323 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
1324 {
1325 const bool printl = fCaosPrint->IsEntryChecked(IDM_kCaosPrintLeds);
1326 const bool printr = fCaosPrint->IsEntryChecked(IDM_kCaosPrintRings);
1327 ZdAz pos;
1328 if (fCosy)
1329 pos = fCosy->GetPointingPos();
1330 center = fCaos->Run(img, printl, printr, pos, t, 50, 3.0);
1331 }
1332
1333 // Find Star at Center---for Tpoint Procedure
1334 if (fDisplay->IsEntryChecked(IDM_kFindStar))
1335 ZdAz zdaz = FindStar(f, f2, center, t, 3.5, 70);
1336
1337 byte zimg[kZOOM*kZOOM];
1338 for (int y=0; y<kZOOM; y++)
1339 for (int x=0; x<kZOOM; x++)
1340 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
1341
1342 fZoomImage->DrawImg(zimg);
1343
1344 if (fCosy)
1345 {
1346 byte simg[(768/2-1)*(576/2-1)];
1347 for (int y=0; y<576/2-1; y++)
1348 for (int x=0; x<768/2-1; x++)
1349 simg[x+y*(768/2-1)] = ((unsigned int)img[2*x+2*y*768]+img[2*x+2*y*768+1]+img[2*x+2*(y+1)*768]+img[2*x+2*(y+1)*768+1])/4;
1350
1351 fCosy->GetWin()->GetImage()->DrawImg(simg);
1352 }
1353
1354 // Find Center of Camera in Starfield Camera picture
1355
1356 Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px]
1357 ZdAz sgcenterzdaz(0, 0); // Center of camera in SG picture [deg]
1358 // (0,0)_deg is at (53.2, 293.6)_px
1359 ZdAz star(0, 0); // Star on curtain in [deg]
1360
1361 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
1362 {
1363 ZdAz pos;
1364 if (fCosy)
1365 pos = fCosy->GetPointingPos();
1366 sgcenter =
1367 fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 30, 3.0); // [px]
1368 const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px]
1369 sgcenterzdaz.Zd((sgcenter.GetY()-293.6) * pixsize /3600 );
1370 sgcenterzdaz.Az((sgcenter.GetX()-53.2) * pixsize /3600 );
1371#ifdef EXPERT
1372 cout << "- LEDs imply offset of Zd="
1373 << sgcenter.GetX()-53.2 << "pix Az="
1374 << sgcenter.GetY()-293.6<< "pix" << endl;
1375#endif
1376 if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) {
1377 star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg]
1378#ifdef EXPERT
1379 cout << "- Star is found to be off Zd=" << star.Zd()*60 << "' Az="
1380 << star.Az()*60 << "'" << endl;
1381#endif
1382 fSZdAz->SetCoordinates(star); // Misspointing found from Camera
1383 }
1384 }
1385
1386 // we calculate the offset given by the three ETH Leds visible to
1387 // the guide camera
1388 // This is an (inferior, obsolete) alternative to the StarCaosFilter
1389 // Led offset;
1390 // if (fDisplay->IsEntryChecked(IDM_kStargLEDFilter))
1391 // fStargLeds->Run(img,offset);
1392
1393 // Position corresponding to the camera center (53.2, 293.6)
1394 Ring skycenter(392, 318);
1395 // MStarList spots;
1396
1397 // we obtain a list of stars in the FOV from the SAO catalog
1398 if (fDisplay->IsEntryChecked(IDM_kCatalog))
1399 {
1400 MTime time(*tm);
1401
1402 XY xy = fCRaDec->GetCoordinates();
1403 fRaDec->Set(xy.X()*360/24, xy.Y());
1404
1405 UpdatePosZoom();
1406
1407 // Always call SetMjd first!
1408 fSao->SetPointing(time.GetMjd(), *fRaDec);
1409 fCZdAz->SetCoordinates(fSao->GetZdAz());
1410
1411 MStarList stars;
1412 fSao->SetBox(230); // Region of interest around center
1413
1414 // very careful: If center of camera cannot be determined
1415 // sgcenter jumps to (0,0)
1416 double sgcenteroffsetX = 0.0;
1417 double sgcenteroffsetY = 0.0;
1418 if ((double)sgcenter.GetX() > 0.0 && (double)sgcenter.GetY() > 0.0) {
1419 sgcenteroffsetX = sgcenter.GetX()-53.2;
1420 sgcenteroffsetY = sgcenter.GetY()-293.6;
1421 }
1422
1423 // we obtain stars in the effective star FOV and draw them.
1424 // coordinates are video frame coords.
1425 // We determine the ideal starfield using camera sagging info
1426 // from the LEDs
1427
1428 //cout << sgcenteroffsetX << " " << sgcenteroffsetY << endl;
1429
1430 fSao->CalcStars(stars, 530, 292,
1431 -8+2-3+sgcenteroffsetX, //x: star<spot =>subs
1432 31.5-3+sgcenteroffsetY); //y: star<spot =>subs?
1433
1434 fSao->DrawStars(stars, cimg);
1435
1436 // There are two corrections to the misspointing
1437 // - Sagging of the camera as measured with the LEDs
1438 // - Star not ideally centered on MAGIC Camera
1439
1440 // Next we evaluate the offset given by the LEDs. This we obtain
1441 // in Zd/Az and add it to the tracking error.
1442
1443 if (fDisplay->IsEntryChecked(IDM_kStarguider))
1444 {
1445 Leds spots;
1446 f.SetBox(230);
1447 double bright;
1448 f.ExecuteAndMark(spots, 530, 292, bright);
1449 MString txt;
1450 txt.Print("Sky Brightness: %.1f", bright);
1451 fSkyBright->SetText(txt);
1452
1453 ULong_t color;
1454 gClient->GetColorByName("Green", color);
1455 if (bright> 60) gClient->GetColorByName("Yellow", color);
1456 if (bright> 85) gClient->GetColorByName("Orange", color);
1457 if (bright> 95) gClient->GetColorByName("Red", color);
1458 fSkyBright->SetBackgroundColor(color);
1459
1460 bool rc = CalcTrackingError(spots, stars, fD, t);
1461
1462 if (rc && (bright <= 1.75* fLastBright) && (bright < 110)) {
1463 fStatus = MDriveCom::kMonitoring;
1464 } else {
1465 fStatus = MDriveCom::kError;
1466 }
1467
1468 if (fCosy)
1469 fPos = fCosy->GetPointingPos();
1470
1471 if (fDisplay->IsEntryChecked(IDM_kStargAnalysis))
1472 fStargHistograms->Fill(spots, stars, fD,
1473 fSao->GetZdAz(), sgcenter, sgcenterzdaz,
1474 star, bright, fPos, t);
1475
1476 fLastBright = bright;
1477
1478 } //kStarguider
1479
1480 f2.DrawCircle(skycenter, 2.0, 0x0a);
1481
1482 f2.DrawCircle(skycenter, 7.4, 0x0a); //0.1deg
1483
1484 f2.DrawCircle(skycenter, 2.06*.5*74.0, 0x0a);
1485 f2.DrawCircle(skycenter, 2.32*.5*74.0, 0x0a);
1486 f2.DrawCircle(skycenter, 3.50*.5*74.0, 0x0a);
1487 f2.DrawCircle(skycenter, 3.84*.5*74.0, 0x0a);
1488
1489 } //CalcStars
1490
1491 if (fCosy) {
1492 MDriveCom &com = *fCosy->GetDriveCom();
1493 com.SendStargReport(fStatus, fD); // Report
1494 }
1495
1496 // Draw Circles around center of Camera
1497 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
1498 {
1499 f2.DrawCircle(center, 0x0a);
1500 f2.DrawCircle(center, 5.0,
1501 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
1502 f2.DrawCircle(center, 115.0, 0x0a);
1503 f2.DrawCircle(center, 230.0, 0x0a);
1504 f2.DrawCircle(center, 245.0, 0x0a);
1505 }
1506
1507 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
1508 {
1509 f2.DrawCircle(sgcenter, 0x0a);
1510 f2.DrawCircle(sgcenter, 5.0,
1511 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
1512 }
1513
1514// if (fDisplay->IsEntryChecked(IDM_kCatalog))
1515// {
1516// fSao->PaintImg(cimg, 768, 576);
1517// const float r = 60*60/fSao->GetPixSize();
1518// f2.DrawCircle(0.5*r, 0x0a);
1519// f2.DrawCircle(1.0*r, 0x0a);
1520// f2.DrawCircle(1.5*r, 0x0a);
1521// }
1522
1523 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
1524 fDisplay->IsEntryChecked(IDM_kCatalog) ||
1525 fDisplay->IsEntryChecked(IDM_kFindStar))
1526 fImage->DrawColImg(img, cimg);
1527 else
1528 fImage->DrawImg(img);
1529}
1530
1531void MStarguider::UpdatePosZoom()
1532{
1533 MString txt;
1534 if (fDisplay->IsEntryChecked(IDM_kCatalog))
1535 {
1536 // FIXME: Necessary?
1537 fSao->Now();
1538 AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
1539 if (aa.Az()<0)
1540 aa.Az(aa.Az()+360);
1541 txt.Print("%.1fd/%.1fd (%d, %d)", -aa.Alt(), aa.Az()-180, fDx, fDy);
1542 }
1543 else
1544 txt.Print("(%d, %d)", fDx, fDy);
1545 fPosZoom->SetText(txt);
1546}
1547
1548Bool_t MStarguider::HandleDoubleClick(Event_t *event)
1549{
1550 const Int_t w = fImage->GetWidth();
1551 const Int_t h = fImage->GetHeight();
1552 const Int_t x = fImage->GetX();
1553 const Int_t y = fImage->GetY();
1554
1555 if (!(event->fX>x && event->fX<x+w && event->fY>y && event->fY<y+h))
1556 return kTRUE;
1557
1558 Int_t dx = event->fX-x;
1559 Int_t dy = event->fY-y;
1560
1561 if (dx<kZOOM/4) dx=kZOOM/4;
1562 if (dy<kZOOM/4) dy=kZOOM/4;
1563 if (dx>766-kZOOM/4) dx=766-kZOOM/4;
1564 if (dy>574-kZOOM/4) dy=574-kZOOM/4;
1565
1566 fDx = dx;
1567 fDy = dy;
1568
1569 UpdatePosZoom();
1570 return kTRUE;
1571}
1572
1573void MStarguider::Print(TString &str, Double_t deg) const
1574{
1575 Char_t sgn;
1576 UShort_t d, m, s;
1577
1578 MAstro::Deg2Dms(deg, sgn, d, m, s);
1579
1580 MString txt;
1581 str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s);
1582}
Note: See TracBrowser for help on using the repository browser.