Changeset 9435 for trunk/MagicSoft/Cosy/main/MStarguider.cc
- Timestamp:
- 04/29/09 13:05:42 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/main/MStarguider.cc
r9132 r9435 9 9 #include <TGraph.h> 10 10 #include <TTimer.h> 11 #include <TEnv.h> 11 12 #include <TSystem.h> 12 13 #include <TFile.h> // temp writeout of histos 13 #include <TSocket.h>14 //#include <TSocket.h> 14 15 15 16 #include <TGMenu.h> … … 111 112 IDM_kStargAnalysis, 112 113 IDM_kStargCaosFilter, 113 IDM_kStargFindStar,114 IDM_kRoqueLampAna,115 114 IDM_kStarguiderMode, 116 115 IDM_kTpointMode … … 273 272 fDisplay->AddEntry("Starguider", IDM_kStarguider); 274 273 fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter); 275 fDisplay->AddEntry("Starguider Find Star", IDM_kStargFindStar);276 274 fDisplay->AddSeparator(); 277 275 if (channel>=0) 278 276 fDisplay->AddPopup("&Input", fChannel); 279 fDisplay->DisableEntry(IDM_kStargFindStar);280 277 fDisplay->CheckEntry(IDM_kStretch); 281 278 fDisplay->Associate(this); … … 298 295 fSetup->Associate(this); 299 296 300 fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);301 297 fOperations->AddEntry("Starguider Analysis", IDM_kStargAnalysis); 302 298 fOperations->DisableEntry(IDM_kStargAnalysis); … … 400 396 AddFrame(fDZdAzText); 401 397 402 #ifdef EXPERT403 l = new TGLabel(this, "Mispointing/FindStar (Experts Only!)");404 l->SetTextJustify(kTextLeft);405 l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*20-5);406 AddFrame(l);407 #endif408 409 398 // Set input box for rotation angle 410 const Double_t angle = -0.2; 411 fSao->SetRotationAngle(angle); 412 413 TString txt; 414 txt += angle; 415 416 fAngle = new TGTextEntry(this, txt, IDM_kAngle); 399 fAngle = new TGTextEntry(this, " ", IDM_kAngle); 417 400 fAngle->SetAlignment(kTextCenterX); 418 401 fAngle->Move(547-410, fMenu->GetDefaultHeight()+667); 419 402 AddFrame(fAngle); 420 403 404 SetRotationAngle(-0.2); 405 421 406 // Set input box for pixel size 422 const Double_t pixsize = 48.9; // used to be 23.4 423 424 fSao->SetPixSize(pixsize); 425 426 txt = ""; 427 txt += pixsize; 428 429 fPixSize = new TGTextEntry(this, txt, IDM_kPixSize); 407 fPixSize = new TGTextEntry(this, " ", IDM_kPixSize); 430 408 fPixSize->SetAlignment(kTextCenterX); 431 409 fPixSize->Move(547-410, fMenu->GetDefaultHeight()+690); 432 410 AddFrame(fPixSize); 433 411 412 SetPixSize(48.9); 413 434 414 // Set input box for cleaning cut 435 const Double_t cut = 3.0; 436 437 txt = ""; 438 txt += cut; 439 440 fCut = new TGTextEntry(this, txt, IDM_kCut); 415 fCut = new TGTextEntry(this, " ", IDM_kCut); 441 416 fCut->SetAlignment(kTextCenterX); 442 417 fCut->Move(547-410, fMenu->GetDefaultHeight()+713); 443 418 AddFrame(fCut); 419 420 SetCut(3.0); 444 421 445 422 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this); … … 505 482 fDx((768-kZOOM)/2), 506 483 fDy((512-kZOOM)/2), 507 fStatus(MDriveCom::kStandby) 484 fStatus(MDriveCom::kStandby), 485 fRadius(200), 486 fTPointFromCC(0) 508 487 { 509 488 gLog << warn << " #### FIXME: Make MCaos Thread safe!" << endl; … … 513 492 SetCleanup(); 514 493 515 fAmcSocket = new TSocket("amc", 7307);516 517 494 fSao = new StarCatalog(obs); 518 495 fRaDec = new RaDec(180, 40); 519 496 520 // fStargLeds = new MStargLeds;521 // fStargLeds->ReadResources();522 523 497 fCaos = new MCaos; 524 fCaos->ReadResources();525 fCaos->SetRadii(237.9, 239.9);526 527 498 fStargCaos = new MCaos; 528 fStargCaos->ReadResources("stargleds.txt");529 fStargCaos->SetMinNumberRings(3);530 fStargCaos->SetRadii(158,164);531 499 532 500 fStargHistograms = new MStargHistograms(); … … 539 507 fTime.Now(); 540 508 541 fTimeFromTp. Set(1970,1,1);509 fTimeFromTp.Clear(); 542 510 fAltAzOffsetFromTp = AltAz(-1000,-1000); 543 511 … … 550 518 } 551 519 520 void MStarguider::SetRotationAngle(Double_t angle) 521 { 522 fSao->SetRotationAngle(angle); 523 524 TString txt; 525 txt += angle; 526 527 fAngle->SetText(txt); 528 } 529 530 void MStarguider::SetPixSize(Double_t size) 531 { 532 fSao->SetPixSize(size); 533 534 TString txt; 535 txt += size; 536 537 fPixSize->SetText(txt); 538 } 539 540 void MStarguider::SetCut(Double_t cut) 541 { 542 TString txt; 543 txt += cut; 544 545 fCut->SetText(txt); 546 } 547 548 void MStarguider::SetupEnv(TEnv &env) 549 { 550 fCaos->ReadEnv(env, "TPointLeds", kTRUE); 551 fStargCaos->ReadEnv(env, "StarguiderLeds", kTRUE); 552 553 SetRotationAngle(env.GetValue("Starguider.RotationAngle", fSao->GetRotationAngle())); 554 SetCut(env.GetValue("Starguider.CleaningLevel", atof(fCut->GetText()))); 555 556 SetPixSize(env.GetValue("StarguiderLeds.ArcsecPerPixel", fSao->GetPixSize())); 557 558 fRadius = env.GetValue("Leds.Radius", fRadius); 559 } 560 552 561 MStarguider::~MStarguider() 553 562 { … … 564 573 delete fCaos; 565 574 delete fStargCaos; 566 // delete fStargLeds;567 575 delete fStargHistograms; 568 576 delete fSao; … … 578 586 delete fOutRq; 579 587 580 delete fAmcSocket;581 582 588 gLog << inf2 << "Camera Display destroyed." << endl; 583 }584 585 bool MStarguider::SendAmcTrigger(const char *msg)586 {587 if (!fAmcSocket->IsValid())588 return false;589 590 TString txt("TRIGGER ");591 txt += msg;592 593 const Int_t len = fAmcSocket->SendRaw(txt.Data(), txt.Length());594 if (len<0)595 {596 gLog << err << "ERROR - Sending Trigger to Amc" << endl;597 return false;598 }599 if (len!=txt.Length())600 {601 gLog << err << "Send wrong number (" << len << ") of Bytes to Amc." << endl;602 return false;603 }604 605 return true;606 589 } 607 590 … … 763 746 SwitchOff(fDisplay, IDM_kStarguider); 764 747 SwitchOff(fDisplay, IDM_kStargCaosFilter); 765 fDisplay->DisableEntry(IDM_kStargFindStar);766 748 } 767 749 else … … 858 840 return kTRUE; 859 841 860 case IDM_kRoqueLampAna:861 Toggle(fOperations, IDM_kRoqueLampAna);862 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))863 fDisplay->CheckEntry(IDM_kStargCaosFilter);864 else865 fDisplay->UnCheckEntry(IDM_kStargCaosFilter);866 867 return kTRUE;868 869 case IDM_kStargFindStar:870 Toggle(fDisplay, IDM_kStargFindStar);871 if (fDisplay->IsEntryChecked(IDM_kStargFindStar))872 fSZdAz->MapWindow();873 else874 fSZdAz->UnmapWindow();875 return kTRUE;876 877 842 case IDM_kStarguider: 878 843 Toggle(fDisplay, IDM_kStarguider); … … 892 857 //uncheck not needed items 893 858 //general 894 fDisplay->UnCheckEntry(IDM_kStargFindStar);895 859 SwitchOff(fDisplay, IDM_kFilter); 896 860 SwitchOff(fChannel, IDM_kChannel3); 897 SwitchOff(fOperations, IDM_kRoqueLampAna);898 861 SwitchOff(fOperations, IDM_kStargAnalysis); 899 862 … … 930 893 fDisplay->EnableEntry(IDM_kFindStar); 931 894 fChannel->EnableEntry(IDM_kChannel3); 932 fOperations->EnableEntry(IDM_kRoqueLampAna);933 895 } 934 896 return kTRUE; … … 941 903 //unchecking not needed items 942 904 //general 943 fDisplay->UnCheckEntry(IDM_kStargFindStar);944 905 SwitchOff(fDisplay, IDM_kFilter); 945 906 SwitchOff(fChannel, IDM_kChannel3); 946 SwitchOff(fOperations, IDM_kRoqueLampAna);947 907 948 908 //from starguider … … 981 941 fChannel->EnableEntry(IDM_kChannel1); 982 942 fChannel->EnableEntry(IDM_kChannel3); 983 fOperations->EnableEntry(IDM_kRoqueLampAna);984 943 985 944 //tpoint … … 1013 972 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter)) 1014 973 { 1015 fDisplay->EnableEntry(IDM_kStargFindStar);1016 974 SwitchOff(fDisplay, IDM_kCaosFilter); 1017 975 SwitchOff(fDisplay, IDM_kFindStar); … … 1023 981 fDisplay->EnableEntry(IDM_kFindStar); 1024 982 fDisplay->EnableEntry(IDM_kCaosFilter); 1025 fDisplay->DisableEntry(IDM_kStargFindStar);1026 983 } 1027 984 return kTRUE; … … 1338 1295 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg; 1339 1296 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+mx, 576/2+my)*kRad2Deg; 1340 /* 1341 ofstream fout1("pointingpos.txt"); 1342 fout1 << setprecision(10) << fSao->GetMjd()-52000 << " "; 1343 if (fCosy) 1344 fout1 << fCosy->GetPointingPos() << " "; 1345 fout1 << -pos1.Alt() << " " << pos1.Az() << endl; 1346 */ 1297 1347 1298 pos1 -= pos0; 1348 /* 1349 ofstream fout2("tracking_error.txt", ios::app); 1350 fout2 << setprecision(10) << fSao->GetMjd()-52000 << " "; 1351 if (fCosy) 1352 fout2 << fCosy->GetPointingPos() << " "; 1353 fout2 << -pos1.Alt() << " " << pos1.Az() << endl; 1354 */ 1299 1355 1300 return ZdAz(-pos1.Alt(), pos1.Az()); 1356 1301 } … … 1360 1305 { 1361 1306 num = leds.GetEntries(); 1362 //cout << "Num: " << num << endl;1363 1307 if (num < 3) //was 1 1364 1308 { 1365 1309 gLog << warn << "Sorry, less than 3 detected spot in FOV!" << endl; 1366 if (fStargTPoint->IsDown()) 1367 fStargTPoint->SetDown(kFALSE); 1310 fStargTPoint->SetDown(kFALSE); 1368 1311 return 0; 1369 1312 } 1370 1313 1371 //cout << "Cat: " << stars.GetRealEntries() << endl;1372 1314 if (stars.GetRealEntries() < 3) 1373 1315 { 1374 1316 gLog << warn << "Sorry, less than 3 stars in FOV!" << endl; 1375 if (fStargTPoint->IsDown()) 1376 fStargTPoint->SetDown(kFALSE); 1317 fStargTPoint->SetDown(kFALSE); 1377 1318 return 0; 1378 1319 } … … 1433 1374 d = TrackingError(x, y, mag, numcor); 1434 1375 if (numcor<1) 1376 { 1377 fStargTPoint->SetDown(kFALSE); 1435 1378 return 0; 1436 1437 //cout << "Cor: " << numcor << endl; 1379 } 1438 1380 1439 1381 fDZdAz->SetCoordinates(d); 1440 1441 //1442 // Calculated offsets1443 //1444 1445 #ifdef EXPERT1446 // round= floor(x+.5)1447 cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;1448 cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;1449 #endif1450 1382 1451 1383 // … … 1476 1408 // Get tracking coordinates 1477 1409 const XY xy = fCRaDec->GetCoordinates(); 1478 const RaDec rd(xy.X()* TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());1410 const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad()); 1479 1411 1480 1412 // From the star position in the camera we calculate the Alt/Az … … 1485 1417 //correction with offset from last tpoint measurement 1486 1418 za0 -= fAltAzOffsetFromTp; 1487 MTime t2 = fTimeFromTp;1488 1419 1489 1420 //if the difference between the tpoint and the starguider tpoint 1490 1421 //is too big, the starguider tpoint is not stored 1491 cout << " mjd difference: " << t.GetMjd()-t2.GetMjd() << endl; 1492 // cout << "t: " << setprecision(11) << t.GetMjd() << endl; 1493 // cout << "t2: " << setprecision(11) << t2.GetMjd() << endl; 1494 if ((t.GetMjd()-t2.GetMjd())>0.001) //1min20sec 1495 { 1496 cout << " time difference between tpoint and starguider-tpoint > 1 min *" << 1497 t.GetMjd()-t2.GetMjd() << "s) " << endl; 1422 if ((t.GetMjd()-fTimeFromTp.GetMjd())>0.001) //1min20sec 1423 { 1424 cout << " time difference between tpoint and starguider-tpoint > 1m20s" << endl; 1498 1425 cout << " => starguider tpoint hasn't been stored. " << endl; 1499 cout << " Please repeat whole procedure. " << endl;1426 cout << " Please repeat whole procedure. " << endl; 1500 1427 return numcor; 1501 1428 } … … 1503 1430 1504 1431 // Write real pointing position 1505 cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;1432 //cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl; 1506 1433 *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " "; 1507 1434 1508 1435 // Write system pointing position 1509 cout << " SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;1436 //cout << " SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl; 1510 1437 *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd(); 1511 1438 … … 1517 1444 *fOutStargTp << endl; 1518 1445 1519 fTimeFromTp. Set(1970,1,1);1446 fTimeFromTp.Clear(); 1520 1447 1521 1448 return numcor; 1522 1449 } 1523 1450 1524 XY MStarguider::FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, Double_t cut, Int_t box, XY SearchCenter) 1525 { 1526 // Set search Paremeters (FIXME: Get them from user input!) 1527 f.SetCut(cut); // 3.5 1528 f.SetBox(box); // 70 1529 1530 // Try to find Led in this area 1531 Leds leds; 1532 f.FindStar(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y(), true); 1533 1534 // Check whether star found 1535 Led *star = (Led*)leds.At(0); 1536 if (!star || leds.GetEntries()<1) 1537 return XY(.0,.0); 1538 1539 // cout << "Found Roque Lamp @ " << flush; 1540 star->Print(); 1541 f.MarkPoint(star->GetX(), star->GetY(), 500); 1542 1543 // cout << "RoquePos: " << star->GetX() << "," << star->GetY() << endl; 1544 1545 XY roquepos(star->GetX(), star->GetY()); 1546 XY relroquepos(roquepos.X()-CameraCenter.GetX(), roquepos.Y()-CameraCenter.GetY()); 1547 1548 // If no file open: open new Roque Lamp file 1549 if (!fOutRq) 1550 { 1551 const TString name = MCosy::GetFileName("tpoint", "roquelamp", "txt"); 1552 cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl; 1553 fOutRq = new ofstream(name); 1554 *fOutRq << "# Magic Roque Lamp file " << t << endl; 1555 } 1556 1557 return relroquepos; 1558 } 1559 1560 ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring ¢er, MTime &t, Double_t cut, Int_t box, Double_t scalefactor = 1.0) 1561 { 1562 // Set search Paremeters (FIXME: Get them from user input!) 1563 f.SetCut(cut); // 3.5 1564 f.SetBox(box); // 70 1565 1566 // Try to find Led in this area 1451 void MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring ¢er, MTime &t) 1452 { 1453 // Try to find the star 1567 1454 Leds leds; 1568 1455 f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY(), true); 1569 1570 if (leds.GetEntries()<0)1571 return ZdAz(0, 0);1572 1456 1573 1457 // Check whether star found … … 1580 1464 gLog << warn << "No star found. Couldn't take a tpoint." << endl; 1581 1465 } 1582 return ZdAz(.0,.0); 1583 } 1466 return; 1467 } 1468 1584 1469 cout << "Found star @ " << flush; 1585 1470 star->Print(); 1586 1471 f2.MarkPoint(star->GetX(), star->GetY(), 2<<2); 1587 1472 1588 // Initialize Star Catalog on th camera plane1473 // Initialize Star Catalog on the camera plane 1589 1474 MGeomCamMagic geom; 1590 1475 MAstroCamera ac; … … 1595 1480 1596 1481 // Get tracking coordinates 1597 const XY xy = fCRaDec->GetCoordinates();1598 const RaDec rd(xy.X()* TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());1482 const XY xy = fCRaDec->GetCoordinates(); // [h, deg] 1483 const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad()); 1599 1484 1600 1485 ac.SetRaDec(rd.Ra(), rd.Dec()); 1601 1486 1487 // Convert from Pixel to millimeter (1pix=2.6mm) [deg/pix / deg/mm = mm/pix] 1488 // Correct for abberation. 1489 const Double_t conv = fCaos->GetArcsecPerPixel()/3600/geom.GetConvMm2Deg()/ 1.0713; 1490 1602 1491 // Adapt coordinate system (GUIs and humans are counting Y in different directions) 1603 Double_t x = star->GetX()-center.GetX(); 1604 Double_t y = center.GetY()-star->GetY(); 1605 1606 #ifdef EXPERT 1607 cout << "STAR-Offset: " << MTime(-1) << " dx=" << x << "pix dy=" << y << "pix" << endl; 1608 #endif 1609 1610 // MAKE SURE THAT THIS VALUE CAN BE SETUP 1611 // (Scalefactor describes the difference between the tpoint (=1) 1612 // and the starguider (!=1) camera 1613 // Convert from Pixel to millimeter (1pix=2.6mm) 1614 x *= (2.58427 * scalefactor); 1615 y *= (2.58427 * scalefactor); 1616 1617 // Correct for abberation. 1618 x /= 1.0713; 1619 y /= 1.0713; 1492 const Double_t dx = (star->GetX()-center.GetX())*conv; 1493 const Double_t dy = (center.GetY()-star->GetY())*conv; 1620 1494 1621 1495 // Convert offset from camera plane into local ccordinates 1622 1496 Double_t dzd, daz; 1623 ac.GetDiffZdAz(x, y, dzd, daz); 1624 1625 #ifdef EXPERT 1626 cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d dAz=" << daz << "d" << endl; 1627 #endif 1497 ac.GetDiffZdAz(dx, dy, dzd, daz); 1628 1498 1629 1499 ZdAz zdaz(dzd,daz); … … 1631 1501 // Check TPoint data set request 1632 1502 if (!fTPoint->IsDown()) 1633 return zdaz; 1503 return; 1504 1634 1505 fTPoint->SetDown(kFALSE); 1635 1506 … … 1641 1512 // 1642 1513 const TString name = MCosy::GetFileName("tpoint", "tpoint", "txt"); 1643 cout << "TPoint -StargFile ********* " << name << " ********** " << endl;1514 cout << "TPoint File ********* " << name << " ********** " << endl; 1644 1515 1645 1516 fOutTp = new ofstream(name); … … 1652 1523 1653 1524 // Output Ra/Dec the drive system thinks that it is currently tracking 1654 cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;1525 //cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl; 1655 1526 1656 1527 // From the star position in the camera we calculate the Alt/Az … … 1664 1535 fTimeFromTp=t; 1665 1536 1666 1667 1537 // From the Shaftencoders we get the current 'pointing' position 1668 1538 // as it is seen by the drive system (system pointing position) 1669 // FIXME???? 1670 const ZdAz za1 = fCosy->GetSePos()*TMath::TwoPi(); 1539 const ZdAz za1 = fCosy->GetSePos()*360; // [deg] 1671 1540 1672 1541 // Write real pointing position 1673 cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;1542 //cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl; 1674 1543 *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " "; 1675 1544 1676 1545 // Write system pointing position 1677 cout << " SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;1546 //cout << " SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl; 1678 1547 *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd(); 1679 1548 … … 1684 1553 *fOutTp << " " << star->GetMag(); 1685 1554 *fOutTp << endl; 1686 1555 /* 1687 1556 MLog &outrep = *fCosy->GetOutRep(); 1688 1557 if (outrep.Lock("MStarguider::FindStar")) … … 1695 1564 outrep << star->GetX() << " " << star->GetY() << " "; 1696 1565 outrep << center.GetX() << " " << center.GetY() << " "; 1697 outrep << x*1.0713/2.58427 << " " << y*1.0713/2.58427<< " " << star->GetMag();1566 outrep << dx/conv << " " << dy/conv << " " << star->GetMag(); 1698 1567 outrep << setprecision(11) << t.GetMjd() << endl; 1699 1568 outrep.UnLock("MStarguider::FindStar"); 1700 } 1569 }*/ 1701 1570 1702 return zdaz;1571 // return zdaz; 1703 1572 } 1704 1573 … … 1730 1599 1731 1600 return true; 1601 } 1602 1603 void MStarguider::DrawZoomImage(const byte *img) 1604 { 1605 byte zimg[kZOOM*kZOOM]; 1606 for (int y=0; y<kZOOM; y++) 1607 for (int x=0; x<kZOOM; x++) 1608 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768]; 1609 1610 fZoomImage->DrawImg(zimg); 1611 } 1612 1613 void MStarguider::DrawCosyImage(const byte *img) 1614 { 1615 if (!fCosy) 1616 return; 1617 1618 byte simg[(768/2-1)*(576/2-1)]; 1619 for (int y=0; y<576/2-1; y++) 1620 for (int x=0; x<768/2-1; x++) 1621 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; 1622 1623 fCosy->GetWin()->GetImage()->DrawImg(simg); 1624 } 1625 1626 void MStarguider::StartStarguider() 1627 { 1628 // Switch to starguider mode 1629 cout << " * Switching to Starguider mode" << endl; 1630 fMode->UnCheckEntry(IDM_kStarguiderMode); 1631 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0); 1632 } 1633 1634 Bool_t MStarguider::DoTPoint() 1635 { 1636 if (fTPointFromCC<0) 1637 return kTRUE; 1638 1639 switch (++fTPointFromCC) 1640 { 1641 case 1: 1642 fTimeFromTp.Clear(); 1643 fNumStarsDetected = 0; 1644 1645 cout << " * Switching to TPoint mode" << endl; 1646 // Switch to tpoint mode 1647 fMode->UnCheckEntry(IDM_kTpointMode); 1648 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kTpointMode, 0); 1649 return kFALSE; 1650 1651 case 2: 1652 cout << " * Waiting one frame" << endl; 1653 // Wait one frame 1654 return kFALSE; 1655 1656 case 3: 1657 cout << " * Taking TPoint" << endl; 1658 fTPoint->SetDown(); // kTRUE 1659 return kTRUE; 1660 1661 case 4: 1662 if (!fTimeFromTp) // TPoint failed 1663 break; 1664 1665 // Switch to starguider mode 1666 cout << " * Switching to Starguider mode" << endl; 1667 fMode->UnCheckEntry(IDM_kStarguiderMode); 1668 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0); 1669 return kFALSE; 1670 1671 case 5: 1672 cout << " * Waiting one frame" << endl; 1673 // Wait one frame 1674 return kFALSE; 1675 1676 case 6: 1677 cout << " * Taking Starguider TPoint" << endl; 1678 fStargTPoint->SetDown(); // kTRUE 1679 return kTRUE; 1680 1681 case 7: 1682 cout << " * Send Report" << endl; 1683 break; 1684 } 1685 1686 // Send report 1687 fTPointFromCC = -1; 1688 1689 if (!fCosy) 1690 return kTRUE; 1691 1692 MDriveCom *com = fCosy->GetDriveCom(); 1693 if (!com) 1694 return kTRUE; 1695 1696 // nominalaz, nominalel, realaz, realel, nomra, nomdec, 1697 // diffaz, diffel, mjd, numleds, artmag 1698 1699 //fTimeFromTp.Clear(); 1700 //fStatus==MDriveCom::kMonitoring 1701 //fNumStarsDetected = numstars; 1702 //fNumStarsCorrelated = rc; 1703 com->SendTPoint(fNumStarsCorrelated>0); 1704 1705 return kTRUE; 1732 1706 } 1733 1707 … … 1778 1752 f.Execute(); 1779 1753 1754 DoTPoint(); 1755 1756 Int_t numleds = 0; 1757 Int_t numrings = 0; 1758 1780 1759 // Find Center of Camera for Caos and Tpoints 1781 1760 Ring center(768/2, 576/2); … … 1787 1766 if (fCosy) 1788 1767 pos = fCosy->GetPointingPos(); 1789 center = fCaos->Run(img, printl, printr, pos, t, 19, 3.0); 1790 cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << " (R=" << center.GetR() << ")" << endl; 1791 1768 1769 center = fCaos->Run(img, printl, printr, pos, t); 1770 1771 numleds = fCaos->GetNumDetectedLEDs(); 1772 numrings = fCaos->GetNumDetectedRings(); 1792 1773 } 1793 1774 … … 1796 1777 center.GetX()>0 && center.GetY()>0) 1797 1778 { 1798 // SCALE FACTOR ASSUMED TO BE 70 1799 FindStar(f, f2, center, t, 3/*3.5*/, 70); 1800 SendAmcTrigger("TPoint"); 1801 } 1802 1803 byte zimg[kZOOM*kZOOM]; 1804 for (int y=0; y<kZOOM; y++) 1805 for (int x=0; x<kZOOM; x++) 1806 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768]; 1807 1808 fZoomImage->DrawImg(zimg); 1809 1810 if (fCosy) 1811 { 1812 byte simg[(768/2-1)*(576/2-1)]; 1813 for (int y=0; y<576/2-1; y++) 1814 for (int x=0; x<768/2-1; x++) 1815 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; 1816 1817 fCosy->GetWin()->GetImage()->DrawImg(simg); 1818 } 1779 // Set search Paremeters (FIXME: Get them from user input!) 1780 f.SetCut(3.0); 1781 f.SetBox(70); 1782 1783 FindStar(f, f2, center, t); 1784 } 1785 1786 DrawZoomImage(img); 1787 DrawCosyImage(img); 1788 1789 // Position corresponding to the camera center (53.2, 293.6) 1790 Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px] 1819 1791 1820 1792 // Find Center of Camera in Starfield Camera picture 1821 1822 Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px]1823 //ZdAz sgcenterzdaz(0, 0); // Center of camera in SG picture [deg]1824 // // (0,0)_deg is at (53.2, 293.6)_px1825 ZdAz star(0, 0); // Star on curtain in [deg]1826 1827 1793 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter)) 1828 1794 { … … 1831 1797 pos = fCosy->GetPointingPos(); 1832 1798 1833 sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 19, 3.0); // [px] 1834 1835 //const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px] 1836 1837 // BE CAREFULL: This transformation is WRONG. It is just 1838 // a transformation of units, but this implies, that the 1839 // coordiante axis in both units look the same. This is 1840 // wrong exspecially near the zenith were az-lines are highly 1841 // curved around the zenith! 1842 //sgcenterzdaz.Zd((sgcenter.GetY()-293.6) * pixsize /3600 ); 1843 //sgcenterzdaz.Az((sgcenter.GetX()-53.2) * pixsize /3600 ); 1844 #ifdef EXPERT 1845 cout << "- LEDs imply offset of Zd=" 1846 << sgcenter.GetX()-53.2 << "pix Az=" 1847 << sgcenter.GetY()-293.6<< "pix" << endl; 1848 #endif 1849 if (fDisplay->IsEntryChecked(IDM_kStargFindStar) && 1850 sgcenter.GetX()>0 && sgcenter.GetY()>0) 1851 { 1852 star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg] 1853 #ifdef EXPERT 1854 cout << "- Star is found to be off Zd=" << star.Zd()*60 << "' Az=" 1855 << star.Az()*60 << "'" << endl; 1856 #endif 1857 fSZdAz->SetCoordinates(star); // Mispointing found from Camera 1858 1859 SendAmcTrigger("Starguider"); 1860 } 1861 } 1862 1863 // Find Roque Lamp 1864 1865 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) 1866 { 1867 1868 Double_t imageclean = 1.5; 1869 Int_t boxradius = 60; 1870 //Double_t scalefactor = 1; 1871 XY searchcenter(768/2-1,576/2+25); 1872 1873 XY roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter); 1874 1875 if (fOutRq) 1876 { 1877 ZdAz pos = fCosy->GetPointingPos(); 1878 1879 *fOutRq << "RoqueLampDirect: " << MTime(-1) << " " 1880 << pos.Zd() << " " << pos.Az() << " " 1881 << roquelamp.X() << " " << roquelamp.Y() << endl; 1882 } 1883 1884 cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl; 1885 cout << ">=>=>=> Roque Lamp found at: >=>=>=> (" << roquelamp.X() << "," 1886 << roquelamp.Y() << ") <=<=<=<" << endl; 1887 1888 } 1889 1890 // Find Spot on Camera Center in Starguider camera 1891 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) 1892 { 1893 XY cameraspot(0,0); 1894 1895 Double_t imageclean = 5; 1896 Int_t boxradius = 60; 1897 //Double_t scalefactor = 1; 1898 // XY searchcenter(sgcenter.GetX(),sgcenter.GetY()); 1899 XY searchcenter(60.,290.); 1900 1901 cameraspot = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter); 1902 1903 if (fOutRq) 1904 { 1905 ZdAz pos = fCosy->GetPointingPos(); 1906 1907 *fOutRq << "RoqueLampReflected: " << MTime(-1) << " " 1908 << pos.Zd() << " " << pos.Az() << " " 1909 << cameraspot.X() << " " << cameraspot.Y() << endl; 1910 } 1911 1912 cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << "," 1913 << cameraspot.Y() << ") <<<<<" << endl; 1914 1915 f2.DrawCircle(sgcenter, 5.0, 0x0fa); 1916 f2.DrawCircle(sgcenter, 115.0, 0x0fa); 1917 } 1918 // we calculate the offset given by the three ETH Leds visible to 1919 // the guide camera 1920 // This is an (inferior, obsolete) alternative to the StarCaosFilter 1921 // Led offset; 1922 // if (fDisplay->IsEntryChecked(IDM_kStargLEDFilter)) 1923 // fStargLeds->Run(img,offset); 1924 1925 // Position corresponding to the camera center (53.2, 293.6) 1926 //Ring skycenter(392, 318); 1927 // MStarList spots; 1799 sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t); // [px] 1800 1801 numleds = fStargCaos->GetNumDetectedLEDs(); 1802 numrings = fStargCaos->GetNumDetectedRings(); 1803 } 1928 1804 1929 1805 // we obtain a list of stars in the FOV from the SAO catalog … … 1932 1808 MTime time(*tm); 1933 1809 1934 1935 fRaDec->Set(xy.X()* 360/24, xy.Y());//[deg,deg]1810 XY xy = fCRaDec->GetCoordinates(); //[h, deg] 1811 fRaDec->Set(xy.X()*15, xy.Y()); //[deg,deg] 1936 1812 1937 1813 UpdatePosZoom(); … … 1941 1817 fCZdAz->SetCoordinates(fSao->GetZdAz()); 1942 1818 1943 MStarList stars;1944 1819 fSao->SetBox(230); // Region of interest around center 1945 1820 1946 // very careful: If center of camera cannot be determined 1947 // sgcenter jumps to (0,0) 1948 1949 //Please never change this offsets!!! 1950 // 53.2 and 293.6 are the "preliminary" camera center 1951 // -9 and 28.5 are the offsets of the pointing position in the sky 1952 1821 // If center of camera cannot be determined sgcenter is (0,0) 1953 1822 const Bool_t centerisvalid = sgcenter.GetX()>0 && sgcenter.GetY()>0; 1954 1823 // if (centerisvalid) … … 1956 1825 // sgcenter.GetY() - 293.6); 1957 1826 1827 // We determine the ideal starfield using camera sagging info 1828 // from the LEDs 1829 //Please never change this offsets!!! 1830 // 53.2 and 293.6 are the "preliminary" camera center 1831 // -9 and 28.5 are the offsets of the pointing position in the sky 1832 const XY off(sgcenter.GetX()- 53.2-9, 1833 sgcenter.GetY()-293.6+28.5); 1834 1958 1835 // we obtain stars in the effective star FOV and draw them. 1959 1836 // coordinates are video frame coords. 1960 // We determine the ideal starfield using camera sagging info 1961 // from the LEDs 1962 const XY off(sgcenter.GetX()- 53.2-9, 1963 sgcenter.GetY()-293.6+28.5); 1964 1837 MStarList stars; 1965 1838 fSao->CalcStars(stars, 530, 292, TMath::FloorNint(off.X()), TMath::FloorNint(off.Y())); 1966 1839 fSao->DrawStars(stars, cimg); … … 2015 1888 2016 1889 if (fOperations->IsEntryChecked(IDM_kStargAnalysis)) 2017 fStargHistograms->Fill(spots, stars, fD, 2018 fSao->GetZdAz(), sgcenter, /*sgcenterzdaz,*/ 2019 star, bright, fPos, t); 1890 fStargHistograms->Fill(spots, stars, fD, fSao->GetZdAz(), 1891 sgcenter, bright, fPos, t); 2020 1892 2021 1893 fNumStarsDetected = numstars; … … 2028 1900 com->SendStargReport(fStatus, fD, fSao->GetZdAz(), 2029 1901 sgcenter, numstars, rc, bright, 2030 time.GetMjd(), 0, 0); // Report1902 time.GetMjd(), numleds, numrings); // Report 2031 1903 } 2032 1904 … … 2068 1940 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) || 2069 1941 fDisplay->IsEntryChecked(IDM_kCatalog) || 2070 fDisplay->IsEntryChecked(IDM_kFindStar) || 2071 fOperations->IsEntryChecked(IDM_kRoqueLampAna)) 1942 fDisplay->IsEntryChecked(IDM_kFindStar)) 2072 1943 fImage->DrawColImg(img, cimg); 2073 1944 else
Note:
See TracChangeset
for help on using the changeset viewer.