Ejemplo n.º 1
0
def main(actor, queues):
    """Main loop for SOP selw thread."""

    threadName = 'slew'
    timeout = myGlobals.actorState.timeout

    while True:
        try:
            msg = queues[sopActor.SLEW].get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform('text=\"Exiting thread {0}\"'.format(
                        threading.current_thread().name))

                return

            elif msg.type == Msg.GOTO_POSITION:
                cmd, cmdState, actorState = master.preprocess_msg(msg)
                goto_position(cmd, cmdState, actorState)

            elif msg.type == Msg.DO_APOGEE_DOME_FLAT:
                cmd, cmdState, actorState = master.preprocess_msg(msg)
                name = 'apogeeDomeFlat'
                finishMsg = "Dome flat done."
                # 50 seconds is the read time for this exposure.
                multiCmd = MultiCommand(cmd, actorState.timeout + 50, name)
                # the dome flat command sends a fail msg if it fails.
                if apogee_dome_flat(cmd, cmdState, actorState, multiCmd):
                    master.finish_command(cmd, cmdState, actorState, finishMsg)

            elif msg.type == Msg.GOTO_GANG_CHANGE:
                cmd, cmdState, actorState = master.preprocess_msg(msg)
                goto_gang_change(cmd, cmdState, actorState)

            else:
                raise ValueError('Unknown message type {0}'.format(msg.type))

        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)

        except Exception, ee:
            sopActor.handle_bad_exception(actor, ee, threadName, msg)
Ejemplo n.º 2
0
def lamp_main(actor, queue, lampName):
    """Main loop for lamps thread"""

    actorState = myGlobals.actorState
    timeout = actorState.timeout
    threadName = lampName
    lampHandler = LampHandler(actorState, queue, lampName)

    while True:
        try:
            msg = queue.get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform('text="Exiting thread %s"' %
                                   (threading.current_thread().name))

                return
            elif msg.type == Msg.LAMP_ON:
                action = "on" if msg.on else "off"
                noWait = hasattr(msg, 'noWait')
                delay = getattr(msg, "delay", None)
                lampHandler.do_lamp(msg.cmd,
                                    action,
                                    msg.replyQueue,
                                    delay=delay,
                                    noWait=noWait)

            elif msg.type == Msg.WAIT_UNTIL:
                # used to delay while the lamps warm up
                lampHandler.wait_until(msg.cmd, msg.endTime, msg.replyQueue)

            elif msg.type == Msg.STATUS:
                if lampName not in ignore_lamps:
                    msg.cmd.inform('text="%s thread"' % threadName)
                    msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)

            else:
                raise ValueError, ("Unknown message type %s" % msg.type)
        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception, e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)
Ejemplo n.º 3
0
def main(actor, queues):
    """Main loop for gcamera ICC thread"""

    threadName = "gcamera"
    actorState = sopActor.myGlobals.actorState
    timeout = actorState.timeout

    while True:
        try:
            msg = queues[sopActor.GCAMERA].get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform('text="Exiting thread %s"' %
                                   (threading.current_thread().name))

                return

            elif msg.type == Msg.EXPOSE:
                msg.cmd.respond('text="starting gcamera exposure"')

                timeLim = msg.expTime + 180.0  # seconds
                cmdVar = actorState.actor.cmdr.call(
                    actor="gcamera",
                    forUserCmd=msg.cmd,
                    cmdStr=("%s time=%g cartridge=%d" %
                            (msg.expType, msg.expTime, msg.cartridge)),
                    keyVars=[],
                    timeLim=timeLim)

                msg.replyQueue.put(Msg.EXPOSURE_FINISHED,
                                   cmd=msg.cmd,
                                   success=not cmdVar.didFail)

            elif msg.type == Msg.STATUS:
                msg.cmd.inform('text="%s thread"' % threadName)
                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)
            else:
                raise ValueError, ("Unknown message type %s" % msg.type)
        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception, e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)
Ejemplo n.º 4
0
def main(actor, queues):
    """Main loop for TCC thread"""

    threadName = "tcc"
    actorState = myGlobals.actorState
    timeout = actorState.timeout
    slewHandler = SlewHandler(actorState, queues[sopActor.TCC])

    while True:
        try:
            msg = queues[sopActor.TCC].get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform("text=\"Exiting thread %s\"" %
                                   (threading.current_thread().name))

                return

            elif msg.type == Msg.AXIS_INIT:
                axis_init(msg.cmd, actorState, msg.replyQueue)

            elif msg.type == Msg.AXIS_STOP:
                axis_stop(msg.cmd, actorState, msg.replyQueue)

            elif msg.type == Msg.SLEW:
                slewHandler.reset()
                slewHandler.parse_args(msg)
                slewHandler.slew(msg.cmd, msg.replyQueue)

            elif msg.type == Msg.STATUS:
                msg.cmd.inform('text="%s thread"' % threadName)
                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)
            else:
                msg.cmd.warn("Unknown message type %s" % msg.type)
        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception, e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)
