Skip to content

Commit

Permalink
For all devices, extend fast polling for 3 seconds after completion o…
Browse files Browse the repository at this point in the history
…f a slew.

Bump version to 6.6.0.13.
  • Loading branch information
astroman133 committed Jun 29, 2022
1 parent 683a582 commit 7041571
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 19 deletions.
62 changes: 53 additions & 9 deletions DeviceHub/DeviceManagers/DomeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,31 +429,70 @@ private void PollDomeTask( CancellationToken token )
Stopwatch watch = new Stopwatch();
double overhead = 0.0;

TimeSpan fastPollExtension = new TimeSpan( 0, 0, 3 ); //Wait 3 seconds after movement stops to return to normal polling.
bool previousMoveStatus = false;
DateTime returnToNormalPollingTime = DateTime.MinValue;
int previousPollingPeriod;

while ( !taskCancelled )
{
DateTime wakeupTime = DateTime.Now;
//Debug.WriteLine( $"Awakened @ {wakeupTime:hh:mm:ss.fff}." );
previousPollingPeriod = PollingPeriod;
PollingPeriod = POLLING_INTERVAL_NORMAL;
int fastPollingMs = Convert.ToInt32( FastPollingPeriod * 1000.0 );

if ( Service.DeviceAvailable )
{
UpdateDomeStatusTask();

if ( !Status.Slewing )
{
SlewTheSlavedDome( ref nextSlaveAdjustmentTime );
UpdateDomeStatusTask();
if ( SlewTheSlavedDome( ref nextSlaveAdjustmentTime ) )
{
UpdateDomeStatusTask();
}
}

bool shutterMoving = Status.ShutterStatus == ShutterState.shutterOpening
|| Status.ShutterStatus == ShutterState.shutterClosing;
bool isMoving = Status.Slewing
|| Status.ShutterStatus == ShutterState.shutterOpening
|| Status.ShutterStatus == ShutterState.shutterClosing;

if ( !( Status.Slewing || shutterMoving ) && PollingPeriod != POLLING_INTERVAL_NORMAL )
if ( isMoving )
{
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {POLLING_INTERVAL_NORMAL} ms." );
// We are moving, so use the fast polling rate.

PollingPeriod = fastPollingMs;
}
else if ( previousMoveStatus )
{
// We stopped moving, so start the timer to return to normal polling.

PollingPeriod = ( Status.Slewing || shutterMoving ) ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_INTERVAL_NORMAL;
}
returnToNormalPollingTime = DateTime.Now + fastPollExtension;
PollingPeriod = fastPollingMs;
}
else if ( DateTime.Now < returnToNormalPollingTime )
{
// Continue fast polling.

PollingPeriod = fastPollingMs;
}
else
{
// Return to normal polling.

returnToNormalPollingTime = DateTime.MinValue;
}

// Remember our state for the next time through this loop.

previousMoveStatus = isMoving;

if ( PollingPeriod == POLLING_INTERVAL_NORMAL && previousPollingPeriod != POLLING_INTERVAL_NORMAL )
{
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {PollingPeriod} ms." );
}
}

TimeSpan waitInterval = wakeupTime.AddMilliseconds( (double)PollingPeriod ) - DateTime.Now;
waitInterval -= TimeSpan.FromMilliseconds( overhead );
Expand Down Expand Up @@ -500,8 +539,9 @@ private void PollDomeTask( CancellationToken token )
IsPolling = false;
}

private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
private bool SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
{
bool retval = false;
ActivityMessageTypes msgType = ActivityMessageTypes.Commands;
DateTime returnTime = nextAdjustmentTime;

Expand Down Expand Up @@ -549,6 +589,7 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
double localHourAngle = TelescopeStatus.CalculateHourAngle( SlavedSlewState.RightAscension );

SlaveDomePointing( scopeTargetPosition, localHourAngle, SlavedSlewState.SideOfPier );
retval = true;
}
catch ( TransformUninitialisedException xcp )
{
Expand Down Expand Up @@ -588,6 +629,7 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
try
{
SlaveDomePointing( scopePosition, TelescopeStatus.LocalHourAngle, TelescopeStatus.SideOfPier );
retval = true;
}
catch ( Exception xcp )
{
Expand All @@ -610,6 +652,8 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
}

nextAdjustmentTime = returnTime;

return retval;
}

private void SlaveDomePointing( Point scopePosition, double localHourAngle, PierSide sideOfPier )
Expand Down
47 changes: 40 additions & 7 deletions DeviceHub/DeviceManagers/FocuserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,23 @@ private void PollFocuserTask( CancellationToken token )
Stopwatch watch = new Stopwatch();
double overhead = 0.0;

TimeSpan fastPollExtension = new TimeSpan( 0, 0, 3 ); //Wait 3 seconds after movement stops to return to normal polling.
bool previousMoveStatus = false;
DateTime returnToNormalPollingTime = DateTime.MinValue;
int previousPollingPeriod;

while ( !taskCancelled )
{
DateTime wakeupTime = DateTime.Now;
//Debug.WriteLine( $"Awakened @ {wakeupTime:hh:mm:ss.fff}." );
previousPollingPeriod = PollingPeriod;
PollingPeriod = POLLING_PERIOD_NORMAL;
int fastPollingMs = Convert.ToInt32( FastPollingPeriod * 1000.0 );

if ( Service.DeviceAvailable )
{
UpdateFocuserStatusTask();

if ( MoveInProgress && !Status.IsMoving )
{
MoveInProgress = false;
Expand All @@ -360,23 +370,46 @@ private void PollFocuserTask( CancellationToken token )
{
Service.TempComp = true;
ReEnableTempComp = false;
UpdateFocuserStatusTask();
}

UpdateFocuserStatusTask();

Messenger.Default.Send( new FocuserMoveCompletedMessage() );
}

if ( MoveInProgress )
{
// Switch to fast polling because the device is moving.
//Debug.WriteLine( "Switching to fast polling because the device is moving." );
PollingPeriod = fastPollingMs;
}
else if ( previousMoveStatus)
{
// We stopped moving, so start the timer to return to normal polling.
//Debug.WriteLine( "We stopped moving, so start the timer to return to normal polling." );
returnToNormalPollingTime = DateTime.Now + fastPollExtension;
PollingPeriod = fastPollingMs;
}
else if ( DateTime.Now < returnToNormalPollingTime)
{
// Continue fast polling.
//Debug.WriteLine( "Continue fast polling." );
PollingPeriod = fastPollingMs;
}
else
{
UpdateFocuserStatusTask();
// Return to normal polling.
//Debug.WriteLine( "Return to normal polling." );
returnToNormalPollingTime = DateTime.MinValue;
}

if ( !MoveInProgress && PollingPeriod != POLLING_PERIOD_NORMAL )
// Remember our state for the next time through this loop.

previousMoveStatus = MoveInProgress;

if ( PollingPeriod == POLLING_PERIOD_NORMAL && previousPollingPeriod != POLLING_PERIOD_NORMAL )
{
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {POLLING_PERIOD_NORMAL} ms." );
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {PollingPeriod} ms." );
}

PollingPeriod = MoveInProgress ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_PERIOD_NORMAL;
}

TimeSpan waitPeriod = wakeupTime.AddMilliseconds( (double)PollingPeriod ) - DateTime.Now;
Expand Down
45 changes: 44 additions & 1 deletion DeviceHub/DeviceManagers/TelescopeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,18 @@ private void PollScopeTask( CancellationToken token )
Stopwatch watch = new Stopwatch();
double overhead = 0.0;

TimeSpan fastPollExtension = new TimeSpan( 0, 0, 3 ); //Wait 3 seconds after movement stops to return to normal polling.
bool previousMoveStatus = false;
DateTime returnToNormalPollingTime = DateTime.MinValue;
int previousPollingPeriod;

while ( !taskCancelled )
{
DateTime wakeupTime = DateTime.Now;
//Debug.WriteLine( $"Awakened @ {wakeupTime:hh:mm:ss.fff}." );
previousPollingPeriod = PollingPeriod;
PollingPeriod = POLLING_PERIOD_NORMAL;
int fastPollingMs = Convert.ToInt32( FastPollingPeriod * 1000.0 );

if ( Service.DeviceAvailable )
{
Expand Down Expand Up @@ -815,7 +823,42 @@ private void PollScopeTask( CancellationToken token )
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {POLLING_PERIOD_NORMAL} ms." );
}

PollingPeriod = ( Status.Slewing ) ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_PERIOD_NORMAL;
//PollingPeriod = ( Status.Slewing ) ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_PERIOD_NORMAL;

if ( Status.Slewing )
{
// We are moving, so use the fast polling rate.

PollingPeriod = fastPollingMs;
}
else if ( previousMoveStatus )
{
// We stopped moving, so start the timer to return to normal polling.

returnToNormalPollingTime = DateTime.Now + fastPollExtension;
PollingPeriod = fastPollingMs;
}
else if ( DateTime.Now < returnToNormalPollingTime )
{
// Continue fast polling.

PollingPeriod = fastPollingMs;
}
else
{
// Return to normal polling.

returnToNormalPollingTime = DateTime.MinValue;
}

// Remember our state for the next time through this loop.

previousMoveStatus = Status.Slewing;

if ( PollingPeriod == POLLING_PERIOD_NORMAL && previousPollingPeriod != POLLING_PERIOD_NORMAL )
{
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {PollingPeriod} ms." );
}
}

TimeSpan waitInterval = wakeupTime.AddMilliseconds( (double)PollingPeriod ) - DateTime.Now;
Expand Down
2 changes: 1 addition & 1 deletion Inno Setup/ASCOM Device Hub Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
;

#define MyAppName "ASCOM.DeviceHub"
#define MyAppVersion "6.6.0.12"
#define MyAppVersion "6.6.0.13"
#define MyDestSubdirName "DeviceHub"
; #define MyPlatformRoot "D:\Github Repos\ASCOMPlatform\"
#define MyPlatformRoot "D:\My Projects\Visual Studio 2022\Ascom\"
Expand Down
2 changes: 1 addition & 1 deletion ProductAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "6.6.0.12" )]
[assembly: AssemblyVersion( "6.6.0.13" )]

0 comments on commit 7041571

Please sign in to comment.