Example #1
0
 def cmd_filter(self, userCmd):
     """! Implement the filter command
     @param[in]  userCmd  a twistedActor command with a parsedCommand attribute
     """
     subCmd = userCmd.parsedCommand.subCommand
     userCmd = expandUserCmd(userCmd)
     if subCmd.cmdName == "initialize":
         if not self.filterWheelDev.isConnected:
             self.filterWheelDev.connect(userCmd)
         else:
             self.filterWheelDev.init(userCmd)
     elif subCmd.cmdName == "connect":
         self.filterWheelDev.connect(userCmd)
     elif subCmd.cmdName == "disconnect":
         self.filterWheelDev.disconnect(userCmd)
     elif subCmd.cmdName == "status":
         self.filterWheelDev.startCmd("status", userCmd=userCmd)
     elif subCmd.cmdName == "home":
         self.filterWheelDev.startCmd("home", userCmd=userCmd)
     elif subCmd.cmdName == "talk":
         talkTxt = subCmd.parsedPositionalArgs[0]
         self.filterWheelDev.startCmd(talkTxt, userCmd=userCmd)
     else:
         userCmd.setState(userCmd.Failed, "unhandled sub command: %s. bug"%(subCmd.cmdName,))
     return True
Example #2
0
 def getStatus(self, userCmd=None):
     """Return current telescope status. Continuously poll.
     """
     log.info("%s.getStatus(userCmd=%s)" % (self, userCmd)) # logging this will flood the log
     # print("%s.getStatus(userCmd=%s)" % (self, userCmd))
     userCmd = expandUserCmd(userCmd)
     if not self.conn.isConnected:
         userCmd.setState(userCmd.Failed, "Not Connected to M2")
         return userCmd
     self._statusTimer.cancel() # incase a status is pending
     userCmd = expandUserCmd(userCmd)
     # userCmd.addCallback(self._statusCallback)
     # gather list of status elements to get
     statusCmd = self.queueDevCmd("status", userCmd)
     LinkCommands(userCmd, [statusCmd])
     return userCmd
Example #3
0
    def focus(self, focusValue, offset=False, userCmd=None):
        """Command an offset or absolute focus move

        @param[in] focusValue: float, focus value in microns
        @param[in] offset, if true this is offset, else absolute
        @param[in] userCmd: a twistedActor BaseCommand

        WARNING!!!
        At APO increasing focus corresponds to decreasing M1-M2 dist.
        The mirror controller at LCO convention is the opposite.
        """
        log.info("%s.focus(userCmd=%s, focusValue=%.2f, offset=%s)" % (self, userCmd, focusValue, str(bool(offset))))
        # if this focus value is < 50 microns
        userCmd = expandUserCmd(userCmd)
        if offset:
            deltaFocus = focusValue
        else:
            deltaFocus = self.status.secFocus - focusValue


        if abs(deltaFocus) < MIN_FOCUS_MOVE:
            # should focus be cancelled or just set to done?
            self.writeToUsers("w", "Focus offset below threshold of < %.2f, moving anyways."%MIN_FOCUS_MOVE, userCmd)
            # userCmd.setState(userCmd.Done)
            # return userCmd

        # focusDir = 1 # use M2's natural coordinates
        # focusDir = -1 # use convention at APO
        return self.move(valueList=[focusValue], offset=offset, userCmd=userCmd)
