Index: trunk/FACT++/scripts/Main.js
===================================================================
--- trunk/FACT++/scripts/Main.js	(revision 18128)
+++ trunk/FACT++/scripts/Main.js	(revision 18169)
@@ -1293,4 +1293,64 @@
         break; // case "RATESCAN2"
 
+    case "CUSTOM":
+
+        // This is a workaround to make sure that we really catch
+        // the new OnTrack state later and not the old one
+        dim.send("DRIVE_CONTROL/STOP");
+        dim.wait("DRIVE_CONTROL", "Armed", 15000);
+
+        // Ramp bias if needed
+        if (!obs[sub].biason)
+            service_feedback.voltageOff();
+        else
+        {
+            // Switch the voltage to a reduced level (Ubd)
+            var bias = dim.state("BIAS_CONTROL").name;
+            if (bias=="VoltageOn" || bias=="Ramping")
+                service_feedback.voltageOn(0);
+        }
+        // Close lid
+        CloseLid();
+
+        // Move to position (zd/az)
+        dim.log("Moving telescope to zd="+obs[sub].zd+" az="+obs[sub].az);
+        dim.send("DRIVE_CONTROL/MOVE_TO", obs[sub].zd, obs[sub].az);
+        v8.sleep(3000);
+        dim.wait("DRIVE_CONTROL", "Armed", 150000); // 110s for turning and 30s for stabilizing
+
+        // Now tracking stable, switch voltage to nominal level and wait
+        // for stability.
+        if (obs[sub].biason)
+        {
+            service_feedback.voltageOn();
+            service_feedback.waitForVoltageOn();
+        }
+
+        if (!irq)
+        {
+            dim.log("Taking custom run with time "+obs[sub].time+"s, threshold="+obs[sub].threshold+", biason="+obs[sub].biason);
+
+            var customRun = function()
+            {
+                v8.sleep(500);//wait that configuration is set
+                dim.wait("FTM_CONTROL", "TriggerOn", 15000);
+                dim.send("FAD_CONTROL/SEND_SINGLE_TRIGGER");
+                dim.send("RATE_CONTROL/STOP");
+                dim.send("FTM_CONTROL/STOP_TRIGGER");
+                dim.wait("FTM_CONTROL", "Valid", 3000);
+                dim.send("FTM_CONTROL/ENABLE_TRIGGER", true);
+                dim.send("FTM_CONTROL/SET_TIME_MARKER_DELAY", 123);
+                dim.send("FTM_CONTROL/SET_THRESHOLD", -1, obs[sub].threshold);
+                v8.sleep(500);//wait that configuration is set
+                dim.send("FTM_CONTROL/START_TRIGGER");
+                dim.wait("FTM_CONTROL", "TriggerOn", 15000);
+            }
+
+            takeRun(customRun, -1, obs[sub].time);
+        }
+        dim.log("Task finished [CUSTOM].");
+        dim.log("");
+        break; // case "CUSTOM"
+
     case "DATA":
 
