Commit 6d63eb89 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Fix setRaDec

parent d7e05bd6
...@@ -10,6 +10,8 @@ import os.path ...@@ -10,6 +10,8 @@ import os.path
config = ConfigParser() config = ConfigParser()
config.readfp(open(os.path.join(os.path.dirname(__file__), 'telescope.ini'))) config.readfp(open(os.path.join(os.path.dirname(__file__), 'telescope.ini')))
logging.basicConfig(level=logging.DEBUG)
class telescope(): class telescope():
def __init__(self, setmode=None, consoleHost=None): def __init__(self, setmode=None, consoleHost=None):
''' '''
...@@ -32,6 +34,13 @@ class telescope(): ...@@ -32,6 +34,13 @@ class telescope():
self.outsocket.connect((config.get('Console','HostName'), self.outsocket.connect((config.get('Console','HostName'),
config.getint('Console','Port_Write_AzEl'))) config.getint('Console','Port_Write_AzEl')))
# Initialize offset socket for all modes where output is desired
if self.setmode is not None:
self.offsetsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.offsetsocket.connect((config.get('Console','HostName'),
config.getint('Console','Port_Write_Offset')))
def getRaDec(self): def getRaDec(self):
''' '''
Get the J200 coordinates of the telescope as an astropy SkyCoord Get the J200 coordinates of the telescope as an astropy SkyCoord
...@@ -50,37 +59,37 @@ class telescope(): ...@@ -50,37 +59,37 @@ class telescope():
setpoint can be an astropy SkyCoord or a tuple (ra,dec) in radians setpoint can be an astropy SkyCoord or a tuple (ra,dec) in radians
''' '''
if self.setmode != 'J2000': if self.setmode != 'J2000':
raise Exception("Cannot set Ra/Dec if mode is not J2000") raise Exception("Cannot set Ra/Dec if mode is not J2000")
if not isinstance(setpoint, SkyCoord): if not isinstance(setpoint, SkyCoord):
coord = SkyCoord(ra =setpoint[0] * u.radian, coord = SkyCoord(ra =setpoint[0] * u.radian,
dec=setpoint[1] * u.radian) dec=setpoint[1] * u.radian)
(ra, dec) = setpoint.to_string('hmsdms').split() (ra, dec) = setpoint.to_string('hmsdms').split()
cmd = bytes(ra + "\t" + dec[1:] + "\n", 'UTF-8') cmd = '{:s}\t{:s}\n'.format(ra, dec).decode('UTF-8')
logging.info('J2000 setpoint sent to DT: {}'.format(cmd)) logging.info('J2000 setpoint sent to DT: {}'.format(cmd))
outsocket.send(cmd) self.outsocket.send(cmd)
def setAzEl(self, setpoint): def setAzEl(self, setpoint):
''' '''
Set the AzEl setpoint of the telescope. Set the AzEl setpoint of the telescope.
Only works if the setmode is 'AZEL' Only works if the setmode is 'AZEL'
setpoint can be an astropy AltAz or a tuple (az,el) in radians setpoint should be a tuple of radians or of astropy Quantity
''' '''
if self.setmode != 'AZEL': if self.setmode != 'AZEL':
raise Exception("Cannot set Az/El i mode is not AZEL") raise Exception("Cannot set Az/El if mode is not AZEL")
if isinstance(setpoint, AltAz): (az, el) = setpoint
az = setpoint.az.radian if isinstance(az, u.Quantity):
el = setpoint.alt.radian az = az.to(u.deg).value
else: if isinstance(el, u.Quantity):
(az, el) = setpoint el = el.to(u.deg).value
md = bytes(az + '\t' + el + '\n', 'UTF-8') cmd = '{:f}\t{:f}\n'.format(az, el).decode('UTF-8')
logging.info('AzEl setpoint sent to DT: {}'.format(cmd)) logging.info('AzEl sent to DT: {}'.format(cmd))
outsocket.send(cmd) self.outsocket.send(cmd)
def setOffset(self, offset): def setOffset(self, offset):
''' '''
...@@ -88,13 +97,15 @@ class telescope(): ...@@ -88,13 +97,15 @@ class telescope():
offset should be a tuple of radians or of astropy Quantity offset should be a tuple of radians or of astropy Quantity
''' '''
if self.setmode is None:
raise Exception("Cannot set offset if mode is None")
(off_az, off_el) = offset (off_az, off_el) = offset
if isinstance(off_az, u.Quantity): if isinstance(off_az, u.Quantity):
off_az = off_az.to(u.rad).value off_az = off_az.to(u.rad).value
if isinstance(off_az, u.Quantity): if isinstance(off_el, u.Quantity):
off_el = off_el.to(u.rad).value off_el = off_el.to(u.rad).value
md = bytes(off_az + '\t' + off_el + '\n', 'UTF-8') cmd = '{:f}\t{:f}\n'.format(off_az, off_el).decode('UTF-8')
logging.info('Offset sent to DT: {}'.format(cmd)) logging.info('Offset sent to DT: {}'.format(cmd))
outsocket.send(cmd) self.offsetsocket.send(cmd)
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