Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hjd1964 committed Mar 1, 2020
1 parent ab05d58 commit 8f89d5c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions AlignEq.ino
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void TGeoAlign::equToInstr(double HA, double Dec, double *HA1, double *Dec1, int
if (Dec < -90.0) Dec=-90.0;

// breaks-down near the pole (limited to > 1' from pole)
if (abs(Dec) < 89.9833) {
if (fabs(Dec) < 89.9833) {

// initial rough guess at instrument HA,Dec
double h=HA/Rad;
Expand Down Expand Up @@ -414,7 +414,7 @@ void TGeoAlign::instrToEqu(double HA, double Dec, double *HA1, double *Dec1, int
if (Dec < -90.0) Dec=-90.0;

// breaks-down near the pole (limited to > 1' from pole)
if (abs(Dec) < 89.98333333) {
if (fabs(Dec) < 89.98333333) {
double h=HA/Rad;
double d=Dec/Rad;
double sinDec=sin(d);
Expand Down
4 changes: 2 additions & 2 deletions AlignHor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void TGeoAlignH::horToInstr(double Alt, double Azm, double *Alt1, double *Azm1,
if (Alt < -90.0) Alt=-90.0;

// breaks-down near the Zenith (limited to > 1' from Zenith)
if (abs(Alt) < 89.98333333) {
if (fabs(Alt) < 89.98333333) {

// initial rough guess at instrument HA,Dec
double z=Azm/Rad;
Expand Down Expand Up @@ -428,7 +428,7 @@ void TGeoAlignH::instrToHor(double Alt, double Azm, double *Alt1, double *Azm1,
if (Alt < -90.0) Alt=-90.0;

// breaks-down near the Zenith (limited to > 1' from Zenith)
if (abs(Alt) < 89.98333333) {
if (fabs(Alt) < 89.98333333) {
double z=Azm/Rad;
double a=Alt/Rad;
double sinAlt=sin(a);
Expand Down
6 changes: 3 additions & 3 deletions Astro.ino
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,13 @@ void setDeltaTrackingRate() {
d2=d-newTargetDec;
if (getInstrPierSide() == PierSideEast) d2=-d2;
#endif
if ((abs(d1) < ArcSecPerStepAxis1/3600.0) && (abs(d2) < ArcSecPerStepAxis2/3600.0)) {
if ((fabs(d1) < ArcSecPerStepAxis1/3600.0) && (fabs(d2) < ArcSecPerStepAxis2/3600.0)) {
trackingSyncSeconds=0;
} else {
f1=(d1*3600.0)/120.0; if (f1 < -5.0) f1=-5.0; if (f1 > 5.0) f1=5.0;
if (abs(d1) < ArcSecPerStepAxis1/3600.0) f1=0.0;
if (fabs(d1) < ArcSecPerStepAxis1/3600.0) f1=0.0;
f2=(d2*3600.0)/120.0; if (f2 < -5.0) f2=-5.0; if (f2 > 5.0) f2=5.0;
if (abs(d2) < ArcSecPerStepAxis2/3600.0) f2=0.0;
if (fabs(d2) < ArcSecPerStepAxis2/3600.0) f2=0.0;
}
}

Expand Down
12 changes: 6 additions & 6 deletions Command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void processCommands() {
// :FC[sn.n]# Set focuser temperature compensation coefficient in um per deg. C (+ moves out as temperature falls)
// Return: 0 on failure
// 1 on success
if (command[1] == 'C') { f = atof(parameter); if (abs(f) < 10000.0) foc->setTcfCoef(f); else commandError=CE_PARAM_RANGE; } else
if (command[1] == 'C') { f = atof(parameter); if (fabs(f) < 10000.0) foc->setTcfCoef(f); else commandError=CE_PARAM_RANGE; } else
// :Fc# Get focuser temperature compensation enable status
// Return: 0 if disabled
// 1 if enabled
Expand Down Expand Up @@ -716,9 +716,9 @@ void processCommands() {
#endif
if (rateCompensation == RC_NONE) {
double tr=getTrackingRate60Hz();
if (abs(tr-57.900)<0.001) reply[1]|=0b10000001; else // Lunar rate selected
if (abs(tr-60.000)<0.001) reply[1]|=0b10000010; else // Solar rate selected
if (abs(tr-60.136)<0.001) reply[1]|=0b10000011; // King rate selected
if (fabs(tr-57.900)<0.001) reply[1]|=0b10000001; else // Lunar rate selected
if (fabs(tr-60.000)<0.001) reply[1]|=0b10000010; else // Solar rate selected
if (fabs(tr-60.136)<0.001) reply[1]|=0b10000011; // King rate selected
}

if (syncToEncodersOnly) reply[1]|=0b10000100; // sync to encoders only
Expand Down Expand Up @@ -1816,14 +1816,14 @@ void processCommands() {
switch (parameter[1]) {
case '9': // minutes past meridianE
degreesPastMeridianE=(double)strtol(&parameter[3],NULL,10)/4.0;
if (abs(degreesPastMeridianE) <= 180) {
if (labs(degreesPastMeridianE) <= 180) {
i=round(degreesPastMeridianE); if (degreesPastMeridianE > 60) i= 60+round((i-60)/2); else if (degreesPastMeridianE < -60) i=-60+round((i+60)/2);
nv.write(EE_dpmE,round(i+128));
} else commandError=CE_PARAM_RANGE;
break;
case 'A': // minutes past meridianW
degreesPastMeridianW=(double)strtol(&parameter[3],NULL,10)/4.0;
if (abs(degreesPastMeridianW) <= 180) {
if (labs(degreesPastMeridianW) <= 180) {
i=round(degreesPastMeridianW); if (degreesPastMeridianW > 60) i= 60+round((i-60)/2); else if (degreesPastMeridianW < -60) i=-60+round((i+60)/2);
nv.write(EE_dpmW,round(i+128));
} else commandError=CE_PARAM_RANGE;
Expand Down
18 changes: 9 additions & 9 deletions MoveTo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void moveTo() {
} else {
// if we're at a low latitude and in the opposite sky, |HA|=6 is very low on the horizon in this orientation and we need to delay arriving there during a meridian flip
// in the extreme case, where the user is very near the (Earths!) equator an Horizon limit of -10 or -15 may be necessary for proper operation.
if ((currentAlt < 20.0) && (abs(latitude) < 45.0) && (getInstrAxis2() < 0.0)) {
if ((currentAlt < 20.0) && (fabs(latitude) < 45.0) && (getInstrAxis2() < 0.0)) {
if (pierSideControl == PierSideFlipWE1) setTargetAxis1(-45.0,PierSideWest); else setTargetAxis1(45.0,PierSideEast);
}
}
Expand All @@ -48,7 +48,7 @@ void moveTo() {
if (pierSideControl == PierSideFlipWE1) setTargetAxis1(-homePositionAxis1,PierSideWest); else setTargetAxis1(homePositionAxis1,PierSideEast);
} else {
// if we're at a low latitude and in the opposite sky, |HA|=6 is very low on the horizon in this orientation and we need to delay arriving there during a meridian flip
if ((currentAlt < 20.0) && (abs(latitude) < 45.0) && (getInstrAxis2() > 0.0)) {
if ((currentAlt < 20.0) && (fabs(latitude) < 45.0) && (getInstrAxis2() > 0.0)) {
if (pierSideControl == PierSideFlipWE1) setTargetAxis1(-45.0,PierSideWest); else setTargetAxis1(45.0,PierSideEast);
}
}
Expand All @@ -61,15 +61,15 @@ void moveTo() {
long distStartAxis1,distStartAxis2,distDestAxis1,distDestAxis2;

cli();
distStartAxis1=abs(posAxis1-startAxis1); // distance from start Axis1
distStartAxis2=abs(posAxis2-startAxis2); // distance from start Axis2
distStartAxis1=labs(posAxis1-startAxis1); // distance from start Axis1
distStartAxis2=labs(posAxis2-startAxis2); // distance from start Axis2
sei();
if (distStartAxis1 < 1) distStartAxis1=1;
if (distStartAxis2 < 1) distStartAxis2=1;

cli();
distDestAxis1=abs(posAxis1-(long)targetAxis1.part.m); // distance from dest Axis1
distDestAxis2=abs(posAxis2-(long)targetAxis2.part.m); // distance from dest Axis2
distDestAxis1=labs(posAxis1-(long)targetAxis1.part.m); // distance from dest Axis1
distDestAxis2=labs(posAxis2-(long)targetAxis2.part.m); // distance from dest Axis2
sei();

// adjust rates near the horizon to help keep from exceeding the minAlt limit
Expand Down Expand Up @@ -135,7 +135,7 @@ void moveTo() {
if (abortSlew != 0) {
if (abortSlew == 2) { a1r=(double)SiderealRate/(double)temp; } else
if (abortSlew == 3) {
double r=1.2-sqrt((abs(a1r)/slewRateX));
double r=1.2-sqrt((fabs(a1r)/slewRateX));
if (r < 0.2) r=0.2; if (r > 1.2) r=1.2;
a1r-=(deaccXPerSec/100.0)*r; if (a1r < 2.0) a1r=2.0;
}
Expand All @@ -154,7 +154,7 @@ void moveTo() {
if (abortSlew != 0) {
if (abortSlew == 2) { a2r=(double)SiderealRate/(double)temp; abortSlew++; } else
if (abortSlew == 3) {
double r=1.2-sqrt((abs(a2r)/slewRateX));
double r=1.2-sqrt((fabs(a2r)/slewRateX));
if (r < 0.2) r=0.2; if (r > 1.2) r=1.2;
a2r-=(deaccXPerSec/100.0)*r;
if (a2r < 2.00) a2r=2.0;
Expand All @@ -180,7 +180,7 @@ void moveTo() {
slewForceEnd=true;
}

if ( ((distDestAxis1 <= ceil(abs(fixedToDouble(fstepAxis1)))+1) && (distDestAxis2 <= ceil(abs(fixedToDouble(fstepAxis2)))+1) ) || slewForceEnd ) {
if ( ((distDestAxis1 <= ceil(fabs(fixedToDouble(fstepAxis1)))+1) && (distDestAxis2 <= ceil(fabs(fixedToDouble(fstepAxis2)))+1) ) || slewForceEnd ) {
slewEnding=false;
slewForceEnd=false;
abortSlew=0;
Expand Down
8 changes: 4 additions & 4 deletions Timer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void timerSupervisor(bool isCentiSecond) {
axis1DriverGotoMode();

// at higher step rates where torque is reduced make smaller rate changes
double r=1.2-sqrt((abs(guideTimerRateAxis1A)/slewRateX));
double r=1.2-sqrt((fabs(guideTimerRateAxis1A)/slewRateX));
if (r < 0.2) r=0.2; if (r > 1.2) r=1.2;

// acceleration/deceleration control
Expand All @@ -142,7 +142,7 @@ void timerSupervisor(bool isCentiSecond) {

// stop guiding
if (guideDirAxis1 == 'b') {
if (abs(guideTimerRateAxis1A) < 0.001) { guideDirAxis1=0; lastGuideDirAxis1=0; guideTimerRateAxis1=0.0; guideTimerRateAxis1A=0.0; guideDirChangeTimerAxis1=0; axis1DriverTrackingMode(false); }
if (fabs(guideTimerRateAxis1A) < 0.001) { guideDirAxis1=0; lastGuideDirAxis1=0; guideTimerRateAxis1=0.0; guideTimerRateAxis1A=0.0; guideDirChangeTimerAxis1=0; axis1DriverTrackingMode(false); }
}
}
}
Expand All @@ -168,7 +168,7 @@ void timerSupervisor(bool isCentiSecond) {
axis2DriverGotoMode();

// at higher step rates where torque is reduced make smaller rate changes
double r=1.2-sqrt((abs(guideTimerRateAxis2A)/slewRateX));
double r=1.2-sqrt((fabs(guideTimerRateAxis2A)/slewRateX));
if (r < 0.2) r=0.2; if (r > 1.2) r=1.2;

// acceleration/deceleration control
Expand All @@ -183,7 +183,7 @@ void timerSupervisor(bool isCentiSecond) {

// stop guiding
if (guideDirAxis2 == 'b') {
if (abs(guideTimerRateAxis2A) < 0.001) { guideDirAxis2=0; lastGuideDirAxis2=0; guideTimerRateAxis2=0.0; guideTimerRateAxis2A=0.0; guideDirChangeTimerAxis2=0; axis2DriverTrackingMode(false); }
if (fabs(guideTimerRateAxis2A) < 0.001) { guideDirAxis2=0; lastGuideDirAxis2=0; guideTimerRateAxis2=0.0; guideTimerRateAxis2A=0.0; guideDirChangeTimerAxis2=0; axis2DriverTrackingMode(false); }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/FocuserStepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class focuserStepper : public focuser {
}

// temperature compensation
void setTcfCoef(double coef) { if (abs(coef) >= 10000.0) coef = 0.0; tcf_coef = coef; nv.writeFloat(nvTcfCoef,tcf_coef); }
void setTcfCoef(double coef) { if (fabs(coef) >= 10000.0) coef = 0.0; tcf_coef = coef; nv.writeFloat(nvTcfCoef,tcf_coef); }
double getTcfCoef() { return tcf_coef; }
void setTcfEnable(boolean enabled) { tcf = enabled; nv.write(nvTcfEn,tcf); }
boolean getTcfEnable() { return tcf; }
Expand Down

0 comments on commit 8f89d5c

Please sign in to comment.