Ejemplo n.º 5
0
def main(actor, queues):
    """Main loop for flat field screen thread"""

    threadName = "ffs"
    actorState = sopActor.myGlobals.actorState
    timeout = actorState.timeout

    while True:
        try:
            msg = queues[sopActor.FFS].get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform("text=\"Exiting thread %s\"" %
                                   (threading.current_thread().name))

                return
            elif msg.type == Msg.FFS_MOVE:
                cmd = msg.cmd

                ffsStatus = actorState.models["mcp"].keyVarDict["ffsStatus"]

                open, closed = 0, 0
                giveUp = False
                for s in ffsStatus:
                    if s == None:
                        cmd.warn(
                            'text="Failed to get state of flat field screen from MCP"'
                        )
                        giveUp = True
                        break

                    open += int(s[0])
                    closed += int(s[1])

                if giveUp:
                    msg.replyQueue.put(Msg.FFS_COMPLETE,
                                       cmd=cmd,
                                       success=False)
                    continue

                action = None  # what we need to do
                if closed == 8:  # flat field screens are all closed
                    if msg.open:
                        action = "open"
                    else:
                        pass  # nothing to do
                elif open == 8:  # flat field screens are all open
                    if msg.open:
                        pass  # nothing to do
                    else:
                        action = "close"
                else:
                    cmd.warn("text=%s" % qstr(
                        "Flat field screens are neither open nor closed (%d v. %d)"
                        % (open, closed)))
                    msg.replyQueue.put(Msg.FFS_COMPLETE,
                                       cmd=cmd,
                                       success=False)

                    continue

                if action:
                    ffsStatusKey = actorState.models["mcp"].keyVarDict[
                        "ffsStatus"]

                    timeLim = 120.0  # seconds
                    cmdVar = actorState.actor.cmdr.call(actor="mcp",
                                                        forUserCmd=cmd,
                                                        cmdStr=("ffs.%s" %
                                                                action),
                                                        keyVars=[ffsStatusKey],
                                                        timeLim=timeLim)
                    if cmdVar.didFail:
                        cmd.warn("text=\"Failed to %s flat field screen\"" %
                                 action)

                        msg.replyQueue.put(Msg.FFS_COMPLETE,
                                           cmd=cmd,
                                           success=False)

                        continue

                msg.replyQueue.put(Msg.FFS_COMPLETE, cmd=cmd, success=True)

            elif msg.type == Msg.STATUS:
                msg.cmd.inform('text="%s thread"' % threadName)
                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)
            else:
                msg.cmd.warn("Unknown message type %s" % msg.type)
        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception, e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)