Example #4
0
    def move(self, position, userCmd=None):
        """!Move to a position

        @param[in] postion: a float, position to move to (mm)
        @param[in] userCmd: a twistedActor BaseCommand
        """
        log.info("%s.move(postion=%.6f, userCmd=%s)" % (self, position, userCmd))
        userCmd=expandUserCmd(userCmd)
        if self.isMoving:
            userCmd.setState(userCmd.Failed, "Cannot move, device is busy moving")
            return userCmd
        # verify position is in range
        minPos, maxPos = self.status.moveRange
        if not minPos<=position<=maxPos:
            userCmd.setState(userCmd.Failed, "Move %.6f not in range [%.4f, %.4f]"%(position, minPos, maxPos))
            return userCmd
        self.iter = 1
        self.targetPos = position
        self.moveUserCmd = userCmd
        print("moving threadring to: ", self.targetPos)
        if not self.moveUserCmd.isActive:
            self.moveUserCmd.setState(self.moveUserCmd.Running)
        self.writeToUsers("i", "DesThreadRingPos=%.4f"%self.targetPos)
        moveDevCmd = self.queueDevCmd(self.getMoveCmdStr(), self.moveUserCmd)
        moveDevCmd.addCallback(self._moveCallback)
        return userCmd
Example #5
0
    def target(self, ra, dec, doHA, userCmd=None):
        """Set coordinates for a slew.

        @param[in] ra: right ascension decimal degrees
        @param[in] dec: declination decimal degrees
        @param[in] doHA: if True, use degrees in hour angle rather than ra.
        @param[in] userCmd: a twistedActor BaseCommand.
        """
        log.info("%s.slew(userCmd=%s, ra=%.2f, dec=%.2f)" % (self, userCmd, ra, dec))
        userCmd = expandUserCmd(userCmd)
        if not self.conn.isConnected:
            userCmd.setState(userCmd.Failed, "Not Connected to TCS")
            return userCmd
        if doHA:
            enterRa = "HAD %.8f"%ra
        else:
            enterRa = "RAD %.8f"%ra
        enterDec = "DECD %.8f"%dec
        enterEpoch = "MP %.2f"%2000 # LCO: HACK should coords always be 2000?
        devCmdList = [DevCmd(cmdStr=cmdStr) for cmdStr in [enterRa, enterDec, enterEpoch]]#, cmdSlew]]
        # set userCmd done only when each device command finishes
        # AND the pending slew is also done.
        # when the last dev cmd is done (the slew), set axis cmd statue to slewing

        LinkCommands(userCmd, devCmdList) #LCO: HACK don't wait for a slew to finish + [self.waitSlewCmd])
        for devCmd in devCmdList:
            self.queueDevCmd(devCmd)

        statusStr = self.status.getStatusStr()
        if statusStr:
            self.writeToUsers("i", statusStr, userCmd)
        return userCmd
Example #6
0
    def getStatus(self, userCmd=None, timeLim=None, linkState=True):
        """!Get status of the device.  If the device is
        busy (eg moving), send the cached status
        note that during moves the thread_ring_axis actual_position gets
        periodically output and thus updated in the status
        """

        # note measScaleDevice could be read even if
        # scaling ring is moving.  do this at somepoint?
        userCmd = expandUserCmd(userCmd)
        if timeLim is None:
            timeLim = 2
        if self.isMoving:
            self.writeToUsers("i", "text=showing cached status", userCmd)
            self.writeStatusToUsers(userCmd)
            userCmd.setState(userCmd.Done)
        else:
            # get a completely fresh status from the device
            statusDevCmd = self.queueDevCmd("status", userCmd)
            # get encoder values too
            encStatusDevCmd = self.measScaleDev.getStatus()
            statusDevCmd.addCallback(self._statusCallback)
            statusDevCmd.setTimeLimit(timeLim)
            if linkState:
                LinkCommands(userCmd, [statusDevCmd, encStatusDevCmd])
                return userCmd
            else:
                # return the device command to be linked outside
                return statusDevCmd
 def getStatus(self, userCmd=None):
     """!Query the device for status
     @param[in] userCmd  a twistedActor.BaseCommand
     """
     userCmd = expandUserCmd(userCmd)
     self.queueDevCmd("status", userCmd)
     userCmd.addCallback(self._statusCallback)
     return userCmd
Example #8
0
 def getStatus(self, userCmd=None):
     """!Query the device for status
     @param[in] userCmd  a twistedActor.BaseCommand
     """
     userCmd = expandUserCmd(userCmd)
     self.queueDevCmd("status", userCmd)
     userCmd.addCallback(self._statusCallback)
     return userCmd
