-
Notifications
You must be signed in to change notification settings - Fork 1
/
tel
executable file
·323 lines (253 loc) · 10.2 KB
/
tel
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/usr/bin/env python3
#
# This file is part of the Robotic Observatory Control Kit (rockit)
#
# rockit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# rockit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with rockit. If not, see <http://www.gnu.org/licenses/>.
"""Commandline client for managing the telescope"""
import glob
import os
import sys
import Pyro4
from astropy.coordinates import Angle, SkyCoord
import astropy.units as u
from rockit.common import print
from rockit.mount.talon import CommandStatus, TelState, Config
SCRIPT_NAME = os.path.basename(sys.argv[0])
sys.excepthook = Pyro4.util.excepthook
def run_command(command, args):
"""Runs a daemon command, handling cancellation and error messages"""
if 'MOUNTD_CONFIG_PATH' in os.environ:
config = Config(os.environ['MOUNTD_CONFIG_PATH'])
else:
# Load the config file defined in the MOUNTD_CONFIG_PATH environment variable or from the
# default system location (/etc/mountd/). Exit with an error if zero or multiple are found.
files = glob.glob("/etc/mountd/*.json")
if len(files) != 1:
print('error: failed to guess the default config file. ' +
'Run as MOUNTD_CONFIG_PATH=/path/to/config.json tel <command> \\[<args>]')
return 1
config = Config(files[0])
try:
ret = command(config, args)
except KeyboardInterrupt:
# ctrl-c terminates the running command
ret = stop(config, args)
# Report successful stop
if ret == 0:
ret = -100
except Pyro4.errors.CommunicationError:
ret = -101
# Print message associated with error codes, except for -1 (error handled locally)
if ret not in (0, -1):
print(CommandStatus.message(ret))
return ret
def park(config, args):
"""Slews the telescope to a named park position"""
if len(args) == 1:
if args[0] not in config.park_positions:
print(f'error: unknown park position \'{args[0]}\'')
return -1
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.park(args[0])
print(f'usage: {SCRIPT_NAME} park <position>')
print()
for name, park in config.park_positions.items():
print(f' {name:6s} {park["desc"]}')
print()
return -1
def slew(config, args):
"""Slews the telescope to a specified RA,Dec position"""
if len(args) != 2:
print(f'usage: {SCRIPT_NAME} slew <HH:MM:SS.S> <DD:MM:SS.S>')
return -1
try:
coord = SkyCoord(ra=args[0], dec=args[1], unit=(u.hourangle, u.deg))
except ValueError as e:
print('error: ' + str(e))
return -1
# TODO: Check against limits
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.slew_radec(coord.ra.to_value(u.deg), coord.dec.to_value(u.deg))
def horizon(config, args):
"""Slews the telescope to a specified Alt,Az position"""
if len(args) != 2:
print(f'usage: {SCRIPT_NAME} horizon <DD:MM:SS.S> <DD:MM:SS.S>')
return -1
try:
coord = SkyCoord(alt=args[0], az=args[1], unit=u.deg, frame='altaz')
except ValueError as e:
print('error: ' + str(e))
return -1
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.slew_altaz(coord.alt.to_value(u.deg), coord.az.to_value(u.deg))
def track(config, args):
"""Slews the telescope to a specified RA,Dec position and begins tracking"""
if len(args) != 2:
print(f'usage: {SCRIPT_NAME} track <HH:MM:SS.S> <DD:MM:SS.S>')
return -1
try:
coord = SkyCoord(ra=args[0], dec=args[1], unit=(u.hourangle, u.deg))
except ValueError as e:
print('error: ' + str(e))
return -1
# TODO: check against limits
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.track_radec(coord.ra.to_value(u.deg), coord.dec.to_value(u.deg))
def offset(config, args):
"""Offsets the telescope by a specified delta RA,Dec"""
if len(args) != 2:
print(f'usage: {SCRIPT_NAME} offset <HH:MM:SS.S> <DD:MM:SS.S>')
return -1
try:
offset_ra = Angle(args[0], unit=u.hourangle)
except ValueError:
print(f'error: failed to parse \'{args[0]}\' as a HH:MM:SS.S right ascension.')
return -1
try:
offset_dec = Angle(args[1], unit=u.deg)
except ValueError:
print(f'error: failed to parse \'{args[1]}\' as a DD:MM:SS.S declination.')
return -1
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.offset_radec(offset_ra.to_value(u.deg), offset_dec.to_value(u.deg))
def focus(config, args):
"""Sets the W1m's focus"""
if not config.is_onemetre:
return -102
if len(args) == 1:
try:
position = float(args[0])
except ValueError:
print(f'error: failed to parse \'{args[0]}\' as a focus position.')
return -1
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.telescope_focus(position)
print(f'usage: {SCRIPT_NAME} focus <position>')
return -1
def calibrate(config, args):
"""Performs the home and limit calibrations"""
if len(args) == 1 and (args[0] == 'home' or args[0] == 'limits'):
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
if args[0] == 'home':
return teld.find_homes()
return teld.find_limits()
print(f'usage: {SCRIPT_NAME} cal \\[home|limits]')
return -1
def status(config, _):
"""Reports the current telescope status"""
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
data = teld.report_status()
print(f' Telescope is {TelState.label(data["state"], formatting=True)}')
# Telescope is disabled
if data['state'] == 0:
return 0
if data['axes_homed']:
coords = SkyCoord(ra=data['ra'], dec=data['dec'], unit=u.deg)
ra_desc = coords.ra.to(u.hourangle).to_string(sep=':', precision=2)
dec_desc = coords.dec.to(u.deg).to_string(sep=':', precision=2)
altaz = SkyCoord(alt=data['alt'], az=data['az'], unit=u.deg, frame='altaz')
alt_desc = altaz.alt.to(u.deg).to_string(sep=':', precision=2)
az_desc = altaz.az.to_string(sep=':', precision=2)
ra_offset_desc = ''
ra_offset = Angle(data['offset_ra'], unit=u.deg).to(u.hourangle)
if ra_offset != 0:
ra_offset_desc = ' with offset [b]' + ra_offset.to_string(sep=':', precision=2) + '[/b]'
dec_offset_desc = ''
dec_offset = Angle(data['offset_dec'], unit=u.deg)
if dec_offset != 0:
dec_offset_desc = ' with offset [b]' + dec_offset.to_string(sep=':', precision=2) + '[/b]'
moon_desc = f'[b]{data["moon_separation"]:.0f}\u00B0[/b]'
sun_desc = f'[b]{data["sun_separation"]:.0f}\u00B0[/b]'
print(f' RA is [b]{ra_desc}[/b]' + ra_offset_desc)
print(f' Dec is [b]{dec_desc}[/b]' + dec_offset_desc)
print(f' Altitude is [b]{alt_desc}[/b]')
print(f' Azimuth is [b]{az_desc}[/b]')
print(' Moon separation is ' + moon_desc)
print(' Sun separation is ' + sun_desc)
if 'telescope_focus_um' in data:
print(f' Telescope focus is [b]{data["telescope_focus_um"]:.2f}[/b]um')
else:
print(' Axes are [b][red]NOT HOMED[/red][/b]')
lst_desc = Angle(data['lst'], unit=u.deg).to(u.hourangle).to_string(sep=':', precision=2)
print(f' Local sidereal time is [b]{lst_desc}[/b]')
return 0
def stop(config, _):
"""Stops any active telescope movement"""
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.stop()
def initialize(config, _):
"""Enables the talon daemon"""
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.initialize()
def shutdown(config, _):
"""Disables the talon daemon"""
ping_teld(config)
with config.daemon.connect(timeout=0) as teld:
return teld.shutdown()
def list_parks(config, _):
"""List available park positions for bash command completion"""
print(' '.join(sorted(config.park_positions.keys())))
return 0
def ping_teld(config):
"""Check that teld is alive"""
with config.daemon.connect(timeout=config.ping_timeout) as teld:
teld.ping()
def print_usage():
"""Prints the utility help"""
print(f'usage: {SCRIPT_NAME} <command> \\[<args>]')
print()
print('general commands:')
print(' status print a human-readable summary of the telescope status')
print(' park park the telescope in a named position')
print()
print('observing commands:')
print(' slew slew the telescope to a given RA, Dec')
print(' horizon slew the telescope to a given Alt, Az')
print(' track slew the telescope to a given RA, Dec and track the target')
print(' offset offset the telescope by a given RA, Dec')
print(' focus adjust the telescope focus')
print(' stop immediately stop any telescope movement')
print()
print('engineering commands:')
print(' cal perform telescope home or limit calibrations')
print()
return 0
if __name__ == '__main__':
commands = {
'park': park,
'slew': slew,
'horizon': horizon,
'track': track,
'offset': offset,
'focus': focus,
'cal': calibrate,
'status': status,
'stop': stop,
'init': initialize,
'kill': shutdown,
'list-parks': list_parks
}
if len(sys.argv) >= 2 and sys.argv[1] in commands:
sys.exit(run_command(commands[sys.argv[1]], sys.argv[2:]))
sys.exit(print_usage())