Skip to content

Commit 7041571

Browse files
committed
For all devices, extend fast polling for 3 seconds after completion of a slew.
Bump version to 6.6.0.13.
1 parent 683a582 commit 7041571

5 files changed

Lines changed: 139 additions & 19 deletions

File tree

DeviceHub/DeviceManagers/DomeManager.cs

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,31 +429,70 @@ private void PollDomeTask( CancellationToken token )
429429
Stopwatch watch = new Stopwatch();
430430
double overhead = 0.0;
431431

432+
TimeSpan fastPollExtension = new TimeSpan( 0, 0, 3 ); //Wait 3 seconds after movement stops to return to normal polling.
433+
bool previousMoveStatus = false;
434+
DateTime returnToNormalPollingTime = DateTime.MinValue;
435+
int previousPollingPeriod;
436+
432437
while ( !taskCancelled )
433438
{
434439
DateTime wakeupTime = DateTime.Now;
435440
//Debug.WriteLine( $"Awakened @ {wakeupTime:hh:mm:ss.fff}." );
441+
previousPollingPeriod = PollingPeriod;
442+
PollingPeriod = POLLING_INTERVAL_NORMAL;
443+
int fastPollingMs = Convert.ToInt32( FastPollingPeriod * 1000.0 );
436444

437445
if ( Service.DeviceAvailable )
438446
{
439447
UpdateDomeStatusTask();
440448

441449
if ( !Status.Slewing )
442450
{
443-
SlewTheSlavedDome( ref nextSlaveAdjustmentTime );
444-
UpdateDomeStatusTask();
451+
if ( SlewTheSlavedDome( ref nextSlaveAdjustmentTime ) )
452+
{
453+
UpdateDomeStatusTask();
454+
}
445455
}
446456

447-
bool shutterMoving = Status.ShutterStatus == ShutterState.shutterOpening
448-
|| Status.ShutterStatus == ShutterState.shutterClosing;
457+
bool isMoving = Status.Slewing
458+
|| Status.ShutterStatus == ShutterState.shutterOpening
459+
|| Status.ShutterStatus == ShutterState.shutterClosing;
449460

450-
if ( !( Status.Slewing || shutterMoving ) && PollingPeriod != POLLING_INTERVAL_NORMAL )
461+
if ( isMoving )
451462
{
452-
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {POLLING_INTERVAL_NORMAL} ms." );
463+
// We are moving, so use the fast polling rate.
464+
465+
PollingPeriod = fastPollingMs;
453466
}
467+
else if ( previousMoveStatus )
468+
{
469+
// We stopped moving, so start the timer to return to normal polling.
454470

455-
PollingPeriod = ( Status.Slewing || shutterMoving ) ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_INTERVAL_NORMAL;
456-
}
471+
returnToNormalPollingTime = DateTime.Now + fastPollExtension;
472+
PollingPeriod = fastPollingMs;
473+
}
474+
else if ( DateTime.Now < returnToNormalPollingTime )
475+
{
476+
// Continue fast polling.
477+
478+
PollingPeriod = fastPollingMs;
479+
}
480+
else
481+
{
482+
// Return to normal polling.
483+
484+
returnToNormalPollingTime = DateTime.MinValue;
485+
}
486+
487+
// Remember our state for the next time through this loop.
488+
489+
previousMoveStatus = isMoving;
490+
491+
if ( PollingPeriod == POLLING_INTERVAL_NORMAL && previousPollingPeriod != POLLING_INTERVAL_NORMAL )
492+
{
493+
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {PollingPeriod} ms." );
494+
}
495+
}
457496

458497
TimeSpan waitInterval = wakeupTime.AddMilliseconds( (double)PollingPeriod ) - DateTime.Now;
459498
waitInterval -= TimeSpan.FromMilliseconds( overhead );
@@ -500,8 +539,9 @@ private void PollDomeTask( CancellationToken token )
500539
IsPolling = false;
501540
}
502541