Ejemplo n.º 6
0
def script_main(actor, queues):
    """Main loop for APOGEE scripting thread"""

    threadName = "apogeeScript"
    actorState = myGlobals.actorState
    timeout = actorState.timeout
    apogeeFlatCB = ApogeeCB()

    script = None

    # Set up readout callback object:

    while True:
        try:
            msg = actorState.queues[sopActor.APOGEE_SCRIPT].get(
                timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform("text=\"Exiting thread %s\"" %
                                   (threading.current_thread().name))
                apogeeFlatCB.shutdown()
                return

            elif msg.type == Msg.NEW_SCRIPT:
                if msg.script:
                    msg.cmd.warn(
                        'text="%s thread is already running a script: %s"' %
                        (threadName, script.name))
                    msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=False)
                msg.script = msg.script
                msg.script.genStartKeys()
                actorState.queues[sopActor.APOGEE_SCRIPT].put(
                    Msg.SCRIPT_STEP, msg.cmd)

            elif msg.type == Msg.SCRIPT_STEP:
                pass

            elif msg.type == Msg.STOP_SCRIPT:
                if not msg.script:
                    msg.cmd.warn(
                        'text="%s thread is not running a script, so cannot stop it."'
                        % (threadName))
                    msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=False)

            elif msg.type == Msg.POST_FLAT:
                cmd = msg.cmd
                n = 3

                actorState.queues[sopActor.APOGEE].put(
                    Msg.EXPOSE,
                    cmd,
                    replyQueue=msg.replyQueue,
                    expTime=50,
                    expType='DomeFlat')
                apogeeFlatCB.waitForNthRead(cmd, n, msg.replyQueue)

            elif msg.type == Msg.APOGEE_PARK_DARKS:
                cmd = msg.cmd
                n = 2
                # expTime = 100.0

                if True:
                    cmd.warn('text="SKIPPING darks"')
                    success = True
                else:
                    success = True

                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=success)

            elif msg.type == Msg.EXPOSURE_FINISHED:
                msg.replyQueue.put(Msg.EXPOSURE_FINISHED,
                                   cmd=msg.cmd,
                                   success=msg.success)

            elif msg.type == Msg.STATUS:
                msg.cmd.inform('text="%s thread"' % threadName)
                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)
            else:
                raise ValueError, ("Unknown message type %s" % msg.type)
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception, e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)
Ejemplo n.º 7
0
def main(actor, queues):
    """Main loop for APOGEE ICC thread"""
    global EXP_COUNTER
    threadName = "apogee"
    actorState = myGlobals.actorState
    timeout = actorState.timeout

    # Set up readout callback object:

    while True:
        try:
            msg = actorState.queues[sopActor.APOGEE].get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform("text=\"Exiting thread %s\"" %
                                   (threading.current_thread().name))
                return

            elif msg.type == Msg.DITHER:
                cmdVar = do_dither(msg.cmd, actorState, msg.dither)
                checkFailure(
                    msg.cmd, msg.replyQueue, cmdVar,
                    "Failed to move APOGEE dither to %s position." %
                    (msg.dither))

            elif msg.type == Msg.APOGEE_SHUTTER:
                position = "open" if msg.open else "close"
                cmdVar = do_shutter(msg.cmd, actorState, position)
                checkFailure(
                    msg.cmd, msg.replyQueue, cmdVar,
                    "Failed to %s APOGEE internal shutter." % (position))

            elif msg.type == Msg.TWODARKS:
                dither = None
                expType = "Dark"
                comment = getattr(msg, 'comment', '')
                nreads = 10
                expTime = None
                success1 = do_expose(msg.cmd, actorState, expTime, dither,
                                     expType, comment, nreads)
                time.sleep(1)
                success2 = do_expose(msg.cmd, actorState, expTime, dither,
                                     expType, comment, nreads)
                success = success1 and success2
                msg.replyQueue.put(msg.EXPOSURE_FINISHED,
                                   cmd=msg.cmd,
                                   success=success)

            elif msg.type == Msg.EXPOSE:
                dither = getattr(msg, 'dither', None)
                expType = getattr(msg, 'expType', 'dark')
                comment = getattr(msg, 'comment', '')
                nreads = getattr(msg, 'nreads', None)
                expTime = getattr(msg, "expTime", None)
                EXP_COUNTER += 1
                msg.cmd.warn(
                    "APOGEE Expose nreads=%i expType=%s expTime=%s expCounter=%i"
                    % (nreads, expType, str(expTime), EXP_COUNTER))
                success = do_expose(msg.cmd, actorState, expTime, dither,
                                    expType, comment, nreads)
                msg.replyQueue.put(Msg.EXPOSURE_FINISHED,
                                   cmd=msg.cmd,
                                   success=success)

            elif msg.type == Msg.APOGEE_DITHER_SET:
                dithers = getattr(msg, 'dithers', 'AB')
                expType = getattr(msg, 'expType', 'object')
                comment = getattr(msg, 'comment', '')
                success = do_apogee_dither_set(msg.cmd, actorState,
                                               msg.expTime, dithers, expType,
                                               comment)

                msg.replyQueue.put(Msg.EXPOSURE_FINISHED,
                                   cmd=msg.cmd,
                                   success=success)

            elif msg.type == Msg.STATUS:
                msg.cmd.inform('text="%s thread"' % threadName)
                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)
            else:
                raise ValueError, ("Unknown message type %s" % msg.type)


