-
Notifications
You must be signed in to change notification settings - Fork 0
/
magtelescope.hpp
2760 lines (2324 loc) · 66 KB
/
magtelescope.hpp
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** \file magtelescope.hpp
* \author Jared R. Males
* \brief Declaration of the magtelescope class.
*/
//***********************************************************************//
// Copyright 2018 Jared R. Males ([email protected])
//
// This file is part of magTCSsim.
//
// magTCSsim 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.
//
// magTCSsim 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 magTCSsim. If not, see <http://www.gnu.org/licenses/>.
//***********************************************************************//
#ifndef magtelescope_hpp
#define magtelescope_hpp
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <boost/math/constants/constants.hpp>
#define PI (boost::math::constants::pi<double>())
#include <mx/sys/timeUtils.hpp>
#include <mx/astro/astroDynamics.hpp>
#include "cmdstr.hpp"
#include "tellog.hpp"
#include "magtelUtils.hpp"
#define dms2dd(d, m, s) (d + (m/60.0) + (s/3600.0))
#define NASW 0
#define NASE 1
#define CASS 2
#define AUX1 3
#define AUX2 4
#define AUX3 5
#define MAGTCS_RESP_SIZE (1024)
#define MAGTCS_INPUT_SIZE (1024)
///A simulated Magellan Telescope
class magtelescope
{
protected:
double m_lon {-29.015}; ///< The telescope longitude [degrees].
double m_lat {-70.69166667}; ///< The telescope latitude [degrees].
int m_dateobs[3] {0,0,0}; ///< The broken down universal date [YYYY, MM, DD].
double m_ut {0}; ///< The current universal time [hrs].
double m_ra {0}; ///< The current right ascension, hours
double m_dec {0}; ///< The current declination, degrees
double m_next_ra {0}; ///< The next value of RA, which will be slewed to.
double m_next_dec {0}; ///< The next value of Dec, which will be slewed to.
double m_off_ra {0}; ///< The offset in RA
double m_off_dec {0}; ///< The offset in Dec
double m_az {0}; ///< azimuth, east of north, degrees
double m_el {0}; ///< elevation, degrees
double m_next_az {0}; ///< The next value of azimuth, which will be slewed to.
double m_next_el {0}; ///< The next value of elevation, which will be slewed to.
double m_epoch {2000.0}; ///< coordinate epoch
double m_airmass {1.0}; ///< the current airmass
int m_telfocus {1725}; ///< Focus, or z, position of the 2ndary mirror.
int m_telx {10}; ///< X position of the 2ndary mirror.
int m_tely {-10}; ///< Y position of the 2ndary mirror.
double m_telh {1.24}; ///< H angle of the 2ndary mirror.
double m_telv {-2.34}; ///< V angle of the 2ndary mirror.
int m_roi {0}; ///< The rotator of interest
double m_rotangle {0}; ///< The rotator angle
double m_next_rotangle {0}; ///< The next rotator angle to slew to.
double m_rotenc {0}; ///< The rotator encoder angle
//Simulation flags
int m_simulating {0}; ///< True if simulating.
int m_tracking {0}; ///< True if telescope tracking.
int m_rottracking {0}; ///< True if rotator tracking (following).
int m_slewing {0}; ///< 1 if currently slewing
int m_was_tracking {0}; ///< to reset tracking after slewing
int m_guiding {0}; ///< 1 if guiding - just a flag, doesn't do anything here.
int m_was_guiding {0}; ///< Flag set to cause a reset to guiding after slewing
int m_rotmode {0}; ///< Current rotator mode. 1 if following
int m_rotwas_following {0}; ///< Flag set to cause a reset to following after slewing
//Simulation time hacks
double m_simstart {0}; ///< Time of simulation start
double m_trackstart {0}; ///< Time of tracking start
double m_slewstart {0}; ///< Time of slew start
double m_rotstart {0}; ///< Time of rotator motion start
//Simulation motion
double m_az_accel {0.1}; ///< Acceleration of the mount in the azimuth direction.
double m_az_rate {2.0}; ///< Maximum slew rate of the mount in the azimuth direction.
double m_curr_az_rate {0.0}; ///< Current slewing rate of the mount in the az direction.
double m_az_lastt {0}; ///< Time of last azimuth slew calculation, used for calculating amount of motion.
double m_el_accel {0.1}; ///< Acceleration of the mount in the elevation direction.
double m_el_rate {1.0}; ///< Maximum slew rate of the mount in the elevation direction.
double m_curr_el_rate {0}; ///< Current slewing rate of the mount in the el direction.
double m_el_lastt {0}; ///< Time of last elevation slew calculation, used for calculating amount of motion.
double m_rotslewing {0};
double m_rotrate {6.0}; ///< The rotator slew rate [deg/sec]
double init_rotangle;
double rotmovesz;
int rotmovedir;
int m_dome_stat {1}; ///< The dome status, 1 is open, 0 is closed.
std::string m_catObj; ///< Catalog object name
double m_catRA; ///< Catalog right ascension [degrees]
double m_catDC; ///< Catalog declination [degrees]
double m_catEP; ///< Catalog epoch
double m_catRO; ///< Catalog rotator offset
int m_catRM; ///< Catalog rotator mode
pthread_mutex_t comMutex;
pthread_mutex_t logmutex;
std::string logstr;
char logval[50];
char lmsg[lmsg_size];
/// Map of commands to command number, for fast lookup.
std::map<std::string, cmdidx> commands;
public:
/// Default c'tor
magtelescope();
protected:
/// Load the commands map.
void loadCommands();
public:
/// Set the typical values of parameters.
void set_typval();
/// Get the telescope latitude.
/** Units: degrees.
*
* \returns the current value of m_lat.
*/
double lat();
/// Get the telescope longitude
/** Units: degrees.
*
* \returns the current value of m_lon.
*/
double lon();
/// Set dateobs to the current date.
/** Gets current UT date from the O/S.
*
* \returns 0 on success.
* \returns -1 on error.
*/
int dateobsNow();
/// Get the current value of dateobs.
/** Call dateobsNow, then fills in the array with YYYY,MM,DD.
*/
void dateobs(int dobs[3] /**< [out] The current value of dateobs [YYY,MM,DD].*/);
/// Get the current UT time.
/** Sets m_ut to the current UT time and returns it.
*
* \returns the current value of m_ut
*/
double ut();
/// Get the current sidereal time.
/** Calculates LMST and returns it.
*
* \returns current value of LMST
*/
double st();
/// Get the current value of Right Ascension.
/** If nocalc==false and the telescope is not tracking, then RA is re-calculated for the current time, az, and el.
*
* \returns the current value of m_ra.
*/
double ra(bool nocalc = false /**< [in] [optional] flag to control whether the RA is recalculated.*/);
/// Set the current value of Right Ascension.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int ra(double ra /**< [in] the new value of Right Ascension*/);
/// Get the current value of Declination.
/** If nocalc==false and the telescope is not tracking, then Dec is re-calculated for the current time, az, and el.
*
* \returns the current value of m_dec.
*/
double dec(bool nocalc = false /**< [in] [optional] flag to control whether the Dec is recalculated.*/);
/// Set the current value of Declination.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int dec(double d /**< [in] the new value of Declination*/);
/// Get the current value of next_ra
/**
* \returns the current value of m_next_ra.
*/
double next_ra();
/// Set the value of next_ra.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int next_ra(double r /**< [in] the new value of next_ra*/);
/// Get the current value of next_dec
/**
* \returns the current value of m_next_dec.
*/
double next_dec();
/// Set the value of next_dec.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int next_dec(double d /**< [in] the new value of next_dec*/);
/// Get the current value of off_ra
/**
* \returns the current value of m_off_ra.
*/
double off_ra();
/// Set the value of next_ra.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int off_ra(double r /**< [in] the new value of off_ra */);
/// Get the current value of off_dec
/**
* \returns the current value of m_off_dec.
*/
double off_dec();
/// Set the value of next_dec.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int off_dec(double d /**< [in] the new value of off_dec */);
/// Get the current value of azimuth
/** The nocalc flag determines whether azimuth is updated based on simulation tracking.
*
* \returns the current value of m_az.
*/
double az( bool nocalc = false /**< [in] [optional] flag to control whether the azimuth is recalculated.*/);
/// Set the value of azimuth.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int az(double a /**< [in] the new value of azimuth*/);
/// Get the current value of elevation
/** The nocalc flag determines whether elevation is updated based on simulation tracking.
*
* \returns the current value of m_el.
*/
double el( bool nocalc = false /**< [in] [optional] flag to control whether the elevation is recalculated.*/);
/// Set the value of elevaton.
/**
* \returns 0 on success.
* \returns -1 on error.
*/
int el( double e /**< [in] the new value of elevation*/);
int set_ra_dec(double nra,
double ndec);
int set_az_el(double naz,
double nel);
double get_ha(bool nocalc = false);
double get_next_ha();
double get_epoch(); // = 2000.00
double get_airmass(); // = 1.000
double get_zd(); // = 0.040398
double get_pa();
double get_next_pa();
double get_wxtemp();
double get_wxpres();
double get_wxhumid();
double get_wxwind();
double get_wxdir();
int get_telfocus(){return m_telfocus;} //= 001725
int get_telz(){return get_telfocus();}
void set_telfocus(int tf);
int get_telx(){return m_telx;}
void set_telx(int tx /**< [in] the new value of */);
int get_tely(){return m_tely;}
void set_tely(int ty /**< [in] the new value of */);
double get_telh(){return m_telh;}
void set_telh(double th /**< [in] the new value of */);
double get_telv(){return m_telv;}
void set_telv(double tv /**< [in] the new value of */);
/*int get_secx(){return secx;}
void set_secx(int sx);
int get_secy(){return secy;}
void set_secy(int sy);*/
int get_roi(){return m_roi;}
double get_rotangle(); //returns the current rotator angle, relative to N
double get_rotenc(); //returns the current rotator encoder angle.
double get_next_rotangle(){return m_next_rotangle;}
int set_next_rotangle(double nr /**< [in] the new value of */);
//Calculates current azimuth and elevation given sidereal time, RA, and Dec.
//Reference: J. Meeus "Astronomical Algorithms", 1991.
int calc_az_el(bool nocalc = false);
int calc_m_next_az_el();
double get_next_az(){return m_next_az;}
double get_next_el(){return m_next_el;}
//Calculates current RA and DEC, given Az, El, and sidereal time.
//Reference: J. Meeus "Astronomical Algorithms", 1991.
int calc_ra_dec(bool nocalc = false);
//Simulation control.
int start_simulating();
int stop_simulating();
int get_simulating() {return m_simulating;}
int reset_simulation();
//Tracking in RA and DEC
int start_tracking();
int stop_tracking();
int get_tracking() {return m_tracking;}
//Guiding
int start_guiding();
int stop_guiding();
int get_guiding() {return m_guiding;}
//Rotator following
int start_following();
int stop_following();
int get_rotmode() {return m_rotmode;}
//Slewing
int start_slew();
int stop_slew();
int offset_slew(int dir);
int slew_az_el();
int slew_az();
int slew_el();
int get_slewing() {return (m_slewing);}
//Rotator moves
int start_rotmove();
int move_rot();
int stop_rotmove();
int get_rotslewing(){ return m_rotslewing;}
//Dome
int get_dome_stat();
int close_dome();
int open_dome();
//Interface
/// The main entry point for command/request processing.
/** Processes inpstr and calls the appropriate function.
* - if there is a space and inpstr begins with "tcssim" then simulator commands are processed.
* - otherwise, if there is a space process_command is called.
* - otherwise, get_status is called.
*
* \returns 0 on success
* \returns -1 on error
*
*/
int process_string( std::string inpstr, ///< [in] The input string to process.
FILE *fp, ///< [in] The FILE to which to write the response
bool statonly ///< [in] Set to true if this is input from a status-only port
);
int process_command(char *response, std::string inpstr);
/// Process a status request and create the response.
/**
* \returns 0 on success
* \returns -1 on error
*/
int get_status( char *status, ///< [out] Buffer to hold the status message
int statlen, ///< [in] The length of the status buffer
char *cmd_str ///< [in[ The command string to interpret as a status request.
);
int do_command(int cmd_N, std::vector<std::string> args);
std::list<std::string> lastcom;
std::list<double> lastcom_time;
std::list<std::string> lastresp;
int set_tgtname(std::string tn);
int set_cat_ra(double cra);
int set_cat_dc(double cdc);
int set_cat_ep(double cep);
int set_cat_ro(double cro);
int set_cat_rm(int crm);
};
inline
magtelescope::magtelescope()
{
loadCommands();
char logname[200];
time_t tl;
tl = time(0);
strftime(logname, 200, "logs/magtel_%m%d%Y%H%M%S.log", localtime(&tl));
tellog(0, 0, 0, "magtelescope", logname);
TELLOG("Initialized.");
for(int i=0;i<10;i++)
{
lastcom.push_back("");
lastcom_time.push_back(-1);
lastresp.push_back("");
}
pthread_mutex_init(&logmutex, 0);
pthread_mutex_init(&comMutex, 0);
srand(time(0));
}
inline
void magtelescope::loadCommands()
{
commands.clear();
commands[DATEOBS]= DATEOBS_N;
commands[UT]= UT_N;
commands[ST]= ST_N;
commands[RA]= RA_N;
commands[DEC]= DEC_N;
commands[EPOCH]= EPOCH_N;
commands[HA]= HA_N;
commands[AIRMASS]= AIRMASS_N;
commands[ZD]= ZD_N;
commands[TELFOCUS]= TELFOCUS_N;
commands[ROTANGLE]= ROTANGLE_N;
commands[TELRA]= TELRA_N;
commands[TELDC]= TELDC_N;
commands[TELEP]= TELEP_N;
commands[TELFC]= TELFC_N;
commands[VEXSET]= VEXSET_N;
commands[VEYSET]= VEYSET_N;
commands[VEZSET]= VEZSET_N;
commands[VEHSET]= VEHSET_N;
commands[VEVSET]= VEVSET_N;
commands[VEXENC]= VEXENC_N;
commands[VEYENC]= VEYENC_N;
commands[VEZENC]= VEZENC_N;
commands[VEHENC]= VEHENC_N;
commands[VEVENC]= VEVENC_N;
commands[VEDATA]= VEDATA_N;
commands[TELUT]= TELUT_N;
commands[TELST]= TELST_N;
commands[TELAM]= TELAM_N;
commands[TELPA]= TELPA_N;
commands[TELHA]= TELHA_N;
commands[TELDM]= TELDM_N;
commands[DMSTAT]= DMSTAT_N;
commands[TELGUIDE]= TELGUIDE_N;
commands[GDRMOUNTMV]= GDRMOUNTMV_N;
commands[DATETIME]= DATETIME_N;
commands[TELPOS]= TELPOS_N;
commands[TELDATA]= TELDATA_N;
commands[TELAZ]= TELAZ_N;
commands[TELEL]= TELEL_N;
commands[INPHA]= INPHA_N;
commands[INPRA]= INPRA_N;
commands[INPDC]= INPDC_N;
commands[INPEP]= INPEP_N;
commands[INPAZ]= INPAZ_N;
commands[INPEL]= INPEL_N;
commands[INPPA]= INPPA_N;
commands[PANGLE]= PANGLE_N;
commands[EANGLE]= EANGLE_N;
commands[GANGLE]= GANGLE_N;
commands[NANGLE]= NANGLE_N;
commands[HANGLE]= HANGLE_N;
commands[FANGLE]= FANGLE_N;
commands[ROTOFH]= ROTOFH_N;
commands[NROTOFF]= NROTOFF_N;
commands[TELROI]= TELROI_N;
commands[ROTATORE]= ROTATORE_N;
commands[P1FILT]= P1FILT_N;
commands[P1MASK]= P1MASK_N;
commands[GUIDERX1]= GUIDERX1_N;
commands[GUIDERY1]= GUIDERY1_N;
commands[P2FILT]= P2FILT_N;
commands[P2MASK]= P2MASK_N;
commands[GUIDERX2]= GUIDERX2_N;
commands[GUIDERY2]= GUIDERY2_N;
commands[P3FILT]= P3FILT_N;
commands[P3MASK]= P3MASK_N;
commands[GUIDERX3]= GUIDERX3_N;
commands[GUIDERY3]= GUIDERY3_N;
commands[C1CUR]= C1CUR_N;
commands[C2CUR]= C2CUR_N;
commands[C3CUR]= C3CUR_N;
commands[C1XY2]= C1XY2_N;
commands[C2XY2]= C2XY2_N;
commands[C3XY2]= C3XY2_N;
commands[C1XY3]= C1XY3_N;
commands[C2XY3]= C2XY3_N;
commands[C3XY3]= C3XY3_N;
commands[C1XY4]= C1XY4_N;
commands[C2XY4]= C2XY4_N;
commands[C3XY4]= C3XY4_N;
commands[C1BOX]= C1BOX_N;
commands[C2BOX]= C2BOX_N;
commands[C3BOX]= C3BOX_N;
commands[CA1]= CA1_N;
commands[CA2]= CA2_N;
commands[CA3]= CA3_N;
commands[WXTEMP]= WXTEMP_N;
commands[WXPRES]= WXPRES_N;
commands[WXHUMID]= WXHUMID_N;
commands[WXWIND]= WXWIND_N;
commands[WXDIR]= WXDIR_N;
commands[TELENV]= TELENV_N;
commands[OFRA]= OFRA_N;
commands[OFDC]= OFDC_N;
commands[OFEP]= OFEP_N;
commands[OFFP]= OFFP_N;
commands[OFFM]= OFFM_N;
commands[DR]= DR_N;
commands[AEG]= AEG_N;
commands[ZSET]= ZSET_N;
commands[ZSTR]= ZSTR_N;
commands[XSET]= XSET_N;
commands[XSTR]= XSTR_N;
commands[YSET]= YSET_N;
commands[YSTR]= YSTR_N;
commands[SLEW]= SLEW_N;
commands[HALT]= HALT_N;
commands[RO]= RO_N;
commands[NRO]= NRO_N;
commands[ROTMODE]= ROTMODE_N;
commands[CATRA]= CATRA_N;
commands[CATDC]= CATDC_N;
commands[CATEP]= CATEP_N;
commands[CATRO]= CATRO_N;
commands[CATRM]= CATRM_N;
commands[CATOBJ]= CATOBJ_N;
commands[CATDATA]= CATDATA_N;
}
inline
void magtelescope::set_typval()
{
dateobsNow();
m_ra = st();
m_dec = lat();
m_next_ra = m_ra;
m_next_dec = m_dec;
mx::astro::calcAzEl(m_az, m_el, st()-m_ra, m_dec, m_lat);
TELLOG("Set typical values.");
}
inline
double magtelescope::lat()
{
return m_lat;
}
inline
double magtelescope::lon()
{
return m_lon;
}
inline
int magtelescope::dateobsNow()
{
time_t rawtime;
time(&rawtime);
struct tm * uttm = gmtime (&rawtime);
int dobs[3];
m_dateobs[0] = 1900+uttm->tm_year;
m_dateobs[1] = uttm->tm_mon+1;
m_dateobs[2] = 1 + uttm->tm_mday;
return 0;
}
inline
void magtelescope::dateobs(int dobs[3])
{
dateobsNow();
for(int i=0;i<3;i++) dobs[i] = m_dateobs[i];
}
inline
double magtelescope::ut()
{
time_t rawtime;
time(&rawtime);
struct tm * uttm = gmtime (&rawtime);
m_ut = uttm->tm_hour + uttm->tm_min/60.0 + uttm->tm_sec/3600.0;
return m_ut;
}
inline
double magtelescope::st()
{
double LMST;
int dobs[3];
dateobs(dobs);
mx::astro::getLMST(LMST, dobs[0],dobs[1], ((double) dobs[2]) +(ut()/24.0), lon());
return LMST;
}
inline
double magtelescope::ra(bool nocalc)
{
if(!m_tracking && !nocalc) calc_ra_dec();
return m_ra;
}
inline
int magtelescope::ra(double r)
{
m_ra = r;
calc_az_el(true);
snprintf(lmsg, lmsg_size, "Set ra: %f", r);
TELLOG(lmsg);
return 0;
}
inline
int magtelescope::dec(double d)
{
m_dec = d;
calc_az_el(true);
snprintf(lmsg, lmsg_size, "Set dec: %f", d);
TELLOG(lmsg);
return 0;
}
inline
double magtelescope::dec(bool nocalc)
{
if(!m_tracking && !nocalc) calc_ra_dec();
return m_dec;
}
inline
double magtelescope::next_ra()
{
return m_next_ra;
}
inline
int magtelescope::next_ra(double r)
{
m_next_ra = r;
calc_m_next_az_el();
snprintf(lmsg, lmsg_size, "Set next ra: %f", r);
TELLOG(lmsg);
return 0;
}
inline
double magtelescope::next_dec()
{
return m_next_dec;
}
inline
int magtelescope::next_dec(double d)
{
m_next_dec = d;
calc_m_next_az_el();
snprintf(lmsg, lmsg_size, "Set next dec: %f", d);
TELLOG(lmsg);
return 0;
}
inline
double magtelescope::off_ra()
{
return m_off_ra;
}
inline
int magtelescope::off_ra(double r)
{
m_off_ra = r;
snprintf(lmsg, lmsg_size, "Set ra offset: %f", r);
TELLOG(lmsg);
return 0;
}
inline
double magtelescope::off_dec()
{
return m_off_dec;
}
inline
int magtelescope::off_dec(double d)
{
m_off_dec = d;
snprintf(lmsg, lmsg_size, "Set dec offset: %f", d);
TELLOG(lmsg);
return 0;
}
inline
double magtelescope::az(bool nocalc)
{
if(m_tracking && !nocalc && !m_slewing)
{
calc_az_el();
}
else if(m_slewing && !nocalc)
{
slew_az_el();
}
return m_az;
}
inline
int magtelescope::az(double a)
{
m_az = a;
calc_ra_dec(true);
snprintf(lmsg, lmsg_size, "Set az: %f", a);
TELLOG(lmsg);
return 0;
}
inline
double magtelescope::el(bool nocalc)
{
if(m_tracking && !nocalc && !m_slewing)
{
calc_az_el();
}
else if(m_slewing && !nocalc)
{
slew_az_el();
}
return m_el;
}
inline
int magtelescope::el(double e)
{
m_el = e;
calc_ra_dec(true);
snprintf(lmsg, lmsg_size, "Set el: %f", e);
TELLOG(lmsg);
return 0;
}
inline
int magtelescope::set_ra_dec(double nra, double ndec)
{
m_ra = nra;
m_dec = ndec;
return calc_az_el(true);
}
inline
double magtelescope::get_ha(bool nocalc)
{
double ha;
ha = fmod(st()-ra(nocalc), 24.0);
if(ha < 0.0) ha += 24.0;
return ha;
}
inline
double magtelescope::get_next_ha()
{
double nha;
nha = fmod(st()-next_ra(), 24.0);
if(nha < 0.0) nha += 24.0;
return nha;
}
inline
double magtelescope::get_epoch()
{
return m_epoch;
}
inline
double magtelescope::get_airmass()
{
return 1./cos(get_zd()*3.14159/180.);
}
inline
double magtelescope::get_zd()
{
return 90.0 - el();
}
inline
double magtelescope::get_pa()
{
return mx::astro::parAngDeg( -get_ha()/24.*360., dec(), m_lat, true); //true is a dummy argument, will be removed in the future
}
inline
double magtelescope::get_next_pa()
{
return mx::astro::parAngDeg( -get_next_ha()/24.*360., next_dec(), m_lat, true); //true is a dummy argument, will be removed in the future
}
inline
double magtelescope::get_wxtemp()
{
return 18. + (.25 - ((double)rand())/((double)RAND_MAX)*.5);
}
inline
double magtelescope::get_wxpres()
{
return 760. + (5. - ((double)rand())/((double)RAND_MAX)*10.);;
}
inline
double magtelescope::get_wxhumid()
{
return 31. + (1. - ((double)rand())/((double)RAND_MAX)*2.);;
}
inline
double magtelescope::get_wxwind()
{
return 10. + + (5. - ((double)rand())/((double)RAND_MAX)*10.);;
}
inline
double magtelescope::get_wxdir()
{
return 90.+ (35. - ((double)rand())/((double)RAND_MAX)*70.);;
}
inline
void magtelescope::set_telfocus(int tf)
{
m_telfocus = tf;
snprintf(lmsg, lmsg_size, "Set telfocus: %i", tf);
TELLOG(lmsg);
}
inline
void magtelescope::set_telx(int tx)
{
m_telx = tx;
snprintf(lmsg, lmsg_size, "Set telx: %i", tx);
TELLOG(lmsg);
}
inline
void magtelescope::set_tely(int ty)
{
m_tely = ty;
snprintf(lmsg, lmsg_size, "Set tely: %i", ty);
TELLOG(lmsg);
}
inline
void magtelescope::set_telh(double th)
{
m_telh = th;
snprintf(lmsg, lmsg_size, "Set telh: %f", th);
TELLOG(lmsg);
}
inline
void magtelescope::set_telv(double tv)
{
m_telv = tv;
snprintf(lmsg, lmsg_size, "Set telv: %f", tv);
TELLOG(lmsg);
}