Instrument Neutral Distributed Interface INDI  2.0.2
astrotrac.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2021 Jasem Mutlaq. All rights reserved.
3 
4  AstroTrac Mount Driver.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9  .
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14  .
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 
21 #pragma once
22 
23 #include "inditelescope.h"
24 #include "indiguiderinterface.h"
25 
27 
28 #include "indipropertynumber.h"
29 #include "indipropertytext.h"
30 #include "indipropertyswitch.h"
31 #include "indielapsedtimer.h"
32 
33 class AstroTrac :
34  public INDI::Telescope,
35  public INDI::GuiderInterface,
37 {
38  public:
39  AstroTrac();
40  virtual ~AstroTrac() = default;
41 
42  virtual const char *getDefaultName() override;
43  virtual bool Handshake() override;
44  virtual bool ReadScopeStatus() override;
45  virtual void ISGetProperties(const char *dev) override;
46  virtual bool initProperties() override;
47  virtual bool updateProperties() override;
48 
49  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
50  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
51  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) 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 
55  protected:
56  // Motion
57  virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
58  virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
59  virtual bool Abort() override;
60 
61  // Time & Location
62  virtual bool updateLocation(double latitude, double longitude, double elevation) override;
63  virtual bool updateTime(ln_date *utc, double utc_offset) override;
64 
65  // GOTO & SYNC
66  virtual bool Goto(double ra, double dec) override;
67  virtual bool Sync(double ra, double dec) override;
68 
69  // Tracking
70  virtual bool SetTrackMode(uint8_t mode) override;
71  virtual bool SetTrackRate(double raRate, double deRate) override;
72  virtual bool SetTrackEnabled(bool enabled) override;
73 
74  // Parking
75  virtual bool SetCurrentPark() override;
76  virtual bool SetDefaultPark() override;
77  virtual bool Park() override;
78  virtual bool UnPark() override;
79 
80  // Guiding
81  virtual IPState GuideNorth(uint32_t ms) override;
82  virtual IPState GuideSouth(uint32_t ms) override;
83  virtual IPState GuideEast(uint32_t ms) override;
84  virtual IPState GuideWest(uint32_t ms) override;
85 
86  // Simulation
87  virtual void simulationTriggered(bool enable) override;
88 
89  // Config items
90  virtual bool saveConfigItems(FILE *fp) override;
91 
92  private:
96  bool getVersion();
97  void getRADEFromEncoders(double haEncoder, double deEncoder, double &ra, double &de);
98  void getEncodersFromRADE(double ra, double de, double &raEncoder, double &deEncoder);
99  double calculateSlewTime(double distance);
100  bool getTelescopeFromSkyCoordinates(double ra, double de, INDI::IEquatorialCoordinates &telescopeCoordinates);
101 
105  bool getAcceleration(INDI_EQ_AXIS axis);
106  bool setAcceleration(INDI_EQ_AXIS axis, uint32_t a);
107 
111  bool getVelocity(INDI_EQ_AXIS axis);
112 
119  bool setVelocity(INDI_EQ_AXIS axis, double value);
120 
121  bool getMaximumSlewVelocity();
122 
123 
127  bool isSlewComplete();
128  bool syncEncoder(INDI_EQ_AXIS axis, double value);
129  bool slewEncoder(INDI_EQ_AXIS axis, double value);
130  bool getEncoderPosition(INDI_EQ_AXIS axis);
131  bool stopMotion(INDI_EQ_AXIS axis);
132 
136 
147  bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
148  void hexDump(char * buf, const char * data, int size);
149  std::vector<std::string> split(const std::string &input, const std::string &regex);
150 
154  // Mount Type
155  INDI::PropertySwitch MountTypeSP {2};
156  enum
157  {
158  MOUNT_GEM,
159  MOUNT_SINGLE_ARM
160  };
161 
162  // Guide Rate
163  INDI::PropertyNumber GuideRateNP {2};
164  // Firmware Version
165  INDI::PropertyText FirmwareTP {1};
166  // Acceleration
167  INDI::PropertyNumber AccelerationNP {2};
168  // Encoders
169  INDI::PropertyNumber EncoderNP {2};
170 
174  struct
175  {
176  // -90 to + 90 degrees.
178  // -180 to +180 degrees.
180  // arcsec/sec
181  double velocity[2] = {TRACKRATE_SIDEREAL, 0};
182  // arcsec/sec^2
183  uint32_t acceleration[2] = {3600, 3600};
184  // 1 Slewing, 0 Stopped
185  uint8_t status[2] = {0, 0};
186  } SimData;
187 
188  INDI::ElapsedTimer m_SimulationTimer;
189  // Process very simply mount simulation. No meridian flips.
190  void simulateMount();
191  // Process basic commands.
192  bool handleSimulationCommand(const char * cmd, char * res, int cmd_len, int res_len);
193 
195  INDI::IEquatorialCoordinates m_MountInternalCoordinates;
199  // > is the stop char
200  static const char DRIVER_STOP_CHAR { 0x3E };
201  // Wait up to a maximum of 3 seconds for serial input
202  static constexpr const uint8_t DRIVER_TIMEOUT {3};
203  // Maximum buffer for sending/receving.
204  static constexpr const uint8_t DRIVER_LEN {64};
205  // Slew Modes
206  static constexpr const uint8_t SLEW_MODES {10};
207  // Slew Speeds
208  static const std::array<uint32_t, SLEW_MODES> SLEW_SPEEDS;
209  // Maximum Slew Velocity. This cannot be set now so it's considered contant until until it can be altered.
210  // arcsec/sec
211  static constexpr double MAX_SLEW_VELOCITY {10800.0};
212  // Target threshold in degrees between mechanical target and current coordinates
213  // If they are within 0.1 degrees, then we consider motion complete
214  static constexpr double DIFF_THRESHOLD {0.1};
215 };
double targetMechanicalDE
Definition: astrotrac.h:179
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: astrotrac.cpp:797
virtual const char * getDefaultName() override
Definition: astrotrac.cpp:54
double velocity[2]
Definition: astrotrac.h:181
virtual bool Handshake() override
perform handshake with device to check communication
Definition: astrotrac.cpp:187
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
Definition: astrotrac.cpp:1022
double currentMechanicalHA
Definition: astrotrac.h:177
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
Definition: astrotrac.cpp:963
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
Definition: astrotrac.cpp:1003
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
Definition: astrotrac.cpp:920
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
Definition: astrotrac.cpp:931
virtual void simulationTriggered(bool enable) override
Handle Simulation Trigger.
Definition: astrotrac.cpp:1171
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
Definition: astrotrac.cpp:507
double currentMechanicalDE
Definition: astrotrac.h:179
virtual bool saveConfigItems(FILE *fp) override
Config Items.
Definition: astrotrac.cpp:1068
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
Definition: astrotrac.cpp:1030
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.
Definition: astrotrac.cpp:821
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
Definition: astrotrac.cpp:847
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...
Definition: astrotrac.cpp:127
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
Definition: astrotrac.cpp:1051
virtual bool Park() override
Park the telescope to its home position.
Definition: astrotrac.cpp:703
uint32_t acceleration[2]
Definition: astrotrac.h:183
virtual bool UnPark() override
Unpark the telescope if already parked.
Definition: astrotrac.cpp:718
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
Definition: astrotrac.cpp:899
double targetMechanicalHA
Definition: astrotrac.h:177
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
Definition: astrotrac.cpp:137
virtual ~AstroTrac()=default
virtual bool ReadScopeStatus() override
Read telescope status.
Definition: astrotrac.cpp:615
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: astrotrac.cpp:741
uint8_t status[2]
Definition: astrotrac.h:185
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
Definition: astrotrac.cpp:984
virtual bool initProperties() override
Called to initialize basic properties required all the time.
Definition: astrotrac.cpp:62
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: astrotrac.cpp:727
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
Definition: astrotrac.cpp:873
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
Definition: astrotrac.cpp:836
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
Definition: astrotrac.cpp:942
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
Definition: astrotrac.cpp:910
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
Definition: astrotrac.cpp:543
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.
double ra
double dec
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
INDI_EQ_AXIS
Definition: indibasetypes.h:34
INDI_DIR_WE
Definition: indibasetypes.h:55
INDI_DIR_NS
Definition: indibasetypes.h:48
#define TRACKRATE_SIDEREAL
Definition: indicom.h:55
__u8 cmd[4]
Definition: pwc-ioctl.h:2