#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception as e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)
Ejemplo n.º 8
0
def main(actor, queues):
    """Main loop for boss ICC thread"""

    threadName = "boss"
    actorState = sopActor.myGlobals.actorState
    timeout = actorState.timeout

    while True:
        try:
            msg = queues[sopActor.BOSS].get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform("text=\"Exiting thread %s\"" %
                                   (threading.current_thread().name))

                return

            elif msg.type == Msg.EXPOSE:
                expType = getattr(msg, 'expType', '')
                if msg.readout and msg.expTime <= 0:
                    cmdTxt = "exposure readout"
                else:
                    cmdTxt = "%s%s exposure" % (((
                        ("%gs " % msg.expTime) if msg.expTime > 0 else ""),
                                                 expType))
                msg.cmd.respond('text="starting %s"' % cmdTxt)
                expTimeCmd, readoutCmd = getExpTimeCmd(msg.expTime, expType,
                                                       msg.cmd, msg.readout)

                timeLim = msg.expTime + 180.0  # seconds
                timeLim += 100
                cmdVar = actorState.actor.cmdr.call(
                    actor="boss",
                    forUserCmd=msg.cmd,
                    cmdStr=("exposure %s %s %s" %
                            (expType, expTimeCmd, readoutCmd)),
                    keyVars=[],
                    timeLim=timeLim)
                if cmdVar.didFail:
                    msg.cmd.error('text="BOSS failed on %s"' % cmdTxt)
                msg.replyQueue.put(Msg.EXPOSURE_FINISHED,
                                   cmd=msg.cmd,
                                   success=not cmdVar.didFail)

            elif msg.type == Msg.SINGLE_HARTMANN:
                single_hartmann(msg.cmd, actorState, msg.replyQueue,
                                msg.expTime, msg.mask)

            elif msg.type == Msg.HARTMANN:
                args = getattr(msg, 'args', None)
                hartmann(msg.cmd, actorState, msg.replyQueue, args)

            elif msg.type == Msg.STATUS:
                msg.cmd.inform('text="%s thread"' % threadName)
                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)
            else:
                raise ValueError, ("Unknown message type %s" % msg.type)
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception, e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)
Ejemplo n.º 9
0
def main(actor, queues):
    """Main loop for general scripting thread.

    Can only run one script at a time, but only because the issues have not
    been thought through."""

    threadName = "script"
    myQueueName = sopActor.SCRIPT
    runningScript = None

    while True:
        actorState = myGlobals.actorState
        timeout = actorState.timeout

        try:
            msg = actorState.queues[myQueueName].get(timeout=timeout)

            if msg.type == Msg.EXIT:
                if msg.cmd:
                    msg.cmd.inform("text=\"Exiting thread %s\"" %
                                   (threading.current_thread().name))
                return

            elif msg.type == Msg.NEW_SCRIPT:
                if runningScript:
                    msg.cmd.fail(
                        'text="%s thread is already running a script: %s"' %
                        (threadName, runningScript.name))
                    continue

                scriptName = msg.scriptName
                runningScript = script.Script(msg.cmd, scriptName)
                actorState.queues[myQueueName].put(Msg.SCRIPT_STEP, msg.cmd)

            elif msg.type == Msg.SCRIPT_STEP:
                if not runningScript:
                    msg.cmd.fail(
                        'text="%s thread is not running a script, so cannot step it."'
                        % (threadName))
                    continue

                scriptLine = runningScript.fetchNextStep()
                if not scriptLine:
                    msg.cmd.finish('text="script %s appears to be done"' %
                                   (runningScript.name))
                    runningScript = None
                    continue

                actorName, cmdStr, maxTime = scriptLine
                if maxTime == 0.0:
                    maxTime = 30.0

                msg.cmd.warn(
                    'text="firing off script line: %s %s (maxTime=%0.1f)"' %
                    (actorName, cmdStr, maxTime))
                cmdVar = actorState.actor.cmdr.call(actor=actorName,
                                                    forUserCmd=msg.cmd,
                                                    cmdStr=cmdStr,
                                                    timeLim=maxTime + 15)
                if cmdVar.didFail:
                    msg.cmd.fail('text="Script %s failed to run %s %s"' %
                                 (runningScript.name, actorName, cmdStr))
                    runningScript = None
                else:
                    actorState.queues[myQueueName].put(Msg.SCRIPT_STEP,
                                                       msg.cmd)

            elif msg.type == Msg.STOP_SCRIPT:
                if not runningScript:
                    msg.cmd.fail(
                        'text="%s thread is not running a script, so cannot stop it."'
                        % (threadName))
                    continue

                # Just signal that we are done.
                runningScript.stop()

            elif msg.type == Msg.STATUS:
                msg.cmd.inform('text="%s thread"' % threadName)
                msg.replyQueue.put(Msg.REPLY, cmd=msg.cmd, success=True)
            else:
                raise ValueError, ("Unknown message type %s" % msg.type)

        except Queue.Empty:
            actor.bcast.diag('text="%s alive"' % threadName)
        except Exception, e:
            sopActor.handle_bad_exception(actor, e, threadName, msg)