503-
private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
542+
private bool SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
504543
{
544+
bool retval = false;
505545
ActivityMessageTypes msgType = ActivityMessageTypes.Commands;
506546
DateTime returnTime = nextAdjustmentTime;
507547

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

551591
SlaveDomePointing( scopeTargetPosition, localHourAngle, SlavedSlewState.SideOfPier );
592+
retval = true;
552593
}
553594
catch ( TransformUninitialisedException xcp )
554595
{
@@ -588,6 +629,7 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
588629
try
589630
{
590631
SlaveDomePointing( scopePosition, TelescopeStatus.LocalHourAngle, TelescopeStatus.SideOfPier );
632+
retval = true;
591633
}
592634
catch ( Exception xcp )
593635
{
@@ -610,6 +652,8 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
610652
}
611653

612654
nextAdjustmentTime = returnTime;
655+
656+
return retval;
613657
}
614658

615659
private void SlaveDomePointing( Point scopePosition, double localHourAngle, PierSide sideOfPier )

DeviceHub/DeviceManagers/FocuserManager.cs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,23 @@ private void PollFocuserTask( CancellationToken token )
345345
Stopwatch watch = new Stopwatch();
346346
double overhead = 0.0;
347347

348+
TimeSpan fastPollExtension = new TimeSpan( 0, 0, 3 ); //Wait 3 seconds after movement stops to return to normal polling.
349+
bool previousMoveStatus = false;
350+
DateTime returnToNormalPollingTime = DateTime.MinValue;
351+
int previousPollingPeriod;
352+
348353
while ( !taskCancelled )
349354
{
350355
DateTime wakeupTime = DateTime.Now;
351356
//Debug.WriteLine( $"Awakened @ {wakeupTime:hh:mm:ss.fff}." );
357+
previousPollingPeriod = PollingPeriod;
358+
PollingPeriod = POLLING_PERIOD_NORMAL;
359+
int fastPollingMs = Convert.ToInt32( FastPollingPeriod * 1000.0 );
352360

353361
if ( Service.DeviceAvailable )
354362
{
363+
UpdateFocuserStatusTask();
364+
355365
if ( MoveInProgress && !Status.IsMoving )
356366
{
357367
MoveInProgress = false;
@@ -360,23 +370,46 @@ private void PollFocuserTask( CancellationToken token )
360370
{
361371
Service.TempComp = true;
362372
ReEnableTempComp = false;
373+
UpdateFocuserStatusTask();
363374
}
364375

365-
UpdateFocuserStatusTask();
366-
367376
Messenger.Default.Send( new FocuserMoveCompletedMessage() );
368377
}
378+
379+
if ( MoveInProgress )
380+
{
381+
// Switch to fast polling because the device is moving.
382+
//Debug.WriteLine( "Switching to fast polling because the device is moving." );
383+
PollingPeriod = fastPollingMs;
384+
}
385+
else if ( previousMoveStatus)
386+
{
387+
// We stopped moving, so start the timer to return to normal polling.
388+
//Debug.WriteLine( "We stopped moving, so start the timer to return to normal polling." );
389+
returnToNormalPollingTime = DateTime.Now + fastPollExtension;
390+
PollingPeriod = fastPollingMs;
391+
}
392+
else if ( DateTime.Now < returnToNormalPollingTime)
393+
{
394+
// Continue fast polling.
395+
//Debug.WriteLine( "Continue fast polling." );
396+
PollingPeriod = fastPollingMs;
397+
}
369398
else
370399
{
371-
UpdateFocuserStatusTask();
400+
// Return to normal polling.
401+
//Debug.WriteLine( "Return to normal polling." );
402+
returnToNormalPollingTime = DateTime.MinValue;
372403
}
373404

374-
if ( !MoveInProgress && PollingPeriod != POLLING_PERIOD_NORMAL )
405+
// Remember our state for the next time through this loop.
406+
407+
previousMoveStatus = MoveInProgress;
408+
409+
if ( PollingPeriod == POLLING_PERIOD_NORMAL && previousPollingPeriod != POLLING_PERIOD_NORMAL )
375410
{
376-
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {POLLING_PERIOD_NORMAL} ms." );
411+
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {PollingPeriod} ms." );
377412
}
378-
379-
PollingPeriod = MoveInProgress ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_PERIOD_NORMAL;
380413
}
381414

382415
TimeSpan waitPeriod = wakeupTime.AddMilliseconds( (double)PollingPeriod ) - DateTime.Now;

DeviceHub/DeviceManagers/TelescopeManager.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,18 @@ private void PollScopeTask( CancellationToken token )
778778
Stopwatch watch = new Stopwatch();
779779
double overhead = 0.0;
780780

781+
TimeSpan fastPollExtension = new TimeSpan( 0, 0, 3 ); //Wait 3 seconds after movement stops to return to normal polling.
782+
bool previousMoveStatus = false;
783+
DateTime returnToNormalPollingTime = DateTime.MinValue;
784+
int previousPollingPeriod;
785+
781786
while ( !taskCancelled )
782787
{
783788
DateTime wakeupTime = DateTime.Now;
784789
//Debug.WriteLine( $"Awakened @ {wakeupTime:hh:mm:ss.fff}." );
790+
previousPollingPeriod = PollingPeriod;
791+
PollingPeriod = POLLING_PERIOD_NORMAL;
792+
int fastPollingMs = Convert.ToInt32( FastPollingPeriod * 1000.0 );
785793

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

818-
PollingPeriod = ( Status.Slewing ) ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_PERIOD_NORMAL;
826+
//PollingPeriod = ( Status.Slewing ) ? Convert.ToInt32( FastPollingPeriod * 1000.0 ) : POLLING_PERIOD_NORMAL;
827+
828+
if ( Status.Slewing )
829+
{
830+
// We are moving, so use the fast polling rate.
831+
832+
PollingPeriod = fastPollingMs;
833+
}
834+
else if ( previousMoveStatus )
835+
{
836+
// We stopped moving, so start the timer to return to normal polling.
837+
838+
returnToNormalPollingTime = DateTime.Now + fastPollExtension;
839+
PollingPeriod = fastPollingMs;
840+
}
841+
else if ( DateTime.Now < returnToNormalPollingTime )
842+
{
843+
// Continue fast polling.
844+
845+
PollingPeriod = fastPollingMs;
846+
}
847+
else
848+
{
849+
// Return to normal polling.
850+
851+
returnToNormalPollingTime = DateTime.MinValue;
852+
}
853+
854+
// Remember our state for the next time through this loop.
855+
856+
previousMoveStatus = Status.Slewing;
857+
858+
if ( PollingPeriod == POLLING_PERIOD_NORMAL && previousPollingPeriod != POLLING_PERIOD_NORMAL )
859+
{
860+
LogActivityLine( ActivityMessageTypes.Commands, $"Returning to normal polling every {PollingPeriod} ms." );
861+
}
819862
}
820863

821864
TimeSpan waitInterval = wakeupTime.AddMilliseconds( (double)PollingPeriod ) - DateTime.Now;

Inno Setup/ASCOM Device Hub Setup.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
;
55

66
#define MyAppName "ASCOM.DeviceHub"
7-
#define MyAppVersion "6.6.0.12"
7+
#define MyAppVersion "6.6.0.13"
88
#define MyDestSubdirName "DeviceHub"
99
; #define MyPlatformRoot "D:\Github Repos\ASCOMPlatform\"
1010
#define MyPlatformRoot "D:\My Projects\Visual Studio 2022\Ascom\"

ProductAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
// You can specify all the values or you can default the Build and Revision Numbers
2121
// by using the '*' as shown below:
2222
// [assembly: AssemblyVersion("1.0.*")]
23-
[assembly: AssemblyVersion( "6.6.0.12" )]
23+
[assembly: AssemblyVersion( "6.6.0.13" )]

0 commit comments

Comments
 (0)