Skip to content

Commit

Permalink
Updated align solve without blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
hjd1964 committed Sep 20, 2018
1 parent 6c692cf commit 2f89c5f
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 234 deletions.
28 changes: 23 additions & 5 deletions Align.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

#pragma once

byte alignNumStars = 0;
byte alignThisStar = 0;

// -----------------------------------------------------------------------------------
// ADVANCED GEOMETRIC ALIGN FOR ALT/AZM MOUNTS (GOTO ASSIST)

Expand Down Expand Up @@ -46,7 +43,7 @@ class TGeoAlignH
bool addStar(int I, int N, double RA, double Dec);
void horToInstr(double Alt, double Azm, double *Alt1, double *Azm1, int PierSide);
void instrToHor(double Alt, double Azm, double *Alt1, double *Azm1, int PierSide);
void autoModel(int n, bool start);
void autoModel(int n);

private:
boolean geo_ready;
Expand Down Expand Up @@ -106,7 +103,8 @@ class TGeoAlign
bool addStar(int I, int N, double RA, double Dec);
void equToInstr(double Lat, double HA, double Dec, double *HA1, double *Dec1, int PierSide);
void instrToEqu(double Lat, double HA, double Dec, double *HA1, double *Dec1, int PierSide);
void autoModel(int n, bool start);
void autoModel(int n);
void model(int n);

private:
boolean geo_ready;
Expand All @@ -133,3 +131,23 @@ class TGeoAlign
TGeoAlign Align;
#endif

byte alignNumStars = 0;
byte alignThisStar = 0;

// checks to see if an alignment is active
boolean alignActive() {
return (alignNumStars>0) && (alignThisStar <= alignNumStars);
}

// adds an alignment star, returns true on success
boolean alignStar() {
// after last star turn meridian flips off when align is done
if ((alignNumStars == alignThisStar) && (meridianFlip == MeridianFlipAlign)) meridianFlip=MeridianFlipNever;

if (alignThisStar <= alignNumStars) {
if (Align.addStar(alignThisStar,alignNumStars,newTargetRA,newTargetDec)) alignThisStar++; else return false;
} else return false;

return true;
}

