Instrument Neutral Distributed Interface INDI 2.2.5
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
33class AstroTrac :
34 public INDI::Telescope,
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, TelescopePierSide &pierSide);
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 bool getVelocity(INDI_EQ_AXIS axis, double &value);
113
120 bool setVelocity(INDI_EQ_AXIS axis, double value);
121
122 bool getMaximumSlewVelocity();
123
124
128 bool isSlewComplete();
129 bool syncEncoder(INDI_EQ_AXIS axis, double value);
130 bool slewEncoder(INDI_EQ_AXIS axis, double value);
131 bool getEncoderPosition(INDI_EQ_AXIS axis);
132 bool stopMotion(INDI_EQ_AXIS axis);
133
137
148 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
149 void hexDump(char * buf, const char * data, int size);
150 std::vector<std::string> split(const std::string &input, const std::string &regex);
151
155 // Mount Type
156 INDI::PropertySwitch MountTypeSP {2};
157 enum
158 {
159 MOUNT_GEM,
160 MOUNT_SINGLE_ARM
161 };
162
163 // Guide Rate
164 INDI::PropertyNumber GuideRateNP {2};
165 // Firmware Version
166 INDI::PropertyText FirmwareTP {1};
167 // Acceleration
168 INDI::PropertyNumber AccelerationNP {2};
169 // Encoders
170 INDI::PropertyNumber EncoderNP {2};
171
175 struct
176 {
177 // -90 to + 90 degrees.
179 // -180 to +180 degrees.
181 // arcsec/sec
182 double velocity[2] = {TRACKRATE_SIDEREAL, 0};
183 // arcsec/sec^2
184 uint32_t acceleration[2] = {3600, 3600};
185 // 1 Slewing, 0 Stopped
186 uint8_t status[2] = {0, 0};
187 } SimData;
188
189 INDI::ElapsedTimer m_SimulationTimer;
190 // Process very simply mount simulation. No meridian flips.
191 void simulateMount();
192 // Process basic commands.
193 bool handleSimulationCommand(const char * cmd, char * res, int cmd_len, int res_len);
194
196 INDI::IEquatorialCoordinates m_MountInternalCoordinates;
197
201 // > is the stop char
202 static const char DRIVER_STOP_CHAR { 0x3E };
203 // Wait up to a maximum of 3 seconds for serial input
204 static constexpr const uint8_t DRIVER_TIMEOUT {3};
205 // Maximum buffer for sending/receiving.
206 static constexpr const uint8_t DRIVER_LEN {64};
207 // Slew Modes
208 static constexpr const uint8_t SLEW_MODES {10};
209 // Slew Speeds
210 static const std::array<uint32_t, SLEW_MODES> SLEW_SPEEDS;
211 // Maximum Slew Velocity. This cannot be set now so it's considered constant until until it can be altered.
212 // arcsec/sec
213 static constexpr double MAX_SLEW_VELOCITY {10800.0};
214 // Target threshold in degrees between mechanical target and current coordinates
215 // If they are within 0.1 degrees, then we consider motion complete
216 static constexpr double DIFF_THRESHOLD {0.1};
217};
double targetMechanicalDE
Definition astrotrac.h:180
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual const char * getDefaultName() override
Definition astrotrac.cpp:54
double velocity[2]
Definition astrotrac.h:182
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
double currentMechanicalHA
Definition astrotrac.h:178
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
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 void simulationTriggered(bool enable) override
Handle Simulation Trigger.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
double currentMechanicalDE
Definition astrotrac.h:180
virtual bool saveConfigItems(FILE *fp) override
Config Items.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
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 MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
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 SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool Park() override
Park the telescope to its home position.
uint32_t acceleration[2]
Definition astrotrac.h:184
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
double targetMechanicalHA
Definition astrotrac.h:178
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual ~AstroTrac()=default
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
uint8_t status[2]
Definition astrotrac.h:186
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
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.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
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:148
IPState
Property state.
Definition indiapi.h:158
INDI_EQ_AXIS
INDI_DIR_WE
INDI_DIR_NS
#define TRACKRATE_SIDEREAL
Definition indimacros.h:39
uint8_t cmd[4]
Definition pwc-ioctl.h:2