Instrument Neutral Distributed Interface INDI 2.2.5
telescope_simulator.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2015 Jasem Mutlaq. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7 .
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12 .
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#pragma once
20
21#include "indiguiderinterface.h"
22#include "inditelescope.h"
23#include "scopesim_helper.h"
25
26#include <random>
27
28#define USE_SIM_TAB
29
47{
48 public:
49 ScopeSim();
50 virtual ~ScopeSim() = default;
51
52 virtual const char *getDefaultName() override;
53 virtual bool Connect() override;
54 virtual bool Disconnect() override;
55 virtual bool ReadScopeStatus() override;
56 virtual bool initProperties() override;
57 virtual void ISGetProperties(const char *dev) override;
58 virtual bool updateProperties() override;
59
60 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
61 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
62 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
63 virtual bool ISSnoopDevice(XMLEle *root) override;
64
65 protected:
66 // Slew Rate
67 virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
68 virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
69 virtual bool Abort() override;
70
71 virtual IPState GuideNorth(uint32_t ms) override;
72 virtual IPState GuideSouth(uint32_t ms) override;
73 virtual IPState GuideEast(uint32_t ms) override;
74 virtual IPState GuideWest(uint32_t ms) override;
75
76 virtual bool SetTrackMode(uint8_t mode) override;
77 virtual bool SetMountType(TelescopeMountType type) override;
78 virtual bool SetTrackEnabled(bool enabled) override;
79 virtual bool SetTrackRate(double raRate, double deRate) override;
80
81 virtual bool Goto(double, double) override;
82 virtual bool Park() override;
83 virtual bool UnPark() override;
84 virtual bool Sync(double ra, double dec) override;
85
86 // Parking
87 virtual bool SetCurrentPark() override;
88 virtual bool SetDefaultPark() override;
89 virtual bool updateLocation(double latitude, double longitude, double elevation) override;
90 virtual bool updateTime(ln_date *utc, double utc_offset) override;
91
92 // Home
93 virtual IPState ExecuteHomeAction(TelescopeHomeAction action) override;
94
95 virtual bool saveConfigItems(FILE *fp) override;
96
97 private:
98 double m_currentRA { 0 };
99 double m_currentDEC { 90 };
100 double m_currentAz { 180 }; // INDI Az convention: 0=North, increasing eastward
101 double m_currentAlt { 0 };
102 double m_targetRA { 0 };
103 double m_targetDEC { 0 };
105 void StartSlew(double ra, double dec, TelescopeStatus status);
106
109 void guideAltAzDecomposed(double dNS, double dEW, uint32_t ms);
110
112 void updateCurrentCoordsFromAxes();
113
115 void setTargetFromAxisPosition(Angle primary, Angle secondary);
116
117 unsigned int DBG_SCOPE { 0 };
118
119 int mcRate = 0;
120
121 // double guiderEWTarget[2];
122 // double guiderNSTarget[2];
123
124 bool guidingNS = false;
125 bool guidingEW = false;
126
130 uint32_t applyGuideErrors(int axis, double &rate, uint32_t ms);
131
132 // True if the last guide pulse moved the axis in the positive direction, per axis.
133 // For DEC this is a little more complicated than north because of pier side...
134 bool m_GuideLastPositive[2] { false, false };
135 // Will be between 0 and the axis backlash. When guide pulses change directions,
136 // a pulse may not completely clear the backlash. This is how much is left
137 // after that pulse.
138 uint32_t m_GuideRemainingBacklash[2] { 0, 0 };
139 std::mt19937 m_GuideRng { std::random_device{}() };
140
141 INDI::PropertyNumber GuideRateNP {2};
142 enum
143 {
144 GUIDE_RATE_WE,
145 GUIDE_RATE_NS
146 };
147
148 double m_Home[2] = {0, 0};
149
150 Axis axisPrimary { "Primary Axis" }; // entails angle of mount for primary axis
151 Axis axisSecondary { "Secondary Axis" }; // entails angle of mount for secondary axis ("mechanical DEC")
152
153 int m_PierSide {-1};
154 int m_MountType {-1};
155
156 Alignment alignment;
157
158 // Parabolic Alt-Az tracking window: three sky positions bracketing the current time,
159 // used to fit a 2nd-order polynomial for axis rate prediction.
160 INDI::IHorizontalCoordinates m_TrackingWindowCoords[3] {};
161 bool m_IsPipelinePrimed { false };
162 double m_LastTrackingRA { 0 };
163 double m_LastTrackingDec { 0 };
164
165 bool updateMountAndPierSide();
166
167#ifdef USE_SIM_TAB
168 // Simulator Tab properties
169 // Scope type and alignment use the standard TELESCOPE_MOUNT_TYPE property (MountTypeSP).
170 INDI::PropertySwitch simPierSideSP {2};
171 enum
172 {
173 PS_OFF,
174 PS_ON
175 };
176
177 INDI::PropertyNumber mountModelNP {6};
178 enum
179 {
180 MM_IH,
181 MM_ID,
182 MM_CH,
183 MM_NP,
184 MM_MA,
185 MM_ME
186 };
187
188 INDI::PropertyNumber mountAxisNP {2};
189 enum
190 {
191 PRIMARY,
192 SECONDARY
193 };
194
195 INDI::PropertyNumber flipHourAngleNP {1};
196 // Per axis guiding errors. Element index is the error type + RA_AXIS/DEC_AXIS.
197 INDI::PropertyNumber guideErrorsNP {8};
198 enum
199 {
200 GE_BACKLASH_RA = 0,
201 GE_RATE_RA = 2,
202 GE_JITTER_RA = 4,
203 GE_DROP_RA = 6
204 };
205
206 INDI::PropertyText PACDeviceTP {1};
207 double m_snoopedAzError { 0 };
208 double m_snoopedAltError { 0 };
209 // Fraction of each requested move the PAC really makes (CORRECTION_GAIN of the PAC simulator)
210 double m_snoopedGain { 1.0 };
211 // True while the PAC reports a move in progress, so each move is applied once
212 bool m_PACMoveActive { false };
213
215 void applyPACCorrection();
216
217#endif
218
220 void publishTruePointing();
221
222 // True pointing position (Wallace errors applied) published as EQUATORIAL_PE so the
223 // CCD simulator can generate star fields at the physically-correct sky position while
224 // EQUATORIAL_EOD_COORD carries the raw encoder position for the INDI alignment module.
225 INDI::PropertyNumber EqPENP {2};
226 enum { PE_RA = 0, PE_DEC = 1 };
227
228};
229
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 ...
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState ExecuteHomeAction(TelescopeHomeAction action) override
Execute a homing action.
virtual const char * getDefaultName() override
virtual bool Disconnect() override
Disconnect from device.
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 updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
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 ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool Park() override
Park the telescope to its home position.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope 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 updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual ~ScopeSim()=default
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool SetMountType(TelescopeMountType type) override
SetMountType Called when the user selects a different mount type in TELESCOPE_MOUNT_TYPE....
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
INDI_DIR_WE
INDI_DIR_NS
*brief user defined string literal for JSON values *sa std::size_t n
struct xml_ele_ XMLEle
Definition lilxml.h:81
uint16_t type
Definition pwc-ioctl.h:0