Instrument Neutral Distributed Interface INDI 2.2.5
skywatcherAPIMount.h
Go to the documentation of this file.
1
16#pragma once
17
18#include "indiguiderinterface.h"
19#include "skywatcherAPI.h"
20#include "indielapsedtimer.h"
21#include "indipropertynumber.h"
22#include "indipropertyswitch.h"
24#include "pid/pid.h"
25#include <numeric>
26
29
31{
32 double DeltaAlt { 0 };
33 double DeltaAz { 0 };
34 int Duration { 0 };
36};
37
38
40 public SkywatcherAPI,
41 public INDI::Telescope,
44{
45 public:
47 virtual ~SkywatcherAPIMount() override = default;
48
49 virtual bool initProperties() override;
50 virtual void ISGetProperties(const char *dev) override;
51 virtual bool updateProperties() override;
52 virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
53 char *formats[], char *names[], int n) override;
54 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
55 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
56 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
57
58 protected:
62 virtual bool Handshake() override;
63 virtual bool ReadScopeStatus() override;
64
68 virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
69 virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
70 virtual bool Goto(double ra, double dec) override;
71 virtual bool Sync(double ra, double dec) override;
72 virtual bool Abort() override;
73 virtual bool SetTrackEnabled(bool enabled) override;
74
78 virtual const char *getDefaultName() override;
79 virtual void TimerHit() override;
80 virtual bool updateLocation(double latitude, double longitude, double elevation) override;
81 virtual bool saveConfigItems(FILE *fp) override;
82 double GetSlewRate();
83 double GetParkDeltaAz(ParkDirection_t target_direction, ParkPosition_t target_position);
84
88 virtual IPState GuideNorth(uint32_t ms) override;
89 virtual IPState GuideSouth(uint32_t ms) override;
90 virtual IPState GuideEast(uint32_t ms) override;
91 virtual IPState GuideWest(uint32_t ms) override;
92
96 virtual bool Park() override;
97 virtual bool UnPark() override;
98 virtual bool SetCurrentPark() override;
99 virtual bool SetDefaultPark() override;
100
101 private:
102
106 void CalculateGuidePulses();
107 void ResetGuidePulses();
108 void ConvertGuideCorrection(double delta_ra, double delta_dec, double &delta_alt, double &delta_az);
109
113 void SkywatcherMicrostepsFromTelescopeDirectionVector(
114 const INDI::AlignmentSubsystem::TelescopeDirectionVector TelescopeDirectionVector, long &Axis1Microsteps,
115 long &Axis2Microsteps);
117 TelescopeDirectionVectorFromSkywatcherMicrosteps(long Axis1Microsteps, long Axis2Microsteps);
118 double AzimuthToDegrees(double degree);
119 double DegreesToAzimuth(double degree);
120 bool isNorthHemisphere() const
121 {
122 return m_Location.latitude >= 0;
123 }
124
128 void UpdateDetailedMountInformation(bool InformClient);
129 bool getCurrentAltAz(INDI::IHorizontalCoordinates &altaz);
130 bool getCurrentRADE(INDI::IHorizontalCoordinates altaz, INDI::IEquatorialCoordinates &rade);
131 // Reset tracking timer to account for drift compensation
132 void resetTracking();
133 // Classical tracking via PID control loop
134 bool trackUsingPID();
135 // Simpler tracking loop develped by Paweł T. Jochym
136 bool trackUsingPredictiveRates();
137 // Get guide ticks
138 void getGuidePulses(double &az, double &alt);
139
148 bool trackByRate(AXISID axis, double rate);
149
150 inline double average(const std::vector<double> &values)
151 {
152 return values.empty() ? 0 : std::accumulate(values.begin(), values.end(), 0.0) / values.size();
153 }
154
158 static constexpr const char *MountInfoTab { "Mount Info" };
159 IText BasicMountInfoT[4] {};
160 ITextVectorProperty BasicMountInfoTP;
161 enum
162 {
163 MOTOR_CONTROL_FIRMWARE_VERSION,
164 MOUNT_CODE,
165 MOUNT_NAME,
166 IS_DC_MOTOR
167 };
168
169 INumber AxisOneInfoN[4];
170 INumberVectorProperty AxisOneInfoNP;
171 INumber AxisTwoInfoN[4];
172 INumberVectorProperty AxisTwoInfoNP;
173 enum
174 {
175 MICROSTEPS_PER_REVOLUTION,
176 STEPPER_CLOCK_FREQUENCY,
177 HIGH_SPEED_RATIO,
178 MICROSTEPS_PER_WORM_REVOLUTION
179 };
180
181
182 ISwitch AxisOneStateS[6];
183 ISwitchVectorProperty AxisOneStateSP;
184 ISwitch AxisTwoStateS[6];
185 ISwitchVectorProperty AxisTwoStateSP;
186 enum
187 {
188 FULL_STOP,
189 SLEWING,
190 SLEWING_TO,
191 SLEWING_FORWARD,
192 HIGH_SPEED,
193 NOT_INITIALISED
194 };
195
196 enum
197 {
198 RAW_MICROSTEPS,
199 MICROSTEPS_PER_ARCSEC,
200 OFFSET_FROM_INITIAL,
201 DEGREES_FROM_INITIAL
202 };
203 INumber AxisOneEncoderValuesN[4];
204 INumberVectorProperty AxisOneEncoderValuesNP;
205 INumber AxisTwoEncoderValuesN[4];
206 INumberVectorProperty AxisTwoEncoderValuesNP;
207
208 ISwitch SlewModesS[2];
209 ISwitchVectorProperty SlewModesSP;
210 // A switch for silent/highspeed slewing modes
211 enum
212 {
213 SLEW_SILENT,
214 SLEW_NORMAL
215 };
216
217 ISwitch SoftPECModesS[2];
218 ISwitchVectorProperty SoftPECModesSP;
219 // A switch for SoftPEC modes
220 enum
221 {
222 SOFTPEC_ENABLED,
223 SOFTPEC_DISABLED
224 };
225
226 // SoftPEC value for tracking mode
227 INumber SoftPecN;
228 INumberVectorProperty SoftPecNP;
229
230 // Guiding rates (RA/Dec)
231 INumber GuidingRatesN[2];
232 INumberVectorProperty GuidingRatesNP;
233
234 // PID controllers
235 INDI::PropertyNumber Axis1PIDNP {3};
236 INDI::PropertyNumber Axis2PIDNP {3};
237 enum
238 {
239 Propotional,
240 Derivative,
241 Integral
242 };
243
244 // Dead Zone
245 INDI::PropertyNumber AxisDeadZoneNP {2};
246
247 // Clock Rate Multiplier
248 INDI::PropertyNumber AxisClockNP {2};
249
250 // Offset
251 INDI::PropertyNumber AxisOffsetNP {5};
252 enum
253 {
254 RAOffset,
255 DEOffset,
256 AZSteps,
257 ALSteps,
258 JulianOffset,
259 };
260
261 // Axis 1 Direct Track Control
262 INDI::PropertyNumber Axis1TrackRateNP {2};
263 INDI::PropertyNumber Axis2TrackRateNP {2};
264 enum
265 {
266 TrackDirection,
267 TrackClockRate,
268 };
269
270 // AUX Encoders
271 INDI::PropertySwitch AUXEncoderSP {2};
272
273 // Snap Port
274 INDI::PropertySwitch SnapPortSP {2};
275
279 // Tracking
280 INDI::IEquatorialCoordinates m_SkyTrackingTarget { 0, 0 };
281 INDI::IEquatorialCoordinates m_SkyCurrentRADE {0, 0};
282 INDI::IHorizontalCoordinates m_MountAltAz {0, 0};
283
284 std::unique_ptr<PID> m_Controllers[2];
285
286 // Maximum delta to track. If drift is above 5 degrees, we abort tracking.
287 static constexpr double MAX_TRACKING_DELTA {5};
288 static constexpr const char *TRACKING_TAB = "Tracking";
289 static constexpr double ALT_BACKLASH_DEG {0.5};
290 static constexpr double AZ_BACKLASH_DEG {0.5};
291 static constexpr double MIN_TRACK_RATE_FACTOR {0.1};
292
293 INDI::ElapsedTimer m_TrackingRateTimer;
294 int32_t m_LastTrackRate[2] = {-1, -1};
295 uint8_t m_LastCustomDirection[2];
296 double GuideDeltaAlt { 0 };
297 double GuideDeltaAz { 0 };
298 double m_LastOffset[2] = {0, 0};
299 uint8_t m_OffsetSwitchSettle[2] = {0, 0};
300
301 GuidingPulse NorthPulse;
302 GuidingPulse WestPulse;
303 std::vector<GuidingPulse> GuidingPulses;
304
305 bool m_ManualMotionActive[2] { false, false };
306 bool m_IterativeGOTOPending {false};
307};
This class encapsulates all the alignment subsystem classes that are useful to driver implementations...
The ElapsedTimer class provides a fast way to calculate elapsed times.
IGeographicCoordinates m_Location
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
virtual void TimerHit() override
Called when setTimer() time is up.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual const char * getDefaultName() override
Misc.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool Handshake() override
Communication.
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual ~SkywatcherAPIMount() override=default
virtual bool Park() override
Parking.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Motion.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual IPState GuideNorth(uint32_t ms) override
Guiding.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
double GetParkDeltaAz(ParkDirection_t target_direction, ParkPosition_t target_position)
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
INDI_DIR_WE
INDI_DIR_NS
ParkDirection_t
@ PARK_CLOCKWISE
@ PARK_COUNTERCLOCKWISE
ParkPosition_t
@ PARK_SOUTH
@ PARK_EAST
@ PARK_NORTH
@ PARK_WEST
Holds a normalised direction vector (direction cosines)
Definition Common.h:69
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244