Instrument Neutral Distributed Interface INDI  2.0.2
indidome.h
Go to the documentation of this file.
1 /*******************************************************************************
2  INDI Dome Base Class
3  Copyright(c) 2014 Jasem Mutlaq. All rights reserved.
4 
5  The code used calculate dome target AZ and ZD is written by Ferran Casarramona, and adapted from code from Markus Wildi.
6  The transformations are based on the paper Matrix Method for Coodinates Transformation written by Toshimi Taki (http://www.asahi-net.or.jp/~zs3t-tk).
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License version 2 as published by the Free Software Foundation.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 *******************************************************************************/
22 
23 #pragma once
24 
25 #include "defaultdevice.h"
26 #include "libastro.h"
27 #include "inditimer.h"
28 
29 #include <string>
30 
31 // Defines a point in a 3 dimension space
32 typedef struct
33 {
34  double x, y, z;
35 } point3D;
36 
37 namespace Connection
38 {
39 class Serial;
40 class TCP;
41 }
42 
71 namespace INDI
72 {
73 
74 class Dome : public DefaultDevice
75 {
76  public:
81  typedef enum
82  {
90 
92  {
94  DOME_CCW
95  };
97  {
100  };
101 
104  {
108  };
109 
113  typedef enum
114  {
118 
121  {
124  };
125 
129  typedef enum
130  {
140  } DomeState;
141 
145  typedef enum
146  {
153 
154  enum
155  {
156  DOME_CAN_ABORT = 1 << 0,
157  DOME_CAN_ABS_MOVE = 1 << 1,
158  DOME_CAN_REL_MOVE = 1 << 2,
159  DOME_CAN_PARK = 1 << 3,
160  DOME_CAN_SYNC = 1 << 4,
161  DOME_HAS_SHUTTER = 1 << 5,
163  DOME_HAS_BACKLASH = 1 << 7
164  };
165 
169  enum
170  {
171  CONNECTION_NONE = 1 << 0,
172  CONNECTION_SERIAL = 1 << 1,
173  CONNECTION_TCP = 1 << 2
175 
176  Dome();
177  virtual ~Dome();
178 
179  virtual bool initProperties() override;
180  virtual void ISGetProperties(const char * dev) override;
181  virtual bool updateProperties() override;
182  virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
183  virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
184  virtual bool ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n) override;
185  virtual bool ISSnoopDevice(XMLEle * root) override;
186 
187  static void buttonHelper(const char * button_n, ISState state, void * context);
188 
194  void setDomeConnection(const uint8_t &value);
195 
199  uint8_t getDomeConnection() const;
200 
204  uint32_t GetDomeCapability() const
205  {
206  return capability;
207  }
208 
213  void SetDomeCapability(uint32_t cap);
214 
218  bool CanAbort()
219  {
220  return capability & DOME_CAN_ABORT;
221  }
222 
226  bool CanAbsMove()
227  {
228  return capability & DOME_CAN_ABS_MOVE;
229  }
230 
234  bool CanRelMove()
235  {
236  return capability & DOME_CAN_REL_MOVE;
237  }
238 
242  bool CanPark()
243  {
244  return capability & DOME_CAN_PARK;
245  }
246 
250  bool CanSync()
251  {
252  return capability & DOME_CAN_SYNC;
253  }
254 
258  bool HasShutter()
259  {
260  return capability & DOME_HAS_SHUTTER;
261  }
262 
267  {
269  }
270 
274  bool HasBacklash()
275  {
276  return capability & DOME_HAS_BACKLASH;
277  }
278 
283  bool isLocked();
284 
286  {
287  return m_DomeState;
288  }
289  void setDomeState(const DomeState &value);
290 
292  {
293  return m_ShutterState;
294  }
295  void setShutterState(const ShutterState &value);
296 
297  IPState getMountState() const;
298 
299  protected:
305  virtual bool SetSpeed(double rpm);
306 
311  virtual IPState Move(DomeDirection dir, DomeMotionCommand operation);
312 
318  virtual IPState MoveAbs(double az);
319 
325  virtual IPState MoveRel(double azDiff);
326 
331  virtual bool Sync(double az);
332 
337  virtual bool Abort();
338 
344  virtual IPState Park();
345 
352  virtual IPState UnPark();
353 
359  virtual bool SetBacklash(int32_t steps);
360 
366  virtual bool SetBacklashEnabled(bool enabled);
367 
374  virtual IPState ControlShutter(ShutterOperation operation);
375 
381  const char * GetShutterStatusString(ShutterState status);
382 
388 
397  bool InitPark();
398 
403  bool isParked();
404 
409  void SetParked(bool isparked);
410 
414  double GetAxis1Park();
415 
419  double GetAxis1ParkDefault();
420 
425  void SetAxis1Park(double value);
426 
431  void SetAxis1ParkDefault(double steps);
432 
437  virtual bool SetCurrentPark();
438 
443  virtual bool SetDefaultPark();
444 
445  //Park
446  const char * LoadParkData();
447  bool WriteParkData();
448 
457  bool GetTargetAz(double &Az, double &Alt, double &minAz, double &maxAz);
458 
472  bool Intersection(point3D p1, point3D p2, double r, double &mu1, double &mu2);
473 
483  bool OpticalCenter(point3D MountCenter, double dOpticalAxis, double Lat, double Ah, point3D &OP);
484 
492  bool OpticalVector(double Az, double Alt, point3D &OV);
493 
501  bool CheckHorizon(double HA, double dec, double lat);
502 
508  virtual bool saveConfigItems(FILE * fp) override;
509 
513  void UpdateMountCoords();
514 
519  virtual void UpdateAutoSync();
520 
522  virtual bool Handshake();
523 
524  double Csc(double x);
525  double Sec(double x);
526 
529 
532 
535 
538 
541 
544 
547 
550 
553 
556 
559 
560  // ISwitch AutoParkS[2];
561  // ISwitchVectorProperty AutoParkSP;
562 
563  uint32_t capability;
565 
568 
569  // Switch to lock id mount is unparked
572 
573  // Shutter control on Park/Unpark
576  enum
577  {
580  };
581 
588 
591  // 0 is East, 1 is West, 2 is as reported by mout, 3 as deducted by Hour Angle
592  // 4 ignore pier side and perform as in a fork mount
593  enum
594  {
600  };
601 
602  int mountOTASide = 0; // Side of the telescope with respect of the mount, 1: west, -1: east, 0 not reported
605 
606  // Backlash toogle
609 
610  // Backlash steps
613 
615 
616  // For Serial and TCP connections
617  int PortFD = -1;
618 
621 
622  // States
626 
627  // Observer geographic coords. Snooped from mount driver.
629  // Do we have valid geographic coords from mount driver?
630  bool HaveLatLong = false;
631 
632  // Mount horizontal and equatorial coords. Snoops from mount driver.
635  // Do we have valid coords from mount driver?
636  bool HaveRaDec = false;
637 
638  private:
639  void processButton(const char * button_n, ISState state);
640  void triggerSnoop(const char * driverName, const char * propertyName);
645  void SyncParkStatus(bool isparked);
650  const char * LoadParkXML();
651 
657  std::string GetHomeDirectory() const;
658 
659  Controller * controller = nullptr;
660 
661  bool IsParked = false;
662  bool IsMountParked = false;
663  bool IsLocked = true;
664  bool AutoSyncWarning = false;
665  bool UseHourAngle = false;
666 
667  const char * ParkDeviceName;
668  const std::string ParkDataFileName;
669  INDI::Timer m_MountUpdateTimer;
670  //int m_HorizontalUpdateTimerID { -1 };
671  XMLEle * ParkdataXmlRoot, *ParkdeviceXml, *ParkstatusXml, *ParkpositionXml, *ParkpositionAxis1Xml;
672 
673  double Axis1ParkPosition;
674  double Axis1DefaultParkPosition;
675 
676  bool callHandshake();
677  uint8_t domeConnection = CONNECTION_SERIAL | CONNECTION_TCP;
678 
679  // How often we update horizontal coordinates (10 seconds).
680  static constexpr uint32_t HORZ_UPDATE_TIMER { 10000 };
681 };
682 
683 }
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
Definition: connectiontcp.h:38
The Controller class provides functionality to access a controller (e.g. joystick) input and send it ...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Class to provide general functionality of a Dome device.
Definition: indidome.h:75
bool CanPark()
Definition: indidome.h:242
ISwitch DomeShutterS[2]
Definition: indidome.h:549
INumberVectorProperty DomeMeasurementsNP
Definition: indidome.h:587
double prev_alt
Definition: indidome.h:614
INDI::IHorizontalCoordinates mountHoriztonalCoords
Definition: indidome.h:633
INumberVectorProperty PresetNP
Definition: indidome.h:583
Connection::TCP * tcpConnection
Definition: indidome.h:620
@ DOME_CAN_PARK
Definition: indidome.h:159
@ DOME_CAN_ABS_MOVE
Definition: indidome.h:157
@ DOME_HAS_SHUTTER
Definition: indidome.h:161
@ DOME_CAN_REL_MOVE
Definition: indidome.h:158
@ DOME_HAS_BACKLASH
Definition: indidome.h:163
@ DOME_CAN_ABORT
Definition: indidome.h:156
@ DOME_CAN_SYNC
Definition: indidome.h:160
@ DOME_HAS_VARIABLE_SPEED
Definition: indidome.h:162
DomeState m_DomeState
Definition: indidome.h:623
@ CONNECTION_SERIAL
Definition: indidome.h:172
@ CONNECTION_TCP
Definition: indidome.h:173
@ CONNECTION_NONE
Definition: indidome.h:171
INumber DomeMeasurementsN[6]
Definition: indidome.h:586
ISwitch DomeMotionS[2]
Definition: indidome.h:531
virtual IPState UnPark()
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
Definition: indidome.cpp:2225
uint32_t capability
Definition: indidome.h:563
void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
Definition: indidome.cpp:1633
void SetDomeCapability(uint32_t cap)
SetDomeCapability set the dome capabilities. All capabilities must be initialized.
Definition: indidome.cpp:1561
void setDomeConnection(const uint8_t &value)
setDomeConnection Set Dome connection mode. Child class should call this in the constructor before Do...
Definition: indidome.cpp:2297
ISwitchVectorProperty PresetGotoSP
Definition: indidome.h:585
const char * GetShutterStatusString(ShutterState status)
getShutterStatusString
Definition: indidome.cpp:1569
INDI::IEquatorialCoordinates mountEquatorialCoords
Definition: indidome.h:634
bool CheckHorizon(double HA, double dec, double lat)
CheckHorizon Returns true if telescope points above horizon.
Definition: indidome.cpp:1476
ISwitch DomeBacklashS[2]
Definition: indidome.h:608
ITextVectorProperty ActiveDeviceTP
Definition: indidome.h:566
ISwitchVectorProperty ShutterParkPolicySP
Definition: indidome.h:574
@ SHUTTER_OPEN_ON_UNPARK
Definition: indidome.h:579
@ SHUTTER_CLOSE_ON_PARK
Definition: indidome.h:578
INumber ParkPositionN[1]
Definition: indidome.h:554
bool isParked()
isParked is dome currently parked?
Definition: indidome.cpp:1639
bool HaveRaDec
Definition: indidome.h:636
bool OpticalCenter(point3D MountCenter, double dOpticalAxis, double Lat, double Ah, point3D &OP)
OpticalCenter This function calculates the distance from the optical axis to the Dome center.
Definition: indidome.cpp:1432
INumber DomeSpeedN[1]
Definition: indidome.h:528
DomeState
Dome status.
Definition: indidome.h:130
@ DOME_UNPARKING
Definition: indidome.h:135
@ DOME_PARKED
Definition: indidome.h:136
@ DOME_ERROR
Definition: indidome.h:139
@ DOME_UNPARKED
Definition: indidome.h:137
@ DOME_PARKING
Definition: indidome.h:134
@ DOME_MOVING
Definition: indidome.h:132
@ DOME_SYNCED
Definition: indidome.h:133
@ DOME_UNKNOWN
Definition: indidome.h:138
virtual bool SetSpeed(double rpm)
SetSpeed Set Dome speed. This does not initiate motion, it sets the speed for the next motion command...
Definition: indidome.cpp:2106
virtual bool Sync(double az)
Sync sets the dome current azimuth as the supplied azimuth position.
Definition: indidome.cpp:2045
ISwitch AbortS[1]
Definition: indidome.h:540
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: indidome.cpp:259
ShutterState m_ShutterState
Definition: indidome.h:624
double prev_dec
Definition: indidome.h:614
bool CanRelMove()
Definition: indidome.h:234
ISwitchVectorProperty OTASideSP
Definition: indidome.h:589
void SetAxis1Park(double value)
SetRAPark Set current AZ parking position. The data park file (stored in ~/.indi/ParkData....
Definition: indidome.cpp:1861
double prev_ra
Definition: indidome.h:614
void UpdateMountCoords()
updateCoords updates the horizontal coordinates (Az & Alt) of the mount from the snooped RA,...
Definition: indidome.cpp:1488
INumber DomeAbsPosN[1]
Definition: indidome.h:534
INumberVectorProperty DomeParamNP
Definition: indidome.h:542
IPState getMountState() const
Definition: indidome.cpp:1114
ISwitch ShutterParkPolicyS[2]
Definition: indidome.h:575
void SetAxis1ParkDefault(double steps)
SetAxis1Park Set default AZ parking position.
Definition: indidome.cpp:1868
ShutterOperation
Shutter operation command.
Definition: indidome.h:114
@ SHUTTER_CLOSE
Definition: indidome.h:116
@ SHUTTER_OPEN
Definition: indidome.h:115
int PortFD
Definition: indidome.h:617
DomeMotionCommand
Definition: indidome.h:97
@ MOTION_STOP
Definition: indidome.h:99
@ MOTION_START
Definition: indidome.h:98
double Csc(double x)
Definition: indidome.cpp:1466
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: indidome.cpp:93
double prev_az
Definition: indidome.h:614
ISwitch ParkOptionS[3]
Definition: indidome.h:557
virtual void UpdateAutoSync()
UpdateAutoSync This function calculates the target dome azimuth from the mount's target coordinates g...
Definition: indidome.cpp:1516
@ DOME_CCW
Definition: indidome.h:94
virtual IPState MoveRel(double azDiff)
Move the Dome to an relative position.
Definition: indidome.cpp:1913
INumberVectorProperty DomeAbsPosNP
Definition: indidome.h:533
@ DM_OTA_SIDE_EAST
Definition: indidome.h:595
@ DM_OTA_SIDE_MOUNT
Definition: indidome.h:597
@ DM_OTA_SIDE_IGNORE
Definition: indidome.h:599
@ DM_OTA_SIDE_WEST
Definition: indidome.h:596
@ DM_OTA_SIDE_HA
Definition: indidome.h:598
double GetAxis1Park()
Definition: indidome.cpp:1851
INumberVectorProperty ParkPositionNP
Definition: indidome.h:555
uint32_t GetDomeCapability() const
GetDomeCapability returns the capability of the dome.
Definition: indidome.h:204
ISwitchVectorProperty AbortSP
Definition: indidome.h:539
ISwitch OTASideS[5]
Definition: indidome.h:590
ISwitchVectorProperty DomeShutterSP
Definition: indidome.h:548
bool CanSync()
Definition: indidome.h:250
bool HasShutter()
Definition: indidome.h:258
ISwitchVectorProperty ParkOptionSP
Definition: indidome.h:558
enum INDI::Dome::@239 DomeConnection
@ SHUTTER_ERROR
Definition: indidome.h:151
@ SHUTTER_MOVING
Definition: indidome.h:149
@ SHUTTER_UNKNOWN
Definition: indidome.h:150
@ SHUTTER_OPENED
Definition: indidome.h:147
@ SHUTTER_CLOSED
Definition: indidome.h:148
bool isLocked()
isLocked, is the dome currently locked?
Definition: indidome.cpp:1077
INumber DomeSyncN[1]
Definition: indidome.h:546
INumberVectorProperty DomeSyncNP
Definition: indidome.h:545
int mountOTASide
Definition: indidome.h:602
bool HasVariableSpeed()
Definition: indidome.h:266
virtual bool SetBacklash(int32_t steps)
SetBacklash Set the dome backlash compensation value.
Definition: indidome.cpp:1027
ISwitchVectorProperty ParkSP
Definition: indidome.h:551
INumber PresetN[3]
Definition: indidome.h:582
double GetAxis1ParkDefault()
Definition: indidome.cpp:1856
IText ActiveDeviceT[1]
Definition: indidome.h:567
virtual IPState Park()
Goto Park Position. The park position is an absolute azimuth value.
Definition: indidome.cpp:2171
const char * LoadParkData()
Definition: indidome.cpp:1758
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indidome.cpp:279
ISwitchVectorProperty DomeBacklashSP
Definition: indidome.h:607
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: indidome.cpp:492
IPState m_MountState
Definition: indidome.h:625
virtual bool SetDefaultPark()
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
Definition: indidome.cpp:2268
bool Intersection(point3D p1, point3D p2, double r, double &mu1, double &mu2)
Intersection Calculate the intersection of a ray and a sphere. The line segment is defined from p1 to...
Definition: indidome.cpp:1408
virtual bool SetBacklashEnabled(bool enabled)
SetBacklashEnabled Enables or disables the dome backlash compensation.
Definition: indidome.cpp:1034
double Sec(double x)
Definition: indidome.cpp:1471
virtual IPState MoveAbs(double az)
Move the Dome to an absolute azimuth.
Definition: indidome.cpp:1981
bool CanAbort()
Definition: indidome.h:218
INumberVectorProperty DomeRelPosNP
Definition: indidome.h:536
IGeographicCoordinates observer
Definition: indidome.h:628
ISwitch PresetGotoS[3]
Definition: indidome.h:584
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: indidome.cpp:822
ISwitchVectorProperty DomeMotionSP
Definition: indidome.h:530
static void buttonHelper(const char *button_n, ISState state, void *context)
Definition: indidome.cpp:1082
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
Definition: indidome.cpp:1043
INumberVectorProperty DomeBacklashNP
Definition: indidome.h:611
ISwitch ParkS[2]
Definition: indidome.h:552
virtual bool SetCurrentPark()
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
Definition: indidome.cpp:2262
INumber DomeParamN[1]
Definition: indidome.h:543
bool CanAbsMove()
Definition: indidome.h:226
@ PARK_AZ_ENCODER
Definition: indidome.h:107
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: indidome.cpp:795
void setShutterState(const ShutterState &value)
Definition: indidome.cpp:1119
bool OpticalVector(double Az, double Alt, point3D &OV)
OpticalVector This function calculates a second point for determining the optical axis.
Definition: indidome.cpp:1453
ISwitch DomeAutoSyncS[2]
Definition: indidome.h:604
virtual ~Dome()
Definition: indidome.cpp:71
bool HasBacklash()
Definition: indidome.h:274
void setDomeState(const DomeState &value)
Definition: indidome.cpp:1156
MountLockingPolicy
Definition: indidome.h:121
@ MOUNT_IGNORED
Definition: indidome.h:122
@ MOUNT_LOCKS
Definition: indidome.h:123
INumberVectorProperty DomeSpeedNP
Definition: indidome.h:527
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
Definition: indidome.cpp:1644
Connection::Serial * serialConnection
Definition: indidome.h:619
void SetParkDataType(DomeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
Definition: indidome.cpp:1587
ISwitchVectorProperty MountPolicySP
Definition: indidome.h:570
bool WriteParkData()
Definition: indidome.cpp:1789
DomeParkData parkDataType
Definition: indidome.h:564
ShutterState getShutterState() const
Definition: indidome.h:291
virtual bool Handshake()
perform handshake with device to check communication
Definition: indidome.cpp:2274
DomeMeasurements
Measurements necessary for dome-slit synchronization. All values are in meters. The displacements are...
Definition: indidome.h:82
@ DM_NORTH_DISPLACEMENT
Definition: indidome.h:85
@ DM_EAST_DISPLACEMENT
Definition: indidome.h:86
@ DM_SHUTTER_WIDTH
Definition: indidome.h:84
@ DM_DOME_RADIUS
Definition: indidome.h:83
@ DM_OTA_OFFSET
Definition: indidome.h:88
@ DM_UP_DISPLACEMENT
Definition: indidome.h:87
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: indidome.cpp:390
INumber DomeRelPosN[1]
Definition: indidome.h:537
bool HaveLatLong
Definition: indidome.h:630
INumber DomeBacklashN[1]
Definition: indidome.h:612
virtual IPState ControlShutter(ShutterOperation operation)
Open or Close shutter.
Definition: indidome.cpp:2127
ISwitchVectorProperty DomeAutoSyncSP
Definition: indidome.h:603
DomeState getDomeState() const
Definition: indidome.h:285
ISwitch MountPolicyS[2]
Definition: indidome.h:571
bool GetTargetAz(double &Az, double &Alt, double &minAz, double &maxAz)
GetTargetAz.
Definition: indidome.cpp:1273
uint8_t getDomeConnection() const
Definition: indidome.cpp:2292
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation)
Move the Dome in a particular direction.
Definition: indidome.cpp:1873
virtual bool Abort()
Abort all dome motion.
Definition: indidome.cpp:2052
The Timer class provides repetitive and single-shot timers.
Definition: inditimer.h:41
double dec
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:34
Namespace to encapsulate INDI client, drivers, and mediator classes.
__le16 type
Definition: pwc-ioctl.h:0
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246
double x
Definition: indidome.h:34