Index: trunk/MagicSoft/Cosy/main/MBending.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MBending.h	(revision 1819)
+++ trunk/MagicSoft/Cosy/main/MBending.h	(revision 1953)
@@ -1,8 +1,4 @@
 #ifndef COSY_MBending
 #define COSY_MBending
-
-#include <TROOT.h>
-
-#include <fstream.h>
 
 #include "coord.h"
@@ -53,4 +49,5 @@
 public:
     MBending() { Clear(); }
+    MBending(const char *name) { Clear(); Load(name); }
 
     void Load(const char *name);
Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1819)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1953)
@@ -13,4 +13,5 @@
 
 #include <TH2.h>
+#include <TH3.h>
 #include <TProfile.h>
 #include <TCanvas.h>
@@ -76,4 +77,5 @@
 }
 
+/*
 ZdAz MCosy::CorrectTarget(const ZdAz &src, const ZdAz &dst)
 {
@@ -145,4 +147,5 @@
     return ret*(16384.0/360.0);
 }
+*/
 
 // --------------------------------------------------------------------------
@@ -329,10 +332,19 @@
 {
     // FIXME, what when waiting times out (Zombie)
+
     while ((fMac1->IsPositioning() || fMac2->IsPositioning()) &&
-           !(Break() || HasError()) && !HasZombie())
+           !(Break() || HasError() || HasZombie()))
         usleep(1);
 
     if (Break() || HasError() || HasZombie())
-        lout << "WaitForEndMovement aborted..." << endl;
+    {
+        lout << "WaitForEndMovement aborted... ";
+        if (Break())
+            lout << "Break signal." << endl;
+        if (HasError())
+            lout << "Network has error." << endl;
+        if (HasZombie())
+            lout << "Network has zombie." << endl;
+    }
 }
 
@@ -382,4 +394,25 @@
 }
 
