Index: trunk/FACT++/scripts/Main.js
===================================================================
--- trunk/FACT++/scripts/Main.js	(revision 18215)
+++ trunk/FACT++/scripts/Main.js	(revision 18216)
@@ -388,5 +388,5 @@
     dim.log("Starting shutdown ["+type+"].");
 
-    var shutdown_start_date = new Date();
+    var now1 = new Date();
 
     var bias = dim.state("BIAS_CONTROL").name;
@@ -396,16 +396,16 @@
     CloseLid();
 
-    var shutdown_after_close_lid_date = new Date();
-
+    var now2 = new Date();
+
+    dim.send("DRIVE_CONTROL/PARK");
+
+    console.out("","Waiting for telescope to park. This may take a while.");
+
+    // FIXME: This might not work is the drive is already close to park position
+    dim.wait("DRIVE_CONTROL", "Locked", 3000);
+
+    //unlock drive if task was sleep
     if (type=="sleep")
-        dim.send("DRIVE_CONTROL/MOVE_TO", 101, 0);
-    else
-        dim.send("DRIVE_CONTROL/PARK");
-
-    console.out("","Waiting for telescope to park. This may take a while.");
-
-    // FIXME: This might not work is the drive is already close to park position
-    if (type!="sleep")
-        dim.wait("DRIVE_CONTROL", "Locked", 3000);
+        dim.send("DRIVE_CONTROL/UNLOCK");
 
     var sub = new Subscription("DRIVE_CONTROL/POINTING_POSITION");
@@ -459,5 +459,5 @@
     dim.log("Finishing shutdown.");
 
-    var shutdown_after_bias_off_data = new Date();
+    var now3 = new Date();
 
     dim.send("FTM_CONTROL/STOP_TRIGGER");
@@ -470,7 +470,13 @@
     {
         dim.send("BIAS_CONTROL/DISCONNECT");
-        dim.send("PWR_CONTROL/TOGGLE_DRIVE");
-        dim.wait("BIAS_CONTROL", "Disconnected", 6000);
-        dim.wait("PWR_CONTROL", "DriveOff", 6000);
+
+        var pwrctrl_state = dim.state("PWR_CONTROL").name;
+        if (pwrctrl_state=="SystemOn" ||
+            pwrctrl_state=="BiasOff"  ||
+            pwrctrl_state=="DriveOn")
+            dim.send("PWR_CONTROL/TOGGLE_DRIVE");
+
+        dim.wait("BIAS_CONTROL", "Disconnected", 3000);
+        dim.wait("PWR_CONTROL",  "DriveOff",     3000);
     }
 
@@ -489,13 +495,7 @@
     console.out("    FTM_CONTROL:   "+dim.state("FTM_CONTROL").name);
     console.out("    BIAS_CONTROL:  "+dim.state("BIAS_CONTROL").name);
-    console.out("    PWR_CONTROL:  "+dim.state("PWR_CONTROL").name);
+    console.out("    PWR_CONTROL:   "+dim.state("PWR_CONTROL").name);
     console.out("");
-    dim.log("Shutdown: end [" 
-                   + (shutdown_after_close_lid_date-shutdown_start_date)/1000 
-                   + "s, " 
-                   + (shutdown_after_bias_off_data-shutdown_after_close_lid_date)/1000 
-                   + "s, " 
-                   + (new Date()-shutdown_after_bias_off_data)/1000+"s]"
-           );
+    dim.log("Shutdown: end ["+(now2-now1)/1000+"s, "+(now3-now2)/1000+"s, "+(new Date()-now3)/1000+"s]");
     console.out("");
 
@@ -625,4 +625,5 @@
          "TNG_WEATHER/DATA",
          "TNG_WEATHER/DUST",
+         "PFMINI_CONTROL/DATA",
         ];
 
@@ -961,4 +962,5 @@
          [ "GPS_CONTROL",         [ "Locked"  ] ],
          [ "SQM_CONTROL",         [ "Disconnected", "Connected", "Valid" ] ],
+         [ "PFMINI_CONTROL",      [ "Disconnected", "Connected", "Receiving" ] ],
         ];
 
@@ -1160,4 +1162,6 @@
             dim.log("Starting ratescan.");
 
+            //set reference to whole camera (in case it was changed)
+            dim.send("RATE_SCAN/SET_REFERENCE_CAMERA");
             // Start rate scan
             dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10, "default");
@@ -1247,4 +1251,6 @@
             dim.log("Starting ratescan 2/1 ["+obs[sub].rstype+"]");
 
+            //set reference to whole camera (in case it was changed)
+            dim.send("RATE_SCAN/SET_REFERENCE_CAMERA");
             // Start rate scan
             dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 300, 20, obs[sub].rstype);
