Fixed problem where SlewToAltAz didn't work correctly. Now uses the RA/Dec slew for everything, and converts the values as needed.

This commit is contained in:
2019-05-19 19:25:43 +01:00
parent d39846fa18
commit 7cb50de30d
6 changed files with 384 additions and 283 deletions
+48 -1
View File
@@ -43,6 +43,53 @@ namespace ASCOM.Meade.net
return h;
}
public double HourAngleToRightAscension(DateTime utcDateTime, double longitude, double hourAngle )
{
var gst = UTtoGST(utcDateTime);
var lst = GSTtoLST( gst, longitude);
var raHours = hourAngle;
var h1 = lst - raHours;
var h = h1;
if (h1 < 0)
{
h += 24;
}
return h;
}
public EquatorialCoordinates ConvertHozToEq( DateTime utcDateTime, double latitude, double longitude, HorizonCoordinates altAz)
{
var az = DegreesToRadians(altAz.Azimuth);
var alt = DegreesToRadians(altAz.Altitude);
var lat = DegreesToRadians(latitude);
var sinDec = Math.Sin(alt) * Math.Sin(lat) + Math.Cos(alt) * Math.Cos(lat) * Math.Cos(az);
var dec = RadiansToDegrees(Math.Asin(sinDec));
var y = -Math.Cos(alt) * Math.Cos(lat) * Math.Sin(az);
var x = Math.Sin(alt) - Math.Sin(lat) * sinDec;
var upperA = Math.Atan2(y,x);
var upperB = RadiansToDegrees(upperA);
var ha = upperB;
if (upperB < 0)
{
ha += 360;
}
ha = ha / 15;
EquatorialCoordinates equatorialCoordinates = new EquatorialCoordinates
{
RightAscension = HourAngleToRightAscension( utcDateTime, longitude, ha ),
Declination = dec
};
return equatorialCoordinates;
}
public HorizonCoordinates ConvertEqToHoz(double hourAngle, double latitude, EquatorialCoordinates raDec)
{
var h = hourAngle * 15;
@@ -51,7 +98,7 @@ namespace ASCOM.Meade.net
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 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);
+31 -4
View File
@@ -1243,14 +1243,41 @@ namespace ASCOM.Meade.net
public void SlewToAltAzAsync(double azimuth, double altitude)
{
tl.LogMessage("SlewToAltAzAsync", $"Az=~{azimuth} Alt={altitude}");
if (altitude > 90)
throw new ASCOM.InvalidValueException("Altitude cannot be greater than 90.");
if (altitude < 0)
throw new ASCOM.InvalidValueException("Altitide cannot be less than 0.");
if (azimuth >= 360)
throw new ASCOM.InvalidValueException("Azimuth cannot be 360 or higher.");
if (azimuth < 0)
throw new ASCOM.InvalidValueException("Azimuth cannot be less than 0.");
tl.LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}");
HorizonCoordinates altAz = new HorizonCoordinates();
altAz.Azimuth = azimuth;
altAz.Altitude = altitude;
var utcDateTime = UTCDate;
var latitude = SiteLatitude;
var longitude = SiteLongitude;
SharedResources.Lock(() =>
{
TargetAltitude = altitude;
TargetAzimuth = azimuth;
var raDec = astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz);
DoSlewAsync(false);
TargetRightAscension = raDec.RightAscension;
TargetDeclination = raDec.Declination;
DoSlewAsync(true);
//TargetAltitude = altitude;
//TargetAzimuth = azimuth;
//DoSlewAsync(false);
});
}