Example #9
0
 def setZero(self, userCmd=None, timeLim=1):
     """!Set the Mitutoyo EV counter into the counting state,
     this is required after a power cycle
     """
     userCmd = expandUserCmd(userCmd)
     zeroDevCmd = self.queueDevCmd(ZERO_SET, userCmd)
     zeroDevCmd.setTimeLimit(timeLim)
     LinkCommands(userCmd, [zeroDevCmd])
     return userCmd
Example #10
0
 def close(self, userCmd=None):
     """!Close the shutter
     @param[in] userCmd  a twistedActor.BaseCommand
     """
     userCmd = expandUserCmd(userCmd)
     self.queueDevCmd(userCmd, "close")
     # when this command finishes set state to closed
     userCmd.addCallback(self._closeCallback)
     return userCmd
Example #11
0
 def holdOpen(self, expTime):
     userCmd = expandUserCmd(None)
     def _holdOpen(userCmd):
         Timer(float(expTime), userCmd.setState, userCmd.Done)
         self.status.shutterTimer.startTimer()
         self.status.lastExpTime = -1
         self.status.lastDesExpTime = expTime
     self.cmdQueue.addCmd(userCmd, _holdOpen)
     return userCmd
Example #12
0
    def init(self, userCmd=None, timeLim=3, getStatus=True):
        """Called automatically on startup after the connection is established.
        Only thing to do is query for status or connect if not connected

        getStatus ignored?
        """
        log.info("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" % (self, userCmd, timeLim, getStatus))
        userCmd = expandUserCmd(userCmd)
        self.getStatus(userCmd) # status links the userCmd
        return userCmd
Example #13
0
    def open(self, userCmd=None):
        """!Open the shutter

        @param[in] position  an integer
        @param[in] userCmd  a twistedActor.BaseCommand
        """
        userCmd = expandUserCmd(userCmd)
        self.queueDevCmd(userCmd, "open")
        userCmd.addCallback(self._openCallback)
        return userCmd
    def init(self, userCmd=None, timeLim=10, getStatus=True):
        """!Initialize the device and cancel all pending commands

        @param[in] userCmd  user command that tracks this command, if any
        @param[in] timeLim  maximum time before command expires, in sec; None for no limit
        @param[in] getStatus  IGNORED (status is automatically output sometime after stop)
        @return userCmd (a new one if the provided userCmd is None)
        """
        userCmd = expandUserCmd(userCmd)
        self.startCmd(cmdStr="init", userCmd=userCmd, timeLim=timeLim)
        return userCmd
 def cmd_status(self, userCmd=None, setDone=True):
     """! Implement the status command
     @param[in]  userCmd  a twistedActor command with a parsedCommand attribute
     """
     log.info("%s.cmd_status(userCmd=%s)" % (self, str(userCmd)))
     userCmd = expandUserCmd(userCmd)
     self.getStatus()
     self.writeToUsers("i", self.status.statusStr, cmd=userCmd)
     if setDone:
         userCmd.setState(userCmd.Done)
     return True
Example #16
0
    def init(self, userCmd=None, timeLim=10, getStatus=True):
        """!Initialize the device and cancel all pending commands

        @param[in] userCmd  user command that tracks this command, if any
        @param[in] timeLim  maximum time before command expires, in sec; None for no limit
        @param[in] getStatus  IGNORED (status is automatically output sometime after stop)
        @return userCmd (a new one if the provided userCmd is None)
        """
        userCmd = expandUserCmd(userCmd)
        self.startCmd(cmdStr="init", userCmd=userCmd, timeLim=timeLim)
        return userCmd
