44using System . Windows ;
55
66using ASCOM . DeviceInterface ;
7+ using ASCOM . Astrometry . Exceptions ;
78using ASCOM . Astrometry . Transform ;
89
910using ASCOM . DeviceHub . MvvmMessenger ;
@@ -456,7 +457,13 @@ private void PollDomeTask( CancellationToken token )
456457 if ( Service . DeviceAvailable )
457458 {
458459 UpdateDomeStatusTask ( ) ;
459- SlewTheSlavedDome ( ref nextSlaveAdjustmentTime ) ;
460+
461+ if ( ! Status . Slewing )
462+ {
463+ SlewTheSlavedDome ( ref nextSlaveAdjustmentTime ) ;
464+ UpdateDomeStatusTask ( ) ;
465+ }
466+
460467 bool shutterMoving = Status . ShutterStatus == ShutterState . shutterOpening
461468 || Status . ShutterStatus == ShutterState . shutterClosing ;
462469
@@ -515,6 +522,7 @@ private void PollDomeTask( CancellationToken token )
515522
516523 private void SlewTheSlavedDome ( ref DateTime nextAdjustmentTime )
517524 {
525+ ActivityMessageTypes msgType = ActivityMessageTypes . Commands ;
518526 DateTime returnTime = nextAdjustmentTime ;
519527
520528 if ( Globals . IsDomeSlaved )
@@ -523,32 +531,33 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
523531 // We need to slew there immediately. We will get another message when the slew has finished, but
524532 // until then we need to suspend normal slaved adjustments.
525533
526- if ( SlavedSlewState . IsSlewInProgress ) // The telescope is being slewed.
534+ SlewInProgressMessage slewState = SlavedSlewState ;
535+
536+ if ( slewState != null && slewState . IsSlewInProgress ) // The telescope is being slewed.
527537 {
528538 if ( ! Status . Slewing || Globals . UseCompositeSlewingFlag )
529539 {
530540 // The telescope is slewing and we are slaved but not slewing so initiate a dome slew
531541 // to the telescope's target position.
532542
533- LogActivityLine ( ActivityMessageTypes . Commands
534- , "Dome position recalculation due to telescope slew-in-progress." ) ;
543+ LogActivityLine ( msgType , "Dome position recalculation due to telescope slew-in-progress." ) ;
544+
545+ Transform xform = new Transform ( ) ;
546+ xform . SiteElevation = TelescopeParameters . SiteElevation ;
547+ xform . SiteLatitude = TelescopeParameters . SiteLatitude ;
548+ xform . SiteLongitude = TelescopeParameters . SiteLongitude ;
549+
550+ EquatorialCoordinateType coordinateType = TelescopeParameters . EquatorialSystem ;
535551
536552 try
537553 {
538- Transform xform = new Transform
539- {
540- SiteElevation = TelescopeParameters . SiteElevation ,
541- SiteLatitude = TelescopeParameters . SiteLatitude ,
542- SiteLongitude = TelescopeParameters . SiteLongitude
543- } ;
544-
545- if ( TelescopeParameters . EquatorialSystem == EquatorialCoordinateType . equJ2000 )
554+ if ( coordinateType == EquatorialCoordinateType . equJ2000 )
546555 {
547- xform . SetJ2000 ( SlavedSlewState . RightAscension , SlavedSlewState . Declination ) ;
556+ xform . SetJ2000 ( slewState . RightAscension , slewState . Declination ) ;
548557 }
549- else
558+ else // Assume JNOW
550559 {
551- xform . SetTopocentric ( SlavedSlewState . RightAscension , SlavedSlewState . Declination ) ;
560+ xform . SetTopocentric ( slewState . RightAscension , slewState . Declination ) ;
552561 }
553562
554563 Point scopeTargetPosition = new Point ( xform . AzimuthTopocentric , xform . ElevationTopocentric ) ;
@@ -559,13 +568,28 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
559568
560569 SlaveDomePointing ( scopeTargetPosition , localHourAngle , SlavedSlewState . SideOfPier ) ;
561570 }
571+ catch ( TransformUninitialisedException xcp )
572+ {
573+ LogActivityLine ( msgType , "Attempting to calculate the slaved dome azimuth. Details follow:" ) ;
574+ LogActivityLine ( msgType , xcp . Message ) ;
575+ LogActivityLine ( msgType , $ "Transform Error site location: latitude = { xform . SiteLatitude : F5} , longitude = { xform . SiteLongitude : F5} , elevation = { xform . SiteElevation : F0} " ) ;
576+ LogActivityLine ( msgType , $ "Transform Error coordinate system: coordinateType = { coordinateType } " ) ;
577+ LogActivityLine ( msgType , $ "Transform Error target position: RA = { slewState . RightAscension } , Dec = { slewState . Declination } " ) ;
578+ }
562579 catch ( Exception xcp )
563580 {
564- LogActivityLine ( ActivityMessageTypes . Commands , "Attempting to calculate a new dome slave position due to telescope "
581+ LogActivityLine ( msgType , "Attempting to calculate a new dome slave position due to telescope "
565582 + "slew caught an exception. Details follow:" ) ;
566- LogActivityLine ( ActivityMessageTypes . Commands , xcp . Message ) ;
583+ LogActivityLine ( msgType , xcp . Message ) ;
567584 }
568585 }
586+ else
587+ {
588+ // If we get here we need to slew to a new target because of a telescope slew, but the dome is already slewing.
589+ // We want to test again quickly and slew the dome again as soon as it has stopped from the current slew.
590+
591+ returnTime = DateTime . Now . AddMilliseconds ( 250.0 ) ;
592+ }
569593 }
570594 else if ( DateTime . Now > nextAdjustmentTime )
571595 {
@@ -654,10 +678,15 @@ private void SlaveDomePointing( Point scopePosition, double localHourAngle, Pier
654678
655679 if ( Double . IsNaN ( targetAltitude ) || targetAltitude < 0.0 || targetAltitude > 180.0 )
656680 {
657- targetsValid = false ;
658- LogActivityLine ( ActivityMessageTypes . Commands
659- , "An invalid altitude value ({0:f2}) was calculated...short circuiting the slew"
660- , targetAltitude ) ;
681+ // Don't report a bad altitude if we are not going to set it anyway.
682+
683+ if ( Capabilities . CanSetAltitude )
684+ {
685+ targetsValid = false ;
686+ LogActivityLine ( ActivityMessageTypes . Commands
687+ , "An invalid altitude value ({0:f2}) was calculated...short circuiting the slew"
688+ , targetAltitude ) ;
689+ }
661690 }
662691
663692 // If either the target azimuth or altitude are invalid, return without slewing the dome!!!
@@ -670,6 +699,8 @@ private void SlaveDomePointing( Point scopePosition, double localHourAngle, Pier
670699 LogActivityLine ( ActivityMessageTypes . Commands , "The calculated dome position is Az: {0:f2}, Alt: {1:f2}."
671700 , domeAltAz . X , domeAltAz . Y ) ;
672701
702+ bool moving = false ;
703+
673704 if ( IsInRange ( targetAzimuth , Status . Azimuth , Globals . DomeLayout . AzimuthAccuracy ) )
674705 {
675706 LogActivityLine ( ActivityMessageTypes . Commands
@@ -680,23 +711,33 @@ private void SlaveDomePointing( Point scopePosition, double localHourAngle, Pier
680711 LogActivityLine ( ActivityMessageTypes . Commands
681712 , "Slaving dome to target azimuth of {0:f2} degrees." , targetAzimuth ) ;
682713
683- Task task = Task . Run ( ( ) =>
684- {
685- SlewToAzimuth ( targetAzimuth ) ;
686- Status . Slewing = true ;
687- SetFastPolling ( ) ;
688- } , CancellationToken . None ) ;
714+ //Task task = Task.Run( () =>
715+ //{
716+ // SlewToAzimuth( targetAzimuth );
717+ // Status.Slewing = true;
718+ // SetFastPolling();
719+ //}, CancellationToken.None );
720+ SlewToAzimuth ( targetAzimuth ) ;
721+ moving = true ;
689722 }
690723
691724 if ( Capabilities . CanSetAltitude && Status . Altitude < targetAltitude )
692725 {
693726 LogActivityLine ( ActivityMessageTypes . Commands
694727 , "Synchronizing dome to target altitude of {0:f2} degrees." , targetAltitude ) ;
695728
696- Task task = Task . Run ( ( ) =>
697- {
698- SlewToAltitude ( targetAltitude ) ;
699- } , CancellationToken . None ) ;
729+ //Task task = Task.Run( () =>
730+ //{
731+ // SlewToAltitude( targetAltitude );
732+ //}, CancellationToken.None );
733+ SlewToAzimuth ( targetAltitude ) ;
734+ moving = true ;
735+ }
736+
737+ if ( moving )
738+ {
739+ Status = new DevHubDomeStatus ( this ) ;
740+ SetFastPolling ( ) ;
700741 }
701742 }
702743
0 commit comments