48 srand(
static_cast<uint32_t
>(time(
nullptr)));
58 return "Telescope Simulator";
79 IUFillNumber(&mountModelN[0],
"MM_IH",
"Ha Zero (IH)",
"%g", -5, 5, 0.01, 0);
80 IUFillNumber(&mountModelN[1],
"MM_ID",
"Dec Zero (ID)",
"%g", -5, 5, 0.01, 0);
81 IUFillNumber(&mountModelN[2],
"MM_CH",
"Cone (CH)",
"%g", -5, 5, 0.01, 0);
82 IUFillNumber(&mountModelN[3],
"MM_NP",
"Ha/Dec (NP)",
"%g", -5, 5, 0.01, 0);
83 IUFillNumber(&mountModelN[4],
"MM_MA",
"Pole Azm (MA)",
"%g", -5, 5, 0.01, 0);
84 IUFillNumber(&mountModelN[5],
"MM_ME",
"Pole elev (ME)",
"%g", -5, 5, 0.01, 0);
88 IUFillNumber(&flipHourAngleN[0],
"FLIP_HA",
"Hour Angle (deg)",
"%g", -20, 20, 0.1, 0);
92 IUFillNumber(&mountAxisN[0],
"PRIMARY",
"Primary (Ha)",
"%g", -180, 180, 0.01, 0);
93 IUFillNumber(&mountAxisN[1],
"SECONDARY",
"Secondary (Dec)",
"%g", -180, 180, 0.01, 0);
169 updateMountAndPierSide();
191 Sync(currentRA, currentDEC);
221 LOG_INFO(
"Telescope simulator is online.");
229 LOG_INFO(
"Telescope simulator is offline.");
243 currentRA =
ra.Hours();
244 currentDEC =
dec.Degrees();
247 if (alignment.
mountType == Alignment::MOUNT_TYPE::EQ_GEM)
260 LOG_INFO(
"Telescope slew is complete. Parked");
271 LOG_INFO(
"Telescope slew is complete. Tracking...");
274 auto dRa = targetRA - currentRA;
275 auto dDec = targetDEC - currentDEC;
276 LOGF_DEBUG(
"slew accuracy %f, %f", dRa * 15 * 3600, dDec * 3600);
283 if (guidingEW && !axisPrimary.
IsGuiding())
291 if (guidingNS && !axisSecondary.
IsGuiding())
303 if (std::fabs(mountAxisN[
AXIS_RA].value - axisRA) > 0.0001 ||
304 std::fabs(mountAxisN[
AXIS_DE].value - axisDE) > 0.0001)
306 mountAxisN[
AXIS_RA].value = axisRA;
307 mountAxisN[
AXIS_DE].value = axisDE;
316 char RAStr[64], DecStr[64];
317 fs_sexa(RAStr, currentRA, 2, 3600);
318 fs_sexa(DecStr, currentDEC, 2, 3600);
319 DEBUGF(DBG_SCOPE,
"Current RA: %s Current DEC: %s", RAStr, DecStr);
343 currentRA = r.
Hours();
363 void ScopeSim::StartSlew(
double ra,
double dec, TelescopeStatus status)
365 Angle primary, secondary;
373 char RAStr[64], DecStr[64];
375 fs_sexa(RAStr, targetRA, 2, 3600);
376 fs_sexa(DecStr, targetDEC, 2, 3600);
378 const char * statusStr;
382 statusStr =
"Parking";
385 statusStr =
"Slewing";
388 statusStr =
"unknown";
392 LOGF_INFO(
"%s to RA: %s - DEC: %s", statusStr, RAStr, DecStr);
407 if (strcmp(name,
"GUIDE_RATE") == 0)
422 if (strcmp(name, mountModelNP.
name) == 0)
427 alignment.
setCorrections(mountModelN[0].value, mountModelN[1].value,
428 mountModelN[2].value, mountModelN[3].value,
429 mountModelN[4].value, mountModelN[5].value);
435 if (strcmp(name, flipHourAngleNP.
name) == 0)
456 if (strcmp(name, mountTypeSP.
name) == 0)
463 updateMountAndPierSide();
466 if (strcmp(name, simPierSideSP.
name) == 0)
473 updateMountAndPierSide();
496 axisSecondary.
Abort();
504 LOG_ERROR(
"Please unpark the mount before issuing any motion commands.");
510 LOGF_DEBUG(
"MoveNS dir %s, motion %s, rate %d", dir ==
DIRECTION_NORTH ?
"N" :
"S", command == 0 ?
"start" :
"stop", rate);
521 LOG_ERROR(
"Please unpark the mount before issuing any motion commands.");
527 LOGF_DEBUG(
"MoveWE dir %d, motion %s, rate %d", dir ==
DIRECTION_EAST ?
"E" :
"W", command == 0 ?
"start" :
"stop", rate);
535 double rate = GuideRateN[
DEC_AXIS].value;
543 double rate = GuideRateN[
DEC_AXIS].value;
551 double rate = GuideRateN[
RA_AXIS].value;
559 double rate = GuideRateN[
RA_AXIS].value;
568 double ha = (alignment.
lst() -
Angle(currentRA, Angle::ANGLE_UNITS::HOURS)).Hours();
638 LOGF_DEBUG(
"Update location %8.3f, %8.3f, %4.0f", latitude, longitude, elevation);
647 bool ScopeSim::updateMountAndPierSide()
652 if (mountType < 0 || pierSide < 0)
656 if (mountType == m_MountType && pierSide == m_PierSide)
659 m_MountType = mountType;
660 m_PierSide = pierSide;
662 LOGF_INFO(
"update mount and pier side: Pier Side %s, mount type %d", pierSide == 0 ?
"Off" :
"On", mountType);
667 if ( mountType == Alignment::MOUNT_TYPE::ALTAZ)
669 LOG_INFO(
"AltAz mount type not implemented yet");
676 if (pierSide == 1 && mountType == 2)
void setCorrections(double ih, double id, double ch, double np, double ma, double me)
setCorrections set the values of the six corrections
void apparentRaDecToMount(Angle apparentRa, Angle apparentDec, Angle *primary, Angle *secondary)
void mountToApparentRaDec(Angle primary, Angle secondary, Angle *apparentRa, Angle *apparentDec)
mountToApparentRaDec: convert mount position to apparent Ra, Dec
void setFlipHourAngle(double deg)
The Angle class This class implements an angle type. This holds an angle that is always in the range ...
Angle TrackingRateDegSec
TrackingRateDegSec.
void setDegrees(double degrees)
void StartGuide(double rate, uint32_t durationMs)
StartGuide start guiding.
void Tracking(bool enabled)
void StartSlew(Angle angle)
void TrackRate(AXIS_TRACK_RATE rate)
TrackRate set the track rate to one of the standard rates.
const char * getDeviceName() const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
uint16_t getDriverInterface() const
void addDebugControl()
Add Debug control to the driver.
virtual void GuideComplete(INDI_EQ_AXIS axis)
Call GuideComplete once the guiding pulse is complete.
INumberVectorProperty GuideNSNP
void initGuiderProperties(const char *deviceName, const char *groupName)
Initilize guider properties. It is recommended to call this function within initProperties() of your ...
INumberVectorProperty GuideWENP
void processGuiderProperties(const char *name, double values[], char *names[], int n)
Call this function whenever client updates GuideNSNP or GuideWSP properties in the primary device....
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
double GetAxis1Park() const
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...
double GetAxis2Park() const
bool isParked()
isParked is mount currently parked?
virtual int AddTrackMode(const char *name, const char *label, bool isDefault=false)
AddTrackMode.
ISwitchVectorProperty SlewRateSP
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
INumberVectorProperty EqNP
@ TELESCOPE_HAS_TRACK_RATE
@ TELESCOPE_HAS_PIER_SIDE
@ TELESCOPE_HAS_TRACK_MODE
@ TELESCOPE_CAN_CONTROL_TRACK
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
INumber ScopeParametersN[4]
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
void setPierSide(TelescopePierSide side)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
void sendTimeFromSystem()
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
The ScopeSim class provides a simple mount simulator of an equatorial mount.
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 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 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 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 MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Implementations for common driver routines.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_EXTRA1(fmt,...)
#define DEBUGF(priority, msg,...)
std::unique_ptr< ScopeSim > telescope_sim(new ScopeSim())
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
int addDebugLevel(const char *debugLevelName, const char *LoggingLevelName)
Adds a new debugging level to the driver.