-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
247 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import time | ||
import signal | ||
|
||
import multiprocessing | ||
|
||
class LVMTelescopeUnit(): | ||
def __init__(self, tel): | ||
self.tel = tel | ||
# self.ag_task = None | ||
self.ag_break = False | ||
self.proc = None | ||
|
||
def handler(self, signum, frame): | ||
self.guide_off() | ||
|
||
def autoguide_supervisor(self, msg): | ||
while True: | ||
self.autoguiding(msg) | ||
if self.ag_break: break | ||
|
||
def autoguiding(self, msg): | ||
time.sleep(1) | ||
print(msg) | ||
|
||
def guide_on(self, timeout=None): | ||
# self.ag_task = True | ||
print(f"{self.tel} | Autoguide Start") | ||
|
||
try: | ||
signal.signal(signal.SIGINT, self.handler) | ||
if timeout is not None: | ||
signal.signal(signal.SIGALRM, self.handler) | ||
signal.alarm(timeout) | ||
self.proc = multiprocessing.Process(target=self.autoguide_supervisor, args=(f"{self.tel} | Autoguiding...", )) | ||
self.proc.start() | ||
except: | ||
raise Exception | ||
# finally: | ||
# self.ag_task = None | ||
|
||
# if not self.proc.is_alive(): | ||
# return print(f"{self.tel} | Autoguide Done") | ||
|
||
def guide_off(self, proc=None): | ||
|
||
if self.proc is not None: | ||
try: | ||
self.proc.terminate() | ||
except: | ||
raise Exception | ||
|
||
# if self.ag_task is not None: | ||
# self.ag_break = True | ||
# else: | ||
# raise Exception | ||
|
||
def expose(self, exptime): | ||
print(f"{self.tel} | Expose Start") | ||
time.sleep(exptime) | ||
print(f"{self.tel} | Expose Done") | ||
self.guide_off() | ||
|
||
|
||
if __name__ == '__main__' : | ||
start = time.perf_counter() | ||
|
||
sci = LVMTelescopeUnit("sci") | ||
# aaa = LVMTelescopeUnit("aaa") | ||
|
||
# p = multiprocessing.Process(target=sci.guide_on) | ||
# p = multiprocessing.Process(target=sci.guide_on, args=(5,)) | ||
# p.start() | ||
|
||
# aaa.expose(1) | ||
# p.join() | ||
sci.guide_on() | ||
sci.expose(5) | ||
|
||
|
||
finish = time.perf_counter() | ||
print(f'Finished in {round(finish-start, 2)} second(s)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import time | ||
import signal | ||
|
||
import threading | ||
|
||
class LVMTelescopeUnit(): | ||
def __init__(self, tel): | ||
self.tel = tel | ||
self.ag_break = False | ||
# self.proc = None | ||
|
||
def handler(self, signum, frame): | ||
self.guide_off() | ||
|
||
def autoguide_supervisor(self, msg): | ||
while True: | ||
self.autoguiding(msg) | ||
if self.ag_break: break | ||
|
||
def autoguiding(self, msg): | ||
time.sleep(1) | ||
print(msg) | ||
|
||
def guide_on(self, timeout=None): | ||
print(f"{self.tel} | Autoguide Start") | ||
|
||
try: | ||
signal.signal(signal.SIGINT, self.handler) | ||
if timeout is not None: | ||
signal.signal(signal.SIGALRM, self.handler) | ||
signal.alarm(timeout) | ||
t = threading.Thread(target=self.autoguide_supervisor, args=(f"{self.tel} | Autoguiding...", )) | ||
t.setDaemon(True) | ||
t.start() | ||
except: | ||
raise Exception | ||
|
||
|
||
def guide_off(self, proc=None): | ||
self.ag_break = True | ||
# if self.proc is not None: | ||
# try: | ||
# self.proc.terminate() | ||
# except: | ||
# raise Exception | ||
|
||
|
||
def expose(self, exptime): | ||
print(f"{self.tel} | Expose Start") | ||
time.sleep(exptime) | ||
print(f"{self.tel} | Expose Done") | ||
self.guide_off() | ||
|
||
|
||
if __name__ == '__main__' : | ||
start = time.perf_counter() | ||
|
||
sci = LVMTelescopeUnit("sci") | ||
|
||
sci.guide_on() | ||
sci.expose(5) | ||
|
||
|
||
finish = time.perf_counter() | ||
print(f'Finished in {round(finish-start, 2)} second(s)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters