diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index 4890ce25667d2..d50a1ab11e63d 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/TelescopeClient.cpp @@ -31,6 +31,7 @@ #include "INDI/TelescopeClientINDI.hpp" #include "StelTranslator.hpp" #include "StelCore.hpp" +#include "StelUtils.hpp" #include @@ -125,6 +126,31 @@ TelescopeClient *TelescopeClient::create(const QString &url) TelescopeClient::TelescopeClient(const QString &name) : nameI18n(name), name(name) {} + +bool TelescopeClient::GetAltAzFromJ2000Position(const Vec3d &j2000Pos,TelescopeControl::Equinox equinox ,double& alt, double &az) const +{ + const StelCore* core = StelApp::getInstance().getCore(); + const bool res = core != nullptr; + if(res) + { + const bool equinoxJNow = equinox == TelescopeControl::EquinoxJNow; + const StelCore::RefractionMode mode = equinoxJNow ? StelCore::RefractionOff : StelCore::RefractionAuto; + const Vec3d positionJ2000 = equinoxJNow ? core->j2000ToEquinoxEqu(j2000Pos,mode) : j2000Pos; + + const Vec3d position_alt_az = core->j2000ToAltAz(positionJ2000,mode); + StelUtils::rectToSphe(&az,&alt,position_alt_az); + + const bool useSouthAzimuth = StelApp::getInstance().getFlagSouthAzimuthUsage(); + const double direction = useSouthAzimuth ? 2. : 3.; // N is zero, E is 90 degrees + az = direction*M_PI - az; + if (az > M_PI*2.0) + { + az -= M_PI*2.0; + } + } + return res; +} + QString TelescopeClient::getInfoString(const StelCore* core, const InfoStringGroup& flags) const { QString str; @@ -258,6 +284,7 @@ void TelescopeTCP::hangup(void) interpolatedPosition.reset(); } + //! queues a GOTO command with the specified position to the write buffer. //! For the data format of the command see the //! "Stellarium telescope control protocol" text file @@ -269,22 +296,36 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject return; Vec3d position = j2000Pos; + if (equinox == TelescopeControl::EquinoxJNow) { const StelCore* core = StelApp::getInstance().getCore(); position = core->j2000ToEquinoxEqu(j2000Pos, StelCore::RefractionOff); } - if (writeBufferEnd - writeBuffer + 20 < static_cast(sizeof(writeBuffer))) + + if (writeBufferEnd - writeBuffer + packetLength < static_cast(sizeof(writeBuffer))) { const double ra_signed = atan2(position[1], position[0]); //Workaround for the discrepancy in precision between Windows/Linux/PPC Macs and Intel Macs: const double ra = (ra_signed >= 0) ? ra_signed : (ra_signed + 2.0 * M_PI); const double dec = atan2(position[2], std::sqrt(position[0]*position[0]+position[1]*position[1])); - unsigned int ra_int = static_cast(std::floor(0.5 + ra*((static_cast(0x80000000))/M_PI))); - int dec_int = static_cast(std::floor(0.5 + dec*((static_cast(0x80000000))/M_PI))); - // length of packet: - *writeBufferEnd++ = 20; + unsigned int ra_int = static_cast(std::floor(0.5 + ra*((static_cast(0x80000000))/M_PI))); + int dec_int = static_cast(std::floor(0.5 + dec*((static_cast(0x80000000))/M_PI))); + + double azimuth = 0.0; + double altitude = 0.0; + if(!GetAltAzFromJ2000Position(j2000Pos,equinox,altitude,azimuth)) + { + qDebug() << "TelescopeTCP(" << name << ")::telescopeGoto: "<< "" + "unable to convert j2000 position to alt az."; + } + + unsigned int az_int = static_cast(std::floor(0.5 + azimuth*((static_cast(0x80000000)/M_PI)))); + int alt_int = static_cast(std::floor(0.5 + altitude*((static_cast(0x80000000)/M_PI)))); + + // length of packet: + *writeBufferEnd++ = packetLength; *writeBufferEnd++ = 0; // type of packet: *writeBufferEnd++ = 0; @@ -322,6 +363,22 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject *writeBufferEnd++ = static_cast(dec_int & 0xFF); dec_int>>=8; *writeBufferEnd++ = static_cast(dec_int & 0xFF); + //alt + *writeBufferEnd++ = static_cast(alt_int & 0xFF); + alt_int>>=8; + *writeBufferEnd++ = static_cast(alt_int & 0xFF); + alt_int>>=8; + *writeBufferEnd++ = static_cast(alt_int & 0xFF); + alt_int>>=8; + *writeBufferEnd++ = static_cast(alt_int & 0xFF); + //az + *writeBufferEnd++ = static_cast(az_int & 0xFF); + az_int>>=8; + *writeBufferEnd++ = static_cast(az_int & 0xFF); + az_int>>=8; + *writeBufferEnd++ = static_cast(az_int & 0xFF); + az_int>>=8; + *writeBufferEnd++ = static_cast(az_int & 0xFF); } else { diff --git a/plugins/TelescopeControl/src/TelescopeClient.hpp b/plugins/TelescopeControl/src/TelescopeClient.hpp index 76257c6fc643a..c57c96e6cb844 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.hpp +++ b/plugins/TelescopeControl/src/TelescopeClient.hpp @@ -110,7 +110,17 @@ class TelescopeClient : public QObject, public StelObject QString nameI18n; const QString name; - virtual QString getTelescopeInfoString(const StelCore* core, const InfoStringGroup& flags) const + /*! + * \brief Get the alt/az in rad from the j2000 position + * \param j2000Pos + * \param equinox + * \param alt [out] + * \param az [out] + * \return true/false if successful or not + */ + bool GetAltAzFromJ2000Position(const Vec3d &j2000Pos,TelescopeControl::Equinox equinox,double& alt, double &az) const; + + virtual QString getTelescopeInfoString(const StelCore* core, const InfoStringGroup& flags) const { Q_UNUSED(core) Q_UNUSED(flags) @@ -231,7 +241,7 @@ class TelescopeTCP : public TelescopeClient char writeBuffer[120]; char *writeBufferEnd; int time_delay; - + static constexpr int packetLength{28}; InterpolatedPosition interpolatedPosition; bool hasKnownPosition(void) const override {