171 changes: 77 additions & 94 deletions AlignEq.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ bool TGeoAlign::isReady() {
bool TGeoAlign::addStar(int I, int N, double RA, double Dec) {

// First star, just sync
if (I==1) {
// set the indexAxis1/2 offset
if (syncEqu(RA,Dec)!=0) return true;
}
if (I==1) { if (syncEqu(RA,Dec)!=GOTO_ERR_NONE) return false; }

mount[I-1].ha=getInstrAxis1()/Rad;
mount[I-1].dec=getInstrAxis2()/Rad;
Expand All @@ -76,16 +73,20 @@ bool TGeoAlign::addStar(int I, int N, double RA, double Dec) {
if (getInstrPierSide()==PierSideEast) { actual[I-1].side=1; mount[I-1].side=1; } else { actual[I-1].side=0; mount[I-1].side=0; }

// two or more stars and finished
if ((I>=2) && (I==N)) {
#ifdef GOTO_ASSIST_DEBUG_ON
DL("");
#endif
autoModel(N,true);
}
if ((I>=2) && (I==N)) model(N);

return true;
}

// kick off modeling
void TGeoAlign::model(int n) {
static bool busy=false;
static int numStars=0;
if (busy) return; // busy
if (n>0) { numStars=n; return; } // command
if (numStars>0) { busy=true; autoModel(numStars); busy=false; numStars=0; } // waiting to solve
}

// returns the correction to be added to the requested RA,Dec to yield the actual RA,Dec that we will arrive at
void TGeoAlign::correct(double ha, double dec, double pierSide, double sf, double _deo, double _pd, double _pz, double _pe, double _da, double _ff, double _tf, double *h1, double *d1) {
double DO1,DOh;
Expand Down Expand Up @@ -239,110 +240,91 @@ void TGeoAlign::do_search(double sf, int p1, int p2, int p3, int p4, int p5, int
if (p9!=0) best_ohw=ohw*Rad*3600.0;
if (p9!=0) best_ohe=ohe*Rad*3600.0;
}

// keep the main loop running
loop2();
}
}

void TGeoAlign::autoModel(int n, bool start) {
static int step=51;
if (start) step=0;
if (step>50) return;
step++;
void TGeoAlign::autoModel(int n) {

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;
best_pz =0.0;
best_pe =0.0;
best_tf =0.0;
best_ff =0.0;
best_df =0.0;
best_ode =0.0;
best_ohe =0.0;

// figure out the average HA offset as a starting point
ohe=0;
for (l=1; l<num; l++) {
h1=actual[l].ha-mount[l].ha;
if (h1>PI) h1=h1-PI*2.0;
if (h1<-PI) h1=h1+PI*2.0;
ohe=ohe+h1;
}
ohe=ohe/num; best_ohe=round(ohe*Rad*3600.0); best_ohw=best_ohe;

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;
best_pz =0.0;
best_pe =0.0;
best_tf =0.0;
best_ff =0.0;
best_df =0.0;
best_ode =0.0;
best_ohe =0.0;

// figure out the average HA offset as a starting point
ohe=0;
for (l=1; l<num; l++) {
h1=actual[l].ha-mount[l].ha;
if (h1>PI) h1=h1-PI*2.0;
if (h1<-PI) h1=h1+PI*2.0;
ohe=ohe+h1;
}
ohe=ohe/num; best_ohe=round(ohe*Rad*3600.0); best_ohw=best_ohe;

#if defined(MOUNT_TYPE_FORK) || defined(MOUNT_TYPE_FORK_ALT) || defined(MOUNT_TYPE_ALTAZM)
Ff=1; Df=0;
Ff=1; Df=0;
#else
Ff=0; Df=1;
Ff=0; Df=1;
#endif
}

// search, this can handle about 9 degrees of polar misalignment, and 4 degrees of cone error
// DoPdPzPeTfFf Df OdOh
do_search(16384,0,0,1,1,0, 0, 0,1,1);
do_search( 8192,1,0,1,1,0, 0, 0,1,1);
do_search( 4096,1,0,1,1,0, 0, 0,1,1);
do_search( 2048,1,0,1,1,0, 0, 0,1,1);
do_search( 1024,1,0,1,1,0, 0, 0,1,1);
do_search( 512,1,0,1,1,0, 0, 0,1,1);
#ifdef HAL_SLOW_PROCESSOR
// search, this can handle about 9 degrees of polar misalignment, and 2 degree of cone error
// DoPdPzPeTfFfDfOdOh
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 4 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,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);
if (step==15) do_search( 512,1,0,1,1,0, 0, 0,1,1);
// DoPdPzPeTfFf Df OdOh
do_search( 256,1,0,1,1,0, 0, 0,1,1);
do_search( 128,1,0,1,1,0, 0, 0,1,1);
#else
if (num>4) {
if (step==20) do_search( 256,1,1,1,1,0,Ff,Df,1,1);
if (step==30) do_search( 128,1,1,1,1,0,Ff,Df,1,1);
if (step==40) do_search( 64,1,1,1,1,0,Ff,Df,1,1);
// DoPdPzPeTfFf Df OdOh
do_search( 256,1,1,1,1,0,Ff,Df,1,1);
do_search( 128,1,1,1,1,0,Ff,Df,1,1);
do_search( 64,1,1,1,1,0,Ff,Df,1,1);
do_search( 32,1,1,1,1,0,Ff,Df,1,1);
} else {
if (step==20) do_search( 256,1,0,1,1,0, 0, 0,1,1);
if (step==30) do_search( 128,1,0,1,1,0, 0, 0,1,1);
if (step==40) do_search( 64,1,0,1,1,0, 0, 0,1,1);
do_search( 256,1,0,1,1,0, 0, 0,1,1);
do_search( 128,1,0,1,1,0, 0, 0,1,1);
do_search( 64,1,0,1,1,0, 0, 0,1,1);
do_search( 32,1,0,1,1,0, 0, 0,1,1);
}
#else
// search, this can handle about 9 degrees of polar misalignment, and 4 degrees of cone error
// DoPdPzPeTfFf Df OdOh
if (step==2) do_search(16384,0,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

if (step==50) {
// geometric corrections
doCor=best_deo/3600.0;
pdCor=best_pd/3600.0;
azmCor=best_pz/3600.0;
altCor=best_pe/3600.0;
// geometric corrections
doCor=best_deo/3600.0;
pdCor=best_pd/3600.0;
azmCor=best_pz/3600.0;
altCor=best_pe/3600.0;

tfCor=best_tf/3600.0;
tfCor=best_tf/3600.0;
#if defined(MOUNT_TYPE_FORK) || defined(MOUNT_TYPE_FORK_ALT) || defined(MOUNT_TYPE_ALTAZM)
dfCor=best_df/3600.0;
dfCor=best_df/3600.0;
#else
dfCor=best_ff/3600.0;
dfCor=best_ff/3600.0;
#endif

ax1Cor=best_ohw/3600.0;
ax2Cor=best_odw/3600.0;
ax1Cor=best_ohw/3600.0;
ax2Cor=best_odw/3600.0;

geo_ready=true;
}
geo_ready=true;
}

// takes the topocentric refracted coordinates and applies corrections to arrive at instrument equatorial coordinates
Expand Down Expand Up @@ -470,4 +452,5 @@ void TGeoAlign::instrToEqu(double Lat, double HA, double Dec, double *HA1, doubl
if (*Dec1>90.0) *Dec1=90.0;
if (*Dec1<-90.0) *Dec1=-90.0;
}

#endif
Loading

0 comments on commit 2f89c5f

Please sign in to comment.