Changeset 7230


Ignore:
Timestamp:
07/28/05 22:24:32 (19 years ago)
Author:
fgoebel
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Changelog

    r6923 r7230  
    11                                                                  -*-*- END -*-*-
     2
     3 2005/07/28 - Florian Goebel
     4
     5  * videodev/FilterLed.[cc,h]
     6    - add GetMeanPositionCircle and FindStarCircle
     7 
     8  * devdrv/shaftencoder.[cc,h]
     9    - add: fDirHasChanged, fDirChangedPos, fDirChangedOffset,
     10           fDirection, fHysteresisPos, fHysteresisNeg
     11
     12  * main/MCosy.cc
     13    - set faster acceleration and Velocity parameters in TrackPositionGRB
     14
     15  * main/MPointing.cc
     16    - correct bug which always set speed to LO-SPEED
     17
     18  * main/MStarguider.[cc,h]
     19    - add new Popup "Operation" (functionality is not ready yet)
     20    - add new procedure: FindRoqueLamp
     21    - in MStarguider::FindStar now use Leds::FindStarCircle
     22      (instead of Leds::FindStar)
     23
     24  * main/MTracking.cc
     25    - calculate DirHasChanged etc.
     26 
    227
    328 2005/04/11 - Thomas Bretz
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc

    r4104 r7230  
    1616ShaftEncoder::ShaftEncoder(const BYTE_t nodeid, const char *name, MLog &out)
    1717    : NodeDrv(nodeid, name, out), fPos(0), fVel(0), fAcc(0),
    18     fTurn(0), fLabel(NULL), fPosHasChanged(false), fReport(NULL),/*fTwin(0),
    19     fIsUpdated(kFALSE),*/ fMotor(0), fOffset(0)
     18    fTurn(0), fLabel(NULL), fPosHasChanged(false), fDirHasChanged(false),
     19    fReport(NULL),
     20    /*fTwin(0), fIsUpdated(kFALSE),*/
     21      fMotor(0), fOffset(0), fDirChangedPos(0),
     22      fDirection(kUndefined), fHysteresisPos(0), fHysteresisNeg(0)
    2023{
    2124}
     
    9396        fPos  = val;
    9497        fTurn = 0;
     98        fDirChangedPos = val;
    9599        fOffset = fMotor ? fMotor->GetPdoPos() : 0;
     100        fPosHasChanged = true;
     101        fDirHasChanged = true;
     102        fDirection = kUndefined;
    96103        //fIsUpdated=kTRUE;
    97104        //fOffset = 0;
     
    198205    //    return;
    199206
     207    // Warning: A multiturn shaftencoder is assumed!
     208    if ((pos>fDirChangedPos && pos<fPos) ||
     209        (pos<fDirChangedPos && pos>fPos))
     210    {
     211        fDirChangedPos = pos;
     212        fDirHasChanged = true;
     213    }
     214    else
     215        fOffset = fMotor ? fMotor->GetPdoPos() : 0;
     216
    200217    fPos = pos;
    201     fOffset = fMotor ? fMotor->GetPdoPos() : 0;
    202218    fTime.Set(*tv);
    203219    fPosHasChanged = true;
     
    225241    //    return;
    226242
     243    // Warning: A multiturn shaftencoder is assumed!
     244    if ((pos>fDirChangedPos && pos<fPos) ||
     245        (pos<fDirChangedPos && pos>fPos))
     246    {
     247        fDirChangedPos = pos;
     248        fDirHasChanged = true;
     249    }
     250    else
     251        fOffset = fMotor ? fMotor->GetPdoPos() : 0;
     252
    227253    //CheckTwin(fPos-pos);
    228254    fPos=pos;
    229     fOffset = fMotor ? fMotor->GetPdoPos() : 0;
    230255    fTime.Set(*tv);
    231256    fPosHasChanged=true;
     
    267292        turn--;
    268293
     294    LWORDS_t multipos = pos+turn*fTicks; // SE position of multiturn shaftencoder
     295
    269296    //if (fPos==pos && fTurn==fTurn)
    270297    //    return;
     
    272299    //CheckTwin(fPos-pos);
    273300
     301    fOffset = fMotor ? fMotor->GetPdoPos() : 0;
     302
     303    // Warning: A multiturn shaftencoder is assumed!
     304    if ((multipos>fDirChangedPos && multipos<fPos) ||
     305        (multipos<fDirChangedPos && multipos>fPos))
     306    {
     307        fDirChangedPos = GetPos();
     308        fDirHasChanged = true;
     309        fDirChangedOffset = fOffset;
     310    }
     311    else
     312    {
     313        fDirHasChanged = false;
     314    }
     315
     316    if (multipos>GetPos()) fDirection = kForward;
     317    else if (multipos<GetPos()) fDirection = kBackward;
     318    else fDirection = kUndefined;
     319
     320
    274321    fPos  = pos;
    275322    fTurn = turn;
    276323
    277     fOffset = fMotor ? fMotor->GetPdoPos() : 0;
    278324    fTime.Set(*tv);
    279325    fPosHasChanged=true;
     
    281327    //fOffset = 0;
    282328
    283 
    284329    if (fReport)
    285330    {
    286331        fReport->Lock("ShaftEncoder::HandlePDOType2");
    287332        *fReport << "SE-REPORT " << (int)GetId() << " " << fTime << " PDO2 " << pos << " " << fVel << " " << fAcc << " " << GetNodeName() << endl;
     333        *fReport << "DIR-REPORT " << (int)GetId() << " " << (Int_t)fDirHasChanged << " " << (Int_t)fDirChangedPos << endl;
    288334        fReport->UnLock("ShaftEncoder::HandlePDOType2");
    289335    }
     
    415461    fPos  = pre%16384;
    416462    fTurn = pre/16384;
    417 
     463    fDirChangedPos = fPos;
    418464    fOffset = fMotor ? fMotor->GetPdoPos() : 0;
     465
     466    fPosHasChanged = true;
     467    fDirHasChanged = true;
     468
     469    fDirection = kUndefined;
    419470}
    420471
  • trunk/MagicSoft/Cosy/devdrv/shaftencoder.h

    r4104 r7230  
    1313class TGLabel;
    1414
     15enum Direction_t { kUndefined, kForward, kBackward };                                                   
     16
    1517class ShaftEncoder : public NodeDrv
    1618{
     
    2325    WORD_t   fTurns; // Number of possible turns
    2426
     27    Direction_t fDirection;
     28 
     29    Float_t fHysteresisPos;
     30    Float_t fHysteresisNeg;
     31
    2532    TGLabel  *fLabel;     //
    2633    LWORDS_t  fUpdPos;    // ticks
    2734
    2835    bool fPosHasChanged;  //!
     36    bool fDirHasChanged;  //!
    2937
    3038    MTime fTime;
    3139    MLog *fReport;
    3240
    33     Macs *fMotor;
    34     Int_t fOffset;
     41    Macs *fMotor;     // Corresponding Motor/MACS
     42    Int_t fOffset;    // offset between SE and Motor
     43    Int_t fDirChangedPos; // Last position at which the SE changed its moving direction
     44    Int_t fDirChangedOffset; // Offset between SE and Motor when SE changed its moving direction last
     45
    3546
    3647    void HandlePDOType0(BYTE_t *data, timeval_t *tv);
     
    6273    void HandlePDO2(BYTE_t *data, timeval_t *tv) { HandlePDOType2(data, tv); }
    6374
    64     LWORDS_t GetPos() const { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0?
     75    LWORDS_t GetPos() const       { return IsZombieNode() ? 0 : fPos+fTurn*fTicks; } // FIXME? 0?
     76    Int_t    GetDirection() const { return IsZombieNode() ? 0 : fPos-fDirChangedPos; } // FIXME? 0?
     77    Int_t    GetDirChangedPos() const { return IsZombieNode() ? 0 : fDirChangedPos; } // FIXME? 0?
    6578    LWORD_t  GetPhysRes() const { return fTicks; }
    6679    Int_t    GetOffset() const { return fOffset; }
     80    Int_t    GetDirChangedOffset() const { return fDirChangedOffset; }
     81
    6782    void     SetOffset(Int_t off) { fOffset = off; }
    6883
     
    7489
    7590    bool PosHasChanged() const { return fPosHasChanged; }
     91    bool DirHasChanged() const { return fDirHasChanged; }
    7692    void ResetPosHasChanged() { fPosHasChanged = false; }
     93    void ResetDirHasChanged() { fDirHasChanged = false; }
    7794
    7895    void SetReport(MLog *log) { fReport = log; }
     96
     97    void SetHysteresisNeg(Float_t f) { fHysteresisNeg = f; }
     98    void SetHysteresisPos(Float_t f) { fHysteresisPos = f; }
     99
     100    Float_t GetPosCorrected() const {
     101      switch (fDirection) {
     102      case kUndefined:
     103        return GetPos();
     104      case kForward:
     105        return GetPos()-fHysteresisPos;
     106      case kBackward:
     107        return GetPos()+fHysteresisNeg;
     108      }
     109    }
    79110
    80111    ClassDef(ShaftEncoder, 0)
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r6841 r7230  
    397397//    point.SetVelocity(0.2); // fast: 0.6, slow: 0.2
    398398//#else
     399
     400// original settings
     401//
    399402    point.SetPointAccDec(0.2, 0.1);
    400403    point.SetPointVelocity(0.1);
     404
     405
    401406//#endif
    402407
     408//    point.SetPointAccDec(0.4, 0.4);
     409//    point.SetPointVelocity(0.4);
     410
     411
     412// original
    403413    return point.SetPosition(dst, track);
     414
     415// test
     416//    return point.SetPosition(dst, kTRUE);
     417
     418
     419
    404420}
    405421
     
    422438//    track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2
    423439//#else
     440
     441
     442
    424443    track.SetPointAccDec(0.2, 0.1);
    425444    track.SetPointVelocity(0.1);
     445
     446    //    track.SetPointAccDec(0.4, 0.4);
     447    // track.SetPointVelocity(0.4);
     448
     449
     450
    426451//#endif
    427452    track.SetTrackAccDec(0.1, 0.1);
     
    438463//    track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2
    439464//#else
    440     track.SetPointAccDec(0.2, 0.1);
    441     track.SetPointVelocity(0.1);
     465    track.SetPointAccDec(0.4, 0.4);
     466    track.SetPointVelocity(0.3);
    442467//#endif
    443468    track.SetTrackAccDec(0.1, 0.1);
  • trunk/MagicSoft/Cosy/main/MPointing.cc

    r4106 r7230  
    202202        else
    203203        {
    204             const Double_t y = 15*fCosy->kGearTot.Y()*fCosy->kResSE.Y();
    205             if (rd.Az()>-y && rd.Az()<y)
    206             {
    207                 //lout << "--- LO-SPEED Mac1 ---" << endl;
    208                 SetAccDec(fCosy->fMac1, 0.05, 0.05);
    209             }
    210             else
    211                 SetAccDec(fCosy->fMac1, fAcc, fDec);
     204            const Double_t y = 15*fCosy->kGearTot.Y()/fCosy->kResSE.Y();
     205
     206//          lout << "MPointing::SetPosition y: " << y << " rd.Az(): " << rd.Az() << endl;
     207//          lout << "MPointing::SetPosition fCosy->kGearTot.Y(): " << fCosy->kGearTot.Y() << " fCosy->kResSE.Y(): " << fCosy->kResSE.Y() << endl;
     208
     209            if (rd.Az()>-y && rd.Az()<y)
     210              {
     211                //lout << "--- LO-SPEED Mac1 ---" << endl;
     212                SetAccDec(fCosy->fMac1, 0.05, 0.05);
     213              }
     214            else
     215              {
     216
     217                //lout << "MPointing::SetPosition SetAccDec Mac1: " << fAcc << fDec << endl;
     218               
     219                SetAccDec(fCosy->fMac1, fAcc, fDec);
     220               
     221              }
     222
     223
     224            // new 16.05.05  F.G.
     225            // SetAccDec(fCosy->fMac1, fAcc, fDec);
    212226
    213227            SetAccDec(fCosy->fMac2, fAcc, fDec);
  • trunk/MagicSoft/Cosy/main/MStarguider.cc

    r6842 r7230  
    7070    IDM_kChannel1,
    7171    IDM_kChannel2,
     72    IDM_kChannel3,
    7273    IDM_kContinous,
    7374    IDM_kRate25ps,
     
    107108    IDM_kStargCaosFilter,
    108109    IDM_kStargLEDFilter,
    109     IDM_kStargFindStar
     110    IDM_kStargFindStar,
     111    IDM_kTPointAna,
     112    IDM_kRoqueLampAna
    110113
    111114};
     
    143146    fChannel->AddEntry("Starfield Camera", IDM_kChannel1);
    144147    fChannel->AddEntry("TPoint Camera", IDM_kChannel2);
    145     fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
     148    fChannel->AddEntry("Read from File", IDM_kChannel3);
     149    if (channel<0) {
     150      fChannel->CheckEntry(IDM_kChannel3);
     151    } else {
     152      fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
     153    }
    146154    fChannel->Associate(this);
    147155    fList->Add(fChannel);
     
    170178    fList->Add(fDisplay);
    171179
     180
     181    fOperations = new MGPopupMenu(p);
     182    fOperations->AddEntry("TPoint Analysis",     IDM_kTPointAna);
     183    fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
     184    fOperations->Associate(this);
     185    fList->Add(fOperations);
     186
     187
    172188    fFileType = new MGPopupMenu(p);
    173189    fFileType->AddEntry("PP&M", IDM_kPPM);
     
    281297
    282298    fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
    283     fMenu->AddPopup("&Display",   fDisplay,         NULL);
    284     fMenu->AddPopup("&WritePics", fWritePictures,   NULL);
    285     fMenu->AddPopup("&Setup",     fSetup,           NULL);
     299    fMenu->AddPopup("&Display",    fDisplay,         NULL);
     300    fMenu->AddPopup("&WritePics",  fWritePictures,   NULL);
     301    fMenu->AddPopup("&Setup",      fSetup,           NULL);
     302
     303    fMenu->AddPopup("&Operations", fOperations,      NULL);
     304
    286305    fMenu->Resize(fMenu->GetDefaultSize());
    287306    fMenu->BindKeys(this);
     
    457476
    458477MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel)
    459     : TGMainFrame(gClient->GetRoot(), 768, 840), fCosy(NULL), fOutTp(0), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2), fStatus(MDriveCom::kStandby)
     478    : TGMainFrame(gClient->GetRoot(), 768, 840),
     479      fCosy(NULL),
     480      fOutTp(0),
     481      fOutRq(0),
     482      fDx((768-kZOOM)/2),
     483      fDy((512-kZOOM)/2),
     484      fStatus(MDriveCom::kStandby)
    460485{
    461486   
     
    517542    if (fOutTp)
    518543        delete fOutTp;
     544
     545    if (fOutRq)
     546        delete fOutRq;
    519547
    520548    cout << "Camera Display destroyed." << endl;
     
    585613                return kTRUE;
    586614
     615           case IDM_kRoqueLampAna:
     616                Toggle(fOperations, IDM_kRoqueLampAna);
     617                //              if (!fDisplay->IsEntryChecked(IDM_kCatalog))
     618                if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) {
     619                  fDisplay->CheckEntry(IDM_kStargCaosFilter);
     620                }
     621                else {
     622                  fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
     623                }
     624                 
     625                return kTRUE;
     626
     627
    587628           case IDM_kStargFindStar:
    588                 Toggle(fDisplay, IDM_kStargFindStar);         
    589                 if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) {
     629                Toggle(fDisplay, IDM_kStargFindStar);         
     630                if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) {
    590631                    fSZdAz->MapWindow();
    591632                } else {
     
    615656
    616657                    const Int_t ch0 =
    617                         fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
    618                     const Int_t ch1 = 0;
    619 
    620                     if (ch0!=ch1)
    621                     {
    622 
     658                      fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
     659                    const Int_t ch1 = 0;
     660                   
     661                    if (ch0!=ch1)
     662                      {
    623663                        delete fGetter;
    624664                        usleep(150000); // FIX: Device or resource busy.
    625                         fGetter = new Camera(*this, ch1);
    626                         ((Camera*)fGetter)->Loop(0);
    627                     }
     665                        if (fChannel->IsEntryChecked(IDM_kChannel3)) {
     666                          fGetter=new PngReader(*this);
     667                        } else {                     
     668                          fGetter = new Camera(*this, ch1);
     669                          ((Camera*)fGetter)->Loop(0);
     670                        }
     671                      }
    628672
    629673                    fChannel->CheckEntry(IDM_kChannel1);
     
    854898                    delete fGetter;
    855899                    usleep(150000); // FIX: Device or resource busy.
    856                     fGetter = new Camera(*this, ch1);
    857                     ((Camera*)fGetter)->Loop(0);
     900                    if (fChannel->IsEntryChecked(IDM_kChannel3))
     901                      fGetter=new PngReader(*this);
     902                    else
     903                      {
     904                        fGetter = new Camera(*this, ch1);
     905                        ((Camera*)fGetter)->Loop(0);
     906                      }
    858907                }
    859908                return kTRUE;
     
    11091158}
    11101159
    1111 ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)
     1160XY MStarguider::FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, Double_t cut, Double_t box, XY SearchCenter)
    11121161{
    11131162    // Set search Paremeters (FIXME: Get them from user input!)
     
    11171166    // Try to find Led in this area
    11181167    Leds leds;
    1119     f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
     1168    f.FindStarCircle(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y());
     1169
     1170    // Check whether star found
     1171    Led *star = (Led*)leds.At(0);
     1172    if (!star || leds.GetEntries()<1)
     1173        return XY(.0,.0);
     1174
     1175//    cout << "Found Roque Lamp @ " << flush;
     1176    star->Print();
     1177    f.MarkPoint(star->GetX(), star->GetY(), 500);
     1178
     1179//    cout << "RoquePos: " << star->GetX() << "," << star->GetY() << endl;
     1180
     1181    XY roquepos(star->GetX(), star->GetY());
     1182    XY relroquepos(roquepos.X()-CameraCenter.GetX(), roquepos.Y()-CameraCenter.GetY());
     1183
     1184    // If no file open: open new Roque Lamp file
     1185    if (!fOutRq)
     1186    {
     1187        const TString name = MCosy::GetFileName("tpoint/starg_roquelamp_%s.txt");
     1188        cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl;
     1189        fOutRq = new ofstream(name);
     1190        *fOutRq << "# Magic Roque Lamp file  " << t << endl;
     1191    }
     1192
     1193
     1194    return relroquepos;
     1195}
     1196 
     1197
     1198ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)
     1199{
     1200    // Set search Paremeters (FIXME: Get them from user input!)
     1201    f.SetCut(cut);  // 3.5
     1202    f.SetBox(box);  // 70
     1203
     1204    // Try to find Led in this area
     1205    Leds leds;
     1206    f.FindStarCircle(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
    11201207
    11211208    // Check whether star found
     
    13291416            pos = fCosy->GetPointingPos();
    13301417        center = fCaos->Run(img, printl, printr, pos, t, 50, 3.0);
     1418
     1419        cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << endl;
     1420
    13311421    }
    13321422
     
    13901480    }
    13911481
     1482// Find Roque Lamp
     1483
     1484    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) {
     1485
     1486        XY roquelamp(0,0);
     1487
     1488        Double_t imageclean = 1.5;
     1489        Double_t boxradius = 60;
     1490        Double_t scalefactor = 1;
     1491        XY searchcenter(768/2-1,576/2+25);
     1492
     1493        roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
     1494
     1495        if (fOutRq) {
     1496          ZdAz pos = fCosy->GetPointingPos();
     1497
     1498          *fOutRq << "RoqueLampDirect:    " << MTime(-1) << "  "
     1499                  << pos.Zd() << " " << pos.Az() << "   "
     1500                  << roquelamp.X() << " " << roquelamp.Y() << endl;
     1501        }
     1502
     1503        cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl;
     1504        cout << ">=>=>=> Roque Lamp found at:         >=>=>=> (" << roquelamp.X() << ","
     1505             << roquelamp.Y() << ") <=<=<=<" << endl;
     1506
     1507    }
     1508
     1509// Find Spot on Camera Center in Starguider camera
     1510
     1511    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) {
     1512
     1513        XY cameraspot(0,0);
     1514
     1515        Double_t imageclean = 5;
     1516        Double_t boxradius = 60;
     1517        Double_t scalefactor = 1;
     1518        //      XY searchcenter(sgcenter.GetX(),sgcenter.GetY());
     1519        XY searchcenter(60.,290.);
     1520
     1521        cameraspot = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
     1522
     1523        if (fOutRq) {
     1524          ZdAz pos = fCosy->GetPointingPos();
     1525
     1526          *fOutRq << "RoqueLampReflected: "  << MTime(-1) << "  "
     1527                  << pos.Zd() << " " << pos.Az() << "   "
     1528                  << cameraspot.X() << " " << cameraspot.Y() << endl;
     1529        }
     1530
     1531        cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << ","
     1532             << cameraspot.Y() << ") <<<<<" << endl;
     1533
     1534        f2.DrawCircle(sgcenter, 5.0, 0x0fa);
     1535        f2.DrawCircle(sgcenter, 115.0, 0x0fa);
     1536
     1537    }
     1538
     1539
     1540
    13921541    // we calculate the offset given by the three ETH Leds visible to
    13931542    // the guide camera
     
    14511600            Leds spots;
    14521601            f.SetBox(230);
     1602//          f.SetCut(1.5);
    14531603            double bright;
    14541604            f.ExecuteAndMark(spots, 530, 292, bright);
     
    15281678    if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
    15291679        fDisplay->IsEntryChecked(IDM_kCatalog)    ||
    1530         fDisplay->IsEntryChecked(IDM_kFindStar))
     1680        fDisplay->IsEntryChecked(IDM_kFindStar)   ||
     1681        fOperations->IsEntryChecked(IDM_kRoqueLampAna))
    15311682        fImage->DrawColImg(img, cimg);
    15321683    else
  • trunk/MagicSoft/Cosy/main/MStarguider.h

    r4865 r7230  
    6767    MGPopupMenu   *fChannel;
    6868
     69    MGPopupMenu   *fOperations;
     70
    6971    MGPopupMenu   *fCaosWrite;
    7072    MGPopupMenu   *fCaosPrint;
     
    104106
    105107    ofstream *fOutTp;
     108    ofstream *fOutRq;
    106109
    107110    Int_t fDx;
     
    121124    ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag) const;
    122125    bool Interpolate(const unsigned long n, byte *img) const;
     126
     127    XY FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t,
     128                     Double_t cut, Double_t box, XY SearchCenter);
     129
    123130    ZdAz FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t,
    124131                  Double_t cut, Double_t box, Double_t scalefactor);
  • trunk/MagicSoft/Cosy/main/MTracking.cc

    r6930 r7230  
    244244ZdAz MTracking::GetPointingPosRE(Bool_t pdo) const
    245245{
    246     // Conversion factor from se to re
    247     const XY re = fCosy->kGearTot/fCosy->kResSE; //[re/se]
    248 
    249     Int_t pzd1 = fCosy->fZd1->GetPos();
    250     Int_t pzd2 = fCosy->fZd2->GetPos();
    251     Int_t paz  = fCosy->fAz->GetPos();
     246     // Conversion factor from se to re
     247     const XY re = fCosy->kGearTot/fCosy->kResSE; //[re/se]
     248
     249     const bool bool1 = fCosy->fZd1->DirHasChanged();
     250     const bool bool2 = fCosy->fZd2->DirHasChanged();
     251
     252     if (bool1 && bool2) {
     253       fCosy->fZd1->ResetDirHasChanged();
     254       fCosy->fZd2->ResetDirHasChanged();
     255     }
     256 
     257     Int_t pzd1 = !bool1 ? fCosy->fZd1->GetPos() : fCosy->fZd1->GetDirChangedPos();
     258     Int_t pzd2 = !bool2 ? fCosy->fZd2->GetPos() : fCosy->fZd2->GetDirChangedPos();
     259     Int_t paz  =          fCosy->fAz->GetPos();
     260 
     261     // Get current shaftencoder position of the telescope
     262     Double_t seposzd1 = ((pzd1+8192)%16384)*re.X();
     263     Double_t seposzd2 = ((pzd2+8192)%16384)*re.X();
     264     Double_t seposaz  =   paz              *re.Y();
     265 
     266     // distance between (To+dt) and To [re]
     267     // position time difference < 5usec
     268     // fRePos does the synchronization between the
     269     // Shaft- and the rotary encoders
     270     const ZdAz repos = pdo ? fCosy->GetRePosPdo() : fCosy->GetRePos();
     271 
     272     const Int_t offset1 = !bool1 ? fCosy->fZd1->GetOffset() : fCosy->fZd1->GetDirChangedOffset();
     273     const Int_t offset2 = !bool2 ? fCosy->fZd2->GetOffset() : fCosy->fZd2->GetDirChangedOffset();
     274 
     275     // Calculate the part of one SE which the motors moved
     276     // since the last SE has changed its value
     277     const Double_t offzd1 = repos.Zd() - offset1;
     278     const Double_t offzd2 = repos.Zd() - offset2;
     279     const Double_t offaz  = repos.Az() - fCosy->fAz->GetOffset();
     280 
     281     // Correct for the direction in which the motor is moving
     282     // (in which the shaftencoders should change its values)
     283     if (offaz<0)
     284         seposaz += re.Y();
     285     if (offzd1<0)
     286         seposzd1 += re.X();
     287     if (offzd2<0)
     288         seposzd2 += re.X();
     289 
     290     // and interpolate the shaftencoder steps using the motor
     291     // encoder positon (Be carefull the minus-sign is important)
     292     seposzd1 += offzd1;
     293     seposzd2 -= offzd2;
     294     seposaz  += offaz;
     295 
     296
     297
     298     return ZdAz((seposzd1-seposzd2)/2, seposaz);
     299}
    252300/*
    253301    if (fCosy->fZd1->DirHasChanged() != fCosy->fZd2->DirHasChanged())
     
    262310    }
    263311  */
    264     // Get current shaftencoder position of the telescope
    265     Double_t seposzd1 = ((pzd1+8192)%16384)*re.X();
    266     Double_t seposzd2 = ((pzd2+8192)%16384)*re.X();
    267     Double_t seposaz  =   paz              *re.Y();
    268 
    269     // distance between (To+dt) and To [re]
    270     // position time difference < 5usec
    271     // fRePos does the synchronization between the
    272     // Shaft- and the rotary encoders
    273     const ZdAz repos = pdo ? fCosy->GetRePosPdo() : fCosy->GetRePos();
    274 
    275     // Calculate the part of one SE which the motors moved
    276     // since the last SE has changed its value
    277     const Double_t offzd1 = repos.Zd() - fCosy->fZd1->GetOffset();
    278     const Double_t offzd2 = repos.Zd() - fCosy->fZd2->GetOffset();
    279     const Double_t offaz  = repos.Az() - fCosy->fAz->GetOffset();
    280 
    281     // Correct for the direction in which the motor is moving
    282     // (in which the shaftencoders should change its values)
    283     if (offaz<0)
    284         seposaz += re.Y();
    285     if (offzd1<0)
    286         seposzd1 += re.X();
    287     if (offzd2<0)
    288         seposzd2 += re.X();
    289 
    290     // and interpolate the shaftencoder steps using the motor
    291     // encoder positon (Be carefull the minus-sign is important)
    292     seposzd1 += offzd1;
    293     seposzd2 -= offzd2;
    294     seposaz  += offaz;
    295 
    296     return ZdAz((seposzd1-seposzd2)/2, seposaz);
    297 }
    298312
    299313void MTracking::TrackPosition(const RaDec &dst) // ra, dec [rad]
  • trunk/MagicSoft/Cosy/videodev/FilterLed.cc

    r4865 r7230  
    120120    return GetMeanPosition(x, y, box, mx, my, sum);
    121121}
     122
     123int FilterLed::GetMeanPositionCircle(const int x, const int y,
     124                                     const int box, float &mx,
     125                                     float &my, unsigned int &sum) const
     126{
     127    unsigned int sumx=0;
     128    unsigned int sumy=0;
     129
     130    //-------------------------------
     131    // Improved algorithm:
     132    // 1. Look for the largest four-pixel signal inside box
     133
     134    int thissum=0, maxsum=0;
     135    int maxx=0, maxy=0;
     136    for (int dx=x-box; dx<x+box+1; dx++)
     137        for (int dy=y-box; dy<y+box+1; dy++)
     138        {
     139            thissum = fImg[dy*fW+dx]+fImg[(dy+1)*fW+dx]+
     140              fImg[dy*fW+(dx+1)]+fImg[(dy+1)*fW+(dx+1)];
     141            if(thissum>maxsum)
     142              {
     143                maxx=dx;
     144                maxy=dy;
     145                maxsum=thissum;
     146              }
     147        }
     148
     149    // 2. Calculate mean position inside a circle around
     150    // the highst four-pixel signal with radius of 5 pixels.
     151
     152    sum=0;
     153    for (int dx=x-box; dx<x+box+1; dx++)
     154        for (int dy=y-box; dy<y+box+1; dy++)
     155        {
     156            const byte &m = fImg[dy*fW+dx];
     157
     158            // Circle
     159            if(sqrt((dx-maxx)*(dx-maxx)+
     160                    (dy-maxy)*(dy-maxy)) <= 6)
     161              {
     162                sumx += m*dx;
     163                sumy += m*dy;
     164                sum  += m;
     165              }
     166        }
     167
     168    mx = (float)sumx/sum;
     169    my = (float)sumy/sum;
     170
     171    return (int)my*fW + (int)mx;
     172}
     173
     174
     175
     176int FilterLed::GetMeanPositionCircle(const int x, const int y,
     177                                     const int box) const
     178{
     179    float mx, my;
     180    unsigned int sum;
     181    return GetMeanPositionCircle(x, y, box, mx, my, sum);
     182}
     183
     184
    122185/*
    123186void FilterLed::RemoveTwins(Leds &leds, Double_t radius)
     
    486549}
    487550
     551void FilterLed::FindStarCircle(Leds &leds, int xc, int yc) const
     552{
     553    // fBox: radius of the inner (signal) box
     554    // Radius of the outer box is fBox*sqrt(2)
     555
     556    //
     557    // Define inner box in which to search the signal
     558    //
     559    int x0 = xc-fBox;
     560    int x1 = xc+fBox;
     561    int y0 = yc-fBox;
     562    int y1 = yc+fBox;
     563
     564    if (x0<0) x0=0;
     565    if (y0<0) y0=0;
     566    if (x1>fW) x1=fW;
     567    if (y1>fH) y1=fH;
     568
     569    //
     570    // Define outer box (excluding inner box) having almost
     571    // the same number of pixels in which the background
     572    // is calculated
     573    //
     574    const double sqrt2 = sqrt(2.);
     575
     576    int xa = xc-(int)rint(fBox*sqrt2);
     577    int xb = xc+(int)rint(fBox*sqrt2);
     578    int ya = yc-(int)rint(fBox*sqrt2);
     579    int yb = yc+(int)rint(fBox*sqrt2);
     580
     581    if (xa<0) xa=0;
     582    if (ya<0) ya=0;
     583    if (xb>fW) xb=fW;
     584    if (yb>fH) yb=fH;
     585
     586    //
     587    // Calculate average and sdev for a square
     588    // excluding the inner part were we expect
     589    // the signal to be.
     590    //
     591    double sum = 0;
     592    double sq  = 0;
     593
     594    int n=0;
     595    for (int x=xa; x<xb; x++)
     596        for (int y=ya; y<yb; y++)
     597        {
     598            if (x>=x0 && x<x1 && y>=y0 && y<y1)
     599                continue;
     600
     601            byte &b = fImg[y*fW+x];
     602
     603            sum += b;
     604            sq  += b*b;
     605            n++;
     606        }
     607
     608    sum /= n;
     609    sq  /= n;
     610
     611    // 254 because b<=max and not b<max
     612    const double sdev = sqrt(sq-sum*sum);
     613    const byte   max  = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev);
     614
     615    //
     616    // clean image from noise
     617    // (FIXME: A lookup table could accelerate things...
     618    //
     619    n=0;
     620    for (int x=x0; x<x1; x++)
     621        for (int y=y0; y<y1; y++)
     622        {
     623            byte &b = fImg[y*fW+x];
     624            if (b<=max)
     625                b = 0;
     626            else
     627                n++;
     628        }
     629
     630    //
     631    // Mark the background region
     632    //
     633    for (int x=xa; x<xb; x+=2)
     634    {
     635        fImg[ya*fW+x]=0xf0;
     636        fImg[yb*fW+x]=0xf0;
     637    }
     638    for (int y=ya; y<yb; y+=2)
     639    {
     640        fImg[y*fW+xa]=0xf0;
     641        fImg[y*fW+xb]=0xf0;
     642    }
     643
     644    //
     645    // Check if any pixel found...
     646    //
     647    if (n<5)
     648        return;
     649
     650    //
     651    // Get the mean position of the star
     652    //
     653    float mx, my;
     654    unsigned int mag;
     655
     656    //    int pos = GetMeanPosition(xc, yc, fBox-1, mx, my, mag);
     657
     658    // try new method
     659    int pos = GetMeanPositionCircle(xc, yc, fBox-1, mx, my, mag);
     660   
     661    if (pos<0 || pos>=fW*fH && fImg[pos]<sum+fCut*sdev)
     662        return;
     663
     664    cout << "Mean=" << sum << "  SDev=" << sdev << "  :  ";
     665    cout << "Sum/n = " << sum << "/" << n << " = " << (n==0?0:mag/n) << endl;
     666
     667    leds.Add(mx, my, 0, 0, -2.5*log10((float)mag)+13.7);
     668}
     669
     670
    488671void FilterLed::Stretch() const
    489672{
  • trunk/MagicSoft/Cosy/videodev/FilterLed.h

    r4865 r7230  
    2424    int  GetMeanPosition(const int x, const int y, const int box,
    2525                         float &mx, float &my, unsigned int &sum) const;
     26
     27    int  GetMeanPositionCircle(const int x, const int y,
     28                               const int box) const;
     29    int  GetMeanPositionCircle(const int x, const int y,
     30                               const int box, float &mx, float &my,
     31                               unsigned int &sum) const;
     32
    2633    void RemoveTwinsInterpol(Leds &leds, Int_t first, Double_t radius) const;
    2734    void DrawBox(const int x1, const int y1,
     
    4350    void SetCut(float cut) { fCut = cut; }
    4451    void FindStar(Leds &leds, int xc, int yc) const;
     52    void FindStarCircle(Leds &leds, int xc, int yc) const;
     53   
    4554    void Execute(Leds &leds, int xc, int yc, double &bright) const;
    4655    void Execute(Leds &leds, int xc, int yc) const;
Note: See TracChangeset for help on using the changeset viewer.