Skip to content

Commit

Permalink
Simplify Dome Manager command logic.
Browse files Browse the repository at this point in the history
Ensure that short slews are handled correctly so that the client can get the downstream driver's Slewing state immediately after the command is issued.
  • Loading branch information
astroman133 committed Jun 25, 2022
1 parent 336d8f0 commit 683a582
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 190 deletions.
218 changes: 30 additions & 188 deletions DeviceHub/DeviceManagers/DomeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ public void OpenDomeShutter()
if ( Connected && Capabilities != null && Status != null
&& Capabilities.CanSetShutter && Status.ShutterStatus != ShutterState.shutterOpen )
{
// Issue the open shutter command and wait for a status update before continuing.
OpenShutter();
Status = new DevHubDomeStatus( this );

var task = OpenShutterAsync();
var result = task.Result;
SetFastPolling();
}
}

Expand All @@ -318,10 +318,10 @@ public void CloseDomeShutter()
if ( Connected && Capabilities != null && Status != null
&& Capabilities.CanSetShutter && Status.ShutterStatus != ShutterState.shutterClosed )
{
// Issue the close shutter command and wait for a status update before returning.
CloseShutter();
Status = new DevHubDomeStatus( this );

var task = CloseShutterAsync();
var result = task.Result;
SetFastPolling();
}
}

Expand All @@ -331,19 +331,21 @@ public void ParkTheDome()
{
ParkingState = ParkingStateEnum.ParkInProgress;

// Issue the park command and wait for a status update before returning;
Park();
Status = new DevHubDomeStatus( this );

var task = ParkDomeAsync();
var result = task.Result;
SetFastPolling();
}
}

public void FindHomePosition()
{
if ( Connected && Capabilities != null && Capabilities.CanFindHome && !Slewing )
{
var task = FindHomeAsync();
var result = task.Result;
FindHome();
Status = new DevHubDomeStatus( this );

SetFastPolling();
}
}

Expand All @@ -354,17 +356,10 @@ public void SlewDomeShutter( double targetAltitude )
if ( Connected && !Slewing && Capabilities.CanSetAltitude
&& ( status != ShutterState.shutterClosed && status != ShutterState.shutterError ) )
{
Task task;
SlewToAltitude( targetAltitude );
Status = new DevHubDomeStatus( this );

try
{
task = SlewShutterAsync( targetAltitude );
task.Wait();
}
catch ( AggregateException xcp )
{
throw xcp.InnerException;
}
SetFastPolling();
}
}

Expand All @@ -378,38 +373,23 @@ public void SetSlavedState( bool state )

public void SlewDomeToAzimuth( double targetAzimuth )
{
if ( Connected && !Slewing && Capabilities.CanSetAzimuth )
if ( Connected && !Status.Slewing && Capabilities.CanSetAzimuth )
{
// We don't actually need the result, but it allows us to wait for the async slew to start
// and for a status update to occur.
SlewToAzimuth( targetAzimuth );
Status = new DevHubDomeStatus( this );

try
{
var task = SlewDomeAsync( targetAzimuth );
var result = task.Result;
}
catch (AggregateException xcp )
{
Exception ex = xcp.InnerException;
throw ex;
}
// Put the polling task into high gear.

SetFastPolling();
}
}

public void StopDomeMotion()
{
if ( Connected )
{
Task<bool> task = Task<bool>.Run( () =>
{
AbortSlew();

WaitForStatusUpdate();

return true;
} );

bool result = task.Result;
AbortSlew();
Status = new DevHubDomeStatus( this );
}
}

Expand Down Expand Up @@ -542,10 +522,12 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )

LogActivityLine( msgType, "Dome position recalculation due to telescope slew-in-progress." );

