Index: trunk/MagicSoft/Cosy/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/Makefile	(revision 3896)
+++ trunk/MagicSoft/Cosy/Makefile	(revision 3897)
@@ -157,3 +157,35 @@
 	@gzip -9 ../cosy.tar
 
+install:
+	@echo Installing cosy to ~stesy/Cosy
+	@echo Copy 'cosy'
+	@chmod u+w /home/stesy/Cosy/cosy
+	@cp cosy /home/stesy/Cosy/
+	@chmod a-w /home/stesy/Cosy/cosy
+	@echo Copy cosy resources '.cosyrc'
+	@chmod u+w /home/stesy/Cosy/.cosyrc
+	@cp .cosyrc /home/stesy/Cosy/
+	@chmod a-w /home/stesy/Cosy/.cosyrc
+	@echo Copy bending model 'bending.txt'
+	@chmod u+w /home/stesy/Cosy/bending.txt
+	@cp bending.txt /home/stesy/Cosy
+	@chmod a-w /home/stesy/Cosy/bending.txt
+	@echo Copy LED offsets 'leds.txt'
+	@chmod u+w /home/stesy/Cosy/leds.txt
+	@cp leds.txt /home/stesy/Cosy/
+	@chmod a-w /home/stesy/Cosy/leds.txt
+	@echo Copy predefined positions 'prepos.txt'
+	@chmod u+w /home/stesy/Cosy/prepos.txt
+	@cp prepos.txt /home/stesy/Cosy/
+	@chmod a-w /home/stesy/Cosy/prepos.txt
+	@echo Copy star catalog 'stars.txt'
+	@chmod u+w /home/stesy/Cosy/stars.txt
+	@cp stars.txt /home/stesy/Cosy/
+	@chmod a-w /home/stesy/Cosy/stars.txt
+	@echo Copy SAO catalog
+	@chmod u+w /home/stesy/Cosy/sao/sao-*
+	@cp sao/sao-* /home/stesy/Cosy/sao/
+	@chmod a-w /home/stesy/Cosy/sao/sao-*
+	@echo finished...
+
 # @endcode
Index: trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 3896)
+++ trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 3897)
@@ -19,5 +19,5 @@
     Slalib::SetMjd(mjd);
 
-    fTt = mjd + slaDtt(mjd)/60./60./24.;
+    fTt = GetMjd() + slaDtt(GetMjd())/60./60./24.;
 
     //
@@ -28,5 +28,5 @@
     double veh[3]; // heliocentric velocity
 
-    slaEvp(mjd + fDt, 2000.0, veb, ceb, veh, fEarth);
+    slaEvp(GetMjd() + fDt, 2000.0, veb, ceb, veh, fEarth);
 }
 
Index: trunk/MagicSoft/Cosy/catalog/SlaStars.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 3896)
+++ trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 3897)
@@ -40,10 +40,9 @@
 
     // prepare calculation: Mean Place to geocentric apperent
-    slaMappa(2000.0, mjd, fAmprms);        // Epoche, TDB
+    slaMappa(2000.0, GetMjd(), fAmprms);   // Epoche, TDB
 
     // prepare: Apperent to observed place
-    slaAoppa(mjd, 0,                       // mjd, Delta UT=UT1-UTC
-             // GetElong(), GetPhi(), 148, // göttingen long, lat, height
-             GetElong(), GetPhi(), GetHeight(), // göttingen long, lat, height
+    slaAoppa(GetMjd(), 0,                  // mjd, Delta UT=UT1-UTC
+             GetElong(), GetPhi(), GetHeight(), // long, lat, height
              0, 0,                         // polar motion x, y-coordinate (radians)
              // 273.155, 1013.25, 0.5,     // temp, pressure, humidity
Index: trunk/MagicSoft/Cosy/catalog/Slalib.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 3896)
+++ trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 3897)
@@ -29,6 +29,14 @@
 {
     fTime.SetMjd(mjd);
-    fAlpha = slaGmst(mjd) + GetElong();
-}
+
+    fAlpha = slaGmst(GetMjd()) + GetElong();
+}
+
+void Slalib::Now(double offset)
+{
+    fTime.Now();
+    SetMjd(fTime.GetMjd()+offset/(24*60*60));
+}
+
 
 ZdAz Slalib::XYZ2ZdAz(double coord[3]) const
Index: trunk/MagicSoft/Cosy/catalog/Slalib.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 3896)
+++ trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 3897)
@@ -23,5 +23,5 @@
     virtual void SetMjd(double mjd);
     Double_t GetMjd() const { return fTime.GetMjd(); }
-    void Now() { fTime.Now(); }
+    void Now(double offset=0);
     const MTime &GetTime() const { return fTime; }
 
Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 3896)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 3897)
@@ -712,6 +712,8 @@
 // velocities are limited to the maximum velocity.
 //
