Bug 400128 - Ekos plate solving angle difference doesn't normalize for 360 degrees
Summary: Ekos plate solving angle difference doesn't normalize for 360 degrees
Status: RESOLVED FIXED
Alias: None
Product: kstars
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Jasem Mutlaq
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-21 21:59 UTC by Hy
Modified: 2018-10-22 10:55 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hy 2018-10-21 21:59:31 UTC
SUMMARY

I downloaded and compiled and am running KStars -- I believe I grabbed it on Sept 24, and when I run it it says it is version 3.0.0.

In kstars/ekos/align.cpp in the method Align::solverFinished(), when determining if the plate solving process might be done, the code computes an angle difference between the target position (e.g. double raDiff = ...; double decDiff = ...;) This difference does not take into account the fact that angles repeat every 360 degrees, and thus the difference between 359 and 1 is not 358, but rather 2 degrees. [Further, angles there are not limited to the range of 0-360--e.g. I saw an angle of 370 degrees when looking into this--though this in itself may not cause a problem]. The lack of normalization of the angle difference can cause the plate solver to never complete.

So solve this, you could, e.g. define the function normalizeAngleDiff(double, double) shown below, and replace these (buggy) lines (taken from Align::solverFinished()

    double raDiff = (alignCoord.ra().Degrees() - targetCoord.ra().Degrees()) * 3600;                                                                                                                        
    double deDiff = (alignCoord.dec().Degrees() - targetCoord.dec().Degrees()) * 3600;     

with something like this:

    double raDiff = normalizedAngleDiff(
        alignCoord.ra().Degrees(), targetCoord.ra().Degrees()) * 3600;
    double deDiff = normalizedAngleDiff(
        alignCoord.dec().Degrees(), targetCoord.dec().Degrees()) * 3600;

Here's an implementation for a normalizedAngleDiff function:

// Computes the difference of two angles (in degrees), taking into account                                                 
// the fact that angles repeat every 360 degrees.                                                                          
double normalizedAngleDiff(double degrees1, double degrees2) {
  double angleDiff = degrees1 - degrees2;

  // Put in the range of [-360,360]                                                                                        
  while (angleDiff > 360) {
    angleDiff -= 360;
  }
  while (angleDiff < -360) {
    angleDiff += 360;
  }
  if (angleDiff > 180) {
    // angleDiff in the range [180,360]                                                                                    
    return 360 - angleDiff;
  } else if (angleDiff < -180) {
    // angleDiff in the range [-360,-180]                                                                                  
    return -(360 + angleDiff);
  } else {
    // angleDiff in the range [-180,180]                                                                                   
    return angleDiff;
  }
}


You likely also have this same problem elsewhere in the file--e.g. where you implement astrometryDifferentialSlewing.


To reproduce this, you need to e.g. set the plate solve solution (alignCoord) and the target (targetCoord) to e.g. 0.001 and 359.999.

This is a real issue, not theoretical. Happened to me while tracking/aligning last night. Aligner had solved the problem, but still thought it was far off. It output the following:

org.kde.kstars.ekos.align: "Solution coordinates: RA (00h 43m 48s) DEC ( 41° 22' 11\") Telescope Coordinates: RA (00h 43m 48s) DEC ( 41° 22' 23\")"
org.kde.kstars.ekos.align: "Target is within  359° 59' 53\" degrees of solution coordinates."
Comment 1 Jasem Mutlaq 2018-10-22 10:55:33 UTC
Git commit fa6ff04bfafda94954e984c2ef60a3b73954f5a5 by Jasem Mutlaq.
Committed on 22/10/2018 at 10:51.
Pushed by mutlaqja into branch 'master'.

Add new function deltaAngle to DMS class to calculate the shortest angle between two angles.

This also fixes angle diff calculation in the alignment module.

Please test the patch and see if it resolves the issue.

M  +46   -0    Tests/auxiliary/testdms.cpp
M  +2    -0    Tests/auxiliary/testdms.h
M  +20   -2    kstars/auxiliary/dms.cpp
M  +7    -0    kstars/auxiliary/dms.h
M  +15   -13   kstars/ekos/align/align.cpp
M  +1    -4    kstars/ekos/capture/capture.cpp
M  +1    -1    kstars/ekos/mount/mount.cpp

https://commits.kde.org/kstars/fa6ff04bfafda94954e984c2ef60a3b73954f5a5