+Bool_t MCosy::CheckRange(const ZdAz &d) const
+{
+    // d [deg]
+
+    if (d.Zd()<fMin.Zd() || d.Zd()>fMax.Zd())
+    {
+        lout << "ERROR: Requested Zenith Angle (" << d.Zd() << "deg) not ";
+        lout << "inside allowed range." << endl;
+        return kFALSE;
+    }
+
+    if (d.Az()<fMin.Az() || d.Az()>fMax.Az())
+    {
+        lout << "ERROR: Requested Azimuth Angle (" << d.Az() << "deg) not ";
+        lout << "inside allowed range." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -396,16 +429,4 @@
 {
     // FIXME: Correct by fOffset ?
-/*
-    ZdAz
-
-    if (dst.Az()<-TMath::Pi()/2)
-        dst.Az(dst.Az() + TMath::Pi()*2);
-
-    if (dst.Az()>3*TMath::Pi()/2)
-        dst.Az(dst.Az() -TMath::Pi()*2);
-*/
- //   track=kFALSE;
-
-   // const ZdAz d1 = track ? CorrectTarget(src, dst) : dst*16384/TMath::Pi()/2; // [se]
 
     const ZdAz d = dst*kRad2Deg;
@@ -413,17 +434,6 @@
     lout << "Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;
 
-    if (d.Zd()<fMin.Zd() || d.Zd()>fMax.Zd())
-    {
-        lout << "ERROR: Requested Zenith Angle (" << d.Zd() << "deg) not ";
-        lout << "inside allowed range." << endl;
+    if (!CheckRange(d))
         return kFALSE;
-    }
-
-    if (d.Az()<fMin.Az() || d.Az()>fMax.Az())
-    {
-        lout << "ERROR: Requested Azimuth Angle (" << d.Az() << "deg) not ";
-        lout << "inside allowed range." << endl;
-        return kFALSE;
-    }
 
     //
@@ -520,4 +530,5 @@
         cout << "Estimated1: " << 16384*dx + dk << endl;
         cout << "Estimated2: " << (16384*dx + dk)/1.085949688 << endl;
+        cout << "Estimated3: " << rd.Zd()*432 << endl;
         // ===========================================
 
@@ -775,4 +786,41 @@
 }
 
+Bool_t MCosy::AlignTrackingPos(ZdAz pointing, ZdAz &za)
+{
+    // pointing [deg]
+
+    if (pointing.Zd()<0)
+    {
+        pointing.Zd(-pointing.Zd());
+        pointing.Az(pointing.Az()+180);
+    }
+
+    const ZdAz se = GetSePos()*360/16384; // [deg]
+    const ZdAz unbendedse = fBending.CorrectBack(se); // ist pointing
+
+    do
+    {
+        const Double_t d = unbendedse.Az() - pointing.Az();
+        if (d>-180 && d<=180)
+            break;
+
+        pointing.Az(pointing.Az()+TMath::Sign(360., -d));
+    } while (1);
+  /*
+    while (pointing.Az()<fMin.Az())
+        pointing.Az(pointing.Az() + 360);
+
+    while (pointing.Az()>fMax.Az())
+        pointing.Az(pointing.Az() - 360);
+        */
+    const Bool_t rc = CheckRange(pointing);
+    za = fBending(pointing/kRad2Deg); // [rad]
+
+    if (!rc)
+        lout << "Error: Aligned position out of Range." << endl;
+
+    return rc;
+}
+
 void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad]
 {
@@ -787,9 +835,16 @@
     ZdAz dest = sla.CalcZdAz(dst);
 
+    // FIXME: Determin tracking start point by star culmination
     if (dest.Az()<-TMath::Pi()/2)
+    {
+        lout << "Adding 360deg to Azimuth " << dest.Az()*kRad2Deg << endl;
         dest.Az(dest.Az() + TMath::Pi()*2);
+    }
 
     if (dest.Az()>3*TMath::Pi()/2)
+    {
+        lout << "Substracting 360deg to Azimuth " << dest.Az()*kRad2Deg << endl;
         dest.Az(dest.Az() -TMath::Pi()*2);
+    }
 
     if (!SetPosition(dest, kTRUE))
@@ -849,6 +904,6 @@
     //
     // *OLD*const float dt = 1;  // 1 second
-    const float dt = 3;  // 2 second
-    while (!(Break() || HasError()) && !HasZombie())
+    const float dt = 5;//3;  // 2 second
+    while (!(Break() || HasError() || HasZombie()))
     {
         //
@@ -860,5 +915,14 @@
         // Request theoretical Position for a time in the future (To+dt) from CPU
         //
-        sla.SetMjd(sla.GetMjd()+dt/(60*60*24));
+        const Double_t mjd = sla.GetMjd()+dt/(60*60*24);
+        const ZdAz pointing = sla.CalcZdAz(fRaDec, mjd)*kRad2Deg; // soll pointing [deg]
+
+        ZdAz dest;
+        if (!AlignTrackingPos(pointing, dest))
+            break;
+
+        dest *= 16384/TMath::Pi()/2;  // [se]
+
+        /*
         ZdAz dummy1 = sla.CalcZdAz(fRaDec);
 
@@ -868,27 +932,20 @@
             dummy1.Az(dummy1.Az() -TMath::Pi()*2);
 
+        if (!CheckRange(dummy1*kRad2Deg))
+        {
+            lout << "Error: Tracking position out of Range." << endl;
+            break;
+        }
+
         ZdAz dummy = fBending(dummy1);
         dest = CorrectTarget(GetSePos(), dummy); // [se]
-
-        const ZdAz d = dest*360./16384; // [deg]
+        */
+
+//*LP*      const ZdAz d = dest*360./16384; // [deg]
         dest *= kGearRatio;  // [re]
 
-        ZdAz min = fBending(fMin/kRad2Deg)*kRad2Deg;
-        ZdAz max = fBending(fMax/kRad2Deg)*kRad2Deg;
-
-        /*
-        if (d.Zd()<min.Zd() || d.Az()<min.Az())
-        {
-            lout << "ERROR: Calculated position for T+dt not inside allowed range." << endl;
-            lout << "<  " << d.Zd() << " " << min.Zd() << "  " << d.Az() << " " << min.Az()  << endl;
-            break;
-        }
-        if (d.Zd()>max.Zd() || d.Az()>max.Az())
-        {
-            lout << "ERROR: Calculated position for T+dt not inside allowed range." << endl;
-            lout << ">  " <<  d.Zd() << " " << max.Zd() << "  " << d.Az() << " " << max.Az()  << endl;
-            break;
-        }
-        */
+//*LP*      ZdAz min = fBending(fMin/kRad2Deg)*kRad2Deg;
+//*LP*      ZdAz max = fBending(fMax/kRad2Deg)*kRad2Deg;
+
         ZdAz vcalc = sla.GetApproxVel(fRaDec) * kGearRatio2*4./60.;  // [re/min]
 
@@ -963,5 +1020,5 @@
         // (This is important on fast machines >500MHz)
         //
-        usleep(50000); // 0.25s
+        usleep(1000000); // 1s
         //usleep(50000); // 0.05s
     }
@@ -989,5 +1046,5 @@
     // set deceleration to 50%
     //
-    cout << "Stopping movement (dec=20%)..." << endl;
+    cout << "Stopping movement (dec=30%)..." << endl;
 
     fMac1->SetDeceleration(0.3*fMac1->GetVelRes());
@@ -1103,5 +1160,5 @@
         StopMovement();
         return NULL;
-
+/*
     case WM_PRESET:
         cout << "WM_Preset: start." << endl;
@@ -1113,5 +1170,6 @@
         cout << "WM_Preset: done. (return 0xaffe)" << endl;
         return (void*)0xaffe;
-
+*/
+        /*
     case WM_CALIB:
         {
@@ -1126,5 +1184,5 @@
 
             //RaDec rd(37.94, 89.2644);      // POLARIS
-            //RaDec rd(213.915417, 19.1825); // ACTURUS
+            //RaDec rd(213.915417, 19.1825); // ARCTURUS
 
             cout << "Calibrating to: " << rd.Ra()*24/360 << "h " << rd.Dec() << "°" << endl;
@@ -1144,4 +1202,5 @@
         }
         return (void*)0xaffe;
+        */
 
     case WM_TPOINT:
@@ -1170,4 +1229,25 @@
         }
         return (void*)0xca1b;
+
+    case WM_TRACKPOS:
+        cout << "WM_TrackPosition: start." << endl;
+        {
+            if (!CheckNetwork())
+                return (void*)0xebb0;
+
+            ZdAz dest = *((ZdAz*)mp) * kDeg2Rad;
+            //if (!SetPosition(dest))
+            //    return (void*)0x1234;
+
+            SlaStars sla(fObservatory);
+            sla.Now();
+
+            RaDec rd = sla.CalcRaDec(dest);
+            cout << dest.Zd()*180/3.1415 << " " << dest.Az()*180/3.1415 << endl;
+            cout << rd.Ra()*12/3.1415 << " " << rd.Dec()*180/3.1415 << endl;
+            TrackPosition(rd);
+        }
+        cout << "WM_TrackPosition: done. (return 0xabcd)" << endl;
+        return (void*)0xabcd;
 
     case WM_POSITION:
@@ -1273,15 +1353,18 @@
             RaDec rd(xy.X()*15., xy.Y()); // [deg]
 
-            ZdAz a0 = sla.CalcZdAz(rd*kDeg2Rad);
-            ZdAz a1 = fBending(a0);
-            ZdAz se = CorrectTarget(GetSePos(), a1);
-            a0 *= kRad2Deg;
-            a1 *= kRad2Deg;
-            ZdAz a2 = a1*16384/360;
+            const ZdAz a0 = sla.CalcZdAz(rd*kDeg2Rad);
+
+            ZdAz a1;
+            AlignTrackingPos(a0, a1);
+            a1 *= 180/TMath::Pi();
+
+            const ZdAz a2 = a1*16384/360;
+            const ZdAz se = a0*16384/360;
+
             cout << "Ra/Dec source: " << xy.X()  << "h " << xy.Y()  << "°" << endl;
-            cout << "Zd/Az source:  " << a0.Zd() << "° " << a0.Az() << "°" << endl;
+            cout << "Zd/Az target:  " << a0.Zd() << "° " << a0.Az() << "°" << endl;
             cout << "Zd/Az bended:  " << a1.Zd() << "° " << a1.Az() << "°" << endl;
+            cout << "SE target:     " << se.Zd() << "  " << se.Az() << endl;
             cout << "SE bended:     " << a2.Zd() << "  " << a2.Az() << endl;
-            cout << "SE target:     " << se.Zd() << "  " << se.Az() << endl;
         }
         return (void*)0xa17a;
