Index: trunk/FACT++/scripts/Main.js
===================================================================
--- trunk/FACT++/scripts/Main.js	(revision 19512)
+++ trunk/FACT++/scripts/Main.js	(revision 19513)
@@ -906,4 +906,12 @@
     }
 
+    if (irq.toUpperCase()=="PREPARE")
+    {
+        dim.log("Preparing for ToO observation.");
+        dim.send("DRIVE_CONTROL/STOP");
+        dim.wait("DRIVE_CONTROL", "Initialized", 15000);
+        return true;
+    }
+
     dim.log("IRQ "+irq+" unhandled... stopping script.");
     return true;
@@ -1058,4 +1066,5 @@
          [ "PFMINI_CONTROL",      [ "Disconnected", "Connected", "Receiving" ] ],
          [ "BIAS_TEMP",           [ "Valid" ] ],
+         [ "SCHEDULER",           [ /*"Connected",*/ "Armed" ] ],
         ];
 
@@ -1516,5 +1525,6 @@
         {
             // Switch the voltage to a reduced voltage level
-            service_feedback.voltageOn(0);
+            if (!obs[sub].grb)
+                service_feedback.voltageOn(0);
 
             // Change wobble position every four runs,
@@ -1552,13 +1562,13 @@
         {
             doDrsCalibration("data");  // will turn voltage off
-
-            // Now we switch on the voltage and a significant amount of
-            // time has been passed, so do the check again.
-            sun = Sun.horizon(-12);
-            if (!was_up && sun.isUp)
-            {
-                dim.log("Sun rise detected....");
-                continue;
-            }
+        }
+
+        // Now we switch on the voltage and a significant amount of
+        // time has been passed, so do the check again.
+        sun = Sun.horizon(-12);
+        if (!was_up && sun.isUp)
+        {
+            dim.log("Sun rise detected....");
+            continue;
         }
 
@@ -1605,5 +1615,5 @@
             // If the lid is not yet open, wait for the lid to be open and
             // go on as usual.
-            if (dim.state("LID_CONTROL")!="Open")
+            if (dim.state("LID_CONTROL").name!="Open")
             {
                 dim.wait("LID_CONTROL", "Open", 30000);
@@ -1621,7 +1631,7 @@
 
             dim.wait("FEEDBACK",      "InProgress",  45000); // This is most likely the first to happen
-            dim.wait("DRIVE_CONTROL", "Tracking",   150000); // 110s for turning and 30s for stabilizing
-
-            v8.wait(1000); // By now we should have collected the required three current events in FEEDBACK
+            dim.wait("DRIVE_CONTROL", "OnTrack",    150000); // 110s for turning and 30s for stabilizing
+
+            v8.sleep(1000); // By now we should have collected the required three current events in FEEDBACK
             // Current are averaged over 10s. So by now we should have a reasonable idea of the brightness of the sky
             // Individual pixels might still suffer wrong settings
@@ -1652,5 +1662,5 @@
         var twilight = Sun.horizon(-16).isUp;
 
-        if (twilight || obs[sub].grb)
+        if (twilight || (obs[sub].grb && run<2))
         {
             for (var i=0; i<5 && !irq; i++)