Example #17
0
 def init(self, userCmd=None, timeLim=None, getStatus=False):
     """Called automatically on startup after the connection is established.
     Only thing to do is query for status or connect if not connected
     """
     log.info("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" % (self, userCmd, timeLim, getStatus))
     userCmd = expandUserCmd(userCmd)
     # stop, set speed, then status?
     stopCmd = self.queueDevCmd("stop", userCmd)
     speedCmd = self.queueDevCmd("speed %.4f"%self.nomSpeed, userCmd)
     statusCmd = self.queueDevCmd("status", userCmd)
     LinkCommands(userCmd, [stopCmd, speedCmd, statusCmd])
     return userCmd
Example #18
0
 def setCountState(self, userCmd=None, timeLim=1):
     """!Set the Mitutoyo EV counter into the counting state,
     this is required after a power cycle
     """
     userCmd = expandUserCmd(userCmd)
     countDevCmd = self.queueDevCmd(COUNTING_STATE, userCmd)
     currValDevCmd = self.queueDevCmd(DISPLAY_CURR, userCmd)
     currValDevCmd.addCallback(self._statusCallback)
     countDevCmd.setTimeLimit(timeLim)
     currValDevCmd.setTimeLimit(timeLim)
     LinkCommands(userCmd, [countDevCmd, currValDevCmd])
     return userCmd
Example #19
0
 def init(self, userCmd=None, timeLim=None, getStatus=None):
     """!Initialize the shutter
     @param[in] userCmd  a twistedActor.BaseCommand
     @param[in] timeLim  time limit for the init
     @param[in] getStatus required argument for init
     """
     userCmd = expandUserCmd(userCmd)
     if not hasattr(userCmd, "cmdVerb"):
         userCmd.cmdVerb = "init"
     if timeLim is not None:
         userCmd.setTimeLimit(timeLim)
     self.queueDevCmd("init", userCmd)
     return userCmd
Example #20
0
 def init(self, userCmd=None, timeLim=None, getStatus=True):
     """Called automatically on startup after the connection is established.
     Only thing to do is query for status or connect if not connected
     """
     log.info("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" % (self, userCmd, timeLim, getStatus))
     # print("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" % (self, userCmd, timeLim, getStatus))
     userCmd = expandUserCmd(userCmd)
     # if not self.isConnected:
     #     return self.connect(userCmd=userCmd)
     # get the speed on startup
     # ignore getStatus flag, just do it always
     self.queueDevCmd("speed")
     return self.getStatus(userCmd=userCmd)
Example #21
0
 def stop(self, userCmd=None):
     userCmd = expandUserCmd(userCmd)
     if not self.waitMoveCmd.isDone:
         self.waitMoveCmd.setState(self.waitMoveCmd.Cancelled, "Stop commanded")
     #print("sec stop commanded")
     stopCmd = self.queueDevCmd("stop", userCmd)
     galilOffCmd = self.queueDevCmd("galil off", userCmd)
     status = self.queueDevCmd("status", userCmd)
     status2 = self.queueDevCmd("status", userCmd)
     # first status gets the error state
     # second status clears it
     LinkCommands(userCmd, [stopCmd, status, galilOffCmd, status2])
     return userCmd
 def init(self, userCmd=None, timeLim=None, getStatus=None):
     """!Initialize the shutter
     @param[in] userCmd  a twistedActor.BaseCommand
     @param[in] timeLim  time limit for the init
     @param[in] getStatus required argument for init
     """
     userCmd = expandUserCmd(userCmd)
     if not hasattr(userCmd, "cmdVerb"):
         userCmd.cmdVerb = "init"
     if timeLim is not None:
         userCmd.setTimeLimit(timeLim)
     self.queueDevCmd("init", userCmd)
     return userCmd