@@ -1401,13 +1484,14 @@
 
     SlaStars sla(fObservatory);
+    sla.Now();
 
     ZdAz old;
-    ZdAz ist;
-
-    ZdAz sollzd;
-    ZdAz sollaz;
-
-    ZdAz istre = -fOffset;                // [re]
+    ZdAz ist = GetSePos();              // [se]
+
+//    ZdAz istre = -fOffset;              // [re]
     ZdAz time;
+
+    ZdAz sollzd = sla.CalcZdAz(fRaDec); // [rad]
+    ZdAz sollaz = sollzd;               // [rad]
 
     //
@@ -1456,5 +1540,5 @@
          continue;
          */
-        istre = GetRePosPdo();
+        ZdAz istre = GetRePosPdo();
 
         //
@@ -1479,9 +1563,9 @@
         if (phca1 || phca2 /*(int)ist.Zd() != (int)old.Zd()*/)
         {
-            sla.SetMjd(time.Zd());
-
+            sollzd = sla.CalcZdAz(fRaDec, time.Zd()); // [rad]
+            /*
             ZdAz dummy = fBending(sla.CalcZdAz(fRaDec));
             sollzd = CorrectTarget(ist, dummy); // [se]
-
+            */
             fOffset.Zd(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight);
         }
@@ -1489,17 +1573,36 @@
         if (phcaz /*(int)ist.Az() != (int)old.Az()*/)
         {
-            sla.SetMjd(time.Az());
-
+            sollaz = sla.CalcZdAz(fRaDec, time.Az()); // [rad]
+            /*
             ZdAz dummy = fBending(sla.CalcZdAz(fRaDec));
             sollaz = CorrectTarget(ist, dummy); // [se]
-
+            */
             fOffset.Az(fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight);
         }
 
