Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 8871)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 8875)
@@ -406,6 +406,6 @@
 
 //#ifdef EXPERT
-    //point.SetPointAccDec(0.3, 0.3);
-    //point.SetPointVelocity(0.3);
+//    point.SetPointAccDec(0.25, 0.25);
+//    point.SetPointVelocity(0.4);
 //#else
 
@@ -449,5 +449,5 @@
     track.SetPointVelocity(0.1);
 
-    //    track.SetPointAccDec(0.4, 0.4);
+    // track.SetPointAccDec(0.4, 0.4);
     // track.SetPointVelocity(0.4);
 
@@ -699,17 +699,15 @@
                 return 0xebb0;
 
-            //const bool arm = *((bool*)mp);
-            //if (arm)
-            //{
+            const bool arm = mp ? *((bool*)mp) : true;
+            if (arm)
+            {
                 fMac1->Arm();
                 fMac2->Arm();
-                //cout << "ARMED" << endl;
-            //}
-            //else
-            //{
-            //    fMac1->Disarm();
-            //    fMac2->Disarm();
-                //cout << "DISARMED" << endl;
-            //}
+            }
+            else
+            {
+                fMac1->Disarm();
+                fMac2->Disarm();
+            }
         }
         //cout << "WM_Position: done. (return 0x7777)" << endl;
@@ -1290,5 +1288,5 @@
     //cout << (fStatus&MDriveCom::kTracking?"TRA: ":"POS: ") << bendist.Zd() << " " << bendist.Az() << endl;
 
-    fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError);
+    fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError, armed);
 
     fWin->UpdateWeather(*fCom);
@@ -1614,5 +1612,5 @@
 }
 
-MCosy::MCosy(MEnv &env, const char *addr, const char *pointing)
+MCosy::MCosy(MEnv &env, MDriveCom *com, const char *pointing)
 : Network(), fObservatory(MObservatory::kMagic1), fStarguider(NULL),
 fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), /*fMac3(0),*/
@@ -1665,6 +1663,7 @@
     fAz->SetDisplay(fWin->GetLabel1());
 
-    fCom = new MDriveCom(this, addr, fOutRep);
-//    fCom->Start();
+    fCom = com;//new MDriveCom(this, addr, tx, rx, fOutRep);
+    fCom->SetOutRep(fOutRep);
+    //    fCom->Start();
 }
 
@@ -1691,4 +1690,10 @@
 MCosy::~MCosy()
 {
+    if(fCom)
+    {
+        fCom->SetMsgQueue(NULL);
+        fCom->SetOutRep(NULL);
+    }
+
     gLog << inf2 << "Deleting GUI timer." << endl;
     // FIXME: Wait until last Update was finished!!!
@@ -1704,8 +1709,9 @@
         delete fOutTp;
     }
+
     delete fOutRep;
 
-    gLog << inf2 << "Deleting CC communication." << endl;
-    delete fCom;
+    //gLog << inf2 << "Deleting CC communication." << endl;
+    //delete fCom;
 
     gLog << inf2 << "Deleting Nodes." << endl;
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 8871)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 8875)
@@ -181,5 +181,5 @@
 
 public:
-    MCosy(MEnv &env, const char *addr, const char *pointing);
+    MCosy(MEnv &env, MDriveCom *com, const char *pointing);
     ~MCosy();
 
@@ -212,5 +212,4 @@
     MLog *GetOutRep() { return fOutRep; }
 
-    //rwagner
     MDriveCom *GetDriveCom() { return fCom; }
 
Index: trunk/MagicSoft/Cosy/main/MSlewing.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MSlewing.cc	(revision 8871)
+++ trunk/MagicSoft/Cosy/main/MSlewing.cc	(revision 8875)
@@ -1,2 +1,3 @@
+#include "MSlewing.h"
 #include "MSlewing.h"
 
@@ -7,4 +8,5 @@
 #include "MDriveCom.h"
 
+#include "MString.h"
 #include "MPointing.h"
 
@@ -165,9 +167,28 @@
         // Round to check whether we are as near as possible
         // to the value we expect
-        cd.Round();
-
+
+        cout << cd.Zd() << " " << cd.Az() << endl;
+
+        cd /= fCosy->kResSE; // Scale to Revolutions
+
+        gLog << inf2 << "- Shaftencoders show a residual deviation of dZd=";
+        gLog << MString::Format("%.2f", cd.Zd()*360*60) << "' and dAz=";
+        gLog << MString::Format("%.2f", cd.Az()*360*60) << "'" << endl;
+
+        cout << cd.Zd() << " " << cd.Az() << endl;
+ 
+        cd *= 1./fMaxResidual; // Scale to units of the maximum residual
+
+        cout << fCosy->kResSE.X() << " " << 1./fMaxResidual << endl;
+        cout << cd.Zd() << " " << cd.Az() << endl;
+
+        cd.Abs();
+
+        // FIXME:: Do NOT check Shaftencoder values!!!
         // Check if there is a control deviation on the axis