Example #23
0
 def getStatus(self, userCmd=None):
     """Return current telescope status. Continuously poll.
     """
     log.info("%s.getStatus(userCmd=%s)" % (self, userCmd)) # logging this will flood the log
     userCmd = expandUserCmd(userCmd)
     if not self.conn.isConnected:
         userCmd.setState(userCmd.Failed, "Not Connected to TCS")
         return userCmd
     self._statusTimer.cancel() # incase a status is pending
     userCmd = expandUserCmd(userCmd)
     userCmd.addCallback(self._statusCallback)
     # record the present RA, DEC (for determining when offsets are done)
     # self.status.previousRA = self.status.statusFieldDict["ra"].value
     # self.status.previousDec = self.status.statusFieldDict["dec"].value
     if self.status.statusFieldDict["mpos"].value is None:
         self.status.previousRA, self.status.previousDec = None, None
     else:
         self.status.previousRA = self.status.statusFieldDict["mpos"].value[0]
         self.status.previousDec = self.status.statusFieldDict["mpos"].value[1]
     # gather list of status elements to get
     devCmdList = [DevCmd(cmdStr=cmdVerb) for cmdVerb in self.status.statusFieldDict.keys()]
     LinkCommands(userCmd, devCmdList)
     for devCmd in devCmdList:
         self.queueDevCmd(devCmd)
     if not self.status.isClamped or self.rotDelay:
         # rotator is moving, get status frequently
         pollTime = PollTimeRot
     elif self.isSlewing:
         # slewing, get status kinda frequently
         pollTime = PollTimeSlew
     elif self.isTracking:
         # tracking, get status less frequently
         pollTime = PollTimeTrack
     else:
         # idle, get status infrequently (as things shouldn't be changing fast)
         pollTime = PollTimeIdle
     self._statusTimer.start(pollTime, self.getStatus)
     return userCmd
 def init(self, userCmd=None, getStatus=True, timeLim=DefaultTimeLim):
     """! Initialize all devices, and get status if wanted
     @param[in]  userCmd  a UserCmd or None
     @param[in]  getStatus if true, query all devices for status
     @param[in]  timeLim
     """
     userCmd = expandUserCmd(userCmd)
     log.info("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" %
              (self, userCmd, timeLim, getStatus))
     if getStatus:
         self.cmd_status(userCmd)  # sets done
     else:
         userCmd.setState(userCmd.Done)
     return userCmd
Example #25
0
    def expose(self, expTime, userCmd=None):
        """!Open the shutter for the desired amount of time, then close it, and get
        exposure time

        @param[in] expTime amount of time to open the shutter for (seconds, float)
        @param[in] userCmd  a twistedActor.BaseCommand
        """
        userCmd = expandUserCmd(userCmd)
        openCmd = self.open()
        holdCmd = self.holdOpen(expTime)
        closeCmd = self.close()
        statusCmd = self.status()
        LinkCommands(userCmd, (openCmd, holdCmd, closeCmd, statusCmd))
        return userCmd
Example #26
0
    def init(self, userCmd=None, getStatus=True, timeLim=DefaultTimeLim):
        """! Initialize all devices, and get status if wanted
        @param[in]  userCmd  a UserCmd or None
        @param[in]  getStatus if true, query all devices for status
        @param[in]  timeLim
        """
        userCmd = expandUserCmd(userCmd)
        log.info("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" % (self, userCmd, timeLim, getStatus))
        # initialize camera
        self.setCamera()
        subCmdList = []
        # connect (if not connected) and initialize devices
        filterDevCmd = expandUserCmd(None)
        shutterDevCmd = expandUserCmd(None)
        subCmdList.append(filterDevCmd)
        subCmdList.append(shutterDevCmd)
        if not self.filterWheelDev.isConnected:
            self.filterWheelDev.connect(userCmd=filterDevCmd)
        else:
            self.filterWheelDev.init(userCmd=filterDevCmd)

        if not self.shutterDev.isConnected:
            self.shutterDev.connect(userCmd=shutterDevCmd)
        else:
            self.shutterDev.init(userCmd=shutterDevCmd)
        if getStatus:
            # get status only when the conn/initialization is done
            def getStatus(foo):
                if userCmd.isDone:
                    self.getStatus()
            userCmd.addCallback(getStatus)
        LinkCommands(mainCmd=userCmd, subCmdList=subCmdList)
        if not self.exposeCmd.isDone:
            self.exposeCmd.setState(self.exposeCmd.Failed, "currently running exposure killed via init")
            self.exposeCleanup()
        return userCmd
