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

Add getters, optionally blocking

parent bb06a272
......@@ -33,6 +33,11 @@ class telescope():
self.dist_az = None
self.dist_el = None
self.az = None
self.el = None
self.radec = None
self.speed_az = None
self.speed_el = None
self._outsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.setmode == 'J2000':
......@@ -173,26 +178,59 @@ class telescope():
logging.info('Offset sent to DT: {}'.format(cmd))
self._offsetsocket.send(cmd)
def getAzEl(self, waitForUpdate=False):
'''
Get azimut and elevation. If waitForUpdate=True, it waits for the
next signal from the socket.
Returns a tuple (az, el) as astropy quantity
'''
if waitForUpdate or self.az is None or self.radec is None:
self._event_traces.clear()
self._event_traces.wait()
return (self.az, self.el)
def getDistance(self, waitForUpdate=False):
'''
Get distance in azimut and elevation. If waitForUpdate=True, it waits
for the next signal from the socket.
Returns a tuple (dist_az, dist_el) as astropy quantity
'''
if waitForUpdate or self.dist_az is None or self.dist_el is None:
self._event_traces.clear()
self._event_traces.wait()
return (self.dist_az, self.dist_el)
def getRaDec(self, waitForUpdate=False):
'''
Get current Ra/Dec. If waitForUpdate=True, it waits for the
next signal from the socket.
Returns an astropy SkyCoord
'''
if waitForUpdate or self.radec is None:
self._event_traces.clear()
self._event_traces.wait()
return self.radec
def waitUntilThere(self):
'''
Wait until distance to the setpoint gets within tolerance
'''
time.sleep(2)
logging.info("Waiting to reach setpoint")
while self.dist_el is None or self.dist_az is None or \
abs(self.dist_el)>0.01*u.deg or abs(self.dist_az)>0.01*u.deg:
continue
distIsSmall = False
while not distIsSmall:
diff = self.getDistance(waitForUpdate=True)
distIsSmall = abs(self.dist_el)<0.01*u.deg and abs(self.dist_az)>0.01*u.deg
def waitUntilMoving(self):
'''
Wait until the telescope reckognizes that it is not at its setpoint
'''
logging.info("Waiting to set setpoint")
while self.dist_el is None or self.dist_az is None or \
(abs(self.dist_el)<0.01*u.deg and abs(self.dist_az)<0.01*u.deg):
continue
distIsBig = False
while not distIsBig:
dist = self.getDistance(waitForUpdate=True)
distIsBig = dist[0]>0.01*u.deg or dist[1]>0.01*u.deg
def getJ2000(self):
'''
......@@ -200,6 +238,7 @@ class telescope():
'setpoint_j2000', containing radec and setpoint_radec, at whichever
speed the console is outputting them (probably once a second).
'''
self._event_traces.clear()
while True:
self._event_j2000.wait()
self._event_j2000.clear()
......@@ -211,6 +250,7 @@ class telescope():
Generates a dict of all traces from trace2port at whichever
rate trace2port generates them (probably once a second).
'''
self._event_traces.clear()
while True:
self._event_traces.wait()
self._event_traces.clear()
......
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