-        ZdAz soll(sollzd.Zd(), sollaz.Az()); // [se]
+        ZdAz soll(sollzd.Zd(), sollaz.Az()); // [rad]
+
+        AlignTrackingPos(soll*360/16384, fZdAzSoll);
+        /*
         fZdAzSoll = fBending.CorrectBack(soll*2*TMath::Pi()/16384);
 
-        fTrackingError.Set((ist.Zd()-sollzd.Zd())*kGearRatio.X(),
-                           (ist.Az()-sollaz.Az())*kGearRatio.Y());
+        // FIXME?
+        if (fZdAzSoll.Az()<-TMath::Pi()/2)
+            fZdAzSoll.Az(fZdAzSoll.Az() + TMath::Pi()*2);
+        if (fZdAzSoll.Az()>3*TMath::Pi()/2)
+            fZdAzSoll.Az(fZdAzSoll.Az() -TMath::Pi()*2);
+
+        // FIXME?
+        while (ist.Az()>3*16384/4/2)
+            ist.Az(ist.Az() - 16384);
+        while (soll.Az()>3*16384/4/2)
+            soll.Az(soll.Az() - 16384);
+        while (ist.Az()<-16384/4)
+            ist.Az(ist.Az() + 16384);
+        while (soll.Az()<-16384/4)
+            soll.Az(soll.Az() + 16384);
+            */
+        ist *= TMath::Pi()*2/16384;
+        fTrackingError.Set(ist.Zd()-fZdAzSoll.Zd(), ist.Az()-fZdAzSoll.Az());
 
         //---            fout << setprecision(15) << setw(17) << time.Zd()*60.*60.*24. << " ";
@@ -1586,10 +1689,12 @@
     }
 
-    //    fHist = new TH2F("Gear", "Gear Ratio Re/Se",
-    //                     201, fMin.Zd(), fMax.Zd(), 61, 349.5, 500.5);
-    fHist = new TH2F("Gear", "Gear Ratio Re/Se",
-                     201, fMin.Az(), fMax.Az(), 61, 419.5, 570.5);
-    fHist->SetXTitle("ZA [\\circ]");
-    fHist->SetYTitle("Re/Se");
+    fHist = new TH3F("Gear", "Gear Ratio Re/Se",
+                     (int)((fMax.Zd()-fMin.Zd())/2.5+1), fMin.Zd(), fMax.Zd(),
+                     (int)((fMax.Az()-fMin.Az())/2.5+1), fMin.Az(), fMax.Az(),
+                     61, 349.5, 500.5);
+
+    fHist->SetXTitle("Zd [\\circ]");
+    fHist->SetYTitle("Az [\\circ]");
+    fHist->SetZTitle("Re/Se");
 
     lout << "Starting Gear determination..." << endl;
@@ -1614,5 +1719,5 @@
         ZdAz dre = re-re0;
 
-        if (fabs(dse.Zd())*144>16384) // Each 2.5deg
+        if (fabs(dse.Zd())*144>16384) // Each 2.5deg (144)
         {
             se0.Zd(se.Zd());
@@ -1620,8 +1725,8 @@
 
             ZdAz bend = fBending.CorrectBack(se*2*TMath::Pi()/16384)*kRad2Deg;
-            fHist->Fill(bend.Zd(), dre.Zd()/dse.Zd());
+            ((TH3*)fHist)->Fill(bend.Zd(), bend.Az(), dre.Zd()/dse.Zd());
         }
 