Example #27
0
 def init(self, userCmd=None, timeLim=None, getStatus=True):
     """Called automatically on startup after the connection is established.
     Only thing to do is query for status or connect if not connected
     """
     log.info("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" % (self, userCmd, timeLim, getStatus))
     # print("%s.init(userCmd=%s, timeLim=%s, getStatus=%s)" % (self, userCmd, timeLim, getStatus))
     userCmd = expandUserCmd(userCmd)
     # if not self.isConnected:
     #     # time lim handled by lco.deviceCmd
     #     return self.connect(userCmd=userCmd)
     if getStatus:
         return self.getStatus(userCmd=userCmd)
     else:
         userCmd.setState(userCmd.Done)
         return userCmd
Example #28
0
    def __init__(self, name, host, port, measScaleDev=None, nomSpeed=NOM_SPEED, callFunc=None):
        """!Construct a ScaleDevice

        Inputs:
        @param[in] name  name of device
        @param[in] host  host address of scaling ring controller
        @param[in] port  port of scaling ring controller
        @param[in] measScaleDev  instance of a MeasScaleDev (access to the mitutoyos for servoing)
        @param[in] nom_speed nominal speed at which to move (this can be modified via the speed command)
        @param[in] callFunc  function to call when state of device changes;
                note that it is NOT called when the connection state changes;
                register a callback with "conn" for that task.
        """
        self.targetPos = None
        # holds a userCommand for "move"
        # set done only when move has reached maxIter
        # or is within tolerance
        self.iter = 0
        self.moveUserCmd = expandUserCmd(None)
        self.moveUserCmd
        self.nomSpeed = nomSpeed
        self.measScaleDev = measScaleDev
        self.status = Status()

        # all commands of equal priority
        # except stop kills a running (or pending move) move
        # priorityDict = {"stop": CommandQueue.Immediate}
        priorityDict = {
            "stop":1,
            "status":1,
            "move":1,
            "speed":1,
        }
        self.devCmdQueue = CommandQueue(
            priorityDict,
            killFunc = self.killFunc,
            )
        # stop will kill a running move
        # else everything queues with equal prioirty
        self.devCmdQueue.addRule(CommandQueue.KillRunning, ["stop"], ["move"])

        TCPDevice.__init__(self,
            name = name,
            host = host,
            port = port,
            callFunc = callFunc,
            cmdInfo = (),
        )
Example #29
0
    def queueDevCmd(self, cmdStr, userCmd=None):
        """Add a device command to the device command queue

        @param[in] cmdStr, string to send to the device.
        """
        log.info("%s.queueDevCmd(cmdStr=%r, cmdQueue: %r"%(self, cmdStr, self.devCmdQueue))
        # print("%s.queueDevCmd(devCmd=%r, devCmdStr=%r, cmdQueue: %r"%(self, devCmd, devCmd.cmdStr, self.devCmdQueue))
        # append a cmdVerb for the command queue (other wise all get the same cmdVerb and cancel eachother)
        # could change the default behavior in CommandQueue?
        userCmd = expandUserCmd(userCmd)
        devCmd = DevCmd(cmdStr)
        devCmd.cmdVerb = cmdStr.split()[0]
        devCmd.userCmd = userCmd
        def queueFunc(devCmd):
            self.startDevCmd(devCmd)
        self.devCmdQueue.addCmd(devCmd, queueFunc)
        return devCmd
Example #30
0
 def getStatus(self, userCmd=None, timeLim=1, linkState=True):
     """!Read all enc positions 1-6 channels, 3 physical gauges.
     """
     # first flush the current status to ensure we don't
     # have stale values
     print("reading migs!")
     userCmd = expandUserCmd(userCmd)
     self.encPos = [None]*6
     statusDevCmd = self.queueDevCmd(READ_ENC, userCmd)
     statusDevCmd.addCallback(self._statusCallback)
     statusDevCmd.setTimeLimit(timeLim)
     if linkState:
         LinkCommands(userCmd, [statusDevCmd])
         return userCmd
     else:
         # return the device command to be linked outside
         return statusDevCmd
