Index: kstars/ekos/capture/capture.h =================================================================== --- kstars/ekos/capture/capture.h +++ kstars/ekos/capture/capture.h @@ -311,7 +311,9 @@ */ void setSettings(const QJsonObject &settings); - public slots: + SkyPoint getInitialMountCoords() const; + +public slots: /** \addtogroup CaptureDBusInterface * @{ @@ -792,5 +794,8 @@ // Captured Frames Map SchedulerJob::CapturedFramesMap capturedFramesMap; + + // Execute the meridian flip + bool executeMeridianFlip(); }; } Index: kstars/ekos/capture/capture.cpp =================================================================== --- kstars/ekos/capture/capture.cpp +++ kstars/ekos/capture/capture.cpp @@ -454,27 +454,6 @@ if (m_DeviationDetected == false && m_State != CAPTURE_SUSPENDED) { meridianFlipStage = MF_NONE; - // Record initial mount coordinates that we may use later to perform a meridian flip - if (currentTelescope) - { - double initialRA, initialDE; - currentTelescope->getEqCoords(&initialRA, &initialDE); - if (currentTelescope->isJ2000()) - { - initialMountCoords.setRA0(initialRA); - initialMountCoords.setDec0(initialDE); - initialMountCoords.apparentCoord(static_cast(J2000), KStars::Instance()->data()->ut().djd()); - } - else - { - initialMountCoords.setRA(initialRA); - initialMountCoords.setDec(initialDE); - } - - qCDebug(KSTARS_EKOS_CAPTURE) << "Initial mount coordinates RA:" << initialMountCoords.ra().toHMSString() - << "DE:" << initialMountCoords.dec().toDMSString(); - } - // start timer to measure time until next forced refocus startRefocusEveryNTimer(); } @@ -3013,6 +2992,26 @@ HFRPixels->setValue(median + (median * (Options::hFRThresholdPercentage() / 100.0))); } +SkyPoint Capture::getInitialMountCoords() const +{ + QVariant const result = mountInterface->property("currentTarget"); + SkyPoint point = result.value(); + return point; +} + +bool Capture::executeMeridianFlip() { + + QDBusReply const reply = mountInterface->call("executeMeridianFlip"); + + if (reply.error().type() == QDBusError::NoError) + return reply.value(); + + // error occured + qCCritical(KSTARS_EKOS_CAPTURE) << QString("Warning: execute meridian flip request received DBUS error: %1").arg(QDBusError::errorString(reply.error().type())); + + return false; +} + int Capture::getTotalFramesCount(QString signature) { int result = 0; @@ -4046,7 +4045,7 @@ { double ra, dec; currentTelescope->getEqCoords(&ra, &dec); - double diffRA = initialMountCoords.ra().Hours() - ra; + double diffRA = getInitialMountCoords().ra().Hours() - ra; // If the mount is actually flipping then we should see a difference in RA // which if it exceeded MF_RA_DIFF_LIMIT (4 hours) then we consider it to be // undertaking the flip. Otherwise, it's not flipping and let timeout takes care of @@ -4188,18 +4187,18 @@ if (isInSequenceFocus || (refocusEveryNCheck->isChecked() && getRefocusEveryNTimerElapsedSec() > 0)) emit resetFocus(); - // FIXME: handle result - slew(initialMountCoords); - - secondsLabel->setText(i18n("Meridian Flip...")); + if (executeMeridianFlip()) + { + secondsLabel->setText(i18n("Meridian Flip...")); - retries = 0; + retries = 0; - m_State = CAPTURE_MERIDIAN_FLIP; - emit newStatus(Ekos::CAPTURE_MERIDIAN_FLIP); + m_State = CAPTURE_MERIDIAN_FLIP; + emit newStatus(Ekos::CAPTURE_MERIDIAN_FLIP); - QTimer::singleShot(MF_TIMER_TIMEOUT, this, &Ekos::Capture::checkMeridianFlipTimeout); - return true; + QTimer::singleShot(MF_TIMER_TIMEOUT, this, &Ekos::Capture::checkMeridianFlipTimeout); + return true; + } } return false; @@ -4222,8 +4221,8 @@ } else { - slew(initialMountCoords); - appendLogText(i18n("Retrying meridian flip again...")); + if (executeMeridianFlip()) + appendLogText(i18n("Retrying meridian flip again...")); } } } @@ -4670,43 +4669,50 @@ IPState Capture::processPreCaptureCalibrationStage() { // Unpark dust cap if we have to take light images. - if (activeJob->getFrameType() == FRAME_LIGHT && dustCap) + if (activeJob->getFrameType() == FRAME_LIGHT) { - if (dustCap->isLightOn() == true) - { - dustCapLightEnabled = false; - dustCap->SetLightEnabled(false); - } - - // If cap is not unparked, unpark it - if (calibrationStage < CAL_DUSTCAP_UNPARKING && dustCap->isParked()) - { - if (dustCap->UnPark()) + // step 1: unpark dust cap + if (dustCap != nullptr) { + if (dustCap->isLightOn() == true) { - calibrationStage = CAL_DUSTCAP_UNPARKING; - appendLogText(i18n("Unparking dust cap...")); - return IPS_BUSY; + dustCapLightEnabled = false; + dustCap->SetLightEnabled(false); } - else + + // If cap is not unparked, unpark it + if (calibrationStage < CAL_DUSTCAP_UNPARKING && dustCap->isParked()) { - appendLogText(i18n("Unparking dust cap failed, aborting...")); - abort(); - return IPS_ALERT; + if (dustCap->UnPark()) + { + calibrationStage = CAL_DUSTCAP_UNPARKING; + appendLogText(i18n("Unparking dust cap...")); + return IPS_BUSY; + } + else + { + appendLogText(i18n("Unparking dust cap failed, aborting...")); + abort(); + return IPS_ALERT; + } } - } - // Wait until cap is unparked - if (calibrationStage == CAL_DUSTCAP_UNPARKING) - { - if (dustCap->isUnParked() == false) - return IPS_BUSY; - else + // Wait until cap is unparked + if (calibrationStage == CAL_DUSTCAP_UNPARKING) { - calibrationStage = CAL_DUSTCAP_UNPARKED; - appendLogText(i18n("Dust cap unparked.")); + if (dustCap->isUnParked() == false) + return IPS_BUSY; + else + { + calibrationStage = CAL_DUSTCAP_UNPARKED; + appendLogText(i18n("Dust cap unparked.")); + } } } + // step 2: check if meridian flip is required + if (meridianFlipStage != MF_NONE || checkMeridianFlip()) + return IPS_BUSY; + calibrationStage = CAL_PRECAPTURE_COMPLETE; if (guideState == GUIDE_SUSPENDED) Index: kstars/ekos/mount/mount.h =================================================================== --- kstars/ekos/mount/mount.h +++ kstars/ekos/mount/mount.h @@ -29,6 +29,7 @@ *@author Jasem Mutlaq *@version 1.3 */ + class Mount : public QWidget, public Ui::Mount { Q_OBJECT @@ -41,6 +42,7 @@ Q_PROPERTY(QList equatorialCoords READ equatorialCoords) Q_PROPERTY(QList horizontalCoords READ horizontalCoords) Q_PROPERTY(QList telescopeInfo READ telescopeInfo WRITE setTelescopeInfo) + Q_PROPERTY(SkyPoint currentTarget READ getCurrentTarget) Q_PROPERTY(double hourAngle READ hourAngle) Q_PROPERTY(double initialHA READ getInitialHA) Q_PROPERTY(int slewRate READ slewRate WRITE setSlewRate) @@ -151,17 +153,22 @@ Q_SCRIPTABLE QList horizontalCoords(); /** DBUS interface function. + * Get Horizontal coords. + */ + Q_SCRIPTABLE SkyPoint getCurrentTarget(); + + /** DBUS interface function. * Get mount hour angle in hours (-12 to +12). */ Q_SCRIPTABLE double hourAngle(); double initialHA; /** DBUS interface function. * Get the hour angle of that time the mount has slewed to the current position. */ - Q_SCRIPTABLE double getInitialHA() {return initialHA; } ; + Q_SCRIPTABLE double getInitialHA() {return initialHA; } - Q_SCRIPTABLE void setInitialHA(double ha) { initialHA = ha; } ; + Q_SCRIPTABLE void setInitialHA(double ha) { initialHA = ha; } /** DBUS interface function. * Aborts the mount motion @@ -238,6 +245,12 @@ // Get list of scopes QJsonArray getScopes() const; + /* + * @brief Execute a meridian flip if necessary. + * @return true if a meridian flip was necessary + */ + Q_INVOKABLE bool executeMeridianFlip(); + public slots: /** @@ -343,6 +356,7 @@ ISD::Telescope *currentTelescope = nullptr; ISD::GDInterface *currentGPS = nullptr; QStringList m_LogText; + SkyPoint currentTargetPosition; SkyPoint telescopeCoord; QString lastNotificationMessage; QTimer updateTimer; @@ -366,4 +380,5 @@ }; } + #endif // Mount Index: kstars/ekos/mount/mount.cpp =================================================================== --- kstars/ekos/mount/mount.cpp +++ kstars/ekos/mount/mount.cpp @@ -46,6 +46,7 @@ namespace Ekos { + Mount::Mount() { setupUi(this); @@ -55,6 +56,7 @@ // Set up DBus interfaces QPointer ekosInterface = new QDBusInterface("org.kde.kstars", "/KStars/Ekos", "org.kde.kstars.Ekos", QDBusConnection::sessionBus(), this); + qDBusRegisterMetaType(); // Connecting DBus signals connect(ekosInterface, SIGNAL(newModule(QString)), this, SLOT(registerNewModule(QString))); @@ -817,9 +819,36 @@ setInitialHA(HA); + currentTargetPosition.setRA(RA); + currentTargetPosition.setDec(DEC); + return currentTelescope->Slew(RA, DEC); } +bool Mount::executeMeridianFlip() { + if (getInitialHA() > 0) + // no meridian flip necessary + return false; + + dms lst = KStarsData::Instance()->geo()->GSTtoLST(KStarsData::Instance()->clock()->utc().gst()); + double HA = lst.Hours() - currentTargetPosition.ra().Hours(); + if (HA > 12.0) + // no meridian flip necessary + return false; + + // execute meridian flip + slew(currentTargetPosition.ra().Hours(), currentTargetPosition.dec().Degrees()); + return true; + +} + +SkyPoint Mount::getCurrentTarget() +{ + return currentTargetPosition; +} + + + bool Mount::sync(const QString &RA, const QString &DEC) { dms ra, de; Index: kstars/org.kde.kstars.Ekos.Mount.xml =================================================================== --- kstars/org.kde.kstars.Ekos.Mount.xml +++ kstars/org.kde.kstars.Ekos.Mount.xml @@ -7,6 +7,9 @@ + + + @@ -51,6 +54,9 @@ + + + Index: kstars/skyobjects/skypoint.h =================================================================== --- kstars/skyobjects/skypoint.h +++ kstars/skyobjects/skypoint.h @@ -23,6 +23,7 @@ #include "kstarsdatetime.h" #include +#include //#define PROFILE_COORDINATE_CONVERSION @@ -648,3 +649,7 @@ protected: double lastPrecessJD { 0 }; // JD at which the last coordinate (see updateCoords) for this SkyPoint was done }; + +Q_DECLARE_METATYPE(SkyPoint) +QDBusArgument &operator<<(QDBusArgument &argument, const SkyPoint &source); +const QDBusArgument &operator>>(const QDBusArgument &argument, SkyPoint &dest); Index: kstars/skyobjects/skypoint.cpp =================================================================== --- kstars/skyobjects/skypoint.cpp +++ kstars/skyobjects/skypoint.cpp @@ -936,3 +936,22 @@ retval = 180. + retval; return retval; } + +QDBusArgument &operator<<(QDBusArgument &argument, const SkyPoint &source) +{ + argument.beginStructure(); + argument << source.ra().Hours() << source.dec().Degrees(); + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, SkyPoint &dest) +{ + double ra, dec; + argument.beginStructure(); + argument >> ra >> dec; + argument.endStructure(); + dest = SkyPoint(ra, dec); + return argument; +} +