Commit 4fd99e25 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Try to configure through ini-file (does not work yet)

parent 5ee3729b
from __future__ import print_function
import socket
import logging
from astropy.coordinates import SkyCoord, AltAz
from astropy import units as u
from configparser import ConfigParser
def create_socket(host, port):
s = None
for res in socket.getaddrinfo(host, port,\
af, socktype, proto, canonname, sa = res
s = socket.socket(af, socktype, proto)
except socket.error, msg:
s = None
except socket.error, msg:
s = None
return s
config = ConfigParser()'telescope.ini')
class telescope():
def __init__(self, lat, long, alt,\
listenOnly = True, connect = False,\
RDPORT = 11030, STPORT = 11031, HOST = 'console'):
self._lat = lat
self._long = long
self._alt = alt
self._connect = connect
if connect:
self._readsocket = create_socket(HOST, RDPORT)
if self._readsocket == None:
print "Failed to create read connection"
elif not(listenOnly):
self._setsocket = create_socket(HOST, STPORT)
if self._setsocket == None:
print "Failed to create set socket"
self._setsocket = None
self._readsocket = None
self._setsocket = None
def lat(self):
return self._lat
def long(self):
return self._long
def alt(self):
return self._alt
def readPos(self):
if self._readsocket != None:
return self._readsocket.recv(1024)
def __init__(self, setmode=None, consoleHost=None):
Initializes a telescope instance. The mode for writing can be
'J2000' or 'AZEL'.
if setmode not in ('J2000', 'AZEL', None):
raise Exception("Mode must be None, 'J2000' or 'AZEL', not " + mode)
self.setmode = setmode
self.readsocketj2000 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.outsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.setmode == 'J2000':
self.outsocket.connect((host, setport_j2000))
elif self.setmode == 'AZEL':
self.outsocket.connect((host, setport_azel))
def getRaDec(self):
Get the J200 coordinates of the telescope as an astropy SkyCoord
msg = self.readsocketj2000.recv(4096)
statusData = msg.split()
ra = statusData[2].decode("utf-8")
dec = statusData[3].decode("utf-8")
return SkyCoord(ra, dec, frame='icrs')
def setRaDec(self, setpoint):
Set the J2000 setpoint of the telescope.
Only works if the setmode is 'J2000'.
setpoint can be an astropy SkyCoord or a tuple (ra,dec) in radians
if self.setmode != 'J2000':
raise Exception("Cannot set Ra/Dec if mode is not J2000")
if not isinstance(setpoint, SkyCoord):
coord = SkyCoord(ra =setpoint[0] * u.radian,
dec=setpoint[1] * u.radian)
(ra, dec) = setpoint.to_string('hmsdms').split()
cmd = bytes(ra + "\t" + dec[1:] + "\n", 'UTF-8')'J2000 setpoint sent to DT: {}'.format(cmd))
def setAzEl(self, setpoint):
Set the AzEl setpoint of the telescope.
Only works if the setmode is 'AZEL'
setpoint can be an astropy AltAz or a tuple (az,el) in radians
if self.setmode != 'AZEL':
raise Exception("Cannot set Az/El i mode is not AZEL")
if isinstance(setpoint, AltAz):
az =
el = setpoint.alt.radian
return None
def setPosRADec(self, RA, Dec):
if self._setsocket:
self._setsocket.send(str(RA)+" "+str(Dec)+"\n")
# The remote host
# Port for receiving setpoint position,
# current position in Ra, Dec, and UT Unix time in format
# "xxhxxmxx.x xxxdxxmxx.xs xxhxxmxx.x xxxdxxmxx.xs xxxxxxxxx"
# Port for setting setpoint position,
# new position in Ra, Dec
# "xxhxxmxx.x xxxdxxmxx.xs
(az, el) = setpoint
md = bytes(az + '\t' + el + '\n', 'UTF-8')'AzEl setpoint sent to DT: {}'.format(cmd))
def setOffset(self, offset):
Set the offset of the telescope in Az / El.
offset should be a tuple of radians or of astropy Quantity
(off_az, off_el) = offset
if isinstance(off_az, u.Quantity):
off_az =
if isinstance(off_az, u.Quantity):
off_el =
md = bytes(off_az + '\t' + off_el + '\n', 'UTF-8')'Offset sent to DT: {}'.format(cmd))
Port_Read_J2000 : 11030
Port_Write_J2000 : 11031
Port_Write_AzEl : 11041
Port_Write_Offset: 11011
HostName: localhost
Port: 11042
Az_idx: 1
El_idx: 2
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment