From 04fb429963c29dc64650c0472105a6cc78ce2bee Mon Sep 17 00:00:00 2001 From: Fabian Uehleke Date: Fri, 20 Nov 2026 16:27:09 +0100 Subject: [PATCH] fix(ASCOM): report SideOfPier from the mount's flip state, not the hour angle The mount only changes pointing state when a slew flips it, so SideOfPier now comes from the sign of the DEC stepper position in :GX# (positive pierWest, negative pierEast, 0 at the pole pierUnknown), in both hemispheres. The old hour-angle formula turned East whenever a target crossed the meridian while tracking, so PHD2 flipped its calibration at the next guide start and N.I.N.A. could skip its meridian flip. Fixes OpenAstroTech/OpenAstroTracker-Firmware#282 --- ASCOM.Driver/TelescopeDriver/Driver.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ASCOM.Driver/TelescopeDriver/Driver.cs b/ASCOM.Driver/TelescopeDriver/Driver.cs index e641db6..c5029d2 100644 --- a/ASCOM.Driver/TelescopeDriver/Driver.cs +++ b/ASCOM.Driver/TelescopeDriver/Driver.cs @@ -833,17 +833,20 @@ public PierSide SideOfPier { get { - // Read once to avoid multiple serial round-trips and to keep the comparison consistent. - double lst = SiderealTime; - double ra = RightAscension; - - // Compute how far the RA is ahead of the LST, wrapping correctly around 0h/24h. - // hourAngle > 0 means the object has already crossed the meridian (telescope pointing west = pier east). - // hourAngle in [0, 12): pier east. hourAngle in [12, 24): pier west. - double hourAngle = (lst - ra + 24.0) % 24.0; - PierSide retVal = hourAngle < 12.0 ? PierSide.pierEast : PierSide.pierWest; + // SideOfPier is the pointing state, which only changes when the mount flips during a slew, not when + // the target crosses the meridian. The firmware flips by turning DEC through the pole, so the sign + // of the DEC stepper position (field 3 of :GX#) is the pointing state, in both hemispheres: + // positive = not flipped = pierWest, negative = flipped = pierEast, zero = at the pole. + var cmdResult = CommandString(":GX#,#"); + var fields = cmdResult.Split(','); + if (fields.Length < 4 || !long.TryParse(fields[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out long decSteps)) + { + LogMessage(LoggingFlags.Scope, $"SideOfPier Get - unexpected :GX# response '{cmdResult}' => pierUnknown"); + return PierSide.pierUnknown; + } - LogMessage(LoggingFlags.Scope, $"SideOfPier Get => {Enum.GetName(typeof(PierSide), retVal)} (LST={lst:0.000}, RA={ra:0.000}, HA={hourAngle:0.000})"); + PierSide retVal = decSteps > 0 ? PierSide.pierWest : decSteps < 0 ? PierSide.pierEast : PierSide.pierUnknown; + LogMessage(LoggingFlags.Scope, $"SideOfPier Get => {Enum.GetName(typeof(PierSide), retVal)} (DEC steps={decSteps})"); return retVal; } set