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

Last change on this file since 7764 was 7764, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 67.3 KB
Line 
1#undef 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_kChannel3,
73 IDM_kContinous,
74 IDM_kRate25ps,
75 IDM_kRate5ps,
76 IDM_kRate1s,
77 IDM_kRate5s,
78 IDM_kRate30s,
79 IDM_kRate1m,
80 IDM_kRate5m,
81 IDM_kSetup,
82 IDM_kLimMag3,
83 IDM_kLimMag4,
84 IDM_kLimMag5,
85 IDM_kLimMag6,
86 IDM_kLimMag7,
87 IDM_kLimMag8,
88 IDM_kLimMag9,
89 IDM_kPixSize,
90 IDM_kAngle,
91 IDM_kInterpol250,
92 IDM_kInterpol125,
93 IDM_kInterpol50,
94 IDM_kInterpol25,
95 IDM_kInterpol10,
96 IDM_kInterpol5,
97 IDM_kInterpol2,
98 IDM_kInterpol1,
99 IDM_kCaosPrintRings,
100 IDM_kCaosPrintLeds,
101 IDM_kCaosAnalStart,
102 IDM_kCaosAnalStop,
103 IDM_kCaosWriteStart,
104 IDM_kCaosWriteStop,
105 IDM_kResetHistograms,
106 IDM_kStargAnalysis,
107 IDM_kStargCaosFilter,
108 IDM_kStargFindStar,
109 IDM_kRoqueLampAna,
110 IDM_kStarguiderMode,
111 IDM_kTpointMode
112
113};
114
115Bool_t MStarguider::HandleTimer(TTimer *t)
116{
117 if (IsMapped())
118 {
119 fImage->DoRedraw();
120 fZoomImage->DoRedraw();
121 }
122
123 if (fCosy && fCosy->GetWin()->IsMapped())
124 fCosy->GetWin()->GetImage()->DoRedraw();
125
126 fGStarg->Update(fPos, fD);
127
128 return kTRUE;
129}
130
131#define kZOOM 96
132
133XY MStarguider::GetCoordinates() const
134{
135 return fPZdAz->GetCoordinates();
136}
137
138void MStarguider::InitGui(Int_t channel)
139{
140 fList = new MGList;
141
142 const TGWindow *p=gClient->GetRoot();
143
144 fChannel = new MGPopupMenu(p);
145 fChannel->AddEntry("Starfield Camera", IDM_kChannel1);
146 fChannel->AddEntry("TPoint Camera", IDM_kChannel2);
147 fChannel->AddEntry("Read from File", IDM_kChannel3);
148 if (channel<0)
149 fChannel->CheckEntry(IDM_kChannel3);
150 else
151 fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
152 fChannel->Associate(this);
153 fList->Add(fChannel);
154
155 //
156 // Create Menu for MStarguider Display
157 //
158 fDisplay = new MGPopupMenu(p);
159 fDisplay->AddEntry("&Filter", IDM_kFilter);
160 fDisplay->AddEntry("Find &Star", IDM_kFindStar);
161 fDisplay->AddEntry("C&aos Filter", IDM_kCaosFilter);
162 fDisplay->AddEntry("SAO &Catalog", IDM_kCatalog);
163 fDisplay->AddEntry("Stretch", IDM_kStretch);
164 fDisplay->AddSeparator();
165 fDisplay->AddEntry("Starguider", IDM_kStarguider);
166 fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter);
167 fDisplay->AddEntry("Starguider Find Star", IDM_kStargFindStar);
168 fDisplay->AddSeparator();
169 if (channel>=0)
170 fDisplay->AddPopup("&Input", fChannel);
171 fDisplay->DisableEntry(IDM_kStargFindStar);
172 fDisplay->CheckEntry(IDM_kStretch);
173 fDisplay->Associate(this);
174 fList->Add(fDisplay);
175
176 fMode = new MGPopupMenu(p);
177 fMode->AddEntry("Starguider", IDM_kStarguiderMode);
178 fMode->AddEntry("Tpoint", IDM_kTpointMode);
179 fMode->Associate(this);
180 fList->Add(fMode);
181
182 fOperations = new MGPopupMenu(p);
183 fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
184 fOperations->AddEntry("Starguider Analysis", IDM_kStargAnalysis);
185 fOperations->DisableEntry(IDM_kStargAnalysis);
186 fOperations->Associate(this);
187 fList->Add(fOperations);
188
189
190 fFileType = new MGPopupMenu(p);
191 fFileType->AddEntry("PP&M", IDM_kPPM);
192 fFileType->AddEntry("&PNG", IDM_kPNG);
193 fFileType->CheckEntry(IDM_kPNG);
194 fFileType->Associate(this);
195 fList->Add(fFileType);
196
197 fWriteType = new MGPopupMenu(p);
198 fWriteType->AddEntry("&Once", IDM_kOnce);
199 fWriteType->AddEntry("&Continous", IDM_kContinous);
200 fWriteType->CheckEntry(IDM_kOnce);
201 fWriteType->Associate(this);
202 fList->Add(fWriteType);
203
204 fWriteRate = new MGPopupMenu(p);
205 fWriteRate->AddEntry("25/s", IDM_kRate25ps);
206 fWriteRate->AddEntry("5/s", IDM_kRate5ps);
207 fWriteRate->AddEntry("1s", IDM_kRate1s);
208 fWriteRate->AddEntry("5s", IDM_kRate5s);
209 fWriteRate->AddEntry("30s", IDM_kRate30s);
210 fWriteRate->AddEntry("1min", IDM_kRate1m);
211 fWriteRate->AddEntry("5min", IDM_kRate5m);
212 fWriteRate->CheckEntry(IDM_kRate1m);
213 fWriteRate->Associate(this);
214 fList->Add(fWriteRate);
215
216 fWrtRate = 25*60;
217
218 fWritePictures = new MGPopupMenu(p);
219 fWritePictures->AddEntry("&Start", IDM_kStart);
220 fWritePictures->AddEntry("Sto&p", IDM_kStop);
221 fWritePictures->AddSeparator();
222 fWritePictures->AddPopup("File &Type", fFileType);
223 fWritePictures->AddPopup("&Write Type", fWriteType);
224 fWritePictures->AddPopup("Write &Rate", fWriteRate);
225 fWritePictures->DisableEntry(IDM_kStop);
226 fWritePictures->Associate(this);
227 fList->Add(fWritePictures);
228
229 fLimMag = new MGPopupMenu(p);
230 fLimMag->AddEntry("3", IDM_kLimMag3);
231 fLimMag->AddEntry("4", IDM_kLimMag4);
232 fLimMag->AddEntry("5", IDM_kLimMag5);
233 fLimMag->AddEntry("6", IDM_kLimMag6);
234 fLimMag->AddEntry("7", IDM_kLimMag7);
235 fLimMag->AddEntry("8", IDM_kLimMag8);
236 fLimMag->AddEntry("9", IDM_kLimMag9);
237 fLimMag->CheckEntry(IDM_kLimMag8);
238 fLimMag->Associate(this);
239 fList->Add(fLimMag);
240
241 fSao->SetLimitMag(7.0);
242
243 fInterpol = new MGPopupMenu(p);
244 fInterpol->AddEntry("250", IDM_kInterpol250);
245 fInterpol->AddEntry("125", IDM_kInterpol125);
246 fInterpol->AddEntry("50", IDM_kInterpol50);
247 fInterpol->AddEntry("25", IDM_kInterpol25);
248 fInterpol->AddEntry("10", IDM_kInterpol10);
249 fInterpol->AddEntry("5", IDM_kInterpol5);
250 fInterpol->AddEntry("2", IDM_kInterpol2);
251 fInterpol->AddEntry("Off", IDM_kInterpol1);
252 fInterpol->Associate(this);
253 fList->Add(fInterpol);
254
255 TString disp=gVirtualX->DisplayName();
256 cout << "Display: " << disp << endl;
257 if (disp.First(':')>=0)
258 disp=disp(0, disp.First(':'));
259
260 if (disp.IsNull() || disp==(TString)"localhost")
261 {
262 fInterpol->CheckEntry(IDM_kInterpol5);
263 fIntRate = 50;
264 }
265 else
266 {
267 fInterpol->CheckEntry(IDM_kInterpol125);
268 fIntRate = 125;
269 }
270
271 fSetup = new MGPopupMenu(p);
272 fSetup->AddPopup("Lim. &Magnitude", fLimMag);
273 fSetup->AddPopup("Disp. &Interpolation", fInterpol);
274 //fSetup->AddEntry("Use Ra/Dec from file", IDM_kUseFileRaDec);
275 fSetup->Associate(this);
276 fList->Add(fSetup);
277
278 fCaosPrint = new MGPopupMenu(p);
279 fCaosPrint->AddEntry("&Leds", IDM_kCaosPrintLeds);
280 fCaosPrint->AddEntry("&Rings", IDM_kCaosPrintRings);
281 fCaosPrint->Associate(this);
282 fList->Add(fCaosPrint);
283
284 fCaosWrite = new MGPopupMenu(p);
285 fCaosWrite->AddEntry("&Start", IDM_kCaosWriteStart);
286 fCaosWrite->AddEntry("Sto&p", IDM_kCaosWriteStop);
287 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
288 fCaosWrite->Associate(this);
289 fList->Add(fCaosWrite);
290
291 fCaosAnalyse = new MGPopupMenu(p);
292 fCaosAnalyse->AddEntry("S&tart Analysis", IDM_kCaosAnalStart);
293 fCaosAnalyse->AddEntry("St&op Analysis", IDM_kCaosAnalStop);
294 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
295 // fCaosAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
296 // fCaosAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
297 fCaosAnalyse->Associate(this);
298 fList->Add(fCaosAnalyse);
299
300 fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
301 fMenu->AddPopup("&Display", fDisplay, NULL);
302 fMenu->AddPopup("&Mode", fMode, NULL);
303 fMenu->AddPopup("&WritePics", fWritePictures, NULL);
304 fMenu->AddPopup("&Setup", fSetup, NULL);
305
306 fMenu->AddPopup("&Operations", fOperations, NULL);
307
308 fMenu->Resize(fMenu->GetDefaultSize());
309 fMenu->BindKeys(this);
310 AddFrame(fMenu);
311 fList->Add(fMenu);
312
313 fCaOs = new MGPopupMenu(p);
314 fCaOs->AddPopup("&Write", fCaosWrite);
315 fCaOs->AddPopup("&Print", fCaosPrint);
316 fCaOs->AddPopup("&Analyse", fCaosAnalyse);
317 fCaOs->Associate(this);
318 fCaOs->BindKeys(fMenu, this);
319 fList->Add(fCaOs);
320
321 TGLayoutHints *hints2a =
322 new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|
323 kLHintsExpandX|kLHintsExpandY,1,1);
324 fList->Add(hints2a);
325
326 fGStarg = new MGStarg(this, 235);
327 fGStarg->Move(530,596+5);
328 fList->Add(fGStarg);
329
330 fCRaDec = new MGCoordinates(this, kETypeRaDec);
331 fCRaDec->Move(4, fMenu->GetDefaultHeight()+584);
332 AddFrame(fCRaDec);
333 fList->Add(fCRaDec);
334
335 fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
336 fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+581+12);
337 AddFrame(fCZdAz);
338 fList->Add(fCZdAz);
339
340 fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
341 fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+627+2*12);
342 AddFrame(fPZdAz);
343 fList->Add(fPZdAz);
344
345 fDZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
346 fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+673+3*12);
347 AddFrame(fDZdAz);
348 fList->Add(fDZdAz);
349
350 fSZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
351 fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+719+4*12);
352 AddFrame(fSZdAz);
353 fList->Add(fSZdAz);
354
355 fTPoint = new TGTextButton(this, "TPoint");
356 fTPoint->Move(4, fMenu->GetDefaultHeight()+722+3*12+25);
357 fTPoint->AllowStayDown(kTRUE);
358 AddFrame(fTPoint);
359 fList->Add(fTPoint);
360
361 fStargTPoint = new TGTextButton(this, "StargTPoint");
362 fStargTPoint->Move(240+12+20, fMenu->GetDefaultHeight()+785);
363 fStargTPoint->AllowStayDown(kTRUE);
364 AddFrame(fStargTPoint);
365 fList->Add(fStargTPoint);
366
367 fFps = new TGLabel(this, "---fps");
368 fFps->SetTextJustify(kTextRight);
369 fFps->Move(650-440, fMenu->GetDefaultHeight()+619+13+60+20);
370 AddFrame(fFps);
371 fList->Add(fFps);
372
373 fPosZoom = new TGLabel(this, "----.--d/----.--d (----, ----)");
374 fPosZoom->SetTextJustify(kTextRight);
375 fPosZoom->Move(4, fMenu->GetDefaultHeight()+765);
376 AddFrame(fPosZoom);
377 fList->Add(fPosZoom);
378
379 fSkyBright = new TGLabel(this, "Sky Brightness: --- ");
380 fSkyBright->SetTextJustify(kTextLeft);
381 fSkyBright->Move(4, fMenu->GetDefaultHeight()+785);
382 AddFrame(fSkyBright);
383 fList->Add(fSkyBright);
384
385 TGLabel *l = new TGLabel(this, "arcsec/pix");
386 l->SetTextJustify(kTextLeft);
387 l->Move(605-400, fMenu->GetDefaultHeight()+619+13+60);
388 AddFrame(l);
389 fList->Add(l);
390
391 l = new TGLabel(this, "deg");
392 l->SetTextJustify(kTextLeft);
393 l->Move(605-410, fMenu->GetDefaultHeight()+619-10+60);
394 AddFrame(l);
395 fList->Add(l);
396
397 l = new TGLabel(this, "Telescope pointing at");
398 l->SetTextJustify(kTextLeft);
399 l->Move(240+12+20, fMenu->GetDefaultHeight()+584-5);
400 AddFrame(l);
401 fList->Add(l);
402
403 l = new TGLabel(this, "Starguider position");
404 l->SetTextJustify(kTextLeft);
405 l->Move(240+12+20, fMenu->GetDefaultHeight()+630+12-5);
406 AddFrame(l);
407 fList->Add(l);
408
409 l = new TGLabel(this, "Misspointing");
410 l->SetTextJustify(kTextLeft);
411 l->Move(240+12+20, fMenu->GetDefaultHeight()+676+2*12-5);
412 AddFrame(l);
413 fList->Add(l);
414
415#ifdef EXPERT
416 l = new TGLabel(this, "Misspointing/FindStar (Experts Only!)");
417 l->SetTextJustify(kTextLeft);
418 l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*12-5);
419 AddFrame(l);
420 fList->Add(l);
421#endif
422
423 const Double_t pixsize = 48.8; // used to be 23.4
424
425 fSao->SetPixSize(pixsize);
426 fSao->SetRotationAngle(0);
427
428 TString txt;
429 txt += pixsize;
430
431 fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
432 fPixSize->SetAlignment(kTextCenterX);
433 fPixSize->Move(547-410, fMenu->GetDefaultHeight()+617+13+60);
434 AddFrame(fPixSize);
435 fList->Add(fPixSize);
436
437 fAngle = new TGTextEntry(this, " 0", IDM_kAngle);
438 fAngle->SetAlignment(kTextCenterX);
439 fAngle->Move(547-410, fMenu->GetDefaultHeight()+617-10+60);
440 AddFrame(fAngle);
441 fList->Add(fAngle);
442
443 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
444 // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
445 // fList->Add(fLineSep);
446
447 //
448 // Create Image Display
449 //
450 fZoomImage = new MGImage(this, kZOOM, kZOOM);
451 // fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
452 fZoomImage->Move(4, 700-kZOOM-2+85);
453 AddFrame(fZoomImage);
454 fList->Add(fZoomImage);
455
456 fImage = new MGImage(this, 768, 576);
457 fImage->Move(0, fMenu->GetDefaultHeight());
458 AddFrame(fImage);
459 fList->Add(fImage);
460
461 //
462 // Make everything visible
463 //
464 SetWindowName("MStarguider Main Window");
465 SetIconName("MStarguider");
466
467 MapSubwindows();
468 fTPoint->UnmapWindow();
469 fStargTPoint->UnmapWindow();
470 fGStarg->UnmapWindow();
471 fPZdAz->UnmapWindow();
472 fDZdAz->UnmapWindow();
473 fSZdAz->UnmapWindow();
474 fSkyBright->UnmapWindow();
475 MapWindow();
476
477
478 //IconifyWindow();
479
480 //------------------------------------------------------------
481 // XY xy(3.819444, 24.05333);
482 // fCRaDec->SetCoordinates(xy);
483 // fRaDec->Set(xy.X()*360/24, xy.Y());
484 //------------------------------------------------------------
485}
486
487MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel)
488 : TGMainFrame(gClient->GetRoot(), 768, 840),
489 fCosy(NULL),
490 fOutTp(0),
491 fOutStargTp(0),
492 fOutRq(0),
493 fDx((768-kZOOM)/2),
494 fDy((512-kZOOM)/2),
495 fStatus(MDriveCom::kStandby)
496{
497
498 cout << " #### FIXME: Make MCaos Thread safe!" << endl;
499
500 fSao = new StarCatalog(obs);
501 fRaDec = new RaDec(180, 40);
502
503 // fStargLeds = new MStargLeds;
504 // fStargLeds->ReadResources();
505
506 fCaos = new MCaos;
507 fCaos->ReadResources();
508
509 fStargCaos = new MCaos;
510 fStargCaos->ReadResources("stargleds.txt");
511 fStargCaos->SetMinNumberRings(3);
512 fStargCaos->SetRadii(158,164);
513
514 fStargHistograms = new MStargHistograms();
515
516 InitGui(channel);
517
518 fTimer=new TTimer(this, 1000/25); // 40ms
519 fTimer->TurnOn();
520
521 fTime.Now();
522
523 fTimeFromTp.Set(1970,1,1);
524 fAltAzOffsetFromTp = AltAz(-1000,-1000);
525
526 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
527
528 if (channel<0)
529 fGetter=new PngReader(*this);
530 else
531 {
532 fGetter = new Camera(*this, channel);
533 ((Camera*)fGetter)->Loop(0);
534 }
535}
536
537MStarguider::~MStarguider()
538{
539 fGetter->ExitLoop();
540 delete fGetter;
541
542 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
543
544 fTimer->TurnOff();
545 delete fTimer;
546
547 delete fList;
548
549 delete fCaos;
550 delete fStargCaos;
551 // delete fStargLeds;
552 delete fStargHistograms;
553 delete fSao;
554 delete fRaDec;
555 delete fTPoint;//
556 delete fStargTPoint;//
557
558 if (fOutTp)
559 delete fOutTp;
560
561 if (fOutStargTp)
562 delete fOutStargTp;
563
564 if (fOutRq)
565 delete fOutRq;
566
567 cout << "Camera Display destroyed." << endl;
568}
569
570void MStarguider::Layout()
571{
572 // Resize(GetDefaultSize());
573}
574
575void MStarguider::CloseWindow()
576{
577 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
578
579 //fClient.ExitLoop();
580 // cout << "FIXME: ExitLoop not called!!!!!!" << endl;
581 gSystem->ExitLoop();
582}
583
584void MStarguider::Toggle(MGPopupMenu *p, UInt_t id)
585{
586 if (p->IsEntryChecked(id))
587 p->UnCheckEntry(id);
588 else
589 p->CheckEntry(id);
590}
591
592void MStarguider::ToggleStargAnalysis()
593{
594 if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
595 fStargHistograms->OpenFile();
596 else
597 fStargHistograms->CloseFile();
598}
599
600void MStarguider::ToggleFindStar()
601{
602 if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
603 fTPoint->MapWindow();
604 else
605 {
606 fTPoint->UnmapWindow();
607 fTPoint->SetDown(kFALSE);
608 }
609}
610
611void MStarguider::ToggleStarguider()
612{
613 if (fDisplay->IsEntryChecked(IDM_kStarguider))
614 {
615 fLastBright = 0xff;
616
617 if (!fChannel->IsEntryEnabled(IDM_kChannel1))
618 fChannel->EnableEntry(IDM_kChannel1);
619 if (fDisplay->IsEntryEnabled(IDM_kFindStar))
620 fDisplay->DisableEntry(IDM_kFindStar);
621 if (fDisplay->IsEntryEnabled(IDM_kCaosFilter))
622 fDisplay->DisableEntry(IDM_kCaosFilter);
623 if (!fOperations->IsEntryEnabled(IDM_kStargAnalysis))
624 fOperations->EnableEntry(IDM_kStargAnalysis);
625
626 fStargTPoint->MapWindow();
627
628 fPZdAz->MapWindow();
629 fDZdAz->MapWindow();
630 fSkyBright->MapWindow();
631
632 fSao->SetLimitMag(8.3);
633 fIntRate = 125;
634
635 if (!fDisplay->IsEntryChecked(IDM_kCatalog))
636 fDisplay->CheckEntry(IDM_kCatalog);
637 fGStarg->MapWindow();
638
639 const Int_t ch0 =
640 fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
641 const Int_t ch1 = 0;
642
643 if (ch0!=ch1)
644 {
645// fGetter->ExitLoop();
646 delete fGetter;
647 usleep(150000); // FIX: Device or resource busy.
648 if (fChannel->IsEntryChecked(IDM_kChannel3))
649 fGetter=new PngReader(*this);
650 else
651 {
652 fGetter = new Camera(*this, ch1);
653 ((Camera*)fGetter)->Loop(0);
654 }
655 }
656
657 if (fChannel->IsEntryChecked(IDM_kChannel2))
658 fChannel->UnCheckEntry(IDM_kChannel2);
659 if (fChannel->IsEntryEnabled(IDM_kChannel2))
660 fChannel->DisableEntry(IDM_kChannel2);
661 if (!fChannel->IsEntryChecked(IDM_kChannel1))
662 fChannel->CheckEntry(IDM_kChannel1);
663
664 }
665 else
666 {
667 fStatus = MDriveCom::kStandby;
668
669 fStargTPoint->UnmapWindow();
670 fStargTPoint->SetDown(kFALSE);
671
672 fPZdAz->UnmapWindow();
673 fDZdAz->UnmapWindow();
674 fSkyBright->UnmapWindow();
675 fGStarg->UnmapWindow();
676 if (!fChannel->IsEntryEnabled(IDM_kChannel2))
677 fChannel->EnableEntry(IDM_kChannel2);
678 if (!fDisplay->IsEntryEnabled(IDM_kFindStar))
679 fDisplay->EnableEntry(IDM_kFindStar);
680 if (!fDisplay->IsEntryEnabled(IDM_kCaosFilter))
681 fDisplay->EnableEntry(IDM_kCaosFilter);
682 if (fOperations->IsEntryEnabled(IDM_kStargAnalysis))
683 fOperations->DisableEntry(IDM_kStargAnalysis);
684 }
685 //gSystem->Unlink("tracking_error.txt");
686}
687
688void MStarguider::ToggleCaosFilter()
689{
690 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
691 {
692 if (!fMode->IsEntryChecked(IDM_kStarguiderMode)
693 && !fMode->IsEntryChecked(IDM_kTpointMode))
694 fMenu->AddPopup("&CaOs", fCaOs, NULL);
695 }
696 else
697 {
698 if (fCaosWrite->IsEntryChecked(IDM_kCaosPrintLeds))
699 fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds);
700 if (fCaosWrite->IsEntryChecked(IDM_kCaosPrintRings))
701 fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings);
702 if (fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop))
703 {
704 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
705 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
706 fCaos->DeleteHistograms();
707 }
708 if (fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop))
709 {
710 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
711 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
712 fCaos->CloseFile();
713 }
714 fMenu->RemovePopup("CaOs");
715 }
716 fMenu->Resize(fMenu->GetDefaultSize());
717 MapSubwindows(); // maps everything, but we don't want that
718 fTPoint->UnmapWindow();
719 fStargTPoint->UnmapWindow();
720 fGStarg->UnmapWindow();
721 fPZdAz->UnmapWindow();
722 fDZdAz->UnmapWindow();
723 fSZdAz->UnmapWindow();
724 fSkyBright->UnmapWindow();
725 MapWindow();
726}
727
728Bool_t MStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
729{
730 switch (GET_MSG(msg))
731 {
732 case kC_TEXTENTRY:
733 if (GET_SUBMSG(msg)==kTE_ENTER)
734 switch (mp1)
735 {
736 case IDM_kPixSize:
737 {
738 const Float_t pixsize = atof(fPixSize->GetText());
739 cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl;
740 fSao->SetPixSize(pixsize);
741 return kTRUE;
742 }
743 case IDM_kAngle:
744 {
745 const Float_t angle = atof(fAngle->GetText());
746 cout << "Rotation Angle changed to " << angle << "deg" << endl;
747 fSao->SetRotationAngle(angle);
748 return kTRUE;
749 }
750 }
751 return kTRUE;
752
753 case kC_COMMAND:
754 switch (GET_SUBMSG(msg))
755 {
756 case kCM_MENU:
757 switch (mp1)
758 {
759 case IDM_kCatalog:
760 Toggle(fDisplay, IDM_kCatalog);
761// if (!fDisplay->IsEntryChecked(IDM_kCatalog))
762// {
763// fDisplay->UnCheckEntry(IDM_kStarguider);
764// fDisplay->DisableEntry(IDM_kStarguider);
765// } else {
766// fDisplay->EnableEntry(IDM_kStarguider);
767// }
768 return kTRUE;
769
770 case IDM_kRoqueLampAna:
771 Toggle(fOperations, IDM_kRoqueLampAna);
772 // if (!fDisplay->IsEntryChecked(IDM_kCatalog))
773 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
774 fDisplay->CheckEntry(IDM_kStargCaosFilter);
775 else
776 fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
777
778 return kTRUE;
779
780 case IDM_kStargFindStar:
781 Toggle(fDisplay, IDM_kStargFindStar);
782 if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
783 fSZdAz->MapWindow();
784 else
785 fSZdAz->UnmapWindow();
786 return kTRUE;
787
788 case IDM_kStarguider:
789 Toggle(fDisplay, IDM_kStarguider);
790 ToggleStarguider();
791 return kTRUE;
792
793 case IDM_kStargAnalysis:
794 Toggle(fOperations, IDM_kStargAnalysis);
795 ToggleStargAnalysis();
796 return kTRUE;
797
798 case IDM_kStarguiderMode:
799 Toggle(fMode, IDM_kStarguiderMode);
800
801 if (fMode->IsEntryChecked(IDM_kStarguiderMode))
802 {
803
804 //uncheck not needed items
805 //general
806 if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
807 fDisplay->UnCheckEntry(IDM_kStargFindStar);
808
809 if (fDisplay->IsEntryChecked(IDM_kFilter))
810 fDisplay->UnCheckEntry(IDM_kFilter);
811 if (fDisplay->IsEntryEnabled(IDM_kFilter))
812 fDisplay->DisableEntry(IDM_kFilter);
813
814 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
815 fOperations->UnCheckEntry(IDM_kRoqueLampAna);
816 if (fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
817 fOperations->DisableEntry(IDM_kRoqueLampAna);
818
819 if (fChannel->IsEntryChecked(IDM_kChannel3))
820 fChannel->UnCheckEntry(IDM_kChannel3);
821 if (fChannel->IsEntryEnabled(IDM_kChannel3))
822 fChannel->DisableEntry(IDM_kChannel3);
823
824 //tpoint
825 if (fDisplay->IsEntryChecked(IDM_kFindStar))
826 fDisplay->UnCheckEntry(IDM_kFindStar);
827 ToggleFindStar();
828
829 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
830 fDisplay->UnCheckEntry(IDM_kCaosFilter);
831 ToggleCaosFilter();
832
833 if (fMode->IsEntryChecked(IDM_kTpointMode))
834 fMode->UnCheckEntry(IDM_kTpointMode);
835
836 //enable starguider items
837// if (!fOperations->IsEntryEnabled(IDM_kStargAnalysis))
838// fOperations->EnableEntry(IDM_kStargAnalysis);
839 if (!fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
840 fDisplay->EnableEntry(IDM_kStargCaosFilter);
841 if (!fDisplay->IsEntryEnabled(IDM_kStarguider))
842 fDisplay->EnableEntry(IDM_kStarguider);
843 if (!fDisplay->IsEntryEnabled(IDM_kCatalog))
844 fDisplay->EnableEntry(IDM_kCatalog);
845
846 //check needed items
847 if (!fDisplay->IsEntryChecked(IDM_kStretch))
848 fDisplay->CheckEntry(IDM_kStretch);
849
850 if (!fDisplay->IsEntryChecked(IDM_kStarguider))
851 fDisplay->CheckEntry(IDM_kStarguider);
852 ToggleStarguider();
853
854 if (!fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
855 fDisplay->CheckEntry(IDM_kStargCaosFilter);
856
857// if (!fOperations->IsEntryChecked(IDM_kStargAnalysis))
858// fOperations->CheckEntry(IDM_kStargAnalysis);
859// ToggleStargAnalysis();
860 if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
861 fOperations->UnCheckEntry(IDM_kStargAnalysis);
862 if (fOperations->IsEntryEnabled(IDM_kStargAnalysis))
863 fOperations->DisableEntry(IDM_kStargAnalysis);
864
865
866 }
867 else
868 {
869 //uncheck starguider items
870// if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
871// fOperations->UnCheckEntry(IDM_kStargAnalysis);
872// ToggleStargAnalysis();
873
874 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
875 fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
876
877 if (fDisplay->IsEntryChecked(IDM_kStarguider))
878 fDisplay->UnCheckEntry(IDM_kStarguider);
879 ToggleStarguider();
880
881 if (fDisplay->IsEntryChecked(IDM_kCatalog))
882 fDisplay->UnCheckEntry(IDM_kCatalog);
883
884 if (!fChannel->IsEntryEnabled(IDM_kChannel3))
885 fChannel->EnableEntry(IDM_kChannel3);
886
887 if (!fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
888 fOperations->EnableEntry(IDM_kRoqueLampAna);
889
890 if (!fDisplay->IsEntryEnabled(IDM_kFilter))
891 fDisplay->EnableEntry(IDM_kFilter);
892
893 }
894 return kTRUE;
895
896 case IDM_kTpointMode:
897 Toggle(fMode, IDM_kTpointMode);
898
899 if (fMode->IsEntryChecked(IDM_kTpointMode))
900 {
901 //unchecking not needed items
902 //general
903 if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
904 fDisplay->UnCheckEntry(IDM_kStargFindStar);
905
906 if (fDisplay->IsEntryChecked(IDM_kFilter))
907 fDisplay->UnCheckEntry(IDM_kFilter);
908 if (fDisplay->IsEntryEnabled(IDM_kFilter))
909 fDisplay->DisableEntry(IDM_kFilter);
910
911 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
912 fOperations->UnCheckEntry(IDM_kRoqueLampAna);
913 if (fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
914 fOperations->DisableEntry(IDM_kRoqueLampAna);
915
916 if (fChannel->IsEntryChecked(IDM_kChannel3))
917 fChannel->UnCheckEntry(IDM_kChannel3);
918 if (fChannel->IsEntryEnabled(IDM_kChannel3))
919 fChannel->DisableEntry(IDM_kChannel3);
920
921 //from starguider
922 if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
923 fOperations->UnCheckEntry(IDM_kStargAnalysis);
924 ToggleStargAnalysis();
925 if (fOperations->IsEntryEnabled(IDM_kStargAnalysis))
926 fOperations->DisableEntry(IDM_kStargAnalysis);
927
928 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
929 fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
930 if (fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
931 fDisplay->DisableEntry(IDM_kStargCaosFilter);
932
933 if (fDisplay->IsEntryChecked(IDM_kStarguider))
934 fDisplay->UnCheckEntry(IDM_kStarguider);
935 ToggleStarguider();
936 if (fDisplay->IsEntryEnabled(IDM_kStarguider))
937 fDisplay->DisableEntry(IDM_kStarguider);
938
939 if (fDisplay->IsEntryChecked(IDM_kCatalog))
940 fDisplay->UnCheckEntry(IDM_kCatalog);
941 if (fDisplay->IsEntryEnabled(IDM_kCatalog))
942 fDisplay->DisableEntry(IDM_kCatalog);
943
944 if (fMode->IsEntryChecked(IDM_kStarguiderMode))
945 fMode->UnCheckEntry(IDM_kStarguiderMode);
946
947 //switch camera
948 const Int_t ch0 =
949 fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
950 const Int_t ch1 = 1;
951
952 if (ch0!=ch1)
953 {
954// fGetter->ExitLoop();
955 delete fGetter;
956 usleep(150000); // FIX: Device or resource busy.
957 fGetter = new Camera(*this, ch1);
958 ((Camera*)fGetter)->Loop(0);
959 }
960
961 if (fChannel->IsEntryChecked(IDM_kChannel1))
962 fChannel->UnCheckEntry(IDM_kChannel1);
963 if (fChannel->IsEntryEnabled(IDM_kChannel1))
964 fChannel->DisableEntry(IDM_kChannel1);
965 if (!fChannel->IsEntryChecked(IDM_kChannel2))
966 fChannel->CheckEntry(IDM_kChannel2);
967
968 //checking needed items
969 if (!fDisplay->IsEntryChecked(IDM_kStretch))
970 fDisplay->CheckEntry(IDM_kStretch);
971
972 if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
973 fDisplay->CheckEntry(IDM_kCaosFilter);
974 ToggleCaosFilter();
975
976 if (!fDisplay->IsEntryChecked(IDM_kFindStar))
977 fDisplay->CheckEntry(IDM_kFindStar);
978 ToggleFindStar();
979
980 }
981 else
982 {
983 //enable starguider items
984 if (!fOperations->IsEntryEnabled(IDM_kStargAnalysis))
985 fOperations->EnableEntry(IDM_kStargAnalysis);
986 if (!fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
987 fDisplay->EnableEntry(IDM_kStargCaosFilter);
988 if (!fDisplay->IsEntryEnabled(IDM_kStarguider))
989 fDisplay->EnableEntry(IDM_kStarguider);
990 if (!fDisplay->IsEntryEnabled(IDM_kCatalog))
991 fDisplay->EnableEntry(IDM_kCatalog);
992
993 if (!fDisplay->IsEntryEnabled(IDM_kFilter))
994 fDisplay->EnableEntry(IDM_kFilter);
995 if (!fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
996 fOperations->EnableEntry(IDM_kRoqueLampAna);
997 if (!fChannel->IsEntryEnabled(IDM_kChannel3))
998 fChannel->EnableEntry(IDM_kChannel3);
999
1000 if (fDisplay->IsEntryChecked(IDM_kFindStar))
1001 fDisplay->UnCheckEntry(IDM_kFindStar);
1002 ToggleFindStar();
1003
1004 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
1005 fDisplay->UnCheckEntry(IDM_kCaosFilter);
1006 ToggleCaosFilter();
1007
1008 if (!fChannel->IsEntryEnabled(IDM_kChannel1))
1009 fChannel->EnableEntry(IDM_kChannel1);
1010
1011 }
1012 return kTRUE;
1013
1014 case IDM_kFilter:
1015 Toggle(fDisplay, IDM_kFilter);
1016 return kTRUE;
1017
1018// case IDM_kFilterStarg:
1019// Toggle(fDisplay, IDM_kFilterStarg);
1020// if (fDisplay->IsEntryChecked(IDM_kFilterStarg))
1021// fDisplay->EnableEntry(IDM_kStarguider);
1022// else
1023// {
1024// fDisplay->UnCheckEntry(IDM_kStarguider);
1025// fDisplay->DisableEntry(IDM_kStarguider);
1026// }
1027// return kTRUE;
1028
1029 case IDM_kFindStar:
1030 Toggle(fDisplay, IDM_kFindStar);
1031 ToggleFindStar();
1032 return kTRUE;
1033
1034 case IDM_kStretch:
1035 Toggle(fDisplay, IDM_kStretch);
1036 return kTRUE;
1037
1038 case IDM_kCaosFilter:
1039 //if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
1040 // fCaos->OpenFile();
1041 Toggle(fDisplay, IDM_kCaosFilter);
1042 ToggleCaosFilter();
1043 return kTRUE;
1044
1045 case IDM_kStargCaosFilter:
1046 Toggle(fDisplay, IDM_kStargCaosFilter);
1047 if (fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
1048 fDisplay->EnableEntry(IDM_kStargFindStar);
1049 else
1050 fDisplay->DisableEntry(IDM_kStargFindStar);
1051 return kTRUE;
1052
1053 case IDM_kCaosPrintLeds:
1054 case IDM_kCaosPrintRings:
1055 Toggle(fCaosPrint, mp1);
1056 return kTRUE;
1057
1058 case IDM_kCaosAnalStart:
1059 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStart);
1060 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStop);
1061 fCaos->InitHistograms();
1062 return kTRUE;
1063
1064 case IDM_kCaosAnalStop:
1065 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
1066 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
1067 fCaos->ShowHistograms();
1068 fCaos->DeleteHistograms();
1069 return kTRUE;
1070
1071 case IDM_kCaosWriteStart:
1072 fCaosWrite->DisableEntry(IDM_kCaosWriteStart);
1073 fCaosWrite->EnableEntry(IDM_kCaosWriteStop);
1074 fCaos->OpenFile();
1075 return kTRUE;
1076
1077 case IDM_kCaosWriteStop:
1078 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
1079 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
1080 fCaos->CloseFile();
1081 return kTRUE;
1082
1083 case IDM_kStart:
1084 fWritePictures->DisableEntry(IDM_kStart);
1085 fWritePictures->EnableEntry(IDM_kStop);
1086 return kTRUE;
1087
1088 case IDM_kStop:
1089 fWritePictures->DisableEntry(IDM_kStop);
1090 fWritePictures->EnableEntry(IDM_kStart);
1091 return kTRUE;
1092
1093 case IDM_kPNG:
1094 fFileType->CheckEntry(IDM_kPNG);
1095 fFileType->UnCheckEntry(IDM_kPPM);
1096 return kTRUE;
1097
1098 case IDM_kPPM:
1099 fFileType->CheckEntry(IDM_kPPM);
1100 fFileType->UnCheckEntry(IDM_kPNG);
1101 return kTRUE;
1102
1103 case IDM_kOnce:
1104 fWriteType->CheckEntry(IDM_kOnce);
1105 fWriteType->UnCheckEntry(IDM_kContinous);
1106 return kTRUE;
1107
1108 case IDM_kContinous:
1109 fWriteType->CheckEntry(IDM_kContinous);
1110 fWriteType->UnCheckEntry(IDM_kOnce);
1111 return kTRUE;
1112
1113 case IDM_kRate25ps:
1114 case IDM_kRate5ps:
1115 case IDM_kRate1s:
1116 case IDM_kRate5s:
1117 case IDM_kRate30s:
1118 case IDM_kRate1m:
1119 case IDM_kRate5m:
1120 for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
1121 if (mp1==i)
1122 fWriteRate->CheckEntry(i);
1123 else
1124 fWriteRate->UnCheckEntry(i);
1125 switch (mp1)
1126 {
1127 case IDM_kRate25ps:
1128 fWrtRate = 1;
1129 return kTRUE;
1130 case IDM_kRate5ps:
1131 fWrtRate = 5;
1132 return kTRUE;
1133 case IDM_kRate1s:
1134 fWrtRate = 25;
1135 return kTRUE;
1136 case IDM_kRate5s:
1137 fWrtRate = 5*25;
1138 return kTRUE;
1139 case IDM_kRate30s:
1140 fWrtRate = 30*25;
1141 return kTRUE;
1142 case IDM_kRate1m:
1143 fWrtRate = 60*25;
1144 return kTRUE;
1145 case IDM_kRate5m:
1146 fWrtRate = 5*60*25;
1147 return kTRUE;
1148 }
1149 return kTRUE;
1150
1151 case IDM_kChannel1:
1152 case IDM_kChannel2:
1153 {
1154 const Int_t ch0 = fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
1155 const Int_t ch1 = mp1==IDM_kChannel1 ? 0 : 1;
1156
1157 if (ch0==ch1)
1158 return kTRUE;
1159
1160 fChannel->CheckEntry (ch1==0?IDM_kChannel1:IDM_kChannel2);
1161 fChannel->UnCheckEntry(ch1==1?IDM_kChannel1:IDM_kChannel2);
1162// fGetter->ExitLoop();
1163 delete fGetter;
1164 usleep(150000); // FIX: Device or resource busy.
1165 if (fChannel->IsEntryChecked(IDM_kChannel3))
1166 fGetter=new PngReader(*this);
1167 else
1168 {
1169 fGetter = new Camera(*this, ch1);
1170 ((Camera*)fGetter)->Loop(0);
1171 }
1172 }
1173 return kTRUE;
1174
1175 case IDM_kInterpol250:
1176 case IDM_kInterpol125:
1177 case IDM_kInterpol50:
1178 case IDM_kInterpol25:
1179 case IDM_kInterpol10:
1180 case IDM_kInterpol5:
1181 case IDM_kInterpol2:
1182 case IDM_kInterpol1:
1183 for (int i=IDM_kInterpol250; i<=IDM_kInterpol1; i++)
1184 if (mp1==i)
1185 fInterpol->CheckEntry(i);
1186 else
1187 fInterpol->UnCheckEntry(i);
1188 switch (mp1)
1189 {
1190 case IDM_kInterpol1:
1191 fIntRate = 1;
1192 return kTRUE;
1193 case IDM_kInterpol2:
1194 fIntRate = 2;
1195 return kTRUE;
1196 case IDM_kInterpol5:
1197 fIntRate = 5;
1198 return kTRUE;
1199 case IDM_kInterpol10:
1200 fIntRate = 10;
1201 return kTRUE;
1202 case IDM_kInterpol25:
1203 fIntRate = 25;
1204 return kTRUE;
1205 case IDM_kInterpol50:
1206 fIntRate = 50;
1207 return kTRUE;
1208 case IDM_kInterpol125:
1209 fIntRate = 125;
1210 return kTRUE;
1211 case IDM_kInterpol250:
1212 fIntRate = 250;
1213 return kTRUE;
1214 }
1215 return kTRUE;
1216
1217 case IDM_kLimMag3:
1218 case IDM_kLimMag4:
1219 case IDM_kLimMag5:
1220 case IDM_kLimMag6:
1221 case IDM_kLimMag7:
1222 case IDM_kLimMag8:
1223 case IDM_kLimMag9:
1224 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
1225 if (mp1==i)
1226 fLimMag->CheckEntry(i);
1227 else
1228 fLimMag->UnCheckEntry(i);
1229
1230 fSao->SetLimitMag(mp1-IDM_kLimMag3+3);
1231 return kTRUE;
1232 }
1233 break;
1234 }
1235 break;
1236 }
1237
1238 return kTRUE;
1239}
1240
1241void MStarguider::SetPointingPosition(RaDec rd)
1242{
1243 rd.Ra(rd.Ra()*24/360);
1244 fCRaDec->SetCoordinates(rd);
1245}
1246
1247ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag,
1248 Int_t &num) const
1249{
1250 num = -1;
1251
1252 // Width of the final 2D gaussian
1253 const Double_t width = 0.8;
1254
1255 // The binning is made 1.7 sigma (which, in the 1D case, gives the
1256 // highest significance of a gaussian signal) (1bin equiv 3x3 sigma)
1257 const Double_t max = 50;
1258 const Int_t n = TMath::Nint(2*max/(1.77*1.7*width));
1259 //1.77=sqrt(pi) comes from pir=bin
1260
1261 // Fill a histogram with the dx/dy values from the file
1262 TH2F hist("Hist", "dX/dY", n, -max, max, n, -max, max);
1263// hist.SetDirectory(0);
1264
1265 //
1266 // Search for matching Magnitudes
1267 //
1268 //for (int i=0; i<mag.GetSize(); i++)
1269 //{
1270 // if (mag[i]>48-15 && mag[i]<48+15)
1271 // h.Fill(x[i], y[i]);
1272 //}
1273
1274 // fill dx and dy into histogram
1275 for (int i=0; i<mag.GetSize(); i++)
1276 hist.Fill(x[i], y[i]);
1277
1278 // Remove all bins which have content of only a single event
1279 // including under- and overflow bins
1280 for (int i=0; i<hist.GetSize(); i++)
1281 if (hist.GetBinContent(i)<1.5)
1282 hist.SetBinContent(i, 0);
1283
1284 // Find the bin containing the maximum
1285 Int_t bx, by, bz;
1286 hist.GetMaximumBin(bx, by, bz);
1287
1288 // In the worst case the events are spread through the
1289 // bins which are the neighbors of the maximum
1290 // Normally neighbors which do not belong to the signal are empty!
1291 hist.GetXaxis()->SetRange(bx-1, bx+1); // 3x3bins ~8x8pix ~9x9sigma
1292 hist.GetYaxis()->SetRange(by-1, by+1); // 3x3bins ~8x8pix ~9x9sigma
1293
1294 // Check whether this region contains events
1295 num = TMath::Nint(hist.Integral());
1296 if (num<1)
1297 return ZdAz();
1298
1299 // Get Mean for the given axis range
1300 Double_t mx = hist.GetMean(1);
1301 Double_t my = hist.GetMean(2);
1302
1303 const Int_t max1 = TMath::Nint(hist.GetBinContent(bx, by));
1304
1305 // Check if the maximum is unique
1306 Int_t bx2, by2, bz2;
1307 hist.GetXaxis()->SetRange(-1, 9999);
1308 hist.GetYaxis()->SetRange(-1, 9999);
1309 hist.SetBinContent(bx, by, 0);
1310 hist.GetMaximumBin(bx2, by2, bz2);
1311
1312 const Int_t max2 = TMath::Nint(hist.GetBinContent(bx2, by2));
1313 if (max1==max2 && TMath::Abs(bx2-bx)+TMath::Abs(by2-by)>1)
1314 return ZdAz();
1315
1316 // loop again over the file and fill the histogram again.
1317 // to get closer to the correct value
1318 Double_t sumx = 0;
1319 Double_t sumy = 0;
1320 num = 0;
1321 for (int i=0; i<mag.GetSize(); i++)
1322 {
1323 // only fill values into the histogram which
1324 // are inside 2*1.7=3.4 sigma (99.7%)
1325 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*3.4)
1326 continue;
1327
1328 sumx += x[i];
1329 sumy += y[i];
1330 num++;
1331 }
1332
1333 if (num<1)
1334 return ZdAz();
1335
1336 // calc MeanX and MeanY
1337 mx = sumx/num;
1338 my = sumy/num;
1339
1340 // loop again to fill the mispointing corrected histograms
1341 // and fill another histogram to check the quality of the calculated
1342 // mispointing.
1343 sumx = 0;
1344 sumy = 0;
1345 num = 0;
1346 for (int i=0; i<mag.GetSize(); i++)
1347 {
1348 // only fill values into the histogram which
1349 // are inside 1.7=3.4 sigma (92%)
1350 // Cut at 1.7 sigma which gives the best background supression
1351 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*1.7)
1352 continue;
1353
1354 sumx += x[i];
1355 sumy += y[i];
1356 num++;
1357 }
1358
1359 if (num<1)
1360 return ZdAz(); // FIXME!!!!!!!!!!!!
1361
1362 // Mispointing
1363 mx = sumx/num;
1364 my = sumy/num;
1365
1366#ifdef EXPERT
1367 cout << "Offset-XY: " << mx << " +- " << my << endl;
1368#endif
1369
1370 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg;
1371 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+mx, 576/2+my)*kRad2Deg;
1372/*
1373 ofstream fout1("pointingpos.txt");
1374 fout1 << setprecision(10) << fSao->GetMjd()-52000 << " ";
1375 if (fCosy)
1376 fout1 << fCosy->GetPointingPos() << " ";
1377 fout1 << -pos1.Alt() << " " << pos1.Az() << endl;
1378
1379 pos1 -= pos0;
1380
1381 ofstream fout2("tracking_error.txt", ios::app);
1382 fout2 << setprecision(10) << fSao->GetMjd()-52000 << " ";
1383 if (fCosy)
1384 fout2 << fCosy->GetPointingPos() << " ";
1385 fout2 << -pos1.Alt() << " " << pos1.Az() << endl;
1386 */
1387 return ZdAz(-pos1.Alt(), pos1.Az());
1388}
1389
1390Int_t MStarguider::CalcTrackingError(Leds &leds, MStarList &stars,
1391 ZdAz &d, MTime &t, double &bright, Int_t &num)
1392{
1393 const Int_t max = leds.GetEntries();
1394 if (stars.GetRealEntries() < 3)
1395 {
1396 cout << "Sorry, less than 3 stars in FOV!" << endl;
1397 if (fStargTPoint->IsDown())
1398 fStargTPoint->SetDown(kFALSE);
1399 return 0;
1400 }
1401 if (max < 3) //was 1
1402 {
1403 cout << "Sorry, less than 3 detected spot in FOV!" << endl;
1404 if (fStargTPoint->IsDown())
1405 fStargTPoint->SetDown(kFALSE);
1406 return 0;
1407 }
1408
1409 stars.Sort(); // Sort by magnitude
1410
1411#ifdef EXPERT
1412 TString str = "data/tracking_";
1413 str += fSao->GetMjd();
1414 str += ".txt";
1415
1416 ofstream fout(str);
1417#endif
1418
1419 TArrayF x, y, mag;
1420
1421 num = 0;
1422
1423 // FIXME: Is predefined value 3 a good idea?
1424
1425 MStar *star;
1426 MStarListIter NextStar(&stars);
1427 while ((star=NextStar()) && num++<max+3)
1428 {
1429 TIter NextSp(&leds);
1430 Led *spot=NULL;
1431 while ((spot=(Led*)NextSp()))
1432 {
1433 const XY dpos(spot->GetX()-(768-star->GetX()),
1434 spot->GetY()-star->GetY());
1435
1436 const Int_t idx = x.GetSize();
1437
1438 x.Set(idx+1);
1439 y.Set(idx+1);
1440 mag.Set(idx+1);
1441
1442 x.AddAt(dpos.X(), idx);
1443 y.AddAt(dpos.Y(), idx);
1444 mag.AddAt(spot->GetMag()/star->GetMag(), idx);
1445#ifdef EXPERT
1446 if (fout)
1447 {
1448 fout << spot->GetX() << " "
1449 << spot->GetY() << " "
1450 << spot->GetMag() << " "
1451 << star->GetX() << " "
1452 << star->GetY() << " "
1453 << star->GetMag() << " ";
1454 fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
1455 }
1456#endif
1457 }
1458 }
1459
1460 Int_t numcor = 0;
1461 d = TrackingError(x, y, mag, numcor);
1462 if (numcor<1)
1463 return 0;
1464
1465 fDZdAz->SetCoordinates(d);
1466
1467 //
1468 // Calculated offsets
1469 //
1470
1471#ifdef EXPERT
1472 // round= floor(x+.5)
1473 cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
1474 cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
1475#endif
1476
1477 //
1478 // Current Pointing position
1479 //
1480 ZdAz cpos = fSao->GetZdAz()-d;
1481 fPZdAz->SetCoordinates(cpos);
1482
1483
1484 // Check StargTPoint data set request
1485 if (!fStargTPoint->IsDown())
1486 return numcor;
1487 fStargTPoint->SetDown(kFALSE);
1488
1489 // If no file open: open new file
1490 if (!fOutStargTp)
1491 {
1492 // open tpoint file
1493 const TString name = MCosy::GetFileName("tpoint/starg_%s.txt");
1494 cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
1495
1496 fOutStargTp = new ofstream(name);
1497 *fOutStargTp << "Magic Model STARGTPOINT data file" << endl;
1498 *fOutStargTp << ": ALTAZ" << endl;
1499 *fOutStargTp << "49 48 0 ";
1500 *fOutStargTp << t << endl;
1501 }
1502
1503 // Get tracking coordinates
1504 const XY xy = fCRaDec->GetCoordinates();
1505 const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
1506
1507 // From the star position in the camera we calculate the Alt/Az
1508 // position we are currently tracking (real pointing position)
1509 fSao->SetMjd(t.GetMjd());
1510 AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
1511
1512 //correction with offset from last tpoint measurement
1513 za0 -= fAltAzOffsetFromTp;
1514 MTime t2 = fTimeFromTp;
1515
1516 //if the difference between the tpoint and the starguider tpoint
1517 //is too big, the starguider tpoint is not stored
1518 cout << " mjd difference: " << t.GetMjd()-t2.GetMjd() << endl;
1519// cout << "t: " << setprecision(11) << t.GetMjd() << endl;
1520// cout << "t2: " << setprecision(11) << t2.GetMjd() << endl;
1521 if ((t.GetMjd()-t2.GetMjd())>0.001) //1min20sec
1522 {
1523 cout << " time difference between tpoint and starguider-tpoint > 1 min *" <<
1524 t.GetMjd()-t2.GetMjd() << "s) " << endl;
1525 cout << " => starguider tpoint hasn't been stored. " << endl;
1526 cout << " Please repeat whole procedure. " << endl;
1527 return numcor;
1528 }
1529
1530
1531 // Write real pointing position
1532 cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
1533 *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
1534
1535 // Write system pointing position
1536 cout << " SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
1537 *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd();
1538
1539 *fOutStargTp << " " << xy.X() << " " << xy.Y();
1540 *fOutStargTp << " " << d.Zd() << " " << d.Az();
1541 *fOutStargTp << " " << setprecision(11) << t.GetMjd();
1542 *fOutStargTp << " " << max;
1543 *fOutStargTp << " " << bright;
1544 *fOutStargTp << endl;
1545
1546 fTimeFromTp.Set(1970,1,1);
1547
1548 return numcor;
1549}
1550
1551XY MStarguider::FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, Double_t cut, Double_t box, XY SearchCenter)
1552{
1553 // Set search Paremeters (FIXME: Get them from user input!)
1554 f.SetCut(cut); // 3.5
1555 f.SetBox(box); // 70
1556
1557 // Try to find Led in this area
1558 Leds leds;
1559 f.FindStarCircle(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y());
1560
1561 // Check whether star found
1562 Led *star = (Led*)leds.At(0);
1563 if (!star || leds.GetEntries()<1)
1564 return XY(.0,.0);
1565
1566// cout << "Found Roque Lamp @ " << flush;
1567 star->Print();
1568 f.MarkPoint(star->GetX(), star->GetY(), 500);
1569
1570// cout << "RoquePos: " << star->GetX() << "," << star->GetY() << endl;
1571
1572 XY roquepos(star->GetX(), star->GetY());
1573 XY relroquepos(roquepos.X()-CameraCenter.GetX(), roquepos.Y()-CameraCenter.GetY());
1574
1575 // If no file open: open new Roque Lamp file
1576 if (!fOutRq)
1577 {
1578 const TString name = MCosy::GetFileName("tpoint/starg_roquelamp_%s.txt");
1579 cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl;
1580 fOutRq = new ofstream(name);
1581 *fOutRq << "# Magic Roque Lamp file " << t << endl;
1582 }
1583
1584
1585 return relroquepos;
1586}
1587
1588
1589ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)
1590{
1591 // Set search Paremeters (FIXME: Get them from user input!)
1592 f.SetCut(cut); // 3.5
1593 f.SetBox(box); // 70
1594
1595 // Try to find Led in this area
1596 Leds leds;
1597 f.FindStarCircle(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
1598
1599 if (leds.GetEntries()<0)
1600 return ZdAz(0, 0);
1601
1602 // Check whether star found
1603 Led *star = (Led*)leds.At(0);
1604 if (!star)
1605 {
1606 if (fTPoint->IsDown())
1607 {
1608 fTPoint->SetDown(kFALSE);
1609 cout << "No star found. Couldn't take a tpoint." << endl;
1610 }
1611 return ZdAz(.0,.0);
1612 }
1613
1614 cout << "Found star @ " << flush;
1615 star->Print();
1616 f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
1617
1618 // Initialize Star Catalog on th camera plane
1619 MGeomCamMagic geom;
1620 MAstroCamera ac;
1621 ac.SetGeom(geom);
1622 ac.SetRadiusFOV(3);
1623 ac.SetObservatory(*fSao);
1624 ac.SetTime(t);
1625
1626 // Get tracking coordinates
1627 const XY xy = fCRaDec->GetCoordinates();
1628 const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
1629
1630 ac.SetRaDec(rd.Ra(), rd.Dec());
1631
1632 // Adapt coordinate system (GUIs and humans are counting Y in different directions)
1633 Double_t x = star->GetX()-center.GetX();
1634 Double_t y = center.GetY()-star->GetY();
1635
1636#ifdef EXPERT
1637 cout << "STAR-Offset: " << MTime(-1) << " dx=" << x << "pix dy=" << y << "pix" << endl;
1638#endif
1639
1640 // Convert from Pixel to millimeter (1pix=2.9mm)
1641 x *= (2.58427 * scalefactor);
1642 y *= (2.58427 * scalefactor);
1643
1644 // Correct for abberation.
1645 x /= 1.0713;
1646 y /= 1.0713;
1647
1648 // Calculate Offset
1649 Double_t dzd, daz;
1650 ac.GetDiffZdAz(x, y, dzd, daz);
1651
1652#ifdef EXPERT
1653 cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d dAz=" << daz << "d" << endl;
1654#endif
1655
1656 ZdAz zdaz(dzd,daz);
1657
1658 // Check TPoint data set request
1659 if (!fTPoint->IsDown())
1660 return zdaz;
1661 fTPoint->SetDown(kFALSE);
1662
1663 // If no file open: open new file
1664 if (!fOutTp)
1665 {
1666 //
1667 // open tpoint file
1668 //
1669 const TString name = MCosy::GetFileName("tpoint/tpoint_%s.txt");
1670 cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
1671
1672 fOutTp = new ofstream(name);
1673 *fOutTp << "Magic Model TPOINT data file" << endl;
1674 *fOutTp << ": ALTAZ" << endl;
1675 *fOutTp << "49 48 0 ";
1676 *fOutTp << t << endl;
1677 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
1678 }
1679
1680 // Output Ra/Dec the drive system thinks that it is currently tracking
1681 cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;
1682
1683 // From the star position in the camera we calculate the Alt/Az
1684 // position we are currently tracking (real pointing position)
1685 fSao->SetMjd(t.GetMjd());
1686 AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
1687
1688 //ZdAz za0 = fSao->GetZdAz();
1689 za0 -= AltAz(-dzd, daz);
1690 fAltAzOffsetFromTp = AltAz(-dzd, daz);
1691 fTimeFromTp=t;
1692
1693
1694 // From the Shaftencoders we get the current 'pointing' position
1695 // as it is seen by the drive system (system pointing position)
1696 const ZdAz za1 = fCosy->GetTrackingPosRaw();
1697
1698 // Write real pointing position
1699 cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
1700 *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
1701
1702 // Write system pointing position
1703 cout << " SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
1704 *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd();
1705
1706 *fOutTp << " " << xy.X() << " " << xy.Y();
1707 *fOutTp << " " << -dzd << " " << -daz;
1708 *fOutTp << " " << setprecision(11) << t.GetMjd();
1709 *fOutTp << " " << setprecision(4) << center.GetMag();
1710 *fOutTp << " " << star->GetMag();
1711 *fOutTp << endl;
1712
1713 MLog &outrep = *fCosy->GetOutRep();
1714 if (outrep.Lock("MStarguider::FindStar"))
1715 {
1716 outrep << "FINDSTAR-REPORT 00 " << MTime(-1) << " " << setprecision(7);
1717 outrep << 90-za0.Alt() << " " << za0.Az() << " ";
1718 outrep << za1.Zd() << " " << za1.Az() << " ";
1719 outrep << xy.X() << " " << xy.Y() << " ";
1720 outrep << -dzd << " " << -daz << " ";
1721 outrep << star->GetX() << " " << star->GetY() << " ";
1722 outrep << center.GetX() << " " << center.GetY() << " ";
1723 outrep << x*1.0713/2.58427 << " " << y*1.0713/2.58427 << " " << star->GetMag();
1724 outrep << setprecision(11) << t.GetMjd() << endl;
1725 outrep.UnLock("MStarguider::FindStar");
1726 }
1727
1728 return zdaz;
1729}
1730
1731bool MStarguider::Interpolate(const unsigned long n, byte *img) const
1732{
1733 if (fIntRate<=1)
1734 return true;
1735
1736 static unsigned short myimg[768*576];
1737
1738 unsigned short *f = myimg;
1739 byte *i = img;
1740 byte *e = img+768*576;
1741
1742 while (i<e)
1743 *f++ += *i++;
1744
1745 if (n%fIntRate)
1746 return false;
1747
1748 f = myimg;
1749 i = img;
1750 e = img+768*576;
1751
1752 while (i<e)
1753 *i++ = (byte)(*f++/fIntRate);
1754
1755 memset(myimg, 0, sizeof(myimg));
1756
1757 return true;
1758}
1759
1760void MStarguider::ProcessFrame(const unsigned long n, byte *img,
1761 struct timeval *tm)
1762{
1763 static unsigned long n0 = n;
1764
1765 MTime t(*tm);
1766
1767 const Double_t d = t-fTime;
1768 if (d>1)
1769 {
1770 MString txt;
1771 txt.Print("%dfps", (int)((n-n0)/d+.5));
1772 fFps->SetText(txt);
1773 fTime = t;
1774 n0 = n;
1775 }
1776
1777 if (!Interpolate(n, img))
1778 return;
1779
1780 byte cimg[768*576];
1781 memset(cimg, 0, 768*576);
1782
1783 FilterLed f(img, 768, 576, 2.5); // 2.5
1784 FilterLed f2(cimg, 768, 576); // former color 0xb0
1785
1786 if (fDisplay->IsEntryChecked(IDM_kStretch))
1787 f.Stretch();
1788
1789 if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
1790 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
1791 {
1792
1793 if (fFileType->IsEntryChecked(IDM_kPNG))
1794 Writer::Png("pix/file", img, tm, fCRaDec->GetCoordinates());
1795
1796 if (fFileType->IsEntryChecked(IDM_kPPM))
1797 Writer::Ppm("pix/file", img, tm, fCRaDec->GetCoordinates());
1798
1799 if (fWriteType->IsEntryChecked(IDM_kOnce))
1800 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
1801 }
1802
1803 // Visual Filter, whole FOV
1804 if (fDisplay->IsEntryChecked(IDM_kFilter))
1805 f.Execute();
1806
1807 /* ----------------------------------
1808 // Visual StarFilter for Starguider
1809 if (fDisplay->IsEntryChecked(IDM_kFilterStarg) && !fDisplay->IsEntryChecked(IDM_kStarguider)) {
1810 f.SetBox(230);
1811 f.AddIgnoreRegion(295,112,384,204);
1812 f.Execute(530, 292);
1813 }
1814 ------------------------------------- */
1815
1816 // Find Center of Camera for Caos and Tpoints
1817 Ring center(768/2, 576/2);
1818 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
1819 {
1820 const bool printl = fCaosPrint->IsEntryChecked(IDM_kCaosPrintLeds);
1821 const bool printr = fCaosPrint->IsEntryChecked(IDM_kCaosPrintRings);
1822 ZdAz pos;
1823 if (fCosy)
1824 pos = fCosy->GetPointingPos();
1825 center = fCaos->Run(img, printl, printr, pos, t, 50, 3.0);
1826 cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << endl;
1827
1828 }
1829
1830 // Find Star at Center---for Tpoint Procedure
1831 if (fDisplay->IsEntryChecked(IDM_kFindStar))
1832 ZdAz zdaz = FindStar(f, f2, center, t, 3.5, 70);
1833
1834 byte zimg[kZOOM*kZOOM];
1835 for (int y=0; y<kZOOM; y++)
1836 for (int x=0; x<kZOOM; x++)
1837 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
1838
1839 fZoomImage->DrawImg(zimg);
1840
1841 if (fCosy)
1842 {
1843 byte simg[(768/2-1)*(576/2-1)];
1844 for (int y=0; y<576/2-1; y++)
1845 for (int x=0; x<768/2-1; x++)
1846 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;
1847
1848 fCosy->GetWin()->GetImage()->DrawImg(simg);
1849 }
1850
1851 // Find Center of Camera in Starfield Camera picture
1852
1853 Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px]
1854 //ZdAz sgcenterzdaz(0, 0); // Center of camera in SG picture [deg]
1855 // // (0,0)_deg is at (53.2, 293.6)_px
1856 ZdAz star(0, 0); // Star on curtain in [deg]
1857
1858 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
1859 {
1860 ZdAz pos;
1861 if (fCosy)
1862 pos = fCosy->GetPointingPos();
1863
1864 sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 30, 3.0); // [px]
1865
1866 const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px]
1867
1868 // BE CAREFULL: This transformation is WRONG. It is just
1869 // a transformation of units, but this implies, that the
1870 // coordiante axis in both units look the same. This is
1871 // wrong exspecially near the zenith were az-lines are highly
1872 // curved around the zenith!
1873 //sgcenterzdaz.Zd((sgcenter.GetY()-293.6) * pixsize /3600 );
1874 //sgcenterzdaz.Az((sgcenter.GetX()-53.2) * pixsize /3600 );
1875#ifdef EXPERT
1876 cout << "- LEDs imply offset of Zd="
1877 << sgcenter.GetX()-53.2 << "pix Az="
1878 << sgcenter.GetY()-293.6<< "pix" << endl;
1879#endif
1880 if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
1881 {
1882 star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg]
1883#ifdef EXPERT
1884 cout << "- Star is found to be off Zd=" << star.Zd()*60 << "' Az="
1885 << star.Az()*60 << "'" << endl;
1886#endif
1887 fSZdAz->SetCoordinates(star); // Misspointing found from Camera
1888 }
1889 }
1890
1891// Find Roque Lamp
1892
1893 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
1894 {
1895
1896 XY roquelamp(0,0);
1897
1898 Double_t imageclean = 1.5;
1899 Double_t boxradius = 60;
1900 Double_t scalefactor = 1;
1901 XY searchcenter(768/2-1,576/2+25);
1902
1903 roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
1904
1905 if (fOutRq)
1906 {
1907 ZdAz pos = fCosy->GetPointingPos();
1908
1909 *fOutRq << "RoqueLampDirect: " << MTime(-1) << " "
1910 << pos.Zd() << " " << pos.Az() << " "
1911 << roquelamp.X() << " " << roquelamp.Y() << endl;
1912 }
1913
1914 cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl;
1915 cout << ">=>=>=> Roque Lamp found at: >=>=>=> (" << roquelamp.X() << ","
1916 << roquelamp.Y() << ") <=<=<=<" << endl;
1917
1918 }
1919
1920 // Find Spot on Camera Center in Starguider camera
1921
1922 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
1923 {
1924 XY cameraspot(0,0);
1925
1926 Double_t imageclean = 5;
1927 Double_t boxradius = 60;
1928 Double_t scalefactor = 1;
1929 // XY searchcenter(sgcenter.GetX(),sgcenter.GetY());
1930 XY searchcenter(60.,290.);
1931
1932 cameraspot = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
1933
1934 if (fOutRq)
1935 {
1936 ZdAz pos = fCosy->GetPointingPos();
1937
1938 *fOutRq << "RoqueLampReflected: " << MTime(-1) << " "
1939 << pos.Zd() << " " << pos.Az() << " "
1940 << cameraspot.X() << " " << cameraspot.Y() << endl;
1941 }
1942
1943 cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << ","
1944 << cameraspot.Y() << ") <<<<<" << endl;
1945
1946 f2.DrawCircle(sgcenter, 5.0, 0x0fa);
1947 f2.DrawCircle(sgcenter, 115.0, 0x0fa);
1948 }
1949
1950 // we calculate the offset given by the three ETH Leds visible to
1951 // the guide camera
1952 // This is an (inferior, obsolete) alternative to the StarCaosFilter
1953 // Led offset;
1954 // if (fDisplay->IsEntryChecked(IDM_kStargLEDFilter))
1955 // fStargLeds->Run(img,offset);
1956
1957 // Position corresponding to the camera center (53.2, 293.6)
1958 //Ring skycenter(392, 318);
1959 Ring skycenter(768/2, 576/2);
1960 // MStarList spots;
1961
1962 // we obtain a list of stars in the FOV from the SAO catalog
1963 if (fDisplay->IsEntryChecked(IDM_kCatalog))
1964 {
1965 MTime time(*tm);
1966
1967 XY xy = fCRaDec->GetCoordinates();
1968 fRaDec->Set(xy.X()*360/24, xy.Y());
1969
1970 UpdatePosZoom();
1971
1972 // Always call SetMjd first!
1973 fSao->SetPointing(time.GetMjd(), *fRaDec);
1974 fCZdAz->SetCoordinates(fSao->GetZdAz());
1975
1976 MStarList stars;
1977 fSao->SetBox(230); // Region of interest around center
1978
1979 // very careful: If center of camera cannot be determined
1980 // sgcenter jumps to (0,0)
1981
1982 //Please never change this offsets!!!
1983 // 53.2 and 293.6 are the "preliminary" camera center
1984 // -9 and 28.5 are the offsets of the pointing position in the sky
1985 const XY offset(53.2-9, 293.6+28.5);
1986
1987 const Bool_t centerisvalid = sgcenter.GetX()>0 && sgcenter.GetY()>0;
1988 if (centerisvalid)
1989 skycenter.SetXY(sgcenter.X() - offset.X(),
1990 sgcenter.Y() - offset.Y());
1991
1992 // we obtain stars in the effective star FOV and draw them.
1993 // coordinates are video frame coords.
1994 // We determine the ideal starfield using camera sagging info
1995 // from the LEDs
1996 fSao->CalcStars(stars, 530, 292, skycenter.GetX(), skycenter.GetY());
1997 fSao->DrawStars(stars, cimg);
1998
1999 // There are two corrections to the misspointing
2000 // - Sagging of the camera as measured with the LEDs
2001 // - Star not ideally centered on MAGIC Camera
2002
2003 // Next we evaluate the offset given by the LEDs. This we obtain
2004 // in Zd/Az and add it to the tracking error.
2005 if (fDisplay->IsEntryChecked(IDM_kStarguider))
2006 {
2007 Leds spots;
2008 f.SetBox(230);
2009// f.SetCut(1.5);
2010 double bright;
2011 f.ExecuteAndMark(spots, 530, 292, bright);
2012 MString txt;
2013 txt.Print("Sky Brightness: %.1f", bright);
2014 fSkyBright->SetText(txt);
2015
2016 const Bool_t brightnessisvalid = bright<1.75*fLastBright &&
2017 bright>30 && bright<110;
2018
2019 fLastBright = bright;
2020
2021 ULong_t color;
2022 gClient->GetColorByName("Green", color);
2023 if (bright> 60)
2024 gClient->GetColorByName("Yellow", color);
2025 if (bright> 85)
2026 gClient->GetColorByName("Orange", color);
2027 if (bright> 95)
2028 gClient->GetColorByName("Red", color);
2029 fSkyBright->SetBackgroundColor(color);
2030
2031 Int_t numstars = 0;
2032 const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright, numstars);
2033
2034 const Bool_t monitoring = brightnessisvalid && centerisvalid;
2035
2036 fStatus = monitoring ? MDriveCom::kMonitoring : MDriveCom::kError;
2037
2038 if (fCosy)
2039 fPos = fCosy->GetPointingPos();
2040
2041 if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
2042 fStargHistograms->Fill(spots, stars, fD,
2043 fSao->GetZdAz(), sgcenter, /*sgcenterzdaz,*/
2044 star, bright, fPos, t);
2045
2046 if (fCosy)
2047 {
2048 MDriveCom &com = *fCosy->GetDriveCom();
2049 com.SendStargReport(fStatus, fD, fSao->GetZdAz(),
2050 sgcenter, numstars, rc, bright,
2051 time.GetMjd(), 0, 0); // Report
2052 }
2053
2054 } //kStarguider
2055
2056 if (centerisvalid)
2057 {
2058 f2.DrawCircle(skycenter, 2.0, 0x0a);
2059
2060 f2.DrawCircle(skycenter, 7.4, 0x0a); //0.1deg
2061
2062 f2.DrawCircle(skycenter, 2.06*.5*74.0, 0x0a);
2063 f2.DrawCircle(skycenter, 2.32*.5*74.0, 0x0a);
2064 f2.DrawCircle(skycenter, 3.50*.5*74.0, 0x0a);
2065 f2.DrawCircle(skycenter, 3.84*.5*74.0, 0x0a);
2066 }
2067
2068 } //CalcStars
2069
2070 // Draw Circles around center of Camera
2071 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
2072 {
2073 f2.DrawCircle(center, 0x0a);
2074 f2.DrawCircle(center, 5.0,
2075 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
2076 f2.DrawCircle(center, 115.0, 0x0a);
2077 f2.DrawCircle(center, 230.0, 0x0a);
2078 f2.DrawCircle(center, 245.0, 0x0a);
2079 }
2080
2081 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
2082 {
2083 f2.DrawCircle(sgcenter, 0x0a);
2084 f2.DrawCircle(sgcenter, 5.0,
2085 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
2086 }
2087
2088// if (fDisplay->IsEntryChecked(IDM_kCatalog))
2089// {
2090// fSao->PaintImg(cimg, 768, 576);
2091// const float r = 60*60/fSao->GetPixSize();
2092// f2.DrawCircle(0.5*r, 0x0a);
2093// f2.DrawCircle(1.0*r, 0x0a);
2094// f2.DrawCircle(1.5*r, 0x0a);
2095// }
2096
2097 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
2098 fDisplay->IsEntryChecked(IDM_kCatalog) ||
2099 fDisplay->IsEntryChecked(IDM_kFindStar) ||
2100 fOperations->IsEntryChecked(IDM_kRoqueLampAna))
2101 fImage->DrawColImg(img, cimg);
2102 else
2103 fImage->DrawImg(img);
2104}
2105
2106void MStarguider::UpdatePosZoom()
2107{
2108 MString txt;
2109 if (fDisplay->IsEntryChecked(IDM_kCatalog))
2110 {
2111 // FIXME: Necessary?
2112 fSao->Now();
2113 AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
2114 if (aa.Az()<0)
2115 aa.Az(aa.Az()+360);
2116 txt.Print("%.1fd/%.1fd (%d, %d)", -aa.Alt(), aa.Az()-180, fDx, fDy);
2117 }
2118 else
2119 txt.Print("(%d, %d)", fDx, fDy);
2120 fPosZoom->SetText(txt);
2121}
2122
2123Bool_t MStarguider::HandleDoubleClick(Event_t *event)
2124{
2125 const Int_t w = fImage->GetWidth();
2126 const Int_t h = fImage->GetHeight();
2127 const Int_t x = fImage->GetX();
2128 const Int_t y = fImage->GetY();
2129
2130 if (!(event->fX>x && event->fX<x+w && event->fY>y && event->fY<y+h))
2131 return kTRUE;
2132
2133 Int_t dx = event->fX-x;
2134 Int_t dy = event->fY-y;
2135
2136 if (dx<kZOOM/4) dx=kZOOM/4;
2137 if (dy<kZOOM/4) dy=kZOOM/4;
2138 if (dx>766-kZOOM/4) dx=766-kZOOM/4;
2139 if (dy>574-kZOOM/4) dy=574-kZOOM/4;
2140
2141 fDx = dx;
2142 fDy = dy;
2143
2144 UpdatePosZoom();
2145 return kTRUE;
2146}
2147
2148void MStarguider::Print(TString &str, Double_t deg) const
2149{
2150 Char_t sgn;
2151 UShort_t d, m, s;
2152
2153 MAstro::Deg2Dms(deg, sgn, d, m, s);
2154
2155 MString txt;
2156 str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s);
2157}
Note: See TracBrowser for help on using the repository browser.