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