-        if (fabs(dse.Az())*144>16384) // Each 2.5deg
+        if (fabs(dse.Az())*144>16384) // Each 2.5deg (144)
         {
             se0.Az(se.Az());
@@ -1629,34 +1734,6 @@
 
             ZdAz bend = fBending.CorrectBack(se*2*TMath::Pi()/16384)*kRad2Deg;
-            fHist->Fill(bend.Az(), dre.Az()/dse.Az());
-
-            cout << bend.Az() << ": " << dre.Az()/dse.Az() << endl;
+            ((TH3*)fHist)->Fill(bend.Az(), bend.Az(), dre.Az()/dse.Az());
         }
-
-        /*
-        const Double_t pos[3] = {
-            (fZd1->GetPos()+8192)%16384,
-            (fZd2->GetPos()+8192)%16384,
-            fAz->GetPos() };
-
-        //
-        //  Estimate Offset from the first ten positions
-        //
-        if (cnt++<10)
-        {
-            offset += pos[0]+pos[1];
-            continue;
-        }
-        if (cnt==11)
-        {
-            offset /= 10;
-            cnt++;
-        }
-
-        Double_t apos = (pos[0]-pos[1])/2 * TMath::Pi()*2 / 16384;
-
-        ZdAz bend = fBending.CorrectBack(ZdAz(apos, pos[2]))*kRad2Deg;
-        fHistTestSe->Fill(bend.Zd(), pos[0]+pos[1]-offset);
-*/
     }
     lout << "Gear Test Stopped... displaying Histogram." << endl;
@@ -1748,12 +1825,6 @@
     lout.UpdateGui();
 
-    fWin->Update(bendist*(360.0/2/TMath::Pi()), fTrackingError/kGearRatio2,
+    fWin->Update(bendist*(360.0/2/TMath::Pi()), fTrackingError,
                  fVelocity, fOffset, fRaDec, fZdAzSoll, fStatus, avail);
-
-    /*
-     cout << (int)(fMac1->GetStatus()&Macs::kOutOfControl) << " ";
-     cout << (int)(fMac2->GetStatus()&Macs::kOutOfControl) << " ";
-     cout << (int)(fMac3->GetStatus()&Macs::kOutOfControl) << endl;
-     */
 
     const Bool_t trigger = fTriggerDisplay;
@@ -1773,5 +1844,5 @@
     lout << "Displaying histogram..." << endl;
 
-    TH2F &hist = *fHist;
+    TH2F &hist = *(TH2F*)fHist;
 
     if (del)
@@ -1796,5 +1867,5 @@
     TH1F p2("spread", "Spread of the differences", hist.GetNbinsX(), hist.GetBinLowEdge(1),
             hist.GetBinLowEdge(hist.GetNbinsX()+1));
-    p2.SetXTitle("ZA [\\circ]");
+    p2.SetXTitle("Zd [\\circ]");
     for (int i=0; i<hist.GetNbinsX(); i++)
         p2.SetBinError(i, p->GetBinError(i));
@@ -1811,5 +1882,5 @@
     lout << "Displaying histogram..." << endl;
 
-    TH2F &hist = *fHist;
+    TH3F &hist = *(TH3F*)fHist;
 
     if (del)
@@ -1820,24 +1891,65 @@
 
     TCanvas *c=new TCanvas("c1", "", 1000, 1000);
-    c->Divide(1,2);
+    c->Divide(2,2);
+
+    // ----------
 
     c->cd(1);
-    TH2 *h=(TH2*)hist.DrawCopy();
-
-    TProfile *p = h->ProfileX("_pfx", -1, 9999, "s");
-    p->SetLineColor(kBlue);
-    p->Draw("same");
-    p->SetBit(kCanDelete);
+    TH2D &h1=*(TH2D*)hist.Project3D("zx"); // Zd
+    h1.SetTitle(" Gear Ratio Zenith Distance [re/se]  ");
+    h1.SetXTitle("Zd [\\circ]");
+    h1.Draw();
+    h1.SetBit(kCanDelete);
+
+    TProfile *p1 = h1.ProfileX("_pfx", -1, 9999, "s");
+    p1->SetLineColor(kBlue);
+    p1->Draw("same");
+    p1->SetBit(kCanDelete);
+
+    // ----------
 
     c->cd(2);
-
-    TH1F p2("spread", "Spread of the gear [16384/1500/4*U/U]", hist.GetNbinsX(), hist.GetBinLowEdge(1),
-            hist.GetBinLowEdge(hist.GetNbinsX()+1));
-    p2.SetXTitle("ZA [\\circ]");
-    for (int i=0; i<hist.GetNbinsX(); i++)
-        p2.SetBinError(i, p->GetBinError(i));
-    p2.SetLineColor(kRed);
-    p2.SetStats(0);
-    p2.DrawCopy();
+    TH2D &h2=*(TH2D*)hist.Project3D("zy"); // Az
+    h2.SetTitle(" Gear Ratio Azimuth [re/se]  ");
+    h2.SetXTitle("Zd [\\circ]");
+    h2.Draw();
+    h2.SetBit(kCanDelete);
+
+    TProfile *p2 = h2.ProfileX("_pfx", -1, 9999, "s");
+    p2->SetLineColor(kBlue);
+    p2->Draw("same");
+    p2->SetBit(kCanDelete);
+
+    // ----------
+
+    c->cd(3);
+
+    TAxis &axe1 = *h1.GetXaxis();
+
+    TH1F f1("spreadzd", " Spread Zenith Distance ",
+            axe1.GetNbins(), axe1.GetXmin(), axe1.GetXmax());
+    f1.SetXTitle("Zd [\\circ]");
+    for (int i=0; i<axe1.GetNbins(); i++)
+        f1.SetBinError(i, p1->GetBinError(i));
+    f1.SetLineColor(kRed);
+    f1.SetStats(0);
+    f1.DrawCopy();
+
+    c->cd(4);
+
+    // ----------
+
+    TAxis &axe2 = *h2.GetXaxis();
+
+    TH1F f2("spreadaz", " Spread Azimuth ",
+            axe2.GetNbins(), axe2.GetXmin(), axe2.GetXmax());
+    f2.SetXTitle("Az [\\circ]");
+    for (int i=0; i<axe2.GetNbins(); i++)
+        f2.SetBinError(i, p2->GetBinError(i));
+    f2.SetLineColor(kRed);
+    f2.SetStats(0);
+    f2.DrawCopy();
+
+    // ----------
 
     if (del)
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 1819)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 1953)
@@ -15,9 +15,9 @@
 
 #define WM_WAIT         WM_NULL