Example #31
0
    def move(self, valueList, offset=False, userCmd=None):
        """Command an offset or absolute orientation move

        @param[in] valueList: list of 1 to 5 values specifying pistion(um), tiltx("), tilty("), transx(um), transy(um)
        @param[in] offset, if true this is offset, else absolute
        @param[in] userCmd: a twistedActor BaseCommand

        Note: increasing distance eg pistion means increasing spacing between primary and
        secondary mirrors.
        """
        log.info("%s.move(userCmd=%s, valueList=%s, offset=%s)" % (self, userCmd, str(valueList), str(bool(offset))))
        userCmd = expandUserCmd(userCmd)
        if not self.waitMoveCmd.isDone:
            userCmd.setState(userCmd.Failed, "Mirror currently moving")
            return userCmd
        if not 1<=len(valueList)<=5:
            userCmd.setState(userCmd.Failed, "Must specify 1 to 5 numbers for a move")
            return userCmd
        self.waitMoveCmd = UserCmd()
        self.waitMoveCmd.userCmd = userCmd # for write to users
        self.status.desOrientation = self.status.orientation[:]
        if offset:
            # if offset is specified, offset from current value
            for ii, value in enumerate(valueList):
                self.status.desOrientation[ii] += value
        else:
            # if absolute is wanted, overwrite all those
            # specified
            for ii, value in enumerate(valueList):
                self.status.desOrientation[ii] = value
        cmdType = "offset" if offset else "move"
        strValList = " ".join(["%.2f"%val for val in valueList])
        cmdStr = "%s %s"%(cmdType, strValList)
        moveCmd = self.queueDevCmd(cmdStr, userCmd)
        statusCmd = self.queueDevCmd("status", userCmd)
        # status immediately to see moving state
        # determine total time for move
        # just use focus distance as proxy (ignore)
        galilOverHead = 2 # galil take roughly 2 secs to boot up.
        extraOverHead = 2 #
        self.status._moveTimeTotal = self.getTimeForMove()
        timeout = self.status._moveTimeTotal+galilOverHead+extraOverHead
        userCmd.setTimeLimit(timeout)
        LinkCommands(userCmd, [moveCmd, statusCmd, self.waitMoveCmd])
        return userCmd
Example #32
0
    def stop(self, userCmd=None):
        """Stop any scaling movement, cancelling any currently executing
        command and any commands waiting on queue

        @param[in] userCmd: a twistedActor BaseCommand
        """
        userCmd=expandUserCmd(userCmd)
        # kill any commands pending on the queue
        # nicely kill move command if it's running
        # if not self.currExeDevCmd.userCmd.isDone:
        #     self.currExeDevCmd.userCmd.setState(self.currExeDevCmd.userCmd.Failed, "Killed by stop")
        if self.moveUserCmd.isActive:
            self.moveUserCmd.setState(self.moveUserCmd.Cancelled, "Scaling ring move cancelled by stop command.")
        stopDevCmd = self.queueDevCmd("stop", userCmd)
        statusDevCmd = self.queueDevCmd("status", userCmd)
        statusDevCmd.addCallback(self._statusCallback)
        LinkCommands(userCmd, [stopDevCmd, statusDevCmd])
        return userCmd
