Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1111)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1275)
@@ -187,5 +187,5 @@
     //
     if (HasError())
-        lout << "Error #6004 (requesting re pos from Macs) happened." << endl;
+        lout << "Error while requesting re pos from Macs (SDO #6004)" << endl;
 
     return kFALSE;
@@ -400,5 +400,6 @@
         if (!cdzd && !cdaz)
         {
-            lout << "Positioning done with " << i << "manuvers." << endl;
+            lout << "Positioning done in " << i << (i==1?" step.":" steps.") << endl;
+            SetStatus(MCosy::kStopped);
             return TRUE;
         }
@@ -468,5 +469,5 @@
     //
     if (HasError())
-        lout << "Error #3006 (setting velocity of Macs) happened." << endl;
+        lout << "Error while setting velocity (SDO #3006)" << endl;
 
     return kFALSE;
@@ -520,7 +521,31 @@
 
     const Float_t limit = 0.25;
-
-    if (sgn(vt->Az()) != sgn(vcalc.Az()) &&
-        fabs(vt->Az()) < limit*fabs(vcalc.Az()))
+/*
+    if (sgn(vt->Az()) != sgn(vcalc.Az()))
+        vt->Az(0);
+//    else
+    {
+        if (fabs(vt->Az()) < fabs(vcalc.Az()) *0.5)
+            vt->Az(0.5*vcalc.Az());
+
+        if (fabs(vt->Az()) > fabs(vcalc.Az()) *1.5)
+            vt->Az(1.5*vcalc.Az());
+    }
+
+    if (sgn(vt->Zd()) != sgn(vcalc.Zd()))
+        vt->Zd(0);
+//    else
+    {
+        if (fabs(vt->Zd()) > fabs(vcalc.Az()) *1.5)
+            vt->Zd(1.5*vcalc.Zd());
+
+        if (fabs(vt->Zd()) < fabs(vcalc.Az()) *0.5)
+            vt->Zd(0.5*vcalc.Zd());
+    }
+    */
+
+    if (sgn(vt->Az()) != sgn(vcalc.Az())
+        && fabs(vt->Az()) < limit*fabs(vcalc.Az())
+       )
         vt->Az(0);
     else
@@ -531,6 +556,7 @@
         }
 
-    if (sgn(vt->Zd()) != sgn(vcalc.Zd()) &&
-        fabs(vt->Zd()) < limit*fabs(vcalc.Zd()))
+    if (sgn(vt->Zd()) != sgn(vcalc.Zd())
+        && fabs(vt->Zd()) < limit*fabs(vcalc.Zd())
+       )
         vt->Zd(0);
     else
@@ -605,4 +631,11 @@
     {
         //
+        // The loop should not be executed faster than the ramp of
+        // a change in the velocity can be followed.
+        // (This is important on fast machines >500MHz)
+        //
+        //usleep(100000000);
+
+        //
         // Request Target position for this moment
         //
@@ -715,5 +748,5 @@
     // Stop revolution mode (movement)
     //
-    cout << "Stoping possibleRPM mode..." << endl;
+    cout << "Stopping possibleRPM mode..." << endl;
     fMac1->SetRpmMode(FALSE);
     fMac2->SetRpmMode(FALSE);
@@ -734,4 +767,5 @@
 void *MCosy::Proc(int msg, void *mp)
 {
+    cout << "MCosy::Proc: 0x" << msg << endl;
     switch (msg)
     {
@@ -846,4 +880,5 @@
      << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl;
      */
+
 
     cout << "Setting up software endswitch..." << flush;
@@ -890,9 +925,6 @@
         // wait until a tracking session is started
         //
-        while (!fTracking && !fTTalk->HasStopFlag())
+        while (!fTracking)
             usleep(1);
-
-        if (fTTalk->HasStopFlag())
-            break;
 
         ofstream fout("log/cosy.err");
@@ -915,5 +947,9 @@
         // only update fTrackingError while tracking
         //
-        while (fTracking && !fTTalk->HasStopFlag())
+        bool phca1=false;
+        bool phca2=false;
+        bool phcaz=false;
+
+        while (fTracking)
         {
             //
@@ -922,17 +958,11 @@
             const float weight = 1.; //0.3;
 
-            ZdAz offset(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight,
-                        fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight);
-
-            fOffset = offset;
-
             //
             // This is the time constant which defines how fast
             // you correct for external influences (like wind)
             //
-            bool phca1;
-            bool phca2;
-            bool phcaz;
-
+            fZd1->ResetPosHasChanged();
+            fZd2->ResetPosHasChanged();
+            fAz->ResetPosHasChanged();
             do
             {
@@ -941,5 +971,6 @@
                 phcaz = fAz->PosHasChanged();
                 usleep(1);
-            } while (!phca1 && !phca2 && !phcaz);
+            } while (!phca1 && !phca2 && !phcaz && fTracking);
+
             //---usleep(100000); // 0.1s
 
@@ -975,4 +1006,6 @@
                 sla.SetMjd(time.Zd());
                 sollzd = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); // [se]
+
+                fOffset.Zd(fOffset.Zd()*(1.-weight)+(ist.Zd()*kGearRatio.X()-istre.Zd())*weight);
             }
 
@@ -981,4 +1014,6 @@
                 sla.SetMjd(time.Az());
                 sollaz = CorrectTarget(ist, sla.CalcZdAz(fRaDec)); // [se]
+
+                fOffset.Az(fOffset.Az()*(1.-weight)+(ist.Az()*kGearRatio.Y()-istre.Az())*weight);
             }
 
@@ -1063,4 +1098,6 @@
     // Create Nodes
     //
+    lout << "- Setting up network." << endl;
+
     fMac1=new Macs(1, "Mac.1/Az",      lout);
     fMac2=new Macs(2, "Mac.2/Zd",      lout);
@@ -1084,6 +1121,8 @@
     // Create Gui Event timer and Gui
     //
+    lout << "- Initializing GUI Timer." << endl;
     fUpdateGui = new TTimer(this, 100); // 100ms
 
+    lout << "- Starting GUI." << endl;
     fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
 
@@ -1108,4 +1147,7 @@
 */
 
+    lout.DisableOutputDevice(MLog::eGui);
+    lout.SetOutputGui(NULL, kFALSE);
+
     gApplication->Terminate(0);
 }
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 1111)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 1275)
@@ -15,5 +15,4 @@
 #define WM_STOP      0x1003
 #define WM_POLARIS   0x1004
-#define WM_QUIT      0x1005
 
 class ShaftEncoder;
@@ -33,6 +32,8 @@
     {
         SetPriority(10);
+        Detach();
         Start();
     }
+    ~MTTalk() { cout << "~MTTalk::MTTalk" << endl; }
 };
 
@@ -41,5 +42,4 @@
 class MCosy : public Network, public MsgQueue, public TObject
 {
-    friend class MTGui;
     friend class MTTalk;
 
@@ -94,5 +94,4 @@
 
     void TalkThread();
-    void GuiThread(MTGui *t);
 
     int  SetPosition(const ZdAz &dst);
