Commit f1f596be authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Update telescope class with more functions

parent 6d63eb89
......@@ -6,6 +6,7 @@ from astropy.coordinates import SkyCoord, AltAz
from astropy import units as u
from configparser import ConfigParser
import os.path
import numpy as np
config = ConfigParser()
config.readfp(open(os.path.join(os.path.dirname(__file__), 'telescope.ini')))
......@@ -40,15 +41,24 @@ class telescope():
# Initialize other traces
self.tracesocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.tracesocket.connect((config.get('Trace2Port', 'Hostname'),
config.getint('Trace2Port', 'Port')))
except:"trace2port not found running, some features won't work")
self.tracesocket = None
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")
msg = self.readsocketj2000.recv(1024)
statusData = msg.strip().split('\n')[-1].split()
ra = statusData[2]
dec = statusData[3]
return SkyCoord(ra, dec, frame='icrs')
def setRaDec(self, setpoint):
......@@ -105,7 +115,66 @@ class telescope():
if isinstance(off_el, u.Quantity):
off_el =
cmd = '{:f}\t{:f}\n'.format(off_az, off_el).decode('UTF-8')
cmd = '{:f}\t{:f}\n'.format(off_az, off_el)'Offset sent to DT: {}'.format(cmd))
def getDistToSetpoint(self):
Get the distance to the current setpoint, as a numpy array with astropy Quantity
This corresponds to the values in the upper right of the console window
Note that this value can be negative
If also other trace values are required, use getTraces()
traces = self.getTraces()
return np.array([traces['azimuth_setpoint_error.difference'].value,
def getAzEl(self):
Get the current azimuth and elevation, as a numpy array with astropy Quantity
This corresponds to the values in the upper left of the console window
If also other trace values are required, use getTraces()
traces = self.getTraces()
return np.array([traces['Azimuth_Position'].value,
def getTraces(self):
Get a dict with the traces of trace2port.
if self.tracesocket is None:
raise Exception("getTraces only works when trace2port is running")
msg = self.tracesocket.recv(1024)
if not msg:
raise Exception("trace2port socket has gone away")
statusData = msg.strip().split('\n')[-1].split()
if len(statusData) < 4:
statusData = msg.strip().split('\n')[-2].split()
ret = dict()
for tracename in ['Azimuth_Position', 'Elevation_Position',
'azimuth_setpoint_error.difference', 'elevation_setpoint_error.difference']:
traceval = float(statusData[config.getint("Trace2Port", tracename)])
ret[tracename] = (traceval*u.rad).to(u.deg)
return ret
def waitUntilThere(self):
Wait until distance to the setpoint gets within tolerance
while not np.all(np.abs(self.getDistToSetpoint())<0.01*u.deg):
# No time.sleep here, because getDistToSetpoint already blocks with an interval
# Socket poll, bitmask met filedesc van (poll is blocking)
......@@ -5,9 +5,10 @@ Port_Write_J2000 : 11031
Port_Write_AzEl : 11041
Port_Write_Offset: 11011
HostName: localhost
Port: 11042
Az_idx: 1
El_idx: 2
Azimuth_Position: 0
Elevation_Position: 1
azimuth_setpoint_error.difference: 2
elevation_setpoint_error.difference: 3
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