Ignore:
Timestamp:
02/25/03 21:07:13 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/main
Files:
2 edited

Legend:

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

    r1760 r1793  
    167167    // Get the values
    168168    //
    169     const int p1 =  fZd1->GetPos();
    170     const int p2 = -fZd2->GetPos();
     169    int p1 =  (fZd1->GetPos()+8192)%16384;
     170    int p2 = -(fZd2->GetPos()+8192)%16384;
    171171
    172172    if (fZd1->IsZombieNode())
     
    180180    float p = (float)(p1+p2)/2;
    181181
    182     //
    183     // calculate 'regelabweichung'
    184     //
    185182    return ZdAz(p, pa);
    186183}
     
    506503        lout << "SetVelocity" << endl;
    507504        if (i)
    508             SetPosVelocity(1.0, 0.1, 0.1);
    509         else
    510             SetPosVelocity(fabs(rd.Ratio()), 0.1, 0.3);
     505            SetPosVelocity(1.0, 0.05, 0.1);
     506        else                              // vel(0.6)  acc(0.5)
     507            SetPosVelocity(fabs(rd.Ratio()), 0.15, 0.4);
     508//            SetPosVelocity(fabs(rd.Ratio()), 0.1, 0.3);
    511509
    512510        rd.Round();
     
    859857        // (This is important on fast machines >500MHz)
    860858        //
    861         usleep(50000); // 0.05s
    862         //usleep(500000); // 0.5s
     859        usleep(50000); // 0.25s
     860        //usleep(50000); // 0.05s
    863861    }
    864862
     
    907905bool MCosy::CheckNetwork()
    908906{
    909     return kTRUE;
     907    //return kTRUE;
    910908    //CheckConnections();
    911909
     
    10301028        cout << "WM_TestSe: done. (return 0x1e51)" << endl;
    10311029        return (void*)0x1e51;
     1030
     1031    case WM_GEAR:
     1032        cout << "WM_Gear: start." << endl;
     1033        fBackground = mp ? kBgdGear : kBgdNone;
     1034        cout << "WM_Gear: done. (return 0xfeaf)" << endl;
     1035        return (void*)0xfeaf;
     1036
     1037    case WM_DISPLAY:
     1038        cout << "WM_Display: start." << endl;
     1039        fTriggerDisplay = kTRUE;
     1040        cout << "WM_Disply: done. (return 0xd1e1)" << endl;
     1041        return (void*)0xd1e1;
    10321042
    10331043    case WM_TRACK:
     
    12651275        {
    12661276            phca1 = fZd1->PosHasChanged();
    1267 //            phca2 = fZd2->PosHasChanged();
     1277            phca2 = fZd2->PosHasChanged();
    12681278            phcaz = fAz->PosHasChanged();
    12691279            usleep(1);
     
    12931303        //
    12941304        // FIXME
    1295         time.Zd(fZd1->GetMjd());
    1296         /* OLD*
     1305        //time.Zd(fZd1->GetMjd());
     1306        /* OLD* */
    12971307        if (fZd1->GetMjd()>fZd2->GetMjd())
    12981308            time.Zd(fZd1->GetMjd());
    12991309        else
    13001310            time.Zd(fZd2->GetMjd());
    1301         */
     1311
    13021312        //time.Zd((fZd1->GetMjd()+fZd2->GetMjd())/2.0);
    13031313        time.Az(fAz->GetMjd());
     
    13381348        //---            fout << setprecision(5)  << setw(7)  << fTrackingError.Az() << endl;
    13391349    }
     1350
     1351    lout << "Tracking Thread done." << endl;
     1352
    13401353    //---        fout << endl << endl;
    13411354}
     
    13461359    //        return;
    13471360
    1348     if (fHistTestSe)
     1361    if (fHist)
    13491362    {
    13501363        lout << "You are much too fast... try again." << endl;
     
    13521365    }
    13531366
    1354     fHistTestSe = new TH2F("Diff", "Difference of SE values",
    1355                            201, fMin.Zd(), fMax.Zd(), 101, -50, 50);
    1356     fHistTestSe->SetXTitle("ZA [\\circ]");
    1357     fHistTestSe->SetYTitle("\\Delta SE");
     1367    fHist = new TH2F("Diff", "Difference of SE values",
     1368                           201, fMin.Zd(), fMax.Zd(), 41, -10.5, 10.5);
     1369    fHist->SetXTitle("ZA [\\circ]");
     1370    fHist->SetYTitle("\\Delta SE");
    13581371
    13591372    Double_t offset = 0;
     
    13721385            usleep(1);
    13731386
    1374         const Double_t pos[3] = { fZd1->GetPos(), fZd2->GetPos(), fAz->GetPos() };
     1387        const Double_t pos[3] = {
     1388            (fZd1->GetPos()+8192)%16384,
     1389            (fZd2->GetPos()+8192)%16384,
     1390            fAz->GetPos() };
    13751391
    13761392        //
     
    13781394        //
    13791395        if (cnt++<10)
     1396        {
    13801397            offset += pos[0]+pos[1];
    1381         if (cnt++==10)
     1398            continue;
     1399        }
     1400        if (cnt==11)
     1401        {
    13821402            offset /= 10;
    1383         if (cnt<11)
     1403            cnt++;
     1404        }
     1405
     1406        Double_t apos = (pos[0]-pos[1])/2 * TMath::Pi()*2 / 16384;
     1407
     1408        ZdAz bend = fBending.CorrectBack(ZdAz(apos, pos[2]))*kRad2Deg;
     1409        fHist->Fill(bend.Zd(), pos[0]+pos[1]-offset);
     1410    }
     1411
     1412    lout << "Shaftencoder Test Stopped... displaying Histogram." << endl;
     1413
     1414    fBackground=kBgdSeTestDispl;
     1415}
     1416
     1417void MCosy::TalkThreadGear()
     1418{
     1419//    if (fZd1->IsZombieNode() || fZd2->IsZombieNode())
     1420    //        return;
     1421
     1422    if (fHist)
     1423    {
     1424        lout << "You are much too fast... try again." << endl;
     1425        return;
     1426    }
     1427
     1428    //    fHist = new TH2F("Gear", "Gear Ratio Re/Se",
     1429    //                     201, fMin.Zd(), fMax.Zd(), 61, 349.5, 500.5);
     1430    fHist = new TH2F("Gear", "Gear Ratio Re/Se",
     1431                     201, fMin.Az(), fMax.Az(), 61, 419.5, 570.5);
     1432    fHist->SetXTitle("ZA [\\circ]");
     1433    fHist->SetYTitle("Re/Se");
     1434
     1435    lout << "Starting Gear determination..." << endl;
     1436
     1437    ZdAz se0 = GetSePos();
     1438    ZdAz re0 = GetRePosPdo();
     1439
     1440    while (fBackground==kBgdGear)
     1441    {
     1442        fZd1->ResetPosHasChanged();
     1443        fZd2->ResetPosHasChanged();
     1444        fAz->ResetPosHasChanged();
     1445
     1446        while (!fZd1->PosHasChanged() && !fZd2->PosHasChanged() &&
     1447               !fAz->PosHasChanged() && fBackground==kBgdGear)
     1448            usleep(1);
     1449
     1450        ZdAz se = GetSePos();
     1451        ZdAz re = GetRePosPdo();
     1452
     1453        ZdAz dse = se-se0;
     1454        ZdAz dre = re-re0;
     1455
     1456        if (fabs(dse.Zd())*144>16384) // Each 2.5deg
     1457        {
     1458            se0.Zd(se.Zd());
     1459            re0.Zd(re.Zd());
     1460
     1461            ZdAz bend = fBending.CorrectBack(se*2*TMath::Pi()/16384)*kRad2Deg;
     1462            fHist->Fill(bend.Zd(), dre.Zd()/dse.Zd());
     1463        }
     1464
     1465        if (fabs(dse.Az())*144>16384) // Each 2.5deg
     1466        {
     1467            se0.Az(se.Az());
     1468            re0.Az(re.Az());
     1469
     1470            ZdAz bend = fBending.CorrectBack(se*2*TMath::Pi()/16384)*kRad2Deg;
     1471            fHist->Fill(bend.Az(), dre.Az()/dse.Az());
     1472
     1473            cout << bend.Az() << ": " << dre.Az()/dse.Az() << endl;
     1474        }
     1475
     1476        /*
     1477        const Double_t pos[3] = {
     1478            (fZd1->GetPos()+8192)%16384,
     1479            (fZd2->GetPos()+8192)%16384,
     1480            fAz->GetPos() };
     1481
     1482        //
     1483        //  Estimate Offset from the first ten positions
     1484        //
     1485        if (cnt++<10)
     1486        {
     1487            offset += pos[0]+pos[1];
    13841488            continue;
     1489        }
     1490        if (cnt==11)
     1491        {
     1492            offset /= 10;
     1493            cnt++;
     1494        }
    13851495
    13861496        Double_t apos = (pos[0]-pos[1])/2 * TMath::Pi()*2 / 16384;
    13871497
    1388         ZdAz bend = fBending(ZdAz(apos, pos[2]))*kRad2Deg;
    1389 
     1498        ZdAz bend = fBending.CorrectBack(ZdAz(apos, pos[2]))*kRad2Deg;
    13901499        fHistTestSe->Fill(bend.Zd(), pos[0]+pos[1]-offset);
    1391     }
    1392 
    1393     lout << "Shaftencoder Test Stopped... displaying Histogram." << endl;
     1500*/
     1501    }
     1502    lout << "Gear Test Stopped... displaying Histogram." << endl;
     1503
     1504    fBackground=kBgdGearDispl;
    13941505}
    13951506
     
    14361547        case kBgdSeTest:
    14371548            TalkThreadSeTest();
     1549            continue;
     1550
     1551        case kBgdGear:
     1552            TalkThreadGear();
     1553            continue;
     1554
     1555        default:
    14381556            continue;
    14391557        }
     
    14791597     */
    14801598
    1481     if (fBackground==kBgdSeTest || fHistTestSe==NULL)
    1482         return kTRUE;
    1483 
    1484     DisplayHistTestSe();
     1599    const Bool_t trigger = fTriggerDisplay;
     1600    fTriggerDisplay = kFALSE;
     1601
     1602    if (fBackground==kBgdSeTestDispl || (trigger&&fBackground==kBgdSeTest))
     1603        DisplayHistTestSe(!trigger);
     1604
     1605    if (fBackground==kBgdGearDispl || (trigger&&fBackground==kBgdGear))
     1606        DisplayHistGear(!trigger);
    14851607
    14861608    return kTRUE;
    14871609}
    14881610
    1489 void MCosy::DisplayHistTestSe()
    1490 {
    1491     TH2F &hist = *fHistTestSe;
    1492     fHistTestSe = NULL;
     1611void MCosy::DisplayHistTestSe(Bool_t del)
     1612{
     1613    lout << "Displaying histogram..." << endl;
     1614
     1615    TH2F &hist = *fHist;
     1616
     1617    if (del)
     1618    {
     1619        fHist = NULL;
     1620        fBackground = kBgdNone;
     1621    }
    14931622
    14941623    TCanvas *c=new TCanvas("c1", "", 1000, 1000);
     
    15141643    p2.DrawCopy();
    15151644
    1516     delete &hist;
     1645    if (del)
     1646        delete &hist;
     1647}
     1648
     1649void MCosy::DisplayHistGear(Bool_t del)
     1650{
     1651    lout << "Displaying histogram..." << endl;
     1652
     1653    TH2F &hist = *fHist;
     1654
     1655    if (del)
     1656    {
     1657        fHist = NULL;
     1658        fBackground = kBgdNone;
     1659    }
     1660
     1661    TCanvas *c=new TCanvas("c1", "", 1000, 1000);
     1662    c->Divide(1,2);
     1663
     1664    c->cd(1);
     1665    TH2 *h=(TH2*)hist.DrawCopy();
     1666
     1667    TProfile *p = h->ProfileX("_pfx", -1, 9999, "s");
     1668    p->SetLineColor(kBlue);
     1669    p->Draw("same");
     1670    p->SetBit(kCanDelete);
     1671
     1672    c->cd(2);
     1673
     1674    TH1F p2("spread", "Spread of the gear [16384/1500/4*U/U]", hist.GetNbinsX(), hist.GetBinLowEdge(1),
     1675            hist.GetBinLowEdge(hist.GetNbinsX()+1));
     1676    p2.SetXTitle("ZA [\\circ]");
     1677    for (int i=0; i<hist.GetNbinsX(); i++)
     1678        p2.SetBinError(i, p->GetBinError(i));
     1679    p2.SetLineColor(kRed);
     1680    p2.SetStats(0);
     1681    p2.DrawCopy();
     1682
     1683    if (del)
     1684        delete &hist;
    15171685}
    15181686
     
    15491717void MCosy::Stop()
    15501718{
    1551 
    15521719    lout << "- Stopping GUI update." << endl;
    15531720    fUpdateGui->TurnOff();
     
    16531820bool MCosy::HasZombie() const
    16541821{
    1655     bool ses = fZd1->IsZombieNode() & fZd2->IsZombieNode();
     1822    bool ses = fZd1->IsZombieNode() | fZd2->IsZombieNode();
    16561823
    16571824    return fMac1->IsZombieNode() | fMac2->IsZombieNode() | fAz->IsZombieNode() | ses;
     
    17291896
    17301897    lout.DisableOutputDevice(MLog::eGui);
    1731     lout.SetOutputGui(NULL, kFALSE);
     1898    // FIXME: WHY DOES THIS CRASH THE APPLICATIOn WHILE TRAKING?
     1899    // lout.SetOutputGui(NULL, kFALSE);
    17321900
    17331901    gApplication->Terminate(0);
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r1760 r1793  
    2727#define WM_HOME         0x100a
    2828#define WM_TESTSE       0x100b
     29#define WM_GEAR         0x100c
     30#define WM_DISPLAY      0x100d
    2931
    3032
     
    8789        kBgdNone,
    8890        kBgdTracking,
    89         kBgdSeTest
     91        kBgdSeTest,
     92        kBgdSeTestDispl,
     93        kBgdGear,
     94        kBgdGearDispl
    9095    };
    9196
     
    101106    ZdAz  fMax;
    102107
    103     TH2F *fHistTestSe;
     108    TH2F  *fHist;
     109    Bool_t fTriggerDisplay;
    104110
    105111    XY kGearRatio;        // describing the gear of the system [re/se]
     
    138144    void TalkThreadTracking();
    139145    void TalkThreadSeTest();
     146    void TalkThreadGear();
    140147
    141     void DisplayHistTestSe();
     148    void DisplayHistTestSe(Bool_t del=kTRUE);
     149    void DisplayHistGear(Bool_t del=kTRUE);
    142150
    143151    int  SetPosition(const ZdAz &dst);
Note: See TracChangeset for help on using the changeset viewer.