Пример #1
0
    def open(self):

        self._tty = serial.Serial(self["device"],
                                  baudrate=9600,
                                  bytesize=serial.EIGHTBITS,
                                  parity=serial.PARITY_NONE,
                                  stopbits=serial.STOPBITS_ONE,
                                  timeout=self["timeout"],
                                  xonxoff=False,
                                  rtscts=False)

        try:
            self._tty.open()

            self._checkMeade()

            #if self["auto_align"]:
            #    self.autoAlign ()

            # manualy initialize scope
            if self["skip_init"]:
                self.log.info("Skipping init as requested.")
            else:
                self._initTelescope()

            return True

        except (serial.SerialException, IOError), e:
            raise MeadeException("Error while opening %s." % self["device"])
Пример #2
0
    def _waitSlew(self, start_time, target, local=False):

        self.slewBegin(target)

        while True:

            # check slew abort event
            if self._abort.isSet():
                self._slewing = False
                return TelescopeStatus.ABORTED

            # check timeout
            if time.time() >= (start_time + self["max_slew_time"]):
                self.abortSlew()
                self._slewing = False
                raise MeadeException("Slew aborted. Max slew time reached.")

            if local:
                position = self.getPositionAltAz()
            else:
                position = self.getPositionRaDec()

            if target.within(position, eps=Coord.fromAS(60)):
                time.sleep(self["stabilization_time"])
                self._slewing = False
                return TelescopeStatus.OK

            time.sleep(self["slew_idle_time"])

        return TelescoopeStatus.ERROR
Пример #3
0
    def setDate(self, date):

        if type(date) == FloatType:
            date = dt.date.fromtimestamp(date)

        self._write(":SC%s#" % date.strftime("%m/%d/%y"))

        ret = self._read(1)

        if ret == "0":
            # discard junk null byte
            self._read(1)
            raise MeadeException("Couldn't set date, invalid format '%s'" %
                                 date)

        elif ret == "1":
            # discard junk message and wait Meade finish update of internal databases
            tmpTimeout = self._tty.timeout
            self._tty.timeout = 60
            self._readline()  # junk message

            self._readline()

            self._tty.timeout = tmpTimeout
            return True
Пример #4
0
    def slewToAltAz(self, position):

        self._validateAltAz(position)

        self.setSlewRate(self["slew_rate"])

        if self.isSlewing():
            # never should happens 'cause @lock
            raise MeadeException("Telescope already slewing.")

        lastAlignMode = self.getAlignMode()

        self.setTargetAltAz(position.alt, position.az)

        status = TelescopeStatus.OK

        try:
            self.setAlignMode(AlignMode.ALT_AZ)
            status = self._slewToAltAz()
            return True
        finally:
            self.slewComplete(self.getPositionRaDec(), status)
            self.setAlignMode(lastAlignMode)

        return False
Пример #5
0
    def setLocalSiderealTime(self, local):

        self._write(":SS%s#" % local.strftime("%H:%M:%S"))

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid Local sidereal time '%s'." % local)

        return True
Пример #6
0
    def setUTCOffset(self, offset):

        offset = "%+02.1f" % offset

        self._write(":SG%s#" % offset)

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid UTC offset '%s'." % offset)

        return True
Пример #7
0
    def getCurrentTrackingRate(self):

        self._write(":GT#")

        ret = self._readline()

        if not ret:
            raise MeadeException("Couldn't get the tracking rate")

        ret = float(ret[:-1])

        return ret
Пример #8
0
    def setTargetDec(self, dec):

        if not isinstance(dec, Coord):
            dec = Coord.fromDMS(dec)

        self._write(":Sd%s#" % dec.strfcoord("%(d)02d\xdf%(m)02d:%(s)02d"))

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid DEC '%s'" % dec)

        return True
Пример #9
0
    def setTargetRa(self, ra):

        if not isinstance(ra, Coord):
            ra = Coord.fromHMS(ra)

        self._write(":Sr%s#" % ra.strfcoord("%(h)02d\xdf%(m)02d:%(s)02d"))

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid RA '%s'" % ra)

        return True
Пример #10
0
    def setLocalTime(self, local):

        if type(local) == FloatType:
            local = dt.datetime.fromtimestamp(local).time()

        self._write(":SL%s#" % local.strftime("%H:%M:%S"))

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid local time '%s'." % local)

        return True
Пример #11
0
    def setLong(self, coord):

        if not isinstance(coord, Coord):
            coord = Coord.fromDMS(coord)

        self._write(":Sg%s#" % coord.strfcoord("%(d)03d\xdf%(m)02d"))

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid Longitude '%s'" % long)

        return True
Пример #12
0
    def _checkMeade(self):

        tmp = self._tty.timeout
        self._tty.timeout = 5

        align = self.getAlignMode()

        self._tty.timeout = tmp

        if align < 0:
            raise MeadeException("Couldn't find a Meade telescope on '%s'." %
                                 self["device"])

        return True
