Skip to content

Commit

Permalink
Improved goto logging and increased thread sleep times for status loops
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorgan001 committed Apr 30, 2022
1 parent ec0801b commit ecb79b1
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<Trademark>GS Server</Trademark>
<NeutralLanguage>en</NeutralLanguage>
<Copyright>Copyright © GreenSwamp Software 2019-2022</Copyright>
<AssemblyVersion>1.0.4.6</AssemblyVersion>
<FileVersion>1.0.4.6</FileVersion>
<ProductVersion>1.0.4.6</ProductVersion>
<Version>1.0.4.6</Version>
<AssemblyVersion>1.0.4.7</AssemblyVersion>
<FileVersion>1.0.4.7</FileVersion>
<ProductVersion>1.0.4.7</ProductVersion>
<Version>1.0.4.7</Version>
</PropertyGroup>
</Project>
143 changes: 113 additions & 30 deletions GS.Server/SkyTelescope/SkyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,19 @@ private set
/// <returns></returns>
private static int SimGoTo(double[] target, bool trackingState)
{

var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"from|{ActualAxisX}|{ActualAxisY}|to|{target[0]}|{target[1]}|tracking|{trackingState}"
};
MonitorLog.LogToMonitor(monitorItem);

const int returncode = 0;
const int timer = 80; // stop slew after seconds
var stopwatch = Stopwatch.StartNew();
Expand Down Expand Up @@ -1221,23 +1234,23 @@ private static int SimGoTo(double[] target, bool trackingState)
}

AxesStopValidate();
var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"Initial|{_targetAxes}|{stopwatch.Elapsed.TotalSeconds}|{simTarget[0]}|{simTarget[1]}"
Message = $"GoToSeconds|{stopwatch.Elapsed.TotalSeconds}|SimTarget|{simTarget[0]}|{simTarget[1]}"
};
MonitorLog.LogToMonitor(monitorItem);

#endregion

#region Final precision slew

Task decTask = Task.Run(() => SimPrecisionGotoDec(target[1], simTarget[1]));
Task decTask = Task.Run(() => SimPrecisionGotoDec(simTarget[1]));
Task raTask = Task.Run(() => SimPrecisionGoToRA(target, trackingState, stopwatch));

Task.WaitAll(decTask, raTask);
Expand All @@ -1253,11 +1266,22 @@ private static int SimGoTo(double[] target, bool trackingState)
/// <summary>
/// Performs a final precision slew of the Dec axis to target if necessary.
/// </summary>
/// <param name="targetDec"></param>
/// <param name="skyTargetDec"></param>
/// <param name="simTargetDec"></param>
/// <returns></returns>
private static int SimPrecisionGotoDec(double targetDec, double skyTargetDec)
private static int SimPrecisionGotoDec(double simTargetDec)
{
var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"from|{ActualAxisY}|to|{simTargetDec}"
};
MonitorLog.LogToMonitor(monitorItem);

const int returncode = 0;
var gotoPrecision = SkySettings.GotoPrecision;
var maxtries = 0;
Expand All @@ -1270,12 +1294,12 @@ private static int SimPrecisionGotoDec(double targetDec, double skyTargetDec)
// Calculate error
var rawPositions = GetRawDegrees();
if (rawPositions == null || double.IsNaN(rawPositions[1])) { break; }
var deltaDegree = Math.Abs(skyTargetDec - rawPositions[1]);
var deltaDegree = Math.Abs(simTargetDec - rawPositions[1]);

if (deltaDegree < gotoPrecision) { break; }
if (SlewState == SlewType.SlewNone) { break; } //check for a stop

object _ = new CmdAxisGoToTarget(0, Axis.Axis2, skyTargetDec); //move to target DEC
object _ = new CmdAxisGoToTarget(0, Axis.Axis2, simTargetDec); //move to target DEC

// track movement until axis is stopped
var stopwatch1 = Stopwatch.StartNew();
Expand All @@ -1287,15 +1311,15 @@ private static int SimPrecisionGotoDec(double targetDec, double skyTargetDec)
if (axis2Status.Stopped) { break; }
}

var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"Dec Precision:{targetDec}|{deltaDegree}"
Message = $"DeltaDegrees|{deltaDegree}"
};
MonitorLog.LogToMonitor(monitorItem);
}
Expand All @@ -1311,6 +1335,19 @@ private static int SimPrecisionGotoDec(double targetDec, double skyTargetDec)
/// <returns></returns>
private static int SimPrecisionGoToRA(double[] target, bool trackingState, Stopwatch stopwatch)
{

var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"from|{ActualAxisX}|to|{target[0]}|state|{trackingState}"
};
MonitorLog.LogToMonitor(monitorItem);

const int returnCode = 0;
if (!trackingState) return returnCode;
//attempt precision moves to target
Expand All @@ -1330,21 +1367,18 @@ private static int SimPrecisionGoToRA(double[] target, bool trackingState, Stopw
var deltaDegree = rate * deltaTime;
if (deltaDegree < gotoPrecision) { break; }


var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"RA Delta:{rate}|{deltaTime}|{deltaDegree}"
Message = $"Deltas|Rate|{rate}|Time|{deltaTime}|Degree|{deltaDegree}"
};
MonitorLog.LogToMonitor(monitorItem);



target[0] += deltaDegree;
var deltaTarget = Axes.AxesAppToMount(target);

Expand All @@ -1370,7 +1404,7 @@ private static int SimPrecisionGoToRA(double[] target, bool trackingState, Stopw
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"RA Precision:{target[0]}|{deltaTime}|{deltaDegree}"
Message = $"Precision|NewTarget|{target[0]}|Time|{deltaTime}|Degree|{deltaDegree}"
};
MonitorLog.LogToMonitor(monitorItem);

Expand Down Expand Up @@ -1619,6 +1653,18 @@ private static Vector GetSlewRate()
/// <returns></returns>
private static int SkyGoTo(double[] target, bool trackingState)
{
var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"from|{ActualAxisX}|{ActualAxisY}|to|{target[0]}|{target[1]}|tracking|{trackingState}"
};
MonitorLog.LogToMonitor(monitorItem);

const int returncode = 0;
// stop slew after 80 seconds
const int timer = 80;
Expand Down Expand Up @@ -1653,22 +1699,22 @@ private static int SkyGoTo(double[] target, bool trackingState)
}

AxesStopValidate();
var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"Initial|{_targetAxes}|Seconds|{stopwatch.Elapsed.TotalSeconds}|Target|{skyTarget[0]}|{skyTarget[1]}"
Message = $"GoToSeconds|{stopwatch.Elapsed.TotalSeconds}|SkyTarget|{skyTarget[0]}|{skyTarget[1]}"
};
MonitorLog.LogToMonitor(monitorItem);

#endregion

#region Final precision slew
Task decTask = Task.Run(() => SkyPrecisionGotoDec(target[1], skyTarget[1]));
Task decTask = Task.Run(() => SkyPrecisionGotoDec(skyTarget[1]));
Task raTask = Task.Run(() => SkyPrecisionGoToRA(target, trackingState, stopwatch));

Task.WaitAll(decTask, raTask);
Expand All @@ -1683,11 +1729,22 @@ private static int SkyGoTo(double[] target, bool trackingState)
/// <summary>
/// Performs a final precision slew of the Dec axis to target if necessary.
/// </summary>
/// <param name="targetDec"></param>
/// <param name="skyTargetDec"></param>
/// <returns></returns>
private static int SkyPrecisionGotoDec(double targetDec, double skyTargetDec)
private static int SkyPrecisionGotoDec(double skyTargetDec)
{
var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"from|{ActualAxisY}|to|{skyTargetDec}"
};
MonitorLog.LogToMonitor(monitorItem);

const int returncode = 0;
var gotoPrecision = SkySettings.GotoPrecision;
var maxtries = 0;
Expand Down Expand Up @@ -1715,17 +1772,18 @@ private static int SkyPrecisionGotoDec(double targetDec, double skyTargetDec)
var statusy = new SkyIsAxisFullStop(SkyQueue.NewId, AxisId.Axis2);
var axis2stopped = Convert.ToBoolean(SkyQueue.GetCommandResult(statusy).Result);
if (axis2stopped) { break; }
Thread.Sleep(100);
}

var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"Precision|Target|{targetDec}|Degree|{deltaDegree}"
Message = $"DeltaDegrees|{deltaDegree}"
};
MonitorLog.LogToMonitor(monitorItem);
}
Expand All @@ -1741,6 +1799,18 @@ private static int SkyPrecisionGotoDec(double targetDec, double skyTargetDec)
/// <returns></returns>
private static int SkyPrecisionGoToRA(double[] target, bool trackingState, Stopwatch stopwatch)
{
var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"from|{ActualAxisX}|to|{target[0]}|tracking|{trackingState}"
};
MonitorLog.LogToMonitor(monitorItem);

