Skip to content

Commit

Permalink
Optimized GTA align modeling routine
Browse files Browse the repository at this point in the history
  • Loading branch information
hjd1964 committed Jul 20, 2018
1 parent 37b967e commit 614cee2
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 67 deletions.
4 changes: 4 additions & 0 deletions Align.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class TGeoAlignH
double avgAlt;
double avgAzm;

double lat,cosLat,sinLat;

long num,l;
long Ff,Df;
double best_deo, best_pd, best_pz, best_pe, best_ohw, best_odw, best_ohe, best_ode, best_tf, best_df, best_ff;
Expand Down Expand Up @@ -111,6 +113,8 @@ class TGeoAlign
double avgDec;
double avgHA;

double lat,cosLat,sinLat;

long num,l;
long Ff,Df;
double best_deo, best_pd, best_pz, best_pe, best_ohw, best_odw, best_ohe, best_ode, best_tf, best_df, best_ff;
Expand Down
75 changes: 42 additions & 33 deletions AlignEq.ino
Original file line number Diff line number Diff line change
Expand Up @@ -108,58 +108,60 @@ void TGeoAlign::correct(double ha, double dec, double pierSide, double sf, doubl
double PD,PDh;
double PZ,PA;
double DF,DFd,TF,FF,FFd,TFh,TFd;
double lat;

lat=latitude/Rad;
double cosDec=cos(dec);
double tanDec=tan(dec);
double sinHa=sin(ha);
double cosHa=cos(ha);

// ------------------------------------------------------------
// A. Misalignment due to tube/optics not being perp. to Dec axis
// negative numbers are further (S) from the NCP, swing to the
// equator and the effect on declination is 0. At the SCP it
// becomes a (N) offset. Unchanged with meridian flips.
DO1 =((_deo*sf)/3600.0)/Rad;
DO1 =_deo*sf;
// works on HA. meridian flips effect this in HA
DOh = DO1*(1.0/cos(dec))*pierSide;
DOh = DO1*(1.0/cosDec)*pierSide;

// ------------------------------------------------------------
// B. Misalignment, Declination axis relative to Polar axis
// expressed as a correction to where the Polar axis is pointing
// negative numbers are further (S) from the NCP, swing to the
// equator and the effect on declination is 0.
// At the SCP it is, again, a (S) offset
PD =((_pd*sf)/3600.0)/Rad;
PD =_pd*sf;
// works on HA.
PDh = -PD*tan(dec)*pierSide;
PDh = -PD*tanDec*pierSide;

// ------------------------------------------------------------
// Misalignment, relative to NCP
// negative numbers are east of the pole
// C. polar left-right misalignment
PZ =((_pz*sf)/3600.0)/Rad;
PZ =_pz*sf;
// D. negative numbers are below the pole
// polar below-above misalignment
PA =((_pe*sf)/3600.0)/Rad;
PA =_pe*sf;

// ------------------------------------------------------------
// Axis flex
DF =((_da*sf)/3600.0)/Rad;
DFd =-DF*(cos(lat)*cos(ha)+sin(lat)*tan(dec));
DF =_da*sf;
DFd =-DF*(cosLat*cosHa+sinLat*tanDec);

// ------------------------------------------------------------
// Fork flex
FF =((_ff*sf)/3600.0)/Rad;
FFd =FF*cos(ha);
FF =_ff*sf;
FFd =FF*cosHa;

// ------------------------------------------------------------
// Optical axis sag
TF =((_tf*sf)/3600.0)/Rad;
TF =_tf*sf;

TFh =TF*(cos(lat)*sin(ha)*(1.0/cos(dec)));
TFd =TF*(cos(lat)*cos(ha)-sin(lat)*cos(dec));
TFh =TF*(cosLat*sinHa*(1.0/cosDec));
TFd =TF*(cosLat*cosHa-sinLat*cosDec);

// ------------------------------------------------------------
*h1 =(-PZ*cos(ha)*tan(dec) + PA*sin(ha)*tan(dec) + DOh + PDh + TFh);
*d1 =(+PZ*sin(ha) + PA*cos(ha) + DFd + FFd + TFd);
*h1 =(-PZ*cosHa*tanDec + PA*sinHa*tanDec + DOh + PDh + TFh);
*d1 =(+PZ*sinHa + PA*cosHa + DFd + FFd + TFd);
}

