Instrument Neutral Distributed Interface INDI 2.2.5
skywatcherAPI.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <string>
20#include <map>
21
22#define INDI_DEBUG_LOGGING
23#ifdef INDI_DEBUG_LOGGING
24#include "inditelescope.h"
25#define MYDEBUG(priority, msg) \
26 INDI::Logger::getInstance().print(pChildTelescope->getDeviceName(), priority, __FILE__, __LINE__, msg)
27#define MYDEBUGF(priority, msg, ...) \
28 INDI::Logger::getInstance().print(pChildTelescope->getDeviceName(), priority, __FILE__, __LINE__, msg, __VA_ARGS__)
29#else
30#define MYDEBUG(priority, msg)
31#define MYDEBUGF(priority, msg, ...)
32#endif
33
35{
37 : FullStop(false), Slewing(false), SlewingTo(false), SlewingForward(false), HighSpeed(false),
38 NotInitialized(true)
39 {
40 }
42 bool Slewing;
47
48 void SetFullStop();
49 void SetSlewing(bool forward, bool highspeed);
50 void SetSlewingTo(bool forward, bool highspeed);
51};
52
54{
55 public:
56 enum AXISID
57 {
58 AXIS1 = 0,
59 AXIS2 = 1
60 };
61
62 // Types
64 {
76 SetSnapPort = 'O', // EQ8/AZEQ6/AZEQ5/EQ6-R/AZ-GTi only
84 GetStepPeriod = 'D', // See Merlin protocol http://www.papywizard.org/wiki/DevelopGuide
85 ActivateMotor = 'B', // See eq6direct implementation http://pierre.nerzic.free.fr/INDI/
87 GetHomePosition = 'd', // Get Home position encoder count (default at startup)
88 SetFeatureCmd = 'W', // EQ8/AZEQ6/AZEQ5 only
89 GetFeatureCmd = 'q', // EQ8/AZEQ6/AZEQ5 only
90 InquireAuxEncoder = 'd', // EQ8/AZEQ6/AZEQ5 only
92 };
93
99
112
113
114 // These values are in radians per second
115 static constexpr double SIDEREALRATE { (2 * M_PI / 86164.09065) };
116 static constexpr double MAX_SPEED { 500.0 };
117 static constexpr double LOW_SPEED_MARGIN { 128.0 * SIDEREALRATE };
118
120 virtual ~SkywatcherAPI() = default;
121
122 unsigned long BCDstr2long(std::string &String);
123 unsigned long Highstr2long(std::string &String);
124 bool CheckIfDCMotor();
125
128 //bool IsVirtuosoMount() const;
129
132 //bool IsMerlinMount() const;
133
136 //bool IsAZGTiMount() const;
137
143 long DegreesPerSecondToClocksTicksPerMicrostep(AXISID Axis, double DegreesPerSecond);
144
149 long DegreesToMicrosteps(AXISID Axis, double AngleInDegrees);
150
154 bool GetEncoder(AXISID Axis);
155
159
165
171
173
175
185
186 bool GetStatus(AXISID Axis);
187
192
193 // Optional: inquire axis features from mount.
194 bool InquireFeatures();
195
196 bool InitializeMC();
197
200 bool InitMount();
201
202 bool HasHomeIndexers();
203 bool HasAuxEncoders();
204 bool HasPPEC();
205 bool HasSnapPort1();
206 bool HasSnapPort2();
207 bool HasPolarLed();
208
209 void TurnEncoder(AXISID axis, bool on);
210 void TurnRAEncoder(bool on);
211 void TurnDEEncoder(bool on);
212 void SetFeature(AXISID axis, uint32_t command);
213
219 bool InstantStop(AXISID Axis);
220
221 void Long2BCDstr(long Number, std::string &String);
222
227 double MicrostepsToDegrees(AXISID Axis, long Microsteps);
228
233 double MicrostepsToRadians(AXISID Axis, long Microsteps);
234
235 void PrepareForSlewing(AXISID Axis, double Speed);
236
242 long RadiansPerSecondToClocksTicksPerMicrostep(AXISID Axis, double RadiansPerSecond);
243
248 long RadiansToMicrosteps(AXISID Axis, double AngleInRadians);
249
254 bool SetEncoder(AXISID Axis, long Microsteps);
255
260 bool SetGotoTargetOffset(AXISID Axis, long OffsetInMicrosteps);
261
273 bool SetAxisMotionMode(AXISID Axis, char Func, char Direction);
274
277 void SetSerialPort(int port)
278 {
279 MyPortFD = port;
280 }
281
284 bool SetClockTicksPerMicrostep(AXISID Axis, long ClockTicksPerMicrostep);
285
290 bool SetSlewModeDeccelerationRampLength(AXISID Axis, long Microsteps);
291
296 bool SetSlewToModeDeccelerationRampLength(AXISID Axis, long Microsteps);
297
300 bool toggleSnapPort(bool enabled);
301
306 void Slew(AXISID Axis, double SpeedInRadiansPerSecond, bool IgnoreSilentMode = true);
307
313 void SlewTo(AXISID Axis, long OffsetInMicrosteps, bool verbose = true);
314
319 bool SlowStop(AXISID Axis);
320
325
326 bool TalkWithAxis(AXISID Axis, SkywatcherCommand Command, std::string &cmdDataStr, std::string &responseStr);
327
331 bool IsInMotion(AXISID Axis);
332
333 // Skywatcher mount status variables
334 unsigned long MCVersion { 0 }; // Motor control board firmware version
335
336 static const char *mountTypeToString(uint8_t type);
337
339 {
340 EQ6 = 0x00,
341 HEQ5 = 0x01,
342 EQ5 = 0x02,
343 EQ3 = 0x03,
344 EQ8 = 0x04,
345 AZEQ6 = 0x05,
346 AZEQ5 = 0x06,
348 EQ8R_PRO = 0x20,
349 AZEQ6_PRO = 0x22,
350 EQ6_PRO = 0x23,
351 EQ5_PRO = 0x31,
352 WAVE_150I = 0x45,
353 WAVE_100I = 0x44,
354 GT = 0x80,
355 MF = 0x81,
356 _114GT = 0x82,
357 DOB = 0x90,
358 AZGTE = 0xA2,
359 AZGTI = 0xA5,
360 };
361
362 typedef struct SkyWatcherFeatures
363 {
364 bool inPPECTraining = false;
365 bool inPPEC = false;
366 bool hasEncoder = false;
367 bool hasPPEC = false;
368 bool hasHomeIndexer = false;
369 bool isAZEQ = false;
370 bool hasPolarLed = false;
371 bool hasCommonSlewStart = false; // supports :J3
373 bool hasWifi = false;
374 } SkyWatcherFeatures;
375
376
377 unsigned long MountCode { 0 };
378 bool IsDCMotor { false };
379 bool SilentSlewMode { true };
380
381 // Values from mount
382 long MicrostepsPerRevolution[2]; // Number of microsteps for 360 degree revolution
383 long StepperClockFrequency[2]; // The stepper clock timer interrupt frequency in ticks per second
384 long HighSpeedRatio[2]; // The speed multiplier for high speed mode.
385 long MicrostepsPerWormRevolution[2]; // Number of microsteps for one revolution of the worm gear.
387
388 // Calculated values
394
395 // SlewTo debugging
397
404
406 double SlewingSpeed[2];
407
408 protected:
409 // Custom debug level
410 unsigned int DBG_SCOPE { 0 };
411
412 private:
413 int MyPortFD { 0 };
415 static constexpr uint8_t SKYWATCHER_MAX_RETRTY {5};
416 static constexpr uint8_t SKYWATCHER_TIMEOUT_S {0};
417 static constexpr long SKYWATCHER_TIMEOUT_US {300000};
418 static constexpr uint8_t SKYWATCHER_MAX_CMD {16};
419
420 static const std::map<int, std::string> errorCodes;
421
422#ifdef INDI_DEBUG_LOGGING
423 public:
425#endif
426};
The Axis class Implements a generic Axis which can be used for equatorial or AltAz mounts for both ax...
bool SetGotoTargetOffset(AXISID Axis, long OffsetInMicrosteps)
Set the goto target offset per the specified axis.
double MicrostepsToRadians(AXISID Axis, long Microsteps)
Convert microsteps to angle in radians.
bool GetHighSpeedRatio(AXISID Axis)
Set the HighSpeedRatio status variable to the ratio between high and low speed stepping modes.
unsigned long BCDstr2long(std::string &String)
SkyWatcherFeatures AxisFeatures[2]
void TurnRAEncoder(bool on)
unsigned long Highstr2long(std::string &String)
long LastSlewToTarget[2]
void SetSerialPort(int port)
Set the serail port to be usb for mount communication.
long LowSpeedGotoMargin[2]
bool SetSlewModeDeccelerationRampLength(AXISID Axis, long Microsteps)
Set the length of the deccelaration ramp for Slew mode.
PositiveRotationSense_t GetPositiveRotationDirection(AXISID Axis)
Returns the rotation direction for a positive step on the designated axis.
static constexpr double SIDEREALRATE
bool GetMotorBoardVersion(AXISID Axis)
static constexpr double LOW_SPEED_MARGIN
double MicrostepsToDegrees(AXISID Axis, long Microsteps)
Convert microsteps to angle in degrees.
unsigned long MountCode
bool GetStepperClockFrequency(AXISID Axis)
Set the StepperClockFrequency status variable to fixed PIC timer interrupt frequency (ticks per secon...
void TurnEncoder(AXISID axis, bool on)
void SlewTo(AXISID Axis, long OffsetInMicrosteps, bool verbose=true)
Slew to the given offset and stop.
void SetFeature(AXISID axis, uint32_t command)
long ZeroPositionEncoders[2]
Zero position encoder values (microsteps).
double MicrostepsPerRadian[2]
unsigned int DBG_SCOPE
long CurrentEncoders[2]
Current encoder values (microsteps).
bool GetStatus(AXISID Axis)
bool GetMicrostepsPerRevolution(AXISID Axis)
Set the MicrostepsPerRevolution status variable to the number of microsteps for a 360 degree revoluti...
unsigned long MCVersion
long RadiansToMicrosteps(AXISID Axis, double AngleInRadians)
Convert angle in radians to microsteps.
bool GetMicrostepsPerWormRevolution(AXISID Axis)
Set the MicrostepsPermWormRevolution status variable to the number of microsteps for a 360 degree rev...
double RadiansPerMicrostep[2]
bool SetEncoder(AXISID Axis, long Microsteps)
Set axis encoder to the specified value.
void PrepareForSlewing(AXISID Axis, double Speed)
long DegreesPerSecondToClocksTicksPerMicrostep(AXISID Axis, double DegreesPerSecond)
Check if the current mount is a Virtuoso (AltAz)
bool InstantStop(AXISID Axis)
Bring the axis to an immediate halt. N.B. This command could cause damage to the mount or telescope a...
@ DISABLE_FULL_CURRENT_LOW_SPEED_CMD
@ ENABLE_FULL_CURRENT_LOW_SPEED_CMD
void TurnDEEncoder(bool on)
virtual ~SkywatcherAPI()=default
long PolarisPositionEncoders[2]
Polaris position (initial) encoder values (microsteps).
bool GetEncoder(AXISID Axis)
Set the CurrentEncoders status variable to the current encoder value in microsteps for the specified ...
long MicrostepsPerWormRevolution[2]
long HighSpeedRatio[2]
double SlewingSpeed[2]
double MicrostepsPerDegree[2]
long DegreesToMicrosteps(AXISID Axis, double AngleInDegrees)
Convert angle in degrees to microsteps.
double DegreesPerMicrostep[2]
bool SlowStop(AXISID Axis)
Bring the axis to slow stop in the distance specified by SetSlewModeDeccelerationRampLength.
bool StartAxisMotion(AXISID Axis)
Start the axis slewing in the previously selected mode.
bool InitMount()
Initialize the communication to the mount.
bool SetSlewToModeDeccelerationRampLength(AXISID Axis, long Microsteps)
Set the length of the deccelaration ramp for SlewTo mode.
long RadiansPerSecondToClocksTicksPerMicrostep(AXISID Axis, double RadiansPerSecond)
Convert a slewing rate in radians per second into the required clock ticks per microstep setting.
void Slew(AXISID Axis, double SpeedInRadiansPerSecond, bool IgnoreSilentMode=true)
Start the axis slewing at the given rate.
bool TalkWithAxis(AXISID Axis, SkywatcherCommand Command, std::string &cmdDataStr, std::string &responseStr)
static constexpr double MAX_SPEED
bool SetAxisMotionMode(AXISID Axis, char Func, char Direction)
Set the motion mode per the specified axis.
long MicrostepsPerRevolution[2]
bool IsInMotion(AXISID Axis)
Check if an axis is moving.
long StepperClockFrequency[2]
bool toggleSnapPort(bool enabled)
Toggle the snap port on or off.
bool SetClockTicksPerMicrostep(AXISID Axis, long ClockTicksPerMicrostep)
Set the PIC internal divider variable which determines how many clock interrupts have to occur betwee...
INDI::Telescope * pChildTelescope
static const char * mountTypeToString(uint8_t type)
void Long2BCDstr(long Number, std::string &String)
AXISSTATUS AxesStatus[2]
#define M_PI
Definition dsp.h:52
const char * Direction[]
int verbose
Definition indidriver.c:49
uint16_t type
Definition pwc-ioctl.h:0
bool NotInitialized
void SetSlewingTo(bool forward, bool highspeed)
void SetFullStop()
bool SlewingForward
void SetSlewing(bool forward, bool highspeed)