Ignore:
Timestamp:
04/29/09 13:05:42 (15 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/main/MStarguider.cc

    r9132 r9435  
    99#include <TGraph.h>
    1010#include <TTimer.h>
     11#include <TEnv.h>
    1112#include <TSystem.h>
    1213#include <TFile.h> // temp writeout of histos
    13 #include <TSocket.h>
     14//#include <TSocket.h>
    1415
    1516#include <TGMenu.h>
     
    111112    IDM_kStargAnalysis,
    112113    IDM_kStargCaosFilter,
    113     IDM_kStargFindStar,
    114     IDM_kRoqueLampAna,
    115114    IDM_kStarguiderMode,
    116115    IDM_kTpointMode
     
    273272    fDisplay->AddEntry("Starguider",            IDM_kStarguider);
    274273    fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter);
    275     fDisplay->AddEntry("Starguider Find Star",  IDM_kStargFindStar);
    276274    fDisplay->AddSeparator();   
    277275    if (channel>=0)
    278276        fDisplay->AddPopup("&Input",   fChannel);
    279     fDisplay->DisableEntry(IDM_kStargFindStar);
    280277    fDisplay->CheckEntry(IDM_kStretch);
    281278    fDisplay->Associate(this);
     
    298295    fSetup->Associate(this);
    299296
    300     fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
    301297    fOperations->AddEntry("Starguider Analysis", IDM_kStargAnalysis);
    302298    fOperations->DisableEntry(IDM_kStargAnalysis);
     
    400396    AddFrame(fDZdAzText);
    401397
    402 #ifdef EXPERT
    403     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 #endif
    408 
    409398    // 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);
    417400    fAngle->SetAlignment(kTextCenterX);
    418401    fAngle->Move(547-410, fMenu->GetDefaultHeight()+667);
    419402    AddFrame(fAngle);
    420403
     404    SetRotationAngle(-0.2);
     405
    421406    // 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);
    430408    fPixSize->SetAlignment(kTextCenterX);
    431409    fPixSize->Move(547-410, fMenu->GetDefaultHeight()+690);
    432410    AddFrame(fPixSize);
    433411
     412    SetPixSize(48.9);
     413
    434414    // 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);
    441416    fCut->SetAlignment(kTextCenterX);
    442417    fCut->Move(547-410, fMenu->GetDefaultHeight()+713);
    443418    AddFrame(fCut);
     419
     420    SetCut(3.0);
    444421
    445422    // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
     
    505482      fDx((768-kZOOM)/2),
    506483      fDy((512-kZOOM)/2),
    507       fStatus(MDriveCom::kStandby)
     484      fStatus(MDriveCom::kStandby),
     485      fRadius(200),
     486      fTPointFromCC(0)
    508487{
    509488    gLog << warn << " #### FIXME: Make MCaos Thread safe!" << endl;
     
    513492    SetCleanup();
    514493
    515     fAmcSocket = new TSocket("amc", 7307);
    516 
    517494    fSao = new StarCatalog(obs);
    518495    fRaDec = new RaDec(180, 40);
    519496
    520     //    fStargLeds = new MStargLeds;
    521     //    fStargLeds->ReadResources();
    522 
    523497    fCaos = new MCaos;
    524     fCaos->ReadResources();
    525     fCaos->SetRadii(237.9, 239.9);
    526 
    527498    fStargCaos = new MCaos;
    528     fStargCaos->ReadResources("stargleds.txt");
    529     fStargCaos->SetMinNumberRings(3);
    530     fStargCaos->SetRadii(158,164);
    531499
    532500    fStargHistograms = new MStargHistograms();
     
    539507    fTime.Now();
    540508
    541     fTimeFromTp.Set(1970,1,1);
     509    fTimeFromTp.Clear();
    542510    fAltAzOffsetFromTp = AltAz(-1000,-1000);
    543511                                             
     
    550518}
    551519
     520void MStarguider::SetRotationAngle(Double_t angle)
     521{
     522    fSao->SetRotationAngle(angle);
     523
     524    TString txt;
     525    txt += angle;
     526
     527    fAngle->SetText(txt);
     528}
     529
     530void MStarguider::SetPixSize(Double_t size)
     531{
     532    fSao->SetPixSize(size);
     533
     534    TString txt;
     535    txt += size;
     536
     537    fPixSize->SetText(txt);
     538}
     539
     540void MStarguider::SetCut(Double_t cut)
     541{
     542    TString txt;
     543    txt += cut;
     544
     545    fCut->SetText(txt);
     546}
     547
     548void 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
    552561MStarguider::~MStarguider()
    553562{
     
    564573    delete fCaos;
    565574    delete fStargCaos;
    566     //    delete fStargLeds;
    567575    delete fStargHistograms;
    568576    delete fSao;
     
    578586        delete fOutRq;
    579587
    580     delete fAmcSocket;
    581 
    582588    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;
    606589}
    607590
     
    763746        SwitchOff(fDisplay, IDM_kStarguider);
    764747        SwitchOff(fDisplay, IDM_kStargCaosFilter);
    765         fDisplay->DisableEntry(IDM_kStargFindStar);
    766748    }
    767749    else
     
    858840                return kTRUE;
    859841
    860            case IDM_kRoqueLampAna:
    861                 Toggle(fOperations, IDM_kRoqueLampAna);
    862                 if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
    863                     fDisplay->CheckEntry(IDM_kStargCaosFilter);
    864                 else
    865                     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                 else
    874                     fSZdAz->UnmapWindow();
    875                 return kTRUE;
    876 
    877842            case IDM_kStarguider:
    878843                Toggle(fDisplay, IDM_kStarguider);
     
    892857                    //uncheck not needed items
    893858                    //general
    894                     fDisplay->UnCheckEntry(IDM_kStargFindStar);
    895859                    SwitchOff(fDisplay, IDM_kFilter);
    896860                    SwitchOff(fChannel, IDM_kChannel3);
    897                     SwitchOff(fOperations, IDM_kRoqueLampAna);
    898861                    SwitchOff(fOperations, IDM_kStargAnalysis);
    899862
     
    930893                    fDisplay->EnableEntry(IDM_kFindStar);
    931894                    fChannel->EnableEntry(IDM_kChannel3);
    932                     fOperations->EnableEntry(IDM_kRoqueLampAna);
    933895                }
    934896                return kTRUE;
     
    941903                    //unchecking not needed items
    942904                    //general
    943                     fDisplay->UnCheckEntry(IDM_kStargFindStar);
    944905                    SwitchOff(fDisplay, IDM_kFilter);
    945906                    SwitchOff(fChannel, IDM_kChannel3);
    946                     SwitchOff(fOperations, IDM_kRoqueLampAna);
    947907
    948908                    //from starguider
     
    981941                    fChannel->EnableEntry(IDM_kChannel1);
    982942                    fChannel->EnableEntry(IDM_kChannel3);
    983                     fOperations->EnableEntry(IDM_kRoqueLampAna);
    984943
    985944                    //tpoint
     
    1013972                if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
    1014973                {
    1015                     fDisplay->EnableEntry(IDM_kStargFindStar);
    1016974                    SwitchOff(fDisplay, IDM_kCaosFilter);
    1017975                    SwitchOff(fDisplay, IDM_kFindStar);
     
    1023981                    fDisplay->EnableEntry(IDM_kFindStar);
    1024982                    fDisplay->EnableEntry(IDM_kCaosFilter);
    1025                     fDisplay->DisableEntry(IDM_kStargFindStar);
    1026983                }
    1027984                return kTRUE;
     
    13381295    AltAz pos0 = fSao->CalcAltAzFromPix(768/2,    576/2)*kRad2Deg;
    13391296    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
    13471298    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
    13551300    return ZdAz(-pos1.Alt(), pos1.Az());
    13561301}
     
    13601305{
    13611306    num = leds.GetEntries();
    1362     //cout << "Num: " << num << endl;
    13631307    if (num < 3) //was 1
    13641308    {
    13651309        gLog << warn << "Sorry, less than 3 detected spot in FOV!" << endl;
    1366         if (fStargTPoint->IsDown())
    1367             fStargTPoint->SetDown(kFALSE);
     1310        fStargTPoint->SetDown(kFALSE);
    13681311        return 0;
    13691312    }
    13701313
    1371     //cout << "Cat: " << stars.GetRealEntries() << endl;
    13721314    if (stars.GetRealEntries() < 3)
    13731315    {
    13741316        gLog << warn << "Sorry, less than 3 stars in FOV!" << endl;
    1375         if (fStargTPoint->IsDown())
    1376             fStargTPoint->SetDown(kFALSE);
     1317        fStargTPoint->SetDown(kFALSE);
    13771318        return 0;
    13781319    }
     
    14331374    d = TrackingError(x, y, mag, numcor);
    14341375    if (numcor<1)
     1376    {
     1377        fStargTPoint->SetDown(kFALSE);
    14351378        return 0;
    1436 
    1437     //cout << "Cor: " << numcor << endl;
     1379    }
    14381380
    14391381    fDZdAz->SetCoordinates(d);
    1440 
    1441     //
    1442     // Calculated offsets
    1443     //
    1444 
    1445 #ifdef EXPERT
    1446     // 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 #endif
    14501382
    14511383    //
     
    14761408    // Get tracking coordinates
    14771409    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());
    14791411
    14801412    // From the star position in the camera we calculate the Alt/Az
     
    14851417    //correction with offset from last tpoint measurement
    14861418    za0 -= fAltAzOffsetFromTp;
    1487     MTime t2 = fTimeFromTp;
    14881419
    14891420    //if the difference between the tpoint and the starguider tpoint
    14901421    //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;
    14981425        cout << "     => starguider tpoint hasn't been stored. " << endl;
    1499         cout << "     Please repeat whole procedure. " << endl;
     1426        cout << "        Please repeat whole procedure. " << endl;
    15001427        return numcor;
    15011428    }
     
    15031430
    15041431    // Write real pointing position
    1505     cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
     1432    //cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
    15061433    *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
    15071434
    15081435    // Write system pointing position
    1509     cout << "     SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
     1436    //cout << "     SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
    15101437    *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd();
    15111438
     
    15171444    *fOutStargTp << endl;
    15181445
    1519     fTimeFromTp.Set(1970,1,1);
     1446    fTimeFromTp.Clear();
    15201447
    15211448    return numcor;
    15221449}
    15231450
    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 &center, 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
     1451void MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t)
     1452{
     1453    // Try to find the star
    15671454    Leds leds;
    15681455    f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY(), true);
    1569 
    1570     if (leds.GetEntries()<0)
    1571         return ZdAz(0, 0);
    15721456
    15731457    // Check whether star found
     
    15801464            gLog << warn << "No star found. Couldn't take a tpoint." << endl;
    15811465        }
    1582         return ZdAz(.0,.0);
    1583     }
     1466        return;
     1467    }
     1468
    15841469    cout << "Found star @ " << flush;
    15851470    star->Print();
    15861471    f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
    15871472
    1588     // Initialize Star Catalog on th camera plane
     1473    // Initialize Star Catalog on the camera plane
    15891474    MGeomCamMagic geom;
    15901475    MAstroCamera ac;
     
    15951480
    15961481    // 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());
    15991484
    16001485    ac.SetRaDec(rd.Ra(), rd.Dec());
    16011486
     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
    16021491    // 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;
    16201494
    16211495    // Convert offset from camera plane into local ccordinates
    16221496    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);
    16281498
    16291499    ZdAz zdaz(dzd,daz);
     
    16311501    // Check TPoint data set request
    16321502    if (!fTPoint->IsDown())
    1633         return zdaz;
     1503        return;
     1504
    16341505    fTPoint->SetDown(kFALSE);
    16351506
     
    16411512        //
    16421513        const TString name = MCosy::GetFileName("tpoint", "tpoint", "txt");
    1643         cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
     1514        cout << "TPoint File ********* " << name << " ********** " << endl;
    16441515
    16451516        fOutTp = new ofstream(name);
     
    16521523
    16531524    // 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;
    16551526
    16561527    // From the star position in the camera we calculate the Alt/Az
     
    16641535    fTimeFromTp=t;
    16651536
    1666 
    16671537    // From the Shaftencoders we get the current 'pointing' position
    16681538    // 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]
    16711540
    16721541    // Write real pointing position
    1673     cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
     1542    //cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
    16741543    *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
    16751544
    16761545    // Write system pointing position
    1677     cout << "     SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
     1546    //cout << "     SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
    16781547    *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd();
    16791548
     
    16841553    *fOutTp << " " << star->GetMag();
    16851554    *fOutTp << endl;
    1686 
     1555/*
    16871556    MLog &outrep = *fCosy->GetOutRep();
    16881557    if (outrep.Lock("MStarguider::FindStar"))
     
    16951564        outrep << star->GetX() << " " << star->GetY() << " ";
    16961565        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();
    16981567        outrep << setprecision(11) << t.GetMjd() << endl;
    16991568        outrep.UnLock("MStarguider::FindStar");
    1700     }
     1569    }*/
    17011570   
    1702     return zdaz;
     1571//    return zdaz;
    17031572}
    17041573
     
    17301599
    17311600    return true;
     1601}
     1602
     1603void 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
     1613void 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
     1626void 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
     1634Bool_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;
    17321706}
    17331707
     
    17781752        f.Execute();
    17791753
     1754    DoTPoint();
     1755
     1756    Int_t numleds = 0;
     1757    Int_t numrings = 0;
     1758
    17801759    // Find Center of Camera for Caos and Tpoints
    17811760    Ring center(768/2, 576/2);
     
    17871766        if (fCosy)
    17881767            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();
    17921773    }
    17931774
     
    17961777        center.GetX()>0 && center.GetY()>0)
    17971778    {
    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]
    18191791
    18201792    // 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)_px
    1825     ZdAz star(0, 0);            // Star on curtain in [deg]
    1826 
    18271793    if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
    18281794    {
     
    18311797            pos = fCosy->GetPointingPos();
    18321798
    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    }
    19281804
    19291805    // we obtain a list of stars in the FOV from the SAO catalog
     
    19321808        MTime time(*tm);
    19331809
    1934         XY xy = fCRaDec->GetCoordinates();  //[h,  deg]
    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]
    19361812
    19371813        UpdatePosZoom();
     
    19411817        fCZdAz->SetCoordinates(fSao->GetZdAz());
    19421818
    1943         MStarList stars;
    19441819        fSao->SetBox(230); // Region of interest around center
    19451820
    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)
    19531822        const Bool_t centerisvalid = sgcenter.GetX()>0 && sgcenter.GetY()>0;
    19541823//        if (centerisvalid)
     
    19561825//                            sgcenter.GetY() - 293.6);
    19571826
     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
    19581835        // we obtain stars in the effective star FOV and draw them.
    19591836        // 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;
    19651838        fSao->CalcStars(stars, 530, 292, TMath::FloorNint(off.X()), TMath::FloorNint(off.Y()));
    19661839        fSao->DrawStars(stars, cimg);
     
    20151888
    20161889            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);
    20201892
    20211893            fNumStarsDetected   = numstars;
     
    20281900                    com->SendStargReport(fStatus, fD, fSao->GetZdAz(),
    20291901                                         sgcenter, numstars, rc, bright,
    2030                                          time.GetMjd(), 0, 0);    // Report
     1902                                         time.GetMjd(), numleds, numrings);    // Report
    20311903            }
    20321904
     
    20681940    if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
    20691941        fDisplay->IsEntryChecked(IDM_kCatalog)    ||
    2070         fDisplay->IsEntryChecked(IDM_kFindStar)   ||
    2071         fOperations->IsEntryChecked(IDM_kRoqueLampAna))
     1942        fDisplay->IsEntryChecked(IDM_kFindStar))
    20721943        fImage->DrawColImg(img, cimg);
    20731944    else
Note: See TracChangeset for help on using the changeset viewer.