void TGeoAlign::do_search(double sf, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9)
Expand All @@ -178,6 +180,8 @@ void TGeoAlign::do_search(double sf, int p1, int p2, int p3, int p4, int p5, int

_deo,_pd,_pz,_pe, _df,_tf,_ff, _ode,_ohe;

double sf1=sf/(3600.0*Rad);

// search
// set Parameter Space
_deo_m=-p1+round(best_deo/sf); _deo_p=p1+round(best_deo/sf);
Expand All @@ -200,9 +204,9 @@ void TGeoAlign::do_search(double sf, int p1, int p2, int p3, int p4, int p5, int
for (_tf=_tf_m; _tf<=_tf_p; _tf++)
for (_ohe=_oh_m; _ohe<=_oh_p; _ohe++)
for (_ode=_od_m; _ode<=_od_p; _ode++) {
ode=((((double)_ode)*sf)/(3600.0*Rad));
ode=((double)_ode)*sf1;
odw=-ode;
ohe=((((double)_ohe)*sf)/(3600.0*Rad));
ohe=((double)_ohe)*sf1;
ohw=ohe;

// check the combinations for all samples
Expand All @@ -220,10 +224,10 @@ void TGeoAlign::do_search(double sf, int p1, int p2, int p3, int p4, int p5, int
mh=mh+ohe;
md=md+ode;
}
correct(mh,md,mount[l].side,sf,_deo,_pd,_pz,_pe,_df,_ff,_tf,&h1,&d1);
correct(mh,md,mount[l].side,sf1,_deo,_pd,_pz,_pe,_df,_ff,_tf,&h1,&d1);

delta[l].ha=actual[l].ha-(mh-h1);
if (delta[l].ha>PI) delta[l].ha=delta[l].ha-PI*2.0;
if (delta[l].ha>PI) delta[l].ha=delta[l].ha-PI*2.0; else
if (delta[l].ha<-PI) delta[l].ha=delta[l].ha+PI*2.0;
delta[l].dec=actual[l].dec-(md-d1);
delta[l].side=mount[l].side;
Expand Down Expand Up @@ -263,6 +267,10 @@ void TGeoAlign::autoModel(int n, bool start) {
if (step==1) {
num=n; // how many stars?

lat=latitude/Rad;
cosLat=cos(lat);
sinLat=sin(lat);

best_dist =3600.0*180.0;
best_deo =0.0;
best_pd =0.0;
Expand Down Expand Up @@ -294,17 +302,18 @@ void TGeoAlign::autoModel(int n, bool start) {
#ifdef HAL_SLOW_PROCESSOR
// search, this can handle about 4.5 degrees of polar misalignment, and 1 degree of cone error
// DoPdPzPeTfFfDfOdOh
if (step==2) do_search( 8192,0,0,1,1,0,0,0,1,1);
if (step==4) do_search( 4096,0,0,1,1,0,0,0,1,1);
if (step==6) do_search( 2048,1,0,1,1,0,0,0,1,1);
if (step==20) do_search( 1024,1,0,1,1,0,0,0,1,1);
if (step==30) do_search( 512,1,0,1,1,0,0,0,1,1);
if (step==40) do_search( 256,1,0,1,1,0,0,0,1,1);
if (step==2) do_search(16384,0,0,1,1,0,0,0,1,0);
if (step==10) do_search( 8192,0,0,1,1,0,0,0,1,0);
if (step==15) do_search( 4096,1,0,1,1,0,0,0,1,0);
if (step==20) do_search( 2048,1,0,1,1,0,0,0,1,0);
if (step==25) do_search( 1024,1,0,1,1,0,0,0,1,0);
if (step==30) do_search( 512,0,0,1,1,0,0,0,1,1);
if (step==40) do_search( 256,0,0,1,1,0,0,0,1,1);
#elif HAL_FAST_PROCESSOR
// search, this can handle about 9 degrees of polar misalignment, and 2 degrees of cone error, 8' of FF/DF/PD
// DoPdPzPeTfFf Df OdOh
if (step==2) do_search(16384,0,0,1,1,0, 0, 0,1,1);
if (step==4) do_search( 8192,0,0,1,1,0, 0, 0,1,1);
if (step==4) do_search( 8192,1,0,1,1,0, 0, 0,1,1);
if (step==6) do_search( 4096,1,0,1,1,0, 0, 0,1,1);
if (step==8) do_search( 2048,1,0,1,1,0, 0, 0,1,1);
if (step==10) do_search( 1024,1,0,1,1,0, 0, 0,1,1);
Expand All @@ -322,11 +331,11 @@ void TGeoAlign::autoModel(int n, bool start) {
// search, this can handle about 9 degrees of polar misalignment, and 2 degrees of cone error
// DoPdPzPeTfFf Df OdOh
if (step==2) do_search(16384,0,0,1,1,0, 0, 0,1,1);
if (step==4) do_search( 8192,0,0,1,1,0, 0, 0,1,1);
if (step==6) do_search( 4096,1,0,1,1,0, 0, 0,1,1);
if (step==8) do_search( 2048,1,0,1,1,0, 0, 0,1,1);
if (step==10) do_search( 1024,1,0,1,1,0, 0, 0,1,1);
if (step==20) do_search( 512,1,0,1,1,0, 0, 0,1,1);
if (step==5) do_search( 8192,1,0,1,1,0, 0, 0,1,1);
if (step==10) do_search( 4096,1,0,1,1,0, 0, 0,1,1);
if (step==15) do_search( 2048,1,0,1,1,0, 0, 0,1,1);
if (step==20) do_search( 1024,1,0,1,1,0, 0, 0,1,1);
if (step==25) do_search( 512,1,0,1,1,0, 0, 0,1,1);
if (step==30) do_search( 256,1,0,1,1,0, 0, 0,1,1);
if (step==40) do_search( 128,1,0,1,1,0, 0, 0,1,1);
#endif
Expand Down
75 changes: 42 additions & 33 deletions AlignHor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,58 +122,60 @@ void TGeoAlignH::correct(double azm, double alt, double pierSide, double sf, dou
double PD,PDh;
double PZ,PA;
double DF,DFd,TF,FF,FFd,TFh,TFd;
double lat;

lat=90.0/Rad; // 90 deg. latitude for Alt/Azm
double cosAlt=cos(alt);
double tanAlt=tan(alt);
double sinAzm=sin(azm);
double cosAzm=cos(azm);

// ------------------------------------------------------------
// A. Misalignment due to tube/optics not being perp. to Dec axis
// negative numbers are further (S) from the NCP, swing to the
// equator and the effect on declination is 0. At the SCP it
// becomes a (N) offset. Unchanged with meridian flips.
DO1 =((_deo*sf)/3600.0)/Rad;
DO1 =_deo*sf;
// works on HA. meridian flips effect this in HA
DOh = DO1*(1.0/cos(alt))*pierSide;
DOh = DO1*(1.0/cosAlt)*pierSide;

// ------------------------------------------------------------
// B. Misalignment, Declination axis relative to Polar axis
// expressed as a correction to where the Polar axis is pointing
// negative numbers are further (S) from the NCP, swing to the
// equator and the effect on declination is 0.
// At the SCP it is, again, a (S) offset
PD =((_pd*sf)/3600.0)/Rad;
PD =_pd*sf;
// works on HA.
PDh = -PD*tan(alt)*pierSide;
PDh = -PD*tanAlt*pierSide;

// ------------------------------------------------------------
// Misalignment, relative to NCP
// negative numbers are east of the pole
// C. polar left-right misalignment
PZ =((_pz*sf)/3600.0)/Rad;
PZ =_pz*sf;
// D. negative numbers are below the pole
// polar below-above misalignment
PA =((_pe*sf)/3600.0)/Rad;
PA =_pe*sf;

// ------------------------------------------------------------
// Axis flex
DF =((_da*sf)/3600.0)/Rad;
DFd =-DF*(cos(lat)*cos(azm)+sin(lat)*tan(alt));
DF =_da*sf;
DFd =-DF*(cosLat*cosAzm+sinLat*tanAlt);

// ------------------------------------------------------------
// Fork flex
FF =((_ff*sf)/3600.0)/Rad;
FFd =FF*cos(azm);
FF =_ff*sf;
FFd =FF*cosAzm;

// ------------------------------------------------------------
// Optical axis sag
TF =((_tf*sf)/3600.0)/Rad;
TF =_tf*sf;

TFh =TF*(cos(lat)*sin(azm)*(1.0/cos(alt)));
TFd =TF*(cos(lat)*cos(azm)-sin(lat)*cos(alt));
TFh =TF*(cosLat*sinAzm*(1.0/cosAlt));
TFd =TF*(cosLat*cosAzm-sinLat*cosAlt);

// ------------------------------------------------------------
*z1 =(-PZ*cos(azm)*tan(alt) + PA*sin(azm)*tan(alt) + DOh + PDh + TFh);
*a1 =(+PZ*sin(azm) + PA*cos(azm) + DFd + FFd + TFd);
*z1 =(-PZ*cosAzm*tanAlt + PA*sinAzm*tanAlt + DOh + PDh + TFh);
*a1 =(+PZ*sinAzm + PA*cosAzm + DFd + FFd + TFd);
}

void TGeoAlignH::do_search(double sf, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9)
Expand All @@ -192,6 +194,8 @@ void TGeoAlignH::do_search(double sf, int p1, int p2, int p3, int p4, int p5, in

_deo,_pd,_pz,_pe, _df,_tf,_ff, _ode,_ohe;

double sf1=sf/(3600.0*Rad);

// search
// set Parameter Space
_deo_m=-p1+round(best_deo/sf); _deo_p=p1+round(best_deo/sf);
Expand All @@ -214,9 +218,9 @@ void TGeoAlignH::do_search(double sf, int p1, int p2, int p3, int p4, int p5, in
for (_tf=_tf_m; _tf<=_tf_p; _tf++)
for (_ohe=_oh_m; _ohe<=_oh_p; _ohe++)
for (_ode=_od_m; _ode<=_od_p; _ode++) {
ode=((((double)_ode)*sf)/(3600.0*Rad));
ode=((double)_ode)*sf1;
odw=-ode;
ohe=((((double)_ohe)*sf)/(3600.0*Rad));
ohe=((double)_ohe)*sf1;
ohw=ohe;

// check the combinations for all samples
Expand All @@ -234,10 +238,10 @@ void TGeoAlignH::do_search(double sf, int p1, int p2, int p3, int p4, int p5, in
mz=mz+ohe;
ma=ma+ode;
}
correct(mz,ma,mount[l].side,sf,_deo,_pd,_pz,_pe,_df,_ff,_tf,&z1,&a1);
correct(mz,ma,mount[l].side,sf1,_deo,_pd,_pz,_pe,_df,_ff,_tf,&z1,&a1);

delta[l].azm=actual[l].azm-(mz-z1);
if (delta[l].azm>PI) delta[l].azm=delta[l].azm-PI*2.0;
if (delta[l].azm>PI) delta[l].azm=delta[l].azm-PI*2.0; else
if (delta[l].azm<-PI) delta[l].azm=delta[l].azm+PI*2.0;
delta[l].alt=actual[l].alt-(ma-a1);
delta[l].side=mount[l].side;
Expand Down Expand Up @@ -276,6 +280,10 @@ void TGeoAlignH::autoModel(int n, bool start) {

if (step==1) {
num=n; // how many stars?

lat=90.0/Rad; // 90 deg. latitude for Alt/Azm
cosLat=cos(lat);
sinLat=sin(lat);

best_dist =3600.0*180.0;
best_deo =0.0;
Expand Down Expand Up @@ -308,17 +316,18 @@ void TGeoAlignH::autoModel(int n, bool start) {
#ifdef HAL_SLOW_PROCESSOR
// search, this can handle about 4.5 degrees of polar misalignment, and 1 degree of cone error
// DoPdPzPeTfFfDfOdOh
if (step==2) do_search( 8192,0,0,1,1,0,0,0,1,1);
if (step==4) do_search( 4096,0,0,1,1,0,0,0,1,1);
if (step==6) do_search( 2048,1,0,1,1,0,0,0,1,1);
if (step==20) do_search( 1024,1,0,1,1,0,0,0,1,1);
if (step==30) do_search( 512,1,0,1,1,0,0,0,1,1);
if (step==40) do_search( 256,1,0,1,1,0,0,0,1,1);
if (step==2) do_search(16384,0,0,1,1,0,0,0,1,0);
if (step==10) do_search( 8192,0,0,1,1,0,0,0,1,0);
if (step==15) do_search( 4096,1,0,1,1,0,0,0,1,0);
if (step==20) do_search( 2048,1,0,1,1,0,0,0,1,0);
if (step==25) do_search( 1024,1,0,1,1,0,0,0,1,0);
if (step==30) do_search( 512,1,0,1,1,0,0,0,1,0);
if (step==40) do_search( 256,1,0,1,1,0,0,0,1,0);
#elif HAL_FAST_PROCESSOR
// search, this can handle about 9 degrees of polar misalignment, and 2 degrees of cone error, 8' of FF/DF/PD
// DoPdPzPeTfFf Df OdOh
if (step==2) do_search(16384,0,0,1,1,0, 0, 0,1,1);
if (step==4) do_search( 8192,0,0,1,1,0, 0, 0,1,1);
if (step==4) do_search( 8192,1,0,1,1,0, 0, 0,1,1);
if (step==6) do_search( 4096,1,0,1,1,0, 0, 0,1,1);
if (step==8) do_search( 2048,1,0,1,1,0, 0, 0,1,1);
if (step==10) do_search( 1024,1,0,1,1,0, 0, 0,1,1);
Expand All @@ -336,11 +345,11 @@ void TGeoAlignH::autoModel(int n, bool start) {
// search, this can handle about 9 degrees of polar misalignment, and 2 degrees of cone error
// DoPdPzPeTfFf Df OdOh
if (step==2) do_search(16384,0,0,1,1,0, 0, 0,1,1);
if (step==4) do_search( 8192,0,0,1,1,0, 0, 0,1,1);
if (step==6) do_search( 4096,1,0,1,1,0, 0, 0,1,1);
if (step==8) do_search( 2048,1,0,1,1,0, 0, 0,1,1);
if (step==10) do_search( 1024,1,0,1,1,0, 0, 0,1,1);
if (step==20) do_search( 512,1,0,1,1,0, 0, 0,1,1);
if (step==5) do_search( 8192,1,0,1,1,0, 0, 0,1,1);
if (step==10) do_search( 4096,1,0,1,1,0, 0, 0,1,1);
if (step==15) do_search( 2048,1,0,1,1,0, 0, 0,1,1);
if (step==20) do_search( 1024,1,0,1,1,0, 0, 0,1,1);
if (step==25) do_search( 512,1,0,1,1,0, 0, 0,1,1);
if (step==30) do_search( 256,1,0,1,1,0, 0, 0,1,1);
if (step==40) do_search( 128,1,0,1,1,0, 0, 0,1,1);
#endif
Expand Down
2 changes: 1 addition & 1 deletion OnStep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define FirmwareDate __DATE__
#define FirmwareVersionMajor 1
#define FirmwareVersionMinor 11
#define FirmwareVersionPatch "d" // for example major.minor patch: 1.3c
#define FirmwareVersionPatch "e" // for example major.minor patch: 1.3c
#define FirmwareVersionConfig 2 // internal, for tracking configuration file changes
#define FirmwareName "On-Step"
#define FirmwareTime __TIME__
Expand Down

0 comments on commit 614cee2

Please sign in to comment.