Redesigned the Altitude and Azimuth readings to use the Right Ascension and Declination co-ordinates and perform the transformation using the date and site details from the scope. This will correct the problem of the Altitude reading from the handset being incorrect.

This commit is contained in:
2019-05-18 23:50:55 +01:00
parent cf5a6c72fe
commit cf28ecc7c2
9 changed files with 506 additions and 19 deletions
+165
View File
@@ -0,0 +1,165 @@
using System;
using ASCOM.Utilities;
namespace ASCOM.Meade.net
{
public class EquatorialCoordinates
{
public double RightAscension { get; set; }
public double Declination { get; set; }
}
public class HorizonCoordinates
{
public double Altitude { get; set; }
public double Azimuth { get; set; }
}
public class AltitudeData
{
public DateTime UtcDateTime { get; set; }
public double SiteLatitude { get; set; }
public double SiteLongitude { get; set; }
public EquatorialCoordinates equatorialCoordinates { get; set; }
}
public class AstroMaths
{
//returns the decimal hour angle for given right ascension on a given datetime for a given logitude.
public double RightAscensionToHourAngle(DateTime utcDateTime, double longitude, double rightAscension)
{
var ut = DateTimeToDecimalHours( utcDateTime);
var gst = UTtoGST( utcDateTime);
var lst = GSTtoLST( gst, longitude);
var raHours = rightAscension;
var h1 = lst - raHours;
var h = h1;
if (h < 0)
h = h + 24;
return h;
}
public HorizonCoordinates ConvertEqToHoz(double hourAngle, double latitude, EquatorialCoordinates raDec)
{
var h = hourAngle * 15;
var h1 = DegreesToRadians(h);
var d = DegreesToRadians(raDec.Declination);
var lat = DegreesToRadians(latitude);
var sinA = Math.Sin(d) * Math.Sin(lat) + Math.Cos(d) * Math.Cos(lat) * Math.Cos(h1);
var y = -Math.Cos(d) * Math.Cos(lat) * Math.Sin(h1);
var x = Math.Sin(d) - Math.Sin(lat) * sinA;
var upperA = Math.Atan2(y, x);
var upperB = RadiansToDegrees(upperA);
var horizonCoordinates = new HorizonCoordinates();
horizonCoordinates.Altitude = RadiansToDegrees(Math.Asin(sinA));
horizonCoordinates.Azimuth = upperB;
if (upperB < 0)
{
horizonCoordinates.Azimuth = 360 + horizonCoordinates.Azimuth;
}
return horizonCoordinates;
}
//todo convert to extension method
public double DegreesToRadians(double degrees)
{
return (Math.PI / 180) * degrees;
}
//todo convert to extension method
public double RadiansToDegrees(double radians)
{
double degrees = (180 / Math.PI) * radians;
return (degrees);
}
//todo convert to extension method
public double DateTimeToDecimalHours( DateTime utcDateTime)
{
double sec = utcDateTime.Second;
double min = utcDateTime.Minute;
double hour = utcDateTime.Hour;
var a = Math.Abs(sec) / 60;
var b = (Math.Abs(min) + a) / 60;
var c = Math.Abs(hour) + b;
var d = c;
if ((hour < 0) || (min < 0) || (sec < 0))
d = -c;
return d;
}
//todo convert to extension method
public double UTtoGST(DateTime utcDateTime)
{
Util util = new Util();
var jd = util.DateUTCToJulian(utcDateTime) - 0.5;
if ((jd % 1) <= 0.5 )
jd = Math.Floor( jd );
else
jd = Math.Floor( jd ) + 0.5;
var s = jd - 2451545.0;
var t = s / 36525.0;
var t0 = 6.697374558 + (2400.051336 * t ) +(0.000025862 * (t * t) );
while (t0 < 0)
{
t0 += 24;
}
while (t0 >= 24)
{
t0 -= 24;
}
var ut = DateTimeToDecimalHours(utcDateTime);
var a = ut * 1.002737909;
var t1 = t0 + a;
while (t1 < 0)
{
t1 += 24;
}
while (t1 >= 24)
{
t1 -= 24;
}
return t1;
}
public double GSTtoLST(double gst, double longitude)
{
var l = longitude/ 15;
var lst = gst + l;
while (lst < 0 )
{
lst += 24;
}
while (lst >= 24)
{
lst -= 24;
}
return lst;
}
}
}
@@ -81,6 +81,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AstroMaths.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="Telescope.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+44 -12
View File
@@ -98,6 +98,8 @@ namespace ASCOM.Meade.net
/// </summary>
private AstroUtils astroUtilities;
private AstroMaths astroMaths;
/// <summary>
/// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
/// </summary>
@@ -117,7 +119,9 @@ namespace ASCOM.Meade.net
connectedState = false; // Initialise connected to false
utilities = new Util(); //Initialise util object
astroUtilities = new AstroUtils(); // Initialise astro utilities object
//TODO: Implement your additional construction here
astroMaths = new AstroMaths();
tl.LogMessage("Telescope", "Completed initialisation");
}
@@ -403,21 +407,45 @@ namespace ASCOM.Meade.net
{
get
{
//todo firmware bug in 44Eg, :GA# is returning the dec, not the altitude!
var result = SharedResources.SendString(":GA#");
//:GA# Get Telescope Altitude
//Returns: sDD* MM# or sDD*MMSS#
//The current scope altitude. The returned format depending on the current precision setting.
var altAz = CalcAltAzFromTelescopeEqData();
tl.LogMessage("Altitude", $"{altAz.Altitude}");
return altAz.Altitude;
var alt = utilities.DMSToDegrees(result);
tl.LogMessage("Altitude", $"{alt}");
return alt;
////todo firmware bug in 44Eg, :GA# is returning the dec, not the altitude!
//var result = SharedResources.SendString(":GA#");
////:GA# Get Telescope Altitude
////Returns: sDD* MM# or sDD*MMSS#
////The current scope altitude. The returned format depending on the current precision setting.
//var alt = utilities.DMSToDegrees(result);
//tl.LogMessage("Altitude", $"{alt}");
//return alt;
//tl.LogMessage("Altitude Get", "Not implemented");
//throw new ASCOM.PropertyNotImplementedException("Altitude", false);
}
}
private HorizonCoordinates CalcAltAzFromTelescopeEqData()
{
var altitudeData = SharedResources.Lock(() => new AltitudeData
{
UtcDateTime = this.UTCDate,
SiteLongitude = this.SiteLongitude,
SiteLatitude = this.SiteLatitude,
equatorialCoordinates = new EquatorialCoordinates()
{
RightAscension = this.RightAscension,
Declination = this.Declination
}
});
double hourAngle = astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, altitudeData.SiteLongitude,
altitudeData.equatorialCoordinates.RightAscension);
var altAz = astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, altitudeData.equatorialCoordinates);
return altAz;
}
public double ApertureArea
{
get
@@ -467,15 +495,19 @@ namespace ASCOM.Meade.net
{
get
{
var result = SharedResources.SendString(":GZ#");
//var result = SharedResources.SendString(":GZ#");
//:GZ# Get telescope azimuth
//Returns: DDD*MM#T or DDD*MMSS#
//The current telescope Azimuth depending on the selected precision.
double az = utilities.DMSToDegrees(result);
//double az = utilities.DMSToDegrees(result);
tl.LogMessage("Azimuth Get", $"{az}");
return az;
//tl.LogMessage("Azimuth Get", $"{az}");
//return az;
var altAz = CalcAltAzFromTelescopeEqData();
tl.LogMessage("Azimuth Get", $"{altAz.Azimuth}");
return altAz.Azimuth;
}
}