-void MCosy::LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const
-{
+Bool_t MCosy::LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const
+{
+    Bool_t rc = kFALSE;
+
     //
     // How to limit the speed. If the wind comes and blowes
@@ -768,6 +770,7 @@
         if (fabs(vt->Az()) > maxtrack*vraz)
         {
-            lout << "Warning: Azimuth speed limit (" << maxtrack*100 << "%) exceeded... limited." << endl;
+            lout << "Warning: Azimuth speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Az()) << " > " << maxtrack*vraz << ")... limited." << endl;
             vt->Az(maxtrack*vraz*sgn(vcalc.Az()));
+            rc=kTRUE;
         }
 /*
@@ -782,7 +785,9 @@
  */       if (fabs(vt->Zd()) > maxtrack*vrzd)
         {
-            lout << "Warning: Altitude speed limit (" << maxtrack*100 << "%) exceeded... limited." << endl;
+            lout << "Warning: Altitude speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Zd()) <<" > " << maxtrack*vrzd << ")... limited." << endl;
             vt->Zd(maxtrack*vrzd*sgn(vcalc.Zd()));
-        }
+            rc=kTRUE;
+        }
+    return rc;
 }
 /*
@@ -829,8 +834,11 @@
         pointing.Zd(-pointing.Zd());
         pointing.Az(pointing.Az()+180);
+        //lout << "ZD=-ZD Az+=180" << endl;
     }
 
     const ZdAz se = GetSePos()*2*TMath::Pi()/16384;   // [rad]
     const ZdAz unbendedse = fBending.CorrectBack(se)*kRad2Deg; // ist pointing
+
+    //lout << "Unbended: " << unbendedse.Zd() << " " << unbendedse.Az() << endl;
 
     do
@@ -839,4 +847,6 @@
         if (d>-180 && d<=180)
             break;
+
+        //lout << "AZ += " << TMath::Sign(360., d) << endl;
 
         pointing.Az(pointing.Az()+TMath::Sign(360., d));
@@ -897,6 +907,4 @@
 void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad]
 {
-    lout << "Track Position: " << dst.Ra()*kRad2Deg/15 << "h, " << dst.Dec()*kRad2Deg << "deg (Ra/Dec)" << endl;
-
     SlaStars sla(fObservatory);
 
@@ -906,4 +914,6 @@
     sla.Now();
     ZdAz dest = sla.CalcZdAz(dst);
+
+    lout << sla.GetTime() << ": Track Position " << dst.Ra()*kRad2Deg/15 << "h, " << dst.Dec()*kRad2Deg <<"deg" << endl;
 
     // FIXME: Determin tracking start point by star culmination
@@ -958,6 +968,7 @@
 
     sla.Now();
-    lout << sla.GetTime() << " - Start tracking:";
-    lout << " Ra: " << xy.X() << "h  " << "Dec: " << xy.Y() << "\xb0" << endl;
+//    lout << sla.GetTime() << " - Start tracking:";
+//    lout << " Ra: " << xy.X() << "h  " << "Dec: " << xy.Y() << "\xb0" << endl;
+
 /*#ifdef EXPERT
     ofstream fout("coordinates.txt");
@@ -971,4 +982,9 @@
     fBackground = kBgdTracking;
 
+    ZdAz pos = sla.CalcZdAz(fRaDec);
+
+    lout << sla.GetTime() << " - Start Tracking: Ra=" <<xy.X() << "h Dec=";
+    lout << xy.Y() << "\xb0 @ Zd=" << pos.Zd()*kRad2Deg <<"deg Az=" << pos.Az()*kRad2Deg <<"deg" << endl;
+
 //---    ofstream fout("log/cosy.pos");
 //---    fout << "Tracking:";
@@ -987,12 +1003,12 @@
         // Request Target position for this moment
         //
-        sla.Now();
+        sla.Now(dt);
 
         //
         // Request theoretical Position for a time in the future (To+dt) from CPU
         //
-        const Double_t mjd = sla.GetMjd()+dt/(60*60*24);
-        const ZdAz pointing = sla.CalcZdAz(fRaDec, mjd); // soll pointing [deg]
-
+         const ZdAz pointing = sla.CalcZdAz(fRaDec); // soll pointing [rad]
+
+        //lout << sla.GetTime() << pointing.Zd()*kRad2Deg << " " << pointing.Az()*kRad2Deg << endl;
         /*
         ZdAz dest;
@@ -1002,9 +1018,13 @@
         ZdAz dest = AlignTrackingPos(pointing);
 
-        ZdAz vcalc = sla.GetApproxVel(fRaDec) * kGearRatio2*4./60.;  // [re/min]
+        // lout << "DEST: " << dest.Zd()*kRad2Deg << " " <<dest.Az()*kRad2Deg << endl;
+
+        ZdAz vcalc = sla.GetApproxVel(fRaDec) * kGearRatio2*4./60.; 
+        //lout << "Vcalc: " << dest.Zd() << " " << dest.Az() << endl;
+        vcalc *= kGearRatio2*4./60.; // [re/min]
 
         float dtime = -1;
         if (kFALSE /*fUseStarguider*/)
-            dtime = Starguider(mjd, dest);
+            dtime = Starguider(sla.GetMjd(), dest);
 
         if (dtime<0)
@@ -1012,4 +1032,6 @@
             dest = fBending(dest);       // [rad]
 
+            //lout << "DEST-BEND: " << dest.Zd()*kRad2Deg << " " <<dest.Az()*kRad2Deg << endl;
+              
             if (!CheckRange(dest))
                 break;
@@ -1032,4 +1054,10 @@
 
             dtime = dt;
+
+            ZdAz repos = GetRePos();
+    //        lout << "Repos: " << repos.Zd()/kGearRatio.X() << " " << repos.Az()*kGearRatio.Y() << endl;
+   //         repos /= kGearRatio;
+            repos /= 16384/TMath::Pi()/2;
+            repos *= kRad2Deg;
         }
 
@@ -1045,5 +1073,10 @@
         //
         ZdAz vt = v/4;
-        LimitSpeed(&vt, vcalc);
+        if (LimitSpeed(&vt, vcalc))
+        {
+            lout << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl;
+            lout << "vt: " << vt.Zd() << " " << vt.Az() << "re/min" << endl;
+            lout << "Dest: " << dest.Zd() << " " << dest.Az() << endl;
+        }              
         vt.Round();
 
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 3896)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 3897)
@@ -143,5 +143,5 @@
     void InitSync();
     bool InitTracking();
-    void LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const;
+    Bool_t LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const;
 
     void TalkThread();