const int returnCode = 0;
if (!trackingState) return returnCode;
//attempt precision moves to target
Expand All @@ -1759,7 +1829,7 @@ private static int SkyPrecisionGoToRA(double[] target, bool trackingState, Stopw
//calculate new target position
var deltaDegree = rate * deltaTime;

var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Expand Down Expand Up @@ -1787,6 +1857,7 @@ private static int SkyPrecisionGoToRA(double[] target, bool trackingState, Stopw
var statusx = new SkyIsAxisFullStop(SkyQueue.NewId, AxisId.Axis1);
var axis1stopped = Convert.ToBoolean(SkyQueue.GetCommandResult(statusx).Result);
if (axis1stopped) { break; }
Thread.Sleep(100);
}

monitorItem = new MonitorEntry
Expand All @@ -1797,7 +1868,7 @@ private static int SkyPrecisionGoToRA(double[] target, bool trackingState, Stopw
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"Precision|Target|{target[0]}|Time|{deltaTime}|Degree|{deltaDegree}"
Message = $"Precision|NewTarget|{target[0]}|Time|{deltaTime}|Degree|{deltaDegree}"
};
MonitorLog.LogToMonitor(monitorItem);

Expand Down Expand Up @@ -2964,7 +3035,7 @@ private static async void GoToAsync(double[] target, SlewType slewState)
Type = MonitorType.Information,
Method = "GoToAsync",
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"Goto finished|{returncode}|{SlewState}|{_util.HoursToHMS(RightAscension, "h ", ":", "", 2)}"
Message = $"{SlewState} finished|code|{returncode}|{_util.HoursToHMS(RightAscension, "h ", ":", "", 2)}|at|{ActualAxisX}|{ActualAxisY}"
};
MonitorLog.LogToMonitor(monitorItem);

Expand Down Expand Up @@ -3054,6 +3125,18 @@ public static void HcMoves(SlewSpeed speed, SlewDirection direction, HCMode HcMo
{
if (!IsMountRunning) { return; }

var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Category = MonitorCategory.Server,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"{SkySettings.HcSpeed}|{HcMode}|{direction}|{ActualAxisX}|{ActualAxisY}"
};
MonitorLog.LogToMonitor(monitorItem);

var change = new double[] { 0, 0 };
double delta;
switch (speed)
Expand Down Expand Up @@ -3211,7 +3294,7 @@ public static void HcMoves(SlewSpeed speed, SlewDirection direction, HCMode HcMo
// Log data to Monitor
if (Math.Abs(change[0]) > 0 || Math.Abs(change[1]) > 0)
{
var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Expand Down Expand Up @@ -3282,7 +3365,7 @@ public static void HcMoves(SlewSpeed speed, SlewDirection direction, HCMode HcMo
// log anti-lash moves
if (Math.Abs(stepsNeededDec) > 0 && HcPrevMoveDec != null)
{
var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Expand All @@ -3296,7 +3379,7 @@ public static void HcMoves(SlewSpeed speed, SlewDirection direction, HCMode HcMo
}
if (Math.Abs(stepsNeededRa) > 0 && HcPrevMoveRa != null)
{
var monitorItem = new MonitorEntry
monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.Server,
Expand Down Expand Up @@ -4297,7 +4380,7 @@ private static void SlewMount(Vector targetPosition, SlewType slewState)
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"{targetPosition.X}|{targetPosition.Y}|{slewState}"
Message = $"from|{ActualAxisX}|{ActualAxisY}|to|{targetPosition.X}|{targetPosition.Y}|SlewType|{slewState}"
};
MonitorLog.LogToMonitor(monitorItem);

Expand Down
11 changes: 11 additions & 0 deletions GS.Server/SkyTelescope/SkyTelescopeVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6216,6 +6216,17 @@ private void AcceptRaGoToDialog()
}

var radec = Transforms.CoordTypeToInternal(GoToRa, GoToDec);
var monitorItem = new MonitorEntry
{
Datetime = HiResDateTime.UtcNow,
Device = MonitorDevice.UI,
Category = MonitorCategory.Interface,
Type = MonitorType.Information,
Method = MethodBase.GetCurrentMethod()?.Name,
Thread = Thread.CurrentThread.ManagedThreadId,
Message = $"From|{SkyServer.ActualAxisX}|{SkyServer.ActualAxisY}|to|{radec.X}|{radec.Y}"
};
MonitorLog.LogToMonitor(monitorItem);
SkyServer.SlewRaDec(radec.X, radec.Y);
IsDialogOpen = false;
}
Expand Down
Loading

0 comments on commit ecb79b1

Please sign in to comment.