Index: /trunk/FACT++/src/ratecontrol.cc
===================================================================
--- /trunk/FACT++/src/ratecontrol.cc	(revision 15028)
+++ /trunk/FACT++/src/ratecontrol.cc	(revision 15029)
@@ -393,7 +393,11 @@
         // Keep all median currents of the past 10 seconds
         fCurrents.push_back(make_pair(time, med));
-        while (fCurrents.size()>0)
-            if (time-fCurrents.front().first>boost::posix_time::seconds(10))
-                fCurrents.pop_front();
+        while (!fCurrents.empty())
+        {
+            if (time-fCurrents.front().first<boost::posix_time::seconds(10))
+                break;
+
+            fCurrents.pop_front();
+        }
 
         // If we are not doing a calibration no further action necessary
@@ -422,4 +426,5 @@
 
         fThresholdMin = 36.0833*pow(avg, 0.638393)+184.037;
+        fThresholdReference = fThresholdMin;
         fThresholds.assign(160, fThresholdMin);
 
@@ -471,6 +476,10 @@
         }
 
+        cout << "-1-" << endl;
+
         if (fDimDrive.state()<Drive::State::kMoving)
             Warn("Drive not even moving...");
+
+        cout << "-2-" << endl;
 
         fCounter = 0;
@@ -478,8 +487,12 @@
         fCalibrationTimeStart = Time();
 
+        cout << "-3-" << endl;
+
         ostringstream out;
         out << "Rate calibration by current " << fThresholdReference << " with a target rate of " << fTargetRate << " Hz";
         Info(out);
 
+        cout << "START" << endl;
+
         return RateControl::State::kSettingGlobalThreshold;
     }
@@ -514,4 +527,5 @@
     int Print() const
     {
+        cout << "PRINT" << endl;
         Out() << fDim << endl;
         Out() << fDimFTM << endl;
@@ -566,5 +580,4 @@
         fDimRS("RATE_SCAN"),
         fDimDrive("DRIVE_CONTROL"),
-
         fDimThreshold("RATE_CONTROL/THRESHOLD", "S:1;D:1;D:1",
                       "Resulting threshold after calibration"
@@ -583,4 +596,5 @@
         fDimFTM.Subscribe(*this);
         fDimRS.Subscribe(*this);
+        fDimDrive.Subscribe(*this);
 
         Subscribe("FTM_CONTROL/TRIGGER_RATES")