Transform xform = new Transform();
xform.SiteElevation = TelescopeParameters.SiteElevation;
xform.SiteLatitude = TelescopeParameters.SiteLatitude;
xform.SiteLongitude = TelescopeParameters.SiteLongitude;
Transform xform = new Transform
{
SiteElevation = TelescopeParameters.SiteElevation,
SiteLongitude = TelescopeParameters.SiteLongitude,
SiteLatitude = TelescopeParameters.SiteLatitude
};

EquatorialCoordinateType coordinateType = TelescopeParameters.EquatorialSystem;

Expand Down Expand Up @@ -857,146 +839,6 @@ private void ReadInitialDomeDataTask()
Messenger.Default.Send( new DomeStatusUpdatedMessage( Status ) );
}

private Task<bool> OpenShutterAsync()
{
// This method creates a task to run on a worker thread. It issues the open shutter command,
// speeds up the polling cycle, and waits until the next status update before completing.
// This allows the caller to wait for completion before continuing.

Task<bool> task = Task<bool>.Run( () =>
{
OpenShutter();

SetFastPolling();

WaitForStatusUpdate();

return Status.ShutterStatus == ShutterState.shutterOpening;
} );

return task;
}

private Task<bool> CloseShutterAsync()
{
// This method creates a task to run on a worker thread. It issues the close shutter command,
// speeds up the polling cycle, and waits until the next status update before completing.
// This allows the caller to wait for completion before continuing.

Task<bool> task = Task<bool>.Run( () =>
{
CloseShutter();

// Put the polling task into high gear.

SetFastPolling();

WaitForStatusUpdate();

return Status.ShutterStatus == ShutterState.shutterClosing;
} );

return task;
}

private Task SlewShutterAsync( double altitude )
{
// This method creates a task to run on a worker thread. It issues the slew shutter command,
// speeds up the polling cycle, and waits until the next status update before completing.
// This allows the caller to wait for completion before continuing.

Task task = Task.Run( () =>
{
SlewToAltitude( altitude );

// Put the polling task into high gear.

SetFastPolling();

WaitForStatusUpdate();
} );

return task;
}

private Task<bool> ParkDomeAsync()
{
// This method creates a task to run on a worker thread. It issues the park command,
// speeds up the polling cycle, and waits until the next status update before completing.
// This allows the caller to wait for completion before continuing.

Task<bool> task = Task<bool>.Run( () =>
{
Park();

// Put the polling task into high gear.

SetFastPolling();

WaitForStatusUpdate();

return Status.AtPark;
} );

return task;
}

private void WaitForStatusUpdate()
{
DateTime lastUpdate = Status.LastUpdateTime;

// Wait for a status update before ending the task.

while ( lastUpdate == Status.LastUpdateTime )
{
Thread.Sleep( 400 );
}
}

private Task<bool> FindHomeAsync()
{
// This method creates a task to run on a worker thread. It issues the FindHome command,
// speeds up the polling cycle, and waits until the next status update before completing.
// This allows the caller to wait for completion before continuing.

Task<bool> task = Task<bool>.Run( () =>
{
FindHome();

// Put the polling task into high gear.

SetFastPolling();

WaitForStatusUpdate();

return Status.AtHome;
} );

return task;
}

private Task<bool> SlewDomeAsync( double toAzimuth )
{
// This method creates a task to run on a worker thread. It issues the slew command,
// speeds up the polling cycle, and waits until the next status update before completing.
// This allows the caller to wait for completion before continuing.

Task<bool> task = Task<bool>.Run( () =>
{
SlewToAzimuth( toAzimuth );

// Put the polling task into high gear.

SetFastPolling();

WaitForStatusUpdate();

return Status.Slewing;
} );

return task;
}

/// <summary>
/// Calculate the pointing position of the dome given the pointing position of the telescope,
/// the hour angle in hours, and the side-of-pier
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.11"
#define MyAppVersion "6.6.0.12"
#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.11" )]
[assembly: AssemblyVersion( "6.6.0.12" )]

0 comments on commit 683a582

Please sign in to comment.