Instrument Neutral Distributed Interface INDI  2.0.2
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 };
35  int OriginalDuration { 0 };
36 };
37 
38 
40  public SkywatcherAPI,
41  public INDI::Telescope,
42  public INDI::GuiderInterface,
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 
122  void UpdateDetailedMountInformation(bool InformClient);
123  bool getCurrentAltAz(INDI::IHorizontalCoordinates &altaz);
124  bool getCurrentRADE(INDI::IHorizontalCoordinates altaz, INDI::IEquatorialCoordinates &rade);
125  // Reset tracking timer to account for drift compensation
126  void resetTracking();
127  inline double average(const std::vector<double> &values)
128  {
129  return values.empty() ? 0 : std::accumulate(values.begin(), values.end(), 0.0) / values.size();
130  }
131 
135  static constexpr const char *MountInfoTab { "Mount Info" };
136  IText BasicMountInfoT[4] {};
137  ITextVectorProperty BasicMountInfoTP;
138  enum
139  {
140  MOTOR_CONTROL_FIRMWARE_VERSION,
141  MOUNT_CODE,
142  MOUNT_NAME,
143  IS_DC_MOTOR
144  };
145 
146  INumber AxisOneInfoN[4];
147  INumberVectorProperty AxisOneInfoNP;
148  INumber AxisTwoInfoN[4];
149  INumberVectorProperty AxisTwoInfoNP;
150  enum
151  {
152  MICROSTEPS_PER_REVOLUTION,
153  STEPPER_CLOCK_FREQUENCY,
154  HIGH_SPEED_RATIO,
155  MICROSTEPS_PER_WORM_REVOLUTION
156  };
157 
158 
159  ISwitch AxisOneStateS[6];
160  ISwitchVectorProperty AxisOneStateSP;
161  ISwitch AxisTwoStateS[6];
162  ISwitchVectorProperty AxisTwoStateSP;
163  enum
164  {
165  FULL_STOP,
166  SLEWING,
167  SLEWING_TO,
168  SLEWING_FORWARD,
169  HIGH_SPEED,
170  NOT_INITIALISED
171  };
172 
173  enum
174  {
175  RAW_MICROSTEPS,
176  MICROSTEPS_PER_ARCSEC,
177  OFFSET_FROM_INITIAL,
178  DEGREES_FROM_INITIAL
179  };
180  INumber AxisOneEncoderValuesN[4];
181  INumberVectorProperty AxisOneEncoderValuesNP;
182  INumber AxisTwoEncoderValuesN[4];
183  INumberVectorProperty AxisTwoEncoderValuesNP;
184 
185  ISwitch SlewModesS[2];
186  ISwitchVectorProperty SlewModesSP;
187  // A switch for silent/highspeed slewing modes
188  enum
189  {
190  SLEW_SILENT,
191  SLEW_NORMAL
192  };
193 
194  ISwitch SoftPECModesS[2];
195  ISwitchVectorProperty SoftPECModesSP;
196  // A switch for SoftPEC modes
197  enum
198  {
199  SOFTPEC_ENABLED,
200  SOFTPEC_DISABLED
201  };
202 
203  // SoftPEC value for tracking mode
204  INumber SoftPecN;
205  INumberVectorProperty SoftPecNP;
206 
207  // Guiding rates (RA/Dec)
208  INumber GuidingRatesN[2];
209  INumberVectorProperty GuidingRatesNP;
210 
211  // PID controllers
212  INDI::PropertyNumber Axis1PIDNP {3};
213  INDI::PropertyNumber Axis2PIDNP {3};
214  enum
215  {
216  Propotional,
217  Derivative,
218  Integral
219  };
220 
221  // Dead Zone
222  INDI::PropertyNumber AxisDeadZoneNP {2};
223 
224  // Clock Rate Multiplier
225  INDI::PropertyNumber AxisClockNP {2};
226 
227  // Offset
228  INDI::PropertyNumber AxisOffsetNP {5};
229  enum
230  {
231  RAOffset,
232  DEOffset,
233  AZSteps,
234  ALSteps,
235  JulianOffset,
236  };
237 
238  // Axis 1 Direct Track Control
239  INDI::PropertyNumber Axis1TrackRateNP {2};
240  INDI::PropertyNumber Axis2TrackRateNP {2};
241  enum
242  {
243  TrackDirection,
244  TrackClockRate,
245  };
246 
247  // AUX Encoders
248  INDI::PropertySwitch AUXEncoderSP {2};
249 
250  // Snap Port
251  INDI::PropertySwitch SnapPortSP {2};
252 
256  // Tracking
257  INDI::IEquatorialCoordinates m_SkyTrackingTarget { 0, 0 };
258  INDI::IEquatorialCoordinates m_SkyCurrentRADE {0, 0};
259  INDI::IHorizontalCoordinates m_MountAltAz {0, 0};
260 
261  std::unique_ptr<PID> m_Controllers[2];
262 
263  // Maximum delta to track. If drift is above 5 degrees, we abort tracking.
264  static constexpr double MAX_TRACKING_DELTA {5};
265  static constexpr const char *TRACKING_TAB = "Tracking";
266 
267  INDI::ElapsedTimer m_TrackingRateTimer;
268  uint8_t m_LastCustomDirection[2];
269  double GuideDeltaAlt { 0 };
270  double GuideDeltaAz { 0 };
271 
272  GuidingPulse NorthPulse;
273  GuidingPulse WestPulse;
274  std::vector<GuidingPulse> GuidingPulses;
275 
276  bool m_ManualMotionActive { false };
277  bool m_IterativeGOTOPending {false};
278 };
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.
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:150
IPState
Property state.
Definition: indiapi.h:160
INDI_DIR_WE
Definition: indibasetypes.h:55
INDI_DIR_NS
Definition: indibasetypes.h:48
ParkDirection_t
@ PARK_CLOCKWISE
@ PARK_COUNTERCLOCKWISE
ParkPosition_t
@ PARK_SOUTH
@ PARK_EAST
@ PARK_NORTH
@ PARK_WEST
Holds a nomalised direction vector (direction cosines)
Definition: Common.h:69
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246