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 bool initProperties() override;
46 virtual bool updateProperties() override;
47
48 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
49 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
50 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
51 virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
52 char *formats[], char *names[], int n) override;
53
54 protected:
55 // Motion
56 virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
57 virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
58 virtual bool Abort() override;
59
60 // Time & Location
61 virtual bool updateLocation(double latitude, double longitude, double elevation) override;
62 virtual bool updateTime(ln_date *utc, double utc_offset) override;
63
64 // GOTO & SYNC
65 virtual bool Goto(double ra, double dec) override;
66 virtual bool Sync(double ra, double dec) override;
67
68 // Tracking
69 virtual bool SetTrackMode(uint8_t mode) override;
70 virtual bool SetTrackRate(double raRate, double deRate) override;
71 virtual bool SetTrackEnabled(bool enabled) override;
72
73 // Mount Type
74 virtual bool SetMountType(TelescopeMountType type) override;
75
76 // Parking
77 virtual bool SetCurrentPark() override;
78 virtual bool SetDefaultPark() override;
79 virtual bool Park() override;
80 virtual bool UnPark() override;
81
82 // Guiding
83 virtual IPState GuideNorth(uint32_t ms) override;
84 virtual IPState GuideSouth(uint32_t ms) override;
85 virtual IPState GuideEast(uint32_t ms) override;
86 virtual IPState GuideWest(uint32_t ms) override;
87
88 // Simulation
89 virtual void simulationTriggered(bool enable) override;
90
91 // Config items
92 virtual bool saveConfigItems(FILE *fp) override;
93
94 private:
98 bool getVersion();
99 void getRADEFromEncoders(double haEncoder, double deEncoder, double &ra, double &de, TelescopePierSide &pierSide);
100 void getEncodersFromRADE(double ra, double de, double &raEncoder, double &deEncoder);
101 double calculateSlewTime(double distance);
102 bool getTelescopeFromSkyCoordinates(double ra, double de, INDI::IEquatorialCoordinates &telescopeCoordinates);
103
107 bool getAcceleration(INDI_EQ_AXIS axis);
108 bool setAcceleration(INDI_EQ_AXIS axis, uint32_t a);
109
113 bool getVelocity(INDI_EQ_AXIS axis);
114 bool getVelocity(INDI_EQ_AXIS axis, double &value);
115
122 bool setVelocity(INDI_EQ_AXIS axis, double value);
123
124 bool getMaximumSlewVelocity();
125
126
130 bool isSlewComplete();
131 bool syncEncoder(INDI_EQ_AXIS axis, double value);
132 bool slewEncoder(INDI_EQ_AXIS axis, double value);
133 bool getEncoderPosition(INDI_EQ_AXIS axis);
134 bool stopMotion(INDI_EQ_AXIS axis);
135
139
150 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
151 void hexDump(char * buf, const char * data, int size);
152 std::vector<std::string> split(const std::string &input, const std::string &regex);
153
157 // Guide Rate
158 INDI::PropertyNumber GuideRateNP {2};
159 // Firmware Version
160 INDI::PropertyText FirmwareTP {1};
161 // Acceleration
162 INDI::PropertyNumber AccelerationNP {2};
163 // Encoders
164 INDI::PropertyNumber EncoderNP {2};
165
169 struct
170 {
171 // -90 to + 90 degrees.
173 // -180 to +180 degrees.
175 // arcsec/sec
176 double velocity[2] = {TRACKRATE_SIDEREAL, 0};
177 // arcsec/sec^2
178 uint32_t acceleration[2] = {3600, 3600};
179 // 1 Slewing, 0 Stopped
180 uint8_t status[2] = {0, 0};
181 } SimData;
182
183 INDI::ElapsedTimer m_SimulationTimer;
184 // Process very simply mount simulation. No meridian flips.
185 void simulateMount();
186 // Process basic commands.
187 bool handleSimulationCommand(const char * cmd, char * res, int cmd_len, int res_len);
188
190 INDI::IEquatorialCoordinates m_MountInternalCoordinates;
191
195 // > is the stop char
196 static const char DRIVER_STOP_CHAR { 0x3E };
197 // Wait up to a maximum of 3 seconds for serial input
198 static constexpr const uint8_t DRIVER_TIMEOUT {3};
199 // Maximum buffer for sending/receiving.
200 static constexpr const uint8_t DRIVER_LEN {64};
201 // Slew Modes
202 static constexpr const uint8_t SLEW_MODES {10};
203 // Slew Speeds
204 static const std::array<uint32_t, SLEW_MODES> SLEW_SPEEDS;
205 // Maximum Slew Velocity. This cannot be set now so it's considered constant until until it can be altered.
206 // arcsec/sec
207 static constexpr double MAX_SLEW_VELOCITY {10800.0};
208 // Target threshold in degrees between mechanical target and current coordinates
209 // If they are within 0.1 degrees, then we consider motion complete
210 static constexpr double DIFF_THRESHOLD {0.1};
211};
double targetMechanicalDE
Definition astrotrac.h:174
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:55
double velocity[2]
Definition astrotrac.h:176
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:172
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:174
virtual bool SetMountType(TelescopeMountType type) override
SetMountType Called when the user selects a different mount type in TELESCOPE_MOUNT_TYPE....
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 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:178
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:172
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:180
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:63
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...
TelescopeMountType
Mount geometry reported in the standard TELESCOPE_MOUNT_TYPE property. The values are the indices of ...
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
*brief user defined string literal for JSON values *sa std::size_t n
#define TRACKRATE_SIDEREAL
Definition indimacros.h:39
uint16_t type
Definition pwc-ioctl.h:0
uint8_t cmd[4]
Definition pwc-ioctl.h:2