Example #33
0
 def speed(self, speedValue, userCmd=None):
     """Set the desired move speed for the thread ring
     @param[in] speedValue: a float, scale value to be converted to steps and sent to motor
     @param[in] userCmd: a twistedActor BaseCommand
     """
     speedValue = float(speedValue)
     userCmd = expandUserCmd(userCmd)
     if self.isMoving:
         userCmd.setState(userCmd.Failed, "Cannot set speed, device is busy moving")
         return userCmd
     elif float(speedValue) > self.status.maxSpeed:
         userCmd.setState(userCmd.Failed, "Max Speed Exceeded: %.4f > %.4f"%(speedValue, self.status.maxSpeed))
         return userCmd
     else:
         speedDevCmd = self.queueDevCmd("speed %.6f"%speedValue, userCmd)
         statusDevCmd = self.queueDevCmd("status", userCmd)
         statusDevCmd.addCallback(self._statusCallback)
         LinkCommands(userCmd, [speedDevCmd, statusDevCmd])
     return userCmd
Example #34
0
    def slewOffset(self, ra, dec, userCmd=None):
        """Offset telescope in right ascension and declination.

        @param[in] ra: right ascension in decimal degrees
        @param[in] dec: declination in decimal degrees
        @param[in] userCmd a twistedActor BaseCommand

        @todo, consolidate similar code with self.target?
        """
        log.info("%s.slewOffset(userCmd=%s, ra=%.6f, dec=%.6f)" % (self, userCmd, ra, dec))
        userCmd = expandUserCmd(userCmd)
        # zero the delta computation so the offset isn't marked done immediately
        self.status.previousDec = ForceSlew
        self.status.previousRA = ForceSlew
        if not self.conn.isConnected:
            userCmd.setState(userCmd.Failed, "Not Connected to TCS")
            return userCmd
        if not self.waitOffsetCmd.isDone:
            self.waitOffsetCmd.setState(self.waitOffsetCmd.Cancelled, "Superseded by new offset")
        waitOffsetCmd = UserCmd()
        self.waitOffsetCmd = waitOffsetCmd
        enterRa = "OFRA %.8f"%(ra*ArcSecPerDeg)
        enterDec = "OFDC %.8f"%(dec*ArcSecPerDeg) #lcohack
        devCmdList = [DevCmd(cmdStr=cmdStr) for cmdStr in [enterRa, enterDec, CMDOFF]]
        # set userCmd done only when each device command finishes
        # AND the pending slew is also done.
        # set an offset done after 6 seconds no matter what
        def setWaitOffsetCmdDone(aWaitingOffsetCmd):
            print("wait offset command state", aWaitingOffsetCmd.state)
            if not aWaitingOffsetCmd.isDone:
                print("Wait offset timed out!!!!")
                self.writeToUsers("w", "Text=OFFSET SET DONE ON TIMER.")
                aWaitingOffsetCmd.setState(aWaitingOffsetCmd.Done, "offset set done on a timer")
        self.waitOffsetTimer.start(8, setWaitOffsetCmdDone, waitOffsetCmd)
        # self.waitOffsetCmd.setTimeLimit(6)
        LinkCommands(userCmd, devCmdList + [self.waitOffsetCmd])
        for devCmd in devCmdList:
            self.queueDevCmd(devCmd)
        statusStr = self.status.getStatusStr()
        if statusStr:
            self.writeToUsers("i", statusStr, userCmd)
        return userCmd
Example #35
0
 def getStatus(self, userCmd=None, doCamera=True, doFilter=True, doShutter=True):
     """! A generic status command, arguments specify which statuses are wanted
     @param[in] userCmd a twistedActor UserCmd or none
     @param[in] doCamera: bool, if true get camera status
     @param[in] doFilter: bool, if true get filter wheel status
     @param[in] doShutter: bool, if true get shutter status
     """
     assert True in [doFilter, doShutter, doCamera]
     userCmd = expandUserCmd(userCmd)
     if doCamera:
         statusStr = self.getCameraStatus()
         self.writeToUsers("i", statusStr, cmd=userCmd)
     subCmdList = []
     if doShutter:
         subCmdList.append(self.shutterDev.getStatus())
     if doFilter:
         subCmdList.append(self.filterWheelDev.startCmd("status"))
     if subCmdList:
         LinkCommands(userCmd, subCmdList)
     else:
         userCmd.setState(userCmd.Done)
     return userCmd