Пример #13
0
    def syncRaDec(self, position):

        self.setTargetRaDec(position.ra, position.dec)

        self._write(":CM#")

        ret = self._readline()

        if not ret:
            raise MeadeException("Error syncing on '%s' '%s'." %
                                 (position.ra, position.dec))

        self.syncComplete(self.getPositionRaDec())

        return True
Пример #14
0
    def setTargetAlt(self, alt):

        if not isinstance(alt, Coord):
            alt = Coord.fromD(alt)

        self._write(":Sa%s#" % alt.strfcoord("%(d)02d\xdf%(m)02d\'%(s)02d"))

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid Altitude '%s'" % alt)

        self._target_alt = alt

        return True
Пример #15
0
    def setLat(self, lat):

        if not isinstance(lat, Coord):
            lat = Coord.fromDMS(lat)

        lat_str = lat.strfcoord("%(d)02d\xdf%(m)02d")

        self._write(":St%s#" % lat_str)

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid Latitude '%s' ('%s')" %
                                 (lat, lat_str))

        return True
Пример #16
0
    def setCurrentTrackingRate(self, trk):

        trk = "%02.1f" % trk

        if len(trk) == 3:
            trk = "0" + trk

        self._write(":ST%s#" % trk)

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid tracking rate '%s'." % trk)

        self._write(":TM#")

        return ret
Пример #17
0
    def slewToRaDec(self, position):

        self._validateRaDec(position)

        if self.isSlewing():
            # never should happens 'cause @lock
            raise MeadeException("Telescope already slewing.")

        self.setTargetRaDec(position.ra, position.dec)

        status = TelescopeStatus.OK

        try:
            status = self._slewToRaDec()
            return True
        finally:
            self.slewComplete(self.getPositionRaDec(), status)

        return False
Пример #18
0
    def getAlignMode(self):

        self._write('\x06')  # ACK

        ret = self._read(1)

        # damn stupid '0' at the start of the mode
        if ret == '0':
            ret = self._read(1, flush=False)

        if not ret or ret not in "APL":
            raise MeadeException(
                "Couldn't get the alignment mode. Is this a Meade??")

        if ret == "A":
            return AlignMode.ALT_AZ
        elif ret == "P":
            return AlignMode.POLAR
        elif ret == "L":
            return AlignMode.LAND
Пример #19
0
    def _slewToRaDec(self):

        self._slewing = True
        self._abort.clear()

        # slew
        self._write(':MS#')

        # to handle timeout
        start_time = time.time()

        err = self._readbool()

        if err:
            # check error message
            msg = self._readline()
            self._slewing = False
            raise MeadeException(msg[:-1])

        # slew possible
        target = self.getTargetRaDec()

        return self._waitSlew(start_time, target)
Пример #20
0
    def _slewToAltAz(self):

        self._slewing = True
        self._abort.clear()

        # slew
        self._write(':MA#')

        # to handle timeout
        start_time = time.time()

        err = self._readbool()

        if err:
            # check error message
            self._slewing = False
            raise MeadeException("Couldn't slew to ALT/AZ: '%s'." %
                                 self.getTargetAltAz())

        # slew possible
        target = self.getTargetAltAz()

        return self._waitSlew(start_time, target, local=True)
Пример #21
0
    def _move(self, direction, duration=1.0, slewRate=SlewRate.GUIDE):

        if duration <= 0:
            raise ValueError("Slew duration cannot be less than 0.")

        # FIXME: concurrent slew commands? YES.. it should works!
        if self.isSlewing():
            raise MeadeException(
                "Telescope is slewing. Cannot move.")  # REALLY? no.

        if slewRate:
            self.setSlewRate(slewRate)

        startPos = self.getPositionRaDec()

        self._slewing = True
        self._write(":M%s#" % str(direction).lower())

        start = time.time()
        finish = start + duration

        self.log.debug("[move] delta: %f s" % (finish - start, ))

        while time.time() < finish:
            pass  # busy wait!

        # FIXME: slew limits
        self._stopMove(direction)
        self._slewing = False

        def calcDelta(start, end):
            return Coord.fromD(end.angsep(start))

        delta = calcDelta(startPos, self.getPositionRaDec())
        self.log.debug("[move] moved %f arcsec" % delta.AS)

        return True
Пример #22
0
    def setTargetAz(self, az):

        if not isinstance(az, Coord):
            az = Coord.fromDMS(az)

        if self['azimuth180Correct']:

            if az.toD() >= 180:
                az = az - Coord.fromD(180)
            else:
                az = az + Coord.fromD(180)

        self._write(":Sz%s#" %
                    az.strfcoord("%(d)03d\xdf%(m)02d:%(s)02d", signed=False))

        ret = self._readbool()

        if not ret:
            raise MeadeException("Invalid Azimuth '%s'" %
                                 az.strfcoord("%(d)03d\xdf%(m)02d"))

        self._target_az = az

        return True