-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit1.cpp
More file actions
975 lines (843 loc) · 31.6 KB
/
Copy pathUnit1.cpp
File metadata and controls
975 lines (843 loc) · 31.6 KB
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
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#include <inifiles.hpp>
#include <stdio.h>
#pragma hdrstop
#include "Unit1.h"
#include "aboutbox.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "AdPort"
#pragma link "AdWnPort"
#pragma link "OoMisc"
#pragma link "AdPort"
#pragma link "AdWnPort"
#pragma link "OoMisc"
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
/* packages needed:
VCL50.BPL
A303_R35.BPL
A303_R51.BPL
VCLX50.BPL
*/
/* TKSolver formulas
á1= HMStoD(á1H, á1M, á1S)
Deg=Hours*15+Mins*15/60+Secs*15/3600
ä1= DMStoD(ä1D, ä1M, ä1S)
Deg=(((Secs/60)+Mins)/60)+Degs
DtoHMS
Hours=Int(Deg/15)
Mins= int(((Deg/15)-Hours)*60)
Secs= ( (Deg/15)-(Hours+Mins/60))*3600
DtoDMS
Degs=int(Deg)
Mins=int((Deg-Degs)*60)
Secs=(Deg-(Degs+Mins/60))*3600
det= cosd(Ö)*(tand(ä1) + tand(ä2))*(1-cosd(h1-h2))
RAratio= Äá/Äa
DECratio= Ää/Äe
h1= á1 - LST
h2= á2 - LST
Äá= Äe*(tand(ä2)*sind(h2) - tand(ä1)*sind(h1)) + Äa*cosd(Ö)*(tand(ä1)*cosd(h1) - tand(ä2)*cosd(h2))
Ää= Äe*(cosd(h2)-cosd(h1)) + Äa*cosd(Ö)*(sind(h2)-sind(h1))
Äe= Äá*cosd(Ö)*(sind(h2)-sind(h1))/det - Ää*cosd(Ö)*(tand(ä1)*cosd(h1)-tand(ä2)*cosd(h2))/det
Äa= Äá*(cosd(h1)-cosd(h2))/det + Ää*(tand(ä2)*sind(h2)-tand(ä1)*sind(h1))/det
variables:
Status Input Name Output Unit Comment
3 á1H
0 á1M
0 á1S
á1 45 deg Right Ascension star 1
h1 45 deg Hour Angle star 1
45 ä1D 0 ä1M
0 ä1S
ä1 45 deg Declination star 1
0 á2H
0 á2M
0 á2S
á2 0 deg Right Ascension star 2
h2 0 deg Hour Angle star 2
45 ä2D
0 ä2M
0 ä2S
ä2 45 deg Declination star 2
45 Ö deg Site Latitude
0 LST deg Local Sidereal Time
L 100 Äá min_arc Error in Right Ascension
100 Ää min_arc Error in Declination
L Äe -70.710678 min_arc Alignment error in elevation (altitude)
L Äa -241.42136 min_arc Alignment error in azimuth
det .414213562
RAratio -.41421356
DECratio -1.4142136
*/
void __fastcall TForm1::NumericOnKeyPress(TObject *Sender, char &Key)
{
if (! ((Key >= '0' && Key <= '9') || Key == '-' || Key == '.' || Key == '\b'))
Key = 0 ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NumericOnExit(TObject *Sender)
{
TEdit *p;
float c;
if((p=dynamic_cast<TEdit*>(Sender))==NULL) return;
try {
p->Text= FloatToStr(StrToFloat(p->Text));
} catch (EConvertError &error) {
p->Text= FloatToStr(0); // stuff zero on error
}
}
//---------------------------------------------------------------------------
struct DMS{
double deg;// degrees
double r; // radians
double D; // deg
double M; // arc min
double S; // arc sec
};
struct HMS{
double deg;
double r; // radians
double H; // hrs
double M; // min
double S; // seconds
};
/* These structures hold 3 versions of angular measurements. If you change one
version, call one of the functions below to update the alternate forms.
*/
HMS S1R; // star 1 Right Ascension
DMS S1D; // star 1 declination
HMS S1H; // star 1 Hour Angle
HMS S2R; // star 2 Right Ascension
DMS S2D; // star 2 declination
HMS S2H; // star 2 Hour Angle
HMS S2oR; // star 2 observed Right Ascension
DMS S2oD; // star 2 observed declination
DMS Lat; // mount's Latitude
// not necessary DMS Long; // mount's Longitude
HMS LST; // local sidereal time (at star 2's observation point)
DMS errD; // declination error observed at star 2
DMS errR; // Right Acension error observed at star 2
DMS errE; // mount's estimated elevation error
DMS errA; // mount's estimated azimuth error
/* the xMStoD functions are tricky because of the signs. If the lower elements,
(M and S below D or H) have a different sign from the lead (non-zero) element,
their sign is taken as relative to the lead sign. So, you can enter -7deg, -30min
which is -6.5deg and is properly re-expressed as -6deg, 30min.
*/
void _fastcall DtoDMS(DMS *x) {
int s= 1; long r;
if(x->deg>180.0) x->deg-= 360.0; // DMS runs 180 to -180;
long tsecs= floor(0.5+x->deg*36000.0); // work with a copy in tenths of an arcsec
if(tsecs<0) { s= -1; tsecs*= s; } // get sign and shift to postive
r= tsecs % 36000; x->D= (tsecs-r)/36000.0; tsecs= r;
r= tsecs % 600; x->M= (tsecs-r)/600.0;
// x->S= r/10;
x->S= ((s*x->deg)-(x->D+x->M/60.0))*3600.0;
if(x->D) x->D*= s; // apply overall sign
else if(x->M) x->M*= s;
else x->S*=s;
x->r= x->deg * M_PI/180.0; // make sure radians are uptodate
}
void _fastcall DMStoD(DMS *x) {
int s; // sign
DMS xx= *x; // work with a copy
if(xx.D) { // extract the sign and go positive
s= (xx.D<0)?-1:1, xx.D*= s; // use D's sign
} else { // D is zero
if(xx.M) s= (xx.M<0)?-1:1, xx.M*= s; // or M's
else s= (xx.S<0)?-1:1, xx.S*= s; // or S's
}
x->deg= s*((((xx.S/60.0) + xx.M)/60.0) + xx.D);
while(x->deg > 360) x->deg-= 360.0;
while(x->deg < 0) x->deg+= 360.0;
x->r= x->deg * M_PI/180.0; // radians
DtoDMS(x); // reset the DMS
}
void _fastcall DtoHMS(HMS * x) { // set .HMS from .deg
int s= 1; long r;
long tsecs= floor(0.5+x->deg*2400.0); // work with a copy in tenths of a sec
if(tsecs<0) { s= -1; tsecs*= s; } // get sign and shift to postive
r= tsecs % 36000; x->H= (tsecs-r)/36000.0; tsecs= r;
r= tsecs % 600; x->M= (tsecs-r)/600.0;
// x->S= r/10;
x->S= ((s*x->deg/15)-(x->H+x->M/60))*3600.0; // all the rest
if(x->H) x->H*= s; // apply overall sign
else if(x->M) x->M*= s;
else x->S*=s;
x->r= x->deg * M_PI/180.0; // make sure radians are uptodate
}
void _fastcall HMStoD(HMS * x) {
int s; // sign
HMS xx= *x;
if(xx.H) { // extract the sign
s= (xx.H<0)?-1:1, xx.H*= s; // use H's sign
} else { // H is zero
if(xx.M) s= (xx.M<0)?-1:1, xx.M*= s; // or M's
else s= (xx.S<0)?-1:1, xx.S*= s; // or S's
}
x->deg= s*15*((((xx.S/60.0)+xx.M)/60.0)+xx.H);
while(x->deg > 360) x->deg-= 360.0;
while(x->deg < 0) x->deg+= 360.0;
x->r= x->deg*M_PI/180.0; // radians
DtoHMS(x); // reset the HMS
}
void _fastcall Transform(HMS *HA, DMS *DEC, HMS *AZ, DMS *ALT, DMS *LAT)
{ // Convert the first pair into the other. You can go RA/DEC to AZ/ALT or vice versa
ALT->r= asin( sin(DEC->r) * sin(LAT->r) +
cos(DEC->r) * cos(LAT->r) * cos(HA->r));
AZ->r= acos( (sin(DEC->r) - sin(ALT->r) * sin(LAT->r)) /
( cos(ALT->r) * cos(LAT->r) ) );
ALT->deg= ALT->r * 180.0/M_PI;
AZ->deg= AZ->r * 180.0/M_PI;
if(sin(HA->deg)> 0) AZ->deg= 360.0 - AZ->deg;
DtoDMS(ALT);
DtoHMS(AZ);
}
//---------------------------------------------------------------------------
int Star1no= 0, Star2no= 0;
bool ECUavail= false;
FILE *in;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// look for star name file
if((in = fopen("LX334STR.ECU", "rt")) != NULL) {
ECUavail= true;
fclose(in);
} else { // if not supported, don't show
Star1Num->Visible= false;
Star1Name->Visible= false;
Star2Num->Visible= false;
Star2Name->Visible= false;
}
// open and collect ini data
TIniFile *ini;
ini = new TIniFile(ChangeFileExt( Application->ExeName, ".INI" ) );
S1D.deg= ini->ReadFloat( "Star1", "Dec", 0.0 );
DtoDMS(&S1D);
S1DD->Text= FloatToStrF(S1D.D,ffFixed, 15,0);
S1DM->Text= FloatToStrF(S1D.M,ffFixed, 15,0);
S1DS->Text= FloatToStrF(S1D.S,ffFixed, 15,1);
S1R.deg= ini->ReadFloat( "Star1", "RA", 0.0 );
DtoHMS(&S1R);
S1RH->Text= FloatToStrF(S1R.H,ffFixed, 15,0);
S1RM->Text= FloatToStrF(S1R.M,ffFixed, 15,0);
S1RS->Text= FloatToStrF(S1R.S,ffFixed, 15,1);
Star1no= ini->ReadInteger( "Star1", "Number", 0);
Star1Num->Text= Star1no;
Star1NumExit(Owner);
S2D.deg= ini->ReadFloat( "Star2", "Dec", 0.0 );
DtoDMS(&S2D);
S2DD->Text= FloatToStrF(S2D.D,ffFixed, 15,0);
S2DM->Text= FloatToStrF(S2D.M,ffFixed, 15,0);
S2DS->Text= FloatToStrF(S2D.S,ffFixed, 15,1);
S2R.deg= ini->ReadFloat( "Star2", "RA", 0.0 );
DtoHMS(&S2R);
S2RH->Text= FloatToStrF(S2R.H,ffFixed, 15,0);
S2RM->Text= FloatToStrF(S2R.M,ffFixed, 15,0);
S2RS->Text= FloatToStrF(S2R.S,ffFixed, 15,1);
Star2no= ini->ReadInteger( "Star2", "Number", 0);
Star2Num->Text= Star2no;
Star2NumExit(Owner);
Lat.deg= ini->ReadFloat( "Location", "Lat", 0.0);
DtoDMS(&Lat);
LatD->Text= FloatToStrF(Lat.D,ffFixed, 15,0);
LatM->Text= FloatToStrF(Lat.M,ffFixed, 15,0);
LatS->Text= FloatToStrF(Lat.S,ffFixed, 15,1);
RAMinError->Text= FloatToStrF(ini->ReadFloat("test errors", "RA", 100.0), ffFixed, 15,0);
DecMinError->Text= FloatToStrF(ini->ReadFloat("test errors", "Dec", 100.0), ffFixed, 15,0);
TestMode->Checked= ini->ReadBool("Setup", "testmode", true);
if(!TestMode->Checked) {
ApdPort1->ComNumber= ini->ReadInteger("Setup", "comport", 0);
}
SlewErrorGrp->Visible= TestMode->Checked;
delete ini;
Application->HelpFile= "PAlign2.hlp";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
ApdPort1->Open= false;
TIniFile *ini;
ini = new TIniFile(ChangeFileExt( Application->ExeName, ".INI" ) );
ini->WriteInteger( "Star1", "Number", Star1no);
ini->WriteFloat( "Star1", "Dec", S1D.deg);
ini->WriteFloat( "Star1", "RA", S1R.deg);
ini->WriteInteger( "Star2", "Number", Star2no);
ini->WriteFloat( "Star2", "Dec", S2D.deg);
ini->WriteFloat( "Star2", "RA", S2R.deg);
ini->WriteFloat( "Location", "Lat", Lat.deg);
ini->WriteBool("setup", "testmode", TestMode->Checked);
ini->WriteInteger("Setup", "comport", ApdPort1->ComNumber);
ini->WriteFloat("test errors", "RA", RAMinError->Text.ToDouble());
ini->WriteFloat("test errors", "Dec", DecMinError->Text.ToDouble());
delete ini;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Star1GrpExit(TObject *Sender)
{
S1R.H= S1RH->Text.ToDouble();
S1R.M= S1RM->Text.ToDouble();
S1R.S= S1RS->Text.ToDouble();
HMStoD(&S1R);
S1RH->Text= FloatToStrF(S1R.H,ffFixed, 15,0);
S1RM->Text= FloatToStrF(S1R.M,ffFixed, 15,0);
S1RS->Text= FloatToStrF(S1R.S,ffFixed, 15,1);
S1D.D= S1DD->Text.ToDouble();
S1D.M= S1DM->Text.ToDouble();
S1D.S= S1DS->Text.ToDouble();
DMStoD(&S1D);
S1DD->Text= FloatToStrF(S1D.D,ffFixed, 15,0);
S1DM->Text= FloatToStrF(S1D.M,ffFixed, 15,0);
S1DS->Text= FloatToStrF(S1D.S,ffFixed, 15,1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Star2GrpExit(TObject *Sender)
{
S2R.H= S2RH->Text.ToDouble();
S2R.M= S2RM->Text.ToDouble();
S2R.S= S2RS->Text.ToDouble();
HMStoD(&S2R);
S2RH->Text= FloatToStrF(S2R.H,ffFixed, 15,0);
S2RM->Text= FloatToStrF(S2R.M,ffFixed, 15,0);
S2RS->Text= FloatToStrF(S2R.S,ffFixed, 15,1);
S2D.D= S2DD->Text.ToDouble();
S2D.M= S2DM->Text.ToDouble();
S2D.S= S2DS->Text.ToDouble();
DMStoD(&S2D);
S2DD->Text= FloatToStrF(S2D.D,ffFixed, 15,0);
S2DM->Text= FloatToStrF(S2D.M,ffFixed, 15,0);
S2DS->Text= FloatToStrF(S2D.S,ffFixed, 15,1);
Edit1->Text= FloatToStrF(S2R.deg, ffFixed, 15,8);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LocationGrpExit(TObject *Sender)
{
Lat.D= LatD->Text.ToDouble();
Lat.M= LatM->Text.ToDouble();
Lat.S= LatS->Text.ToDouble();
DMStoD(&Lat);
LatD->Text= FloatToStrF(Lat.D,ffFixed, 15,0);
LatM->Text= FloatToStrF(Lat.M,ffFixed, 15,0);
LatS->Text= FloatToStrF(Lat.S,ffFixed, 15,1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ObsPanelExit(TObject *Sender) // panel
{
errD.D= errDD->Text.ToDouble();
errD.M= errDM->Text.ToDouble();
errD.S= errDS->Text.ToDouble();
DMStoD(&errD);
errDD->Text= FloatToStrF(errD.D,ffFixed, 15,0);
errDM->Text= FloatToStrF(errD.M,ffFixed, 15,0);
errDS->Text= FloatToStrF(errD.S,ffFixed, 15,1);
errDD->Hint= errD.deg; errDM->Hint= errD.deg*60; errDS->Hint= errD.deg*3600;
errR.D= errRD->Text.ToDouble();
errR.M= errRM->Text.ToDouble();
errR.S= errRS->Text.ToDouble();
DMStoD(&errR);
errRD->Text= FloatToStrF(errR.D,ffFixed, 15,0);
errRM->Text= FloatToStrF(errR.M,ffFixed, 15,0);
errRS->Text= FloatToStrF(errR.S,ffFixed, 15,1);
errRD->Hint= errR.deg; errRM->Hint= errR.deg*60; errRS->Hint= errR.deg*3600;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LSTPanelExit(TObject *Sender)
{
LST.H= LSTH->Text.ToDouble();
LST.M= LSTM->Text.ToDouble();
LST.S= LSTS->Text.ToDouble();
HMStoD(&LST);
LSTH->Text= FloatToStrF(LST.H,ffFixed, 15,0);
LSTM->Text= FloatToStrF(LST.M,ffFixed, 15,0);
LSTS->Text= FloatToStrF(LST.S,ffFixed, 15,1);
}
//---------------------------------------------------------------------------
// goto Star 1
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// set star1 position
char s[100], t[100];
// get site latitude
// "Gt#", ret "sDD*MM#" for Lat
SendRcv(":Gt#", s);
//Label6->Caption= s;
sscanf(s, "%lf\337%lf#", &Lat.D, &Lat.M); // nb \337 is octal for ascii 223
// which is used for degrees
Lat.S= 0;
DMStoD(&Lat);
LatD->Text= FloatToStrF(Lat.D,ffFixed, 15,0);
LatM->Text= FloatToStrF(Lat.M,ffFixed, 15,0);
LatS->Text= FloatToStrF(Lat.S,ffFixed, 15,1);
/*
// "Gg#", ret "DDD\337MM#" for Long
SendRcv(":Gg#", s);
//Label10->Caption= s;
sscanf(s, "%lf\337%lf#", &Long.D, &Long.M);
Long.S= 0;
DMStoD(&Long);
LongD->Text= FloatToStrF(Long.D,ffFixed, 15,0);
LongM->Text= FloatToStrF(Long.M,ffFixed, 15,0);
LongS->Text= FloatToStrF(Long.S,ffFixed, 15,1);
*/
// confirm long format with "U#"; check return from GD
SendRcv(":GD#", s);
if(7==strlen(s)) SendRcv(":U#", NULL);
// load coord of star 1 and goto
// ":Sr HH:MM:SS#" ret "1"
sprintf(t, ":Sr %02.0lf:%02.0lf:%02.0lf#", S1R.H, S1R.M, S1R.S);
//Label10->Caption= t;
SendRcv(t, NULL);
//Label6->Caption= s;
// ":Sd sDD*MM:SS#" ret "1"
sprintf(t, ":Sd %+03.0lf\337%02.0lf:%02.0lf#", S1D.D, S1D.M, S1D.S);
SendRcv(t, NULL);
// goto the star 1
// setSTOPbutton(); // when do we know we're there? beep?
// ":MS#", ret "0" (if "1.." or 2..", can't reach it)
SendRcv(":MS#", NULL);
ActiveControl= Button2;
}
//---------------------------------------------------------------------------
// goto Star 2
void __fastcall TForm1::Button2Click(TObject *Sender)
{
char s[100], t[100];
// sync to 1, goto star2 position,
// ":Sr HH:MM:SS#" ret "1"
// ":Sd sDD*MM:SS#" ret "1"
// ":CM#", ret "Coordinates matched. #"
SendRcv(":CM#", s);
// load coord of star 2 and goto
// ":Sr HH:MM:SS#" ret "1"
sprintf(t, ":Sr %02.0lf:%02.0lf:%02.0lf#", S2R.H, S2R.M, S2R.S);
SendRcv(t, NULL);
// ":Sd sDD*MM:SS#" ret "1"
sprintf(t, ":Sd %+03.0lf\337%02.0lf:%02.0lf#", S2D.D, S2D.M, S2D.S);
SendRcv(t, NULL);
// goto the star 2
// setSTOPbutton(); // when do we know we're there? beep?
// ":MS#", ret "0" (if "1.." or 2..", can't reach it)
SendRcv(":MS#", NULL);
ActiveControl= Button3;
}
//---------------------------------------------------------------------------
double det;
// "Compute Error"
void __fastcall TForm1::Button3Click(TObject *Sender)
{
char s[100], t[100];
// get star 2 error, compute & display mount errors
// Get Right Acension ":GR#", ret "HH:MM:SS#" into S2oR
if(TestMode->Checked) {
S2oR= S2R;
S2oR.H+= RAMinError->Text.ToDouble() /(15.0*60.0); // introduce an error of 100 arc min
} else {
SendRcv(":GR#", s); //Label6->Caption= s;
sscanf(s, "%lf:%lf:%lf#", &S2oR.H, &S2oR.M, &S2oR.S);
}
HMStoD(&S2oR);
errR.deg= S2oR.deg - S2R.deg;
DtoDMS(&errR);
errRD->Text= FloatToStrF(errR.D,ffFixed, 15,0);
errRM->Text= FloatToStrF(errR.M,ffFixed, 15,0);
errRS->Text= FloatToStrF(errR.S,ffFixed, 15,1);
errRD->Hint= errR.deg; errRM->Hint= errR.deg*60; errRS->Hint= errR.deg*3600;
// Get Declination ":GD#", ret "sDD*MM:SS#" into S2oD
if(TestMode->Checked) {
S2oD= S2D;
S2oD.M+= DecMinError->Text.ToDouble(); // introduce an error 100 arc min
} else {
SendRcv(":GD#", s); //Label10->Caption= s;
sscanf(s, "%lf\337%lf:%lf#", &S2oD.D, &S2oD.M, &S2oD.S);
}
DMStoD(&S2oD);
errD.deg= S2oD.deg- S2D.deg;
DtoDMS(&errD);
errDD->Text= FloatToStrF(errD.D,ffFixed, 15,0);
errDM->Text= FloatToStrF(errD.M,ffFixed, 15,0);
errDS->Text= FloatToStrF(errD.S,ffFixed, 15,1);
errDD->Hint= errD.deg; errDM->Hint= errD.deg*60; errDS->Hint= errD.deg*3600;
// get LST; do average?
// Get Sideral Time ":GS#", ret "HH:MM:SS#"
if(TestMode->Checked) {
//LST= S2R;
} else {
SendRcv(":GS#", s);
sscanf(s, "%lf:%lf:%lf#", &LST.H, &LST.M, &LST.S);
}
HMStoD(&LST);
LSTH->Text= FloatToStrF(LST.H,ffFixed, 15,0);
LSTM->Text= FloatToStrF(LST.M,ffFixed, 15,0);
LSTS->Text= FloatToStrF(LST.S,ffFixed, 15,1);
// crank the formula
/*
HMS S1R; // star 1 Right Ascension
HMS S2R; // star 2 Right Ascension
HMS S1H; // star 1 Hour Angle
HMS S2H; // star 2 Hour Angle
DMS S1D; // star 1 declination
DMS S2D; // star 2 declination
DMS Lat; // mounts Latitude
HMS LST; // local sidereal time (at star 2's observation point)
DMS errD; // declination error observed at star 2
DMS errR; // Right Ascension error observed at star 2
DMS errE; // mount's estimated elevation error
DMS errA; // mount's estimated azimuth error
Äe= Äá*cosd(Ö)*(sind(h2)-sind(h1))/det - Ää*cosd(Ö)*(tand(ä1)*cosd(h1)-tand(ä2)*cosd(h2))/det
Äa= Äá*(cosd(h1)-cosd(h2))/det + Ää*(tand(ä2)*sind(h2)-tand(ä1)*sind(h1))/det
*/
S1H.r= S1R.r - LST.r;
S2H.r= S2R.r - LST.r;
det= cos(Lat.r)*(tan(S1D.r) + tan(S2D.r))*(1-cos(S1H.r-S2H.r));
detD->Text= FloatToStrF(det, ffFixed, 15,8);
if(det==0) {
ShowMessage("Determinant is Zero!");
return;
}
// elevation error
errE.deg= (errR.deg*cos(Lat.r)*(sin(S2H.r)-sin(S1H.r))/det)
- (errD.deg*cos(Lat.r)*(tan(S1D.r)*cos(S1H.r)-tan(S2D.r)*cos(S2H.r))/det);
DtoDMS(&errE);
Memo1->Lines->Add( errR.deg); //*cos(Lat.r) );
Memo1->Lines->Add( sin(S2H.r) -sin(S1H.r) );
Memo1->Lines->Add( errD.deg*cos(Lat.r)*(tan(S1D.r)*cos(S1H.r) ));
Memo1->Lines->Add( -tan(S2D.r)*cos(S2H.r) );
errED->Text= FloatToStrF(errE.D,ffFixed, 15,0);
errEM->Text= FloatToStrF(errE.M,ffFixed, 15,0);
errES->Text= FloatToStrF(errE.S,ffFixed, 15,1);
errED->Hint= errE.deg; errEM->Hint= errE.deg*60; errES->Hint= errE.deg*3600;
// azimuth error
errA.deg= (errR.deg*(cos(S1H.r)-cos(S2H.r))/det)
+ (errD.deg*(tan(S2D.r)*sin(S2H.r)-tan(S1D.r)*sin(S1H.r))/det);
Label6->Caption= FloatToStrF(errA.deg,ffFixed, 15, 4);
DtoDMS(&errA);
Label10->Caption= FloatToStrF(errA.deg,ffFixed, 15, 4);
errAD->Text= FloatToStrF(errA.D,ffFixed, 15,0);
errAM->Text= FloatToStrF(errA.M,ffFixed, 15,0);
errAS->Text= FloatToStrF(errA.S,ffFixed, 15,1);
errAD->Hint= errA.deg; errAM->Hint= errA.deg*60; errAS->Hint= errA.deg*3600;
//Label6->Caption= "22";
DecRatD->Text= FloatToStrF(errE.deg?(errD.deg/errE.deg):0, ffFixed, 15, 8);
RARatD->Text= FloatToStrF(errA.deg?(errR.deg/errA.deg):0, ffFixed, 15, 8);
ActiveControl= Button4;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
ShiftError(Sender, false);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
ShiftError(Sender, false);
}
//---------------------------------------------------------------------------
// Move scope so that shifting Azimuth until recentered, corrects the error
void __fastcall TForm1::ShiftError(TObject *Sender, boolean elevation)
{
// convert alt/az, add error, convert back, load and go
DMS ALT, tDEC; HMS AZ, tRA; char t[100];
Transform(&S2oR, &S2oD, &AZ, &ALT, &Lat);
if(elevation) ALT.deg+= errE.deg;
else AZ.deg+= errA.deg;
DtoDMS(&ALT); DtoHMS(&AZ);
Transform(&AZ, &ALT, &tRA, &tDEC, &Lat);
DtoHMS(&tRA); DtoDMS(&tDEC);
// load coord of star and goto
// ":Sr HH:MM:SS#" ret "1"
sprintf(t, ":Sr %02.0lf:%02.0lf:%02.0lf#", tRA.H, tRA.M, tRA.S);
if(TestMode->Checked) Label34->Caption= t;
else SendRcv(t, NULL);
// ":Sd sDD*MM:SS#" ret "1"
sprintf(t, ":Sd %+03.0lf\337%02.0lf:%02.0lf#", tDEC.D, tDEC.M, tDEC.S);
if(TestMode->Checked) Label35->Caption= t;
else SendRcv(t, NULL);
// goto the star 2
// ":MS#", ret "0" (if "1.." or 2..", can't reach it)
if(!TestMode->Checked)
SendRcv(":MS#", NULL);
//ActiveControl= Button3;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
// swap star 1 and star 2
HMS tempR; DMS tempD; int tempI;
tempD= S1D; S1D= S2D; S2D= tempD;
tempR= S1R; S1R= S2R; S2R= tempR;
tempI= Star1no; Star1no= Star2no; Star2no= tempI;
S1DD->Text= FloatToStrF(S1D.D,ffFixed, 15,0);
S1DM->Text= FloatToStrF(S1D.M,ffFixed, 15,0);
S1DS->Text= FloatToStrF(S1D.S,ffFixed, 15,1);
S1RH->Text= FloatToStrF(S1R.H,ffFixed, 15,0);
S1RM->Text= FloatToStrF(S1R.M,ffFixed, 15,0);
S1RS->Text= FloatToStrF(S1R.S,ffFixed, 15,1);
Star1Num->Text= Star1no;
Star1NumExit(Owner);
S2DD->Text= FloatToStrF(S2D.D,ffFixed, 15,0);
S2DM->Text= FloatToStrF(S2D.M,ffFixed, 15,0);
S2DS->Text= FloatToStrF(S2D.S,ffFixed, 15,1);
S2RH->Text= FloatToStrF(S2R.H,ffFixed, 15,0);
S2RM->Text= FloatToStrF(S2R.M,ffFixed, 15,0);
S2RS->Text= FloatToStrF(S2R.S,ffFixed, 15,1);
Star2Num->Text= Star2no;
Star2NumExit(Owner);
DecMinError->Text= - DecMinError->Text.ToDouble();
RAMinError->Text= - RAMinError->Text.ToDouble();
ActiveControl= (TestMode->Checked)?Button3:Button2;
// reverse the error
// char s[100];
// if(SendRcv(":GA#", s))
// Label6->Caption= s;
// else ShowMessage("command error");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::test(TObject *Sender)
{
S1D.deg= DecRatD->Text.ToDouble();
DtoDMS(&S1D);
S1DD->Text= FloatToStrF(S1D.D,ffFixed, 15,0);
S1DM->Text= FloatToStrF(S1D.M,ffFixed, 15,0);
S1DS->Text= FloatToStrF(S1D.S,ffFixed, 15,1);
S1R.deg= RARatD->Text.ToDouble();
DtoHMS(&S1R);
S1RH->Text= FloatToStrF(S1R.H,ffFixed, 15,0);
S1RM->Text= FloatToStrF(S1R.M,ffFixed, 15,0);
S1RS->Text= FloatToStrF(S1R.S,ffFixed, 15,1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StopBtnClick(TObject *Sender)
{
SendRcv(":Q#", NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TestModeClick(TObject *Sender)
{
if(TestMode->Checked) { // test mode
ApdPort1->Open= false;
ApdPort1->ComNumber= 0;
Button1->Enabled= false;
Button2->Enabled= false;
StopBtn->Enabled= false;
errRD->ReadOnly= false;
errRM->ReadOnly= false;
errRS->ReadOnly= false;
errDD->ReadOnly= false;
errDM->ReadOnly= false;
errDS->ReadOnly= false;
LSTPanel->Enabled= true;
Star1Grp->Enabled= true;
Star2Grp->Enabled= true;
LocationGrp->Enabled= true;
} else { // talk to the scope
ApdPort1->Open= true;
if(ApdPort1->Open) { // successfully opened
Button1->Enabled= true;
Button2->Enabled= true;
StopBtn->Enabled= true;
errRD->ReadOnly= true;
errRM->ReadOnly= true;
errRS->ReadOnly= true;
errDD->ReadOnly= true;
errDM->ReadOnly= true;
errDS->ReadOnly= true;
LSTPanel->Enabled= false;
// Star1Grp->Enabled= false;
// Star2Grp->Enabled= false;
// LocationGrp->Enabled= false;
} else { // failed open
TestMode->Checked= true;
}
}
}
//---------------------------------------------------------------------------
EventTimer ET;
int busy= 0;
int __fastcall TForm1::SendRcv(char *cmd, char *rsp)
{
int i= 0;
int done= true;
char C;
// while(busy) ; // attempt to prevent re-entry....
busy= 1;
ApdPort1->FlushInBuffer();
ApdPort1->PutString(cmd);
Memo1->Lines->Add(cmd);
if(rsp==NULL) {
busy= 0; return -1;
} else {
NewTimer(ET, 20);
do {
ApdPort1->ProcessCommunications();
Application->ProcessMessages();
if(ApdPort1->CharReady()) {
C= ApdPort1->GetChar();
rsp[i++]= C;
if(C=='#')
done= false; // normal end
if(TimerExpired(ET)) {
ShowMessage("ET timer expired");
busy= 0; return 0;
}
}
} while (done);
rsp[i]= 0;
busy= 0;
Memo1->Lines->Add(rsp);
return(strlen(rsp));
}
}
void __fastcall TForm1::Button5Click(TObject *Sender)
{
// SendRcv(":U#", NULL);
// char t[22];
// char s[]= "+42z56#";
// sscanf(s,
// SendRcv(":Gt#", s);
//Label6->Caption= s;
// sscanf( s, "%lfz%lf#", &Lat.D, &Lat.M);
// sprintf(t, ":Sd %+03.0lf\337%02.0lf:%02.0lf#", S1D.D, S1D.M, S1D.S);
// sprintf(t, ":%02.0lf:%02.0lf:%02.0lf#", S1R.H, S1R.M, S1R.S);
//Label6->Caption= t;
// ":GR#", ret "HH:MM:SS#" into S2oR
char s[100];
strcpy(s,"14:15:16#");
// SendRcv(":GR#", s);
//Label6->Caption= s;
sscanf(s, "%lf:%lf:%lf#", &S2oR.H, &S2oR.M, &S2oR.S);
DTH->Text= FloatToStrF(S2oR.H,ffFixed, 15,0);
DTM->Text= FloatToStrF(S2oR.M,ffFixed, 15,0);
DTS->Text= FloatToStrF(S2oR.S,ffFixed, 15,1);
HMStoD(&S2oR);
errR.deg= S2oR.deg - S2R.deg;
DtoDMS(&errR);
errRD->Text= FloatToStrF(errR.D,ffFixed, 15,0);
errRM->Text= FloatToStrF(errR.M,ffFixed, 15,0);
errRS->Text= FloatToStrF(errR.S,ffFixed, 15,1);
errRD->Hint= errR.deg; errRM->Hint= errR.deg*60; errRS->Hint= errR.deg*3600;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Exit(TObject *Sender)
{
S2R.deg= Edit1->Text.ToDouble();
DtoHMS(&S2R);
DTH->Text= FloatToStrF(S2R.H,ffFixed, 15,0);
DTM->Text= FloatToStrF(S2R.M,ffFixed, 15,0);
DTS->Text= FloatToStrF(S2R.S,ffFixed, 15,1);
Edit1->Text= FloatToStrF(S2R.deg,ffFixed,15,8);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Star1NumExit(TObject *Sender)
{
// if file exists, validate number, open file, get data
char s[200], ns[15];
int i1, i2, i3; float f1, f2, f3;
int sn;
// if the file isn't available, don't bother
if(ECUavail) {
in= fopen("LX334STR.ECU", "rt");
// is there a value input?
try {
Star1no= Star1Num->Text.ToInt();
if(Star1no<1) {
Star1no= 0;
} else {
if(Star1no>351) Star1no= 351;
Star1Num->Text= Star1no;
for(int i= 0; i<Star1no; i++) fgets(s, 190, in);
sscanf(s, "%i %f %i %f %i %f %15c", &i1, &f1, &i2, &f2, &i3, &f3, ns);
S1R.deg= 15.0 * f1; DtoHMS(&S1R);
S1RH->Text= FloatToStrF(S1R.H,ffFixed, 15,0);
S1RM->Text= FloatToStrF(S1R.M,ffFixed, 15,0);
S1RS->Text= FloatToStrF(S1R.S,ffFixed, 15,1);
S1D.deg= f2; DtoDMS(&S1D);
S1DD->Text= FloatToStrF(S1D.D,ffFixed, 15,0);
S1DM->Text= FloatToStrF(S1D.M,ffFixed, 15,0);
S1DS->Text= FloatToStrF(S1D.S,ffFixed, 15,1);
S1RH->ReadOnly= true; S1RM->ReadOnly= true; S1RS->ReadOnly= true;
S1DD->ReadOnly= true; S1DM->ReadOnly= true; S1DS->ReadOnly= true;
i1= 0; while((!isalpha(ns[i1])) && (ns[i1])) i1++;
Star1Name->Caption= &ns[i1];
}
} catch (EConvertError &error) {
Star1no= 0;
}
fclose(in);
} else {
Star1no= 0;
}
if(!Star1no) {
Star1Num->Text= "0"; Star1Name->Caption= "";
S1RH->ReadOnly= false; S1RM->ReadOnly= false; S1RS->ReadOnly= false;
S1DD->ReadOnly= false; S1DM->ReadOnly= false; S1DS->ReadOnly= false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Star2NumExit(TObject *Sender)
{
// if file exists, validate number, open file, get data
char s[200], ns[15];
int i1, i2, i3; float f1, f2, f3;
int sn;
// if the file isn't available, don't bother
if(ECUavail) {
in= fopen("LX334STR.ECU", "rt");
// is there a value input?
try {
Star2no= Star2Num->Text.ToInt();
if(Star2no<1) {
Star2no= 0;
} else {
if(Star2no>351) Star2no= 351;
Star2Num->Text= Star2no;
for(int i= 0; i<Star2no; i++) fgets(s, 190, in);
sscanf(s, "%i %f %i %f %i %f %15c", &i1, &f1, &i2, &f2, &i3, &f3, ns);
S2R.deg= 15.0 * f1; DtoHMS(&S2R);
S2RH->Text= FloatToStrF(S2R.H,ffFixed, 15,0);
S2RM->Text= FloatToStrF(S2R.M,ffFixed, 15,0);
S2RS->Text= FloatToStrF(S2R.S,ffFixed, 15,1);
S2D.deg= f2; DtoDMS(&S2D);
S2DD->Text= FloatToStrF(S2D.D,ffFixed, 15,0);
S2DM->Text= FloatToStrF(S2D.M,ffFixed, 15,0);
S2DS->Text= FloatToStrF(S2D.S,ffFixed, 15,1);
S2RH->ReadOnly= true; S2RM->ReadOnly= true; S2RS->ReadOnly= true;
S2DD->ReadOnly= true; S2DM->ReadOnly= true; S2DS->ReadOnly= true;
i1= 0; while((!isalpha(ns[i1])) && (ns[i1])) i1++;
Star2Name->Caption= &ns[i1];
}
} catch (EConvertError &error) {
Star2no= 0;
}
fclose(in);
} else {
Star2no= 0;
}
if(!Star2no) {
Star2Num->Text= "0"; Star2Name->Caption= "";
S2RH->ReadOnly= false; S2RM->ReadOnly= false; S2RS->ReadOnly= false;
S2DD->ReadOnly= false; S2DM->ReadOnly= false; S2DS->ReadOnly= false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Exit1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::About1Click(TObject *Sender)
{
fAbout->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Help2Click(TObject *Sender)
{
Application->HelpJump("Introduction");
}
//---------------------------------------------------------------------------