From 408c3fbde601005024d1b908b7d3a4ad23b0620f Mon Sep 17 00:00:00 2001 From: Aghilas Date: Sat, 20 Jan 2024 22:19:27 +0100 Subject: [PATCH 1/5] figured out conversion to alt az --- .../TelescopeControl/src/TelescopeClient.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index 4890ce25667d2..f5eb1c2741d10 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 @@ -269,14 +270,32 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject return; Vec3d position = j2000Pos; + Vec3d position_alt_az = j2000Pos; + const StelCore* core = StelApp::getInstance().getCore(); + position_alt_az = core->j2000ToAltAz(j2000Pos,StelCore::RefractionAuto); if (equinox == TelescopeControl::EquinoxJNow) { const StelCore* core = StelApp::getInstance().getCore(); position = core->j2000ToEquinoxEqu(j2000Pos, StelCore::RefractionOff); + } if (writeBufferEnd - writeBuffer + 20 < static_cast(sizeof(writeBuffer))) { + const double a = position_alt_az[0]; + const double b = position_alt_az[1]; + const double x = position_alt_az[2]; + //StelUtils::rectToSphe(&az, &alt, pos); + double az,alt; + const bool useSouthAzimuth = StelApp::getInstance().getFlagSouthAzimuthUsage(); + StelUtils::rectToSphe(&az,&alt,position_alt_az); + const double direction = useSouthAzimuth ? 2. : 3.; // N is zero, E is 90 degrees + az = direction*M_PI - az; + if (az > M_PI*2) + az -= M_PI*2; + az*=M_180_PI; + alt*=M_180_PI; + 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); @@ -322,6 +341,7 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject *writeBufferEnd++ = static_cast(dec_int & 0xFF); dec_int>>=8; *writeBufferEnd++ = static_cast(dec_int & 0xFF); + } else { From 1d4ec9be6b9390eb2d4474f4ab6c3cf0f46a4777 Mon Sep 17 00:00:00 2001 From: Aghilas Date: Sat, 3 Feb 2024 21:54:48 +0100 Subject: [PATCH 2/5] Added altitude and azimuth to TelescopeTCP. The interpretation of the stellarium packet for alt/az is the same as for dec/ra --- .../TelescopeControl/src/TelescopeClient.cpp | 80 ++++++++++++++----- .../TelescopeControl/src/TelescopeClient.hpp | 14 +++- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index f5eb1c2741d10..83b4ed92c15bd 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/TelescopeClient.cpp @@ -126,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; @@ -259,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 @@ -270,31 +296,16 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject return; Vec3d position = j2000Pos; - Vec3d position_alt_az = j2000Pos; - const StelCore* core = StelApp::getInstance().getCore(); - position_alt_az = core->j2000ToAltAz(j2000Pos,StelCore::RefractionAuto); + 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 a = position_alt_az[0]; - const double b = position_alt_az[1]; - const double x = position_alt_az[2]; - //StelUtils::rectToSphe(&az, &alt, pos); - double az,alt; - const bool useSouthAzimuth = StelApp::getInstance().getFlagSouthAzimuthUsage(); - StelUtils::rectToSphe(&az,&alt,position_alt_az); - const double direction = useSouthAzimuth ? 2. : 3.; // N is zero, E is 90 degrees - az = direction*M_PI - az; - if (az > M_PI*2) - az -= M_PI*2; - az*=M_180_PI; - alt*=M_180_PI; const double ra_signed = atan2(position[1], position[0]); //Workaround for the discrepancy in precision between Windows/Linux/PPC Macs and Intel Macs: @@ -302,8 +313,20 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject 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; + + 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; @@ -341,7 +364,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 { From 1bb858891ed043e53f3a50b291157b6db33e4695 Mon Sep 17 00:00:00 2001 From: Aghilas Date: Sat, 3 Feb 2024 22:46:17 +0100 Subject: [PATCH 3/5] Fixed clang warnings --- plugins/TelescopeControl/src/TelescopeClient.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index 83b4ed92c15bd..e8eb20da18bf9 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/TelescopeClient.cpp @@ -311,12 +311,12 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject //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))); + 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)) + double altitutde = 0.0; + if(!GetAltAzFromJ2000Position(j2000Pos,equinox,altitutde,azimuth)) { qDebug() << "TelescopeTCP(" << name << ")::telescopeGoto: "<< "" "unable to convert j2000 position to alt az."; From cd961d52429a001953391236637d7205524c1fa9 Mon Sep 17 00:00:00 2001 From: Aghilas Date: Sat, 3 Feb 2024 23:16:09 +0100 Subject: [PATCH 4/5] Typo fixed --- plugins/TelescopeControl/src/TelescopeClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index e8eb20da18bf9..6acc838ca48a3 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/TelescopeClient.cpp @@ -315,8 +315,8 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject int dec_int = static_cast(std::floor(0.5 + dec*((static_cast(0x80000000))/M_PI))); double azimuth = 0.0; - double altitutde = 0.0; - if(!GetAltAzFromJ2000Position(j2000Pos,equinox,altitutde,azimuth)) + double altitude = 0.0; + if(!GetAltAzFromJ2000Position(j2000Pos,equinox,altitude,azimuth)) { qDebug() << "TelescopeTCP(" << name << ")::telescopeGoto: "<< "" "unable to convert j2000 position to alt az."; From 3529f73e88a3edd32ef62109958826079526383e Mon Sep 17 00:00:00 2001 From: huntflex Date: Sun, 4 Feb 2024 13:39:24 +0100 Subject: [PATCH 5/5] Fixed codefactor comment Fixed codefactor comment "blank line at start of code block" --- plugins/TelescopeControl/src/TelescopeClient.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index 6acc838ca48a3..d50a1ab11e63d 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/TelescopeClient.cpp @@ -306,7 +306,6 @@ void TelescopeTCP::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject 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);