-
Notifications
You must be signed in to change notification settings - Fork 2
/
TelescopeSrv.py
executable file
·82 lines (70 loc) · 2.35 KB
/
TelescopeSrv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import sys, traceback, Ice, os
Ice.loadSlice("HinOTORI.ice")
import HinOTORI
import AllunaToolKit
import time
import config
import logging
logging.basicConfig(format=config.FORMAT, level=config.loglevel)
logger=logging.getLogger(__name__)
class TelescopeServer(Ice.Application):
def run(self,args):
self.shutdownOnInterrupt() # make sure clean up
adapter = self.communicator().createObjectAdapterWithEndpoints(
os.path.basename(__file__), "default -h %s -p %d"
% ( \
config.nodesetting["telescope"]['ip'], \
config.nodesetting["telescope"]['port'] \
))
telescope = Telescope()
adapter.add(telescope, self.communicator().stringToIdentity("telescope"))
adapter.activate()
self.communicator().waitForShutdown()
return 0
class Telescope(HinOTORI.Telescope,AllunaToolKit.Telescope):
def __init__(self):
self.z=0.
HinOTORI.Telescope.__init__(self)
AllunaToolKit.Telescope.__init__(self)
self.Connect()
self.FocusingHomePosition()
def __check(self):
for i in range(config.ntrial):
try:
self.CheckAppStatus()
break # if success, go next
except:
if i == config.ntrial-1:
raise
logger.error(traceback.format_exc())
logger.error("Try to reconnect")
self.app.kill_()
self.Connect()
self.FocusingPosition()
def GetFocusZ(self,current=None):
self.__check()
self.z = self.FocusingPosition()
logger.info("Telescope: z= %lf, %d" % (self.z, int(self.z/config.focusconv)))
return self.z
def SetFocusZ(self,targetz,current=None):
self.__check()
self.z=int(targetz/config.focusconv)
for i in range(config.ntrial):
self.FocusingTargetPosition(self.z)
if self.z != int(self.GetFocusZ()/config.focusconv):
if i==config.ntrial-1:
raise HinOTORI.Error("Focus seems not to be right position")
else:
logger.error("Focus seems not to be right position, try again")
break
def OpenMirror(self,current=None):
self.__check()
self.DustcoverOpen()
def CloseMirror(self,current=None):
self.__check()
self.DustcoverClose()
if __name__ == "__main__":
app = TelescopeServer()
status = app.main(sys.argv)
sys.exit(status)