-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceControl.cs
277 lines (252 loc) · 9.34 KB
/
DeviceControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// --------------------------------------------------------------------------------
// VariScan module
//
// Description:
//
// Environment: Windows 10 executable, 32 and 64 bit
//
// Usage: TBD
//
// Author: (REM) Rick McAlister, [email protected]
//
// Edit Log: Rev 1.0 Initial Version
//
// Date Who Vers Description
// ----------- --- ----- -------------------------------------------------------
//
// ---------------------------------------------------------------------------------
//
using System;
using TheSky64Lib;
namespace VariScan
{
class DeviceControl
{
public bool TelescopeStartUp()
{
//Method for connecting and unparking the TSX mount,
// leaving it connected
sky6RASCOMTele tsxm = new sky6RASCOMTele();
if (tsxm.IsConnected == 0)
tsxm.Connect();
//If parked, try to unpark, if fails return false
try
{ if (tsxm.IsParked()) tsxm.Unpark(); }
catch { return false; }
//Otherwise return true;
return true;
}
public void TelescopePrePosition(string side)
{
// Directs the mount to point either to the "East" or "West" side of the
// meridian at a location of 80 degrees altitude. Used for autofocus routine
// and for starting off the target search
sky6RASCOMTele tsxm = new sky6RASCOMTele();
tsxm.Asynchronous = 0;
tsxm.Connect();
if (side == "East")
{
tsxm.SlewToAzAlt(90.0, 80.0, "");
while (tsxm.IsSlewComplete == 0) System.Threading.Thread.Sleep(1000);
}
else
{
tsxm.SlewToAzAlt(270.0, 80.0, "");
while (tsxm.IsSlewComplete == 0) System.Threading.Thread.Sleep(1000);
}
return;
}
public bool TelescopeShutDown()
//Method for connecting and parking and disconnecting the TSX mount
{
sky6RASCOMTele tsxm = new sky6RASCOMTele();
if (tsxm.IsConnected == 0) { tsxm.Connect(); }
try
{
tsxm.Park();
tsxm.Disconnect();
}
catch { return false; }
return true;
}
public bool CameraStartUp()
{
//Method for connecting and initializing the TSX camera
ccdsoftCamera tsxc = new ccdsoftCamera();
try { tsxc.Connect(); }
catch { return false; }
return true;
}
public bool FocuserStartUp()
{
//Method for connecting and initializing the TSX camera
ccdsoftCamera tsxc = new ccdsoftCamera();
try { tsxc.focConnect(); }
catch { return false; }
return true;
}
public bool RotatorStartUp()
{
//Method for connecting and initializing the TSX camera
ccdsoftCamera tsxc = new ccdsoftCamera();
try { tsxc.rotatorConnect(); }
catch { return false; }
return true;
}
public bool HasRotator()
{
//Returns true if a rotator is connected, else false
ccdsoftCamera tsxc = new ccdsoftCamera();
if (tsxc.rotatorIsConnected() == 1) //rotator is present and powered up
return true;
else return false;
}
public void SetCameraTemperature(double settemp)
{
//Method for setting TSX camera temp
const int temperatureSettlingRange = 1;
ccdsoftCamera tsxc = new ccdsoftCamera();
tsxc.TemperatureSetPoint = settemp;
tsxc.RegulateTemperature = 1;
while (!Utility.CloseEnough(tsxc.Temperature, settemp, temperatureSettlingRange))
{
System.Threading.Thread.Sleep(1000);
};
return;
}
public void ReliableRADecSlew(double RA, double Dec, string name, bool hasDome)
{
//
//Checks for dome tracking underway, waits half second if so -- doesn't solve race condition, but may avoid
sky6RASCOMTele tsxt = new sky6RASCOMTele();
if (hasDome)
{
while (IsDomeTrackingUnderway()) System.Threading.Thread.Sleep(500);
int result = -1;
while (result != 0)
{
result = 0;
try { tsxt.SlewToRaDec(RA, Dec, name); }
catch (Exception ex) { result = ex.HResult - 1000; }
}
}
else tsxt.SlewToRaDec(RA, Dec, name);
return;
}
public int ReliableClosedLoopSlew(double RA, double Dec, string name, bool hasDome, string reductionType)
{
//Tries to perform CLS without running into dome tracking race condition
//
//First set camera for image reduction
ccdsoftCamera tsxc = new ccdsoftCamera();
switch (reductionType)
{
case "None":
{ tsxc.ImageReduction = ccdsoftImageReduction.cdNone; break; }
case "2":
{ tsxc.ImageReduction = ccdsoftImageReduction.cdAutoDark; break; }
case "3":
{ tsxc.ImageReduction = ccdsoftImageReduction.cdBiasDarkFlat; break; }
}
ReliableRADecSlew(RA, Dec, name, hasDome);
ClosedLoopSlew tsx_cl = new ClosedLoopSlew();
int clsStatus = 123;
//If dome, Turn off tracking
if (hasDome)
{
DomeCouplingOff();
while (clsStatus == 123)
{
try { clsStatus = tsx_cl.exec(); }
catch (Exception ex)
{
clsStatus = ex.HResult - 1000;
};
if (clsStatus == 123) System.Threading.Thread.Sleep(500);
}
DomeCouplingOn();
}
else
{
try { clsStatus = tsx_cl.exec(); }
catch (Exception ex)
{
clsStatus = ex.HResult - 1000;
};
}
return clsStatus;
}
private bool IsDomeTrackingUnderway()
{
//Test to see if a dome tracking operation is underway.
// If so, doing a IsGotoComplete will throw an Error 212.
// return true
// otherwise return false
return false;
//sky6Dome tsxd = new sky6Dome();
//int testDomeTrack;
//try { testDomeTrack = tsxd.IsGotoComplete; }
//catch { return true; }
//if (testDomeTrack == 0) return true;
//else return false;
}
public void ToggleDomeCoupling()
{
//Uncouple dome tracking, then recouple dome tracking (synchronously)
sky6Dome tsxd = new sky6Dome();
tsxd.IsCoupled = 0;
System.Threading.Thread.Sleep(1000);
tsxd.IsCoupled = 1;
//Wait for all dome activity to stop
while (IsDomeTrackingUnderway()) { System.Threading.Thread.Sleep(1000); }
return;
}
public void DomeCouplingOn()
{
//Uncouple dome tracking, then recouple dome tracking (synchronously)
sky6Dome tsxd = new sky6Dome();
tsxd.IsCoupled = 1;
System.Threading.Thread.Sleep(500);
while (IsDomeTrackingUnderway())
{ System.Threading.Thread.Sleep(1000); }
return;
}
public void DomeCouplingOff()
{
//Uncouple dome tracking, then recouple dome tracking (synchronously)
sky6Dome tsxd = new sky6Dome();
tsxd.IsCoupled = 0;
System.Threading.Thread.Sleep(500);
while (IsDomeTrackingUnderway()) { System.Threading.Thread.Sleep(1000); }
return;
}
public double? CurrentIPA()
{
//Will return Image PA of most recent image link
double? currentImagePA = null;
if (!HasRotator())
return currentImagePA;
ImageLinkResults ilr = new ImageLinkResults();
try
{ currentImagePA = ilr.imagePositionAngle; }
catch
{ return currentImagePA; }
return currentImagePA;
}
public bool RotateToImagePA(double destinationIPA)
{
//Move the rotator to a position that gives an image position angle of tImagePA
// Assumes that the rotator position angle variables are current
//Returns false if failure, true if good
if (!HasRotator())
return false;
ccdsoftCamera tsxc = new ccdsoftCamera();
//target rotation PA = current image PA + current rotator PA - target image PA
double rotatorPA = tsxc.rotatorPositionAngle();
double destRotationPA = ((double)CurrentIPA() - destinationIPA) + rotatorPA;
double destRotationPAnormalized = AstroMath.Transform.NormalizeDegreeRange(destRotationPA);
tsxc.rotatorGotoPositionAngle(destRotationPAnormalized);
return true;
}
}
}