-        const Bool_t cdzd = (int)cd.Zd() ? kTRUE : kFALSE;
-        const Bool_t cdaz = (int)cd.Az() ? kTRUE : kFALSE;
+        const Bool_t cdzd = cd.Zd()>0.5 ? kTRUE : kFALSE;
+        const Bool_t cdaz = cd.Az()>0.5 ? kTRUE : kFALSE;
+
+        cout << (int)cdzd << " " << (int)cdaz << endl;
 
         // check if we reached the correct position already
@@ -183,17 +204,20 @@
         // ==============================================
         //   Estimate the noncircularity of the zd axis
-        const ZdAz ist = dst-rd*TMath::TwoPi()/fCosy->kResSE;
-
-        const double p1 = ist.Zd()-19.0605/kRad2Deg;
-        const double p2 = dst.Zd()-19.0605/kRad2Deg;
-
-        const double f1 = (-26.0101*sin(p1)+443.761*ist.Zd())*rad2se;
-        const double f2 = (-26.0101*sin(p2)+443.761*dst.Zd())*rad2se;
-        // ==++=========================================
+//        const ZdAz ist = dst-rd*TMath::TwoPi()/fCosy->kResSE;
+
+//        const double p1 = ist.Zd()-19.0605/kRad2Deg;
+//        const double p2 = dst.Zd()-19.0605/kRad2Deg;
+
+ //       const double f1 = (-26.0101*sin(p1)+443.761*ist.Zd())*rad2se;
+ //       const double f2 = (-26.0101*sin(p2)+443.761*dst.Zd())*rad2se;
+        // ===========================================
+
+        gLog << warn << "WARNING - The center of the elevation axis is taken as center of the drive bow" << endl;
+
 
         // change units from se to re
 //        rd *= fCosy->kGearTot/fCosy->kResSE; // [re]
         rd *= Div(fCosy->kGearTot,fCosy->kResSE); // [re]
-        rd.Zd(f2-f1);
+//        rd.Zd(f2-f1);
 
         // Initialize Velocities so that we reach both positions
@@ -201,7 +225,7 @@
         if (i)
         {
-            //lout << "--- LO-SPEED ---" << endl;
-            SetAccDec(fCosy->fMac1, 0.1, 0.1);
-            SetAccDec(fCosy->fMac2, 0.1, 0.1);
+            //cout << "--- LO-SPEED ---" << endl;
+            SetAccDec(fCosy->fMac1, 0.05, 0.05);
+            SetAccDec(fCosy->fMac2, 0.05, 0.05);
 
             SetPosVelocity(1.0, 0.05);
@@ -209,4 +233,5 @@
         else
         {
+            // 15 motor revolutions
             const Double_t y = 15*fCosy->kGearTot.Y()/fCosy->kResSE.Y();
 
@@ -215,20 +240,7 @@
 
 	    if (rd.Az()>-y && rd.Az()<y)
-	      {
-		//lout << "--- LO-SPEED Mac1 ---" << endl;
 		SetAccDec(fCosy->fMac1, 0.05, 0.05);
-	      }
 	    else
-	      {
-
- 		//lout << "MSlewing::SetPosition SetAccDec Mac1: " << fAcc << fDec << endl;
-		
- 		SetAccDec(fCosy->fMac1, fAcc, fDec);
-		
-	      }
-
-
-	    // new 16.05.05  F.G.
-	    // SetAccDec(fCosy->fMac1, fAcc, fDec);
+                SetAccDec(fCosy->fMac1, fAcc, fDec);
 
             SetAccDec(fCosy->fMac2, fAcc, fDec);
@@ -267,5 +279,5 @@
 
     t.Now();
-    gLog << warn << t << " - Warning: Requested position not reached (i=" << dec << i << ")" << endl;
+    gLog << warn << t << " - Warning: Requested position not reached (i=" << i << ")" << endl;
 
     fCosy->fCom->SendStatus("Target position missed!");
Index: trunk/MagicSoft/Cosy/main/MSlewing.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MSlewing.h	(revision 8871)
+++ trunk/MagicSoft/Cosy/main/MSlewing.h	(revision 8875)
@@ -23,13 +23,16 @@
     Float_t fDec;
 
+    Float_t fMaxResidual; // [rev] Maximum residual deviation to stop pointin
+
     void DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2);
     void SetPosVelocity(const Float_t ratio, Float_t vel);
 
 public:
-    MSlewing(MCosy *cosy) : fCosy(cosy), fVel(0.1), fAcc(0.2), fDec(0.1) { }
+    MSlewing(MCosy *cosy) : fCosy(cosy), fVel(0.1), fAcc(0.2), fDec(0.1), fMaxResidual(1./16384) { }
 
     void SetPointAccDec(Float_t acc, Float_t dec) { fAcc = acc; fDec = dec; }
     void SetPointVelocity(Float_t vel) { fVel = vel; }
     int  SetPosition(const ZdAz &dst, Bool_t track=kFALSE);
+    void SetMaxResidual(Float_t ac) { fMaxResidual = ac; }
 
     ClassDef(MSlewing, 0)