-#define WM_PRESET       0x1000
+//#define WM_PRESET       0x1000
 #define WM_POSITION     0x1001
 #define WM_TRACK        0x1002
 #define WM_STOP         0x1003
-#define WM_CALIB        0x1004
+//#define WM_CALIB        0x1004
 #define WM_TPOINT       0x1005
 #define WM_NEWTRACK     0x1006
@@ -29,4 +29,5 @@
 #define WM_GEAR         0x100c
 #define WM_DISPLAY      0x100d
+#define WM_TRACKPOS     0x100e
 
 class ShaftEncoder;
@@ -34,5 +35,5 @@
 class MGCosy;
 class MCosy;
-class TH2F;
+class TH1;
 
 class MTTalk : public MThread
@@ -96,7 +97,7 @@
     BackgroundAction_t fBackground;    // Flag for present backgroundthread
 
-    ZdAz  fTrackingError; // Tracking Offset between SE and calc-pos [re]
+    ZdAz  fTrackingError; // [rad] Tracking Offset between SE and calc-pos
     ZdAz  fOffset;        // Offset between se and re coordinate system [re]
-    ZdAz  fZdAzSoll;      // Soll position when moving
+    ZdAz  fZdAzSoll;      // [rad] Soll position when moving
     RaDec fRaDec;         // Position to track
     ZdAz  fAccuracy;      // Actual accuracy of Tracking
@@ -105,5 +106,5 @@
     ZdAz  fMax;
 
-    TH2F  *fHist;
+    TH1  *fHist;
     Bool_t fTriggerDisplay;
 
@@ -116,4 +117,7 @@
 
     ofstream *tpout;
+
+    Bool_t AlignTrackingPos(ZdAz pointing, ZdAz &za);
+    Bool_t CheckRange(const ZdAz &d) const;
 
     double Rad2SE(double rad) const;
@@ -182,5 +186,5 @@
     Bool_t HandleTimer(TTimer *t);
 
-    static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
+    // static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
     //    static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
 
