From bc12777f1854a751985d6daf4b40cf04378035ad Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Thu, 18 Dec 2025 18:21:17 +0300 Subject: [PATCH] ... --- mcc/mcc_ccte_erfa.h | 11 +++ mcc/mcc_defaults.h | 201 +++++++++++++++++++++++--------------------- mcc/mcc_generics.h | 56 +++--------- mcc/mcc_telemetry.h | 57 ++++++++++--- 4 files changed, 175 insertions(+), 150 deletions(-) diff --git a/mcc/mcc_ccte_erfa.h b/mcc/mcc_ccte_erfa.h index 3ef1ad0..a7b99e7 100644 --- a/mcc/mcc_ccte_erfa.h +++ b/mcc/mcc_ccte_erfa.h @@ -590,7 +590,18 @@ public: // the main scenario: from ICRS to apparent if (from_pt.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { + to_pt->RA_ICRS = from_pt.X; + to_pt->DEC_ICRS = from_pt.Y; + return icrs2obs(from_pt, to_pt); + } else { // from apparent (2025-12-18: according to addition of RA/DEC_OCRS to mcc_eqt_hrz_coord_c) + cpt.pair_kind = MccCoordPairKind::COORDS_KIND_RADEC_ICRS; + ret = transformCoordinates(from_pt, &cpt); // to ICRS + if (!ret) { + ret = transformCoordinates(cpt, to_pt); + } + + return ret; } // from apparent: copy corresponded coordinates and compute other ones (ignore to_pt->pair_kind) diff --git a/mcc/mcc_defaults.h b/mcc/mcc_defaults.h index cd8f757..a5074e8 100644 --- a/mcc/mcc_defaults.h +++ b/mcc/mcc_defaults.h @@ -441,23 +441,12 @@ struct MccGenericEqtHrzCoords : MccGenericCelestialPoint { using MccGenericCelestialPoint::time_point; - coord_t RA_APP{}, DEC_APP{}, HA{}, AZ{}, ZD{}, ALT{}; + coord_t RA_ICRS{}, DEC_ICRS{}, RA_APP{}, DEC_APP{}, HA{}, AZ{}, ZD{}, ALT{}; }; typedef MccGenericEqtHrzCoords MccEqtHrzCoords; -template -struct MccGenericPointingTarget : MccGenericEqtHrzCoords { - using typename MccGenericEqtHrzCoords::coord_t; - - coord_t RA_ICRS{}, DEC_ICRS{}; -}; - - -typedef MccGenericPointingTarget MccPointingTarget; - - template struct MccGenericPCMResult { @@ -479,7 +468,7 @@ struct MccGenericTelemetryData : MccGenericEqtHrzCoords { MccGenericCelestialPoint entered_target{}; - MccGenericPointingTarget target{}; + MccGenericEqtHrzCoords target{}; coord_t speedX, speedY; @@ -505,7 +494,6 @@ struct MccPositionControls : CCTE_T, HARDWARE_T, PCM_T { static_assert(mcc_julday_c, ""); static_assert(mcc_celestial_point_c, ""); -static_assert(mcc_pointing_target_coord_c>, ""); static_assert(mcc_telemetry_data_c, ""); @@ -918,13 +906,20 @@ public: template void operator()(const T& value, OR& bytes) { - // output format: RA, DEC, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point + // output format: RA_ICRS, DEC_ICRS, RA, DEC, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point // in the case of sexagesimal output X,Y coordinates will be interpretated // according to value.pair_kind field if (_currentFormat == SerializedCoordFormat::CFMT_DEGREES) { - toDegrees(bytes, value.RA_APP, value.DEC_APP, value.HA, value.AZ, value.ZD, value.ALT, value.X, value.Y); + toDegrees(bytes, value.RA_ICRS, value.DEC_ICRS, value.RA_APP, value.DEC_APP, value.HA, value.AZ, value.ZD, + value.ALT, value.X, value.Y); } else if (_currentFormat == SerializedCoordFormat::CFMT_SGM) { + toSexagesimalHour(bytes, value.RA_ICRS); + std::format_to(std::back_inserter(bytes), "{}", _delimiter); + + toSexagesimalDeg(bytes, value.DEC_ICRS); + std::format_to(std::back_inserter(bytes), "{}", _delimiter); + toSexagesimalHour(bytes, value.RA_APP); std::format_to(std::back_inserter(bytes), "{}", _delimiter); @@ -967,54 +962,65 @@ public: template std::error_code operator()(IR&& bytes, T& value) { - // valid format: RA, DEC, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point + // valid format: RA_ICRS, DEC_ICRS, RA, DEC, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point // in the case of sexagesimal input the X,Y coordinates will be interpretated // according to value.pair_kind field auto els = splitToElements(std::forward(bytes)); - if (els.size() < 10) { + if (els.size() < 12) { // return std::make_error_code(std::errc::invalid_argument); return MccCoordinateConvErrorCode::ERROR_ARG_LEN; } MccEqtHrzCoords pt; - pt.pair_kind = MccCoordStrToPairKind(els[8]); + pt.pair_kind = MccCoordStrToPairKind(els[10]); if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_UNKNOWN) { // return std::make_error_code(std::errc::invalid_argument); return MccCoordinateConvErrorCode::ERROR_INVALID_CPAIR; } - auto err = parseTimePoint(els[9], pt); + auto err = parseTimePoint(els[11], pt); if (err) { return err; } - err = parseHourRepr(els[0], pt.RA_APP); + size_t idx = 0; + err = parseHourRepr(els[idx++], pt.RA_ICRS); if (err) { return err; } - err = parseDegreeRepr(els[1], pt.DEC_APP); + err = parseDegreeRepr(els[idx++], pt.DEC_ICRS); if (err) { return err; } - err = parseHourRepr(els[2], pt.HA); + err = parseHourRepr(els[idx++], pt.RA_APP); if (err) { return err; } - err = parseDegreeRepr(els[4], pt.AZ); + err = parseDegreeRepr(els[idx++], pt.DEC_APP); if (err) { return err; } - err = parseDegreeRepr(els[5], pt.ZD); + err = parseHourRepr(els[idx++], pt.HA); if (err) { return err; } - err = parseDegreeRepr(els[6], pt.ALT); + err = parseDegreeRepr(els[idx++], pt.AZ); + if (err) { + return err; + } + + err = parseDegreeRepr(els[idx++], pt.ZD); + if (err) { + return err; + } + + err = parseDegreeRepr(els[idx++], pt.ALT); if (err) { return err; } @@ -1023,16 +1029,16 @@ public: case MccCoordPairKind::COORDS_KIND_RADEC_ICRS: case MccCoordPairKind::COORDS_KIND_RADEC_APP: case MccCoordPairKind::COORDS_KIND_HADEC_APP: - err = parseHourRepr(els[7], pt.X); + err = parseHourRepr(els[idx++], pt.X); break; default: - err = parseDegreeRepr(els[7], pt.X); + err = parseDegreeRepr(els[idx++], pt.X); } if (err) { return err; } - err = parseDegreeRepr(els[8], pt.Y); + err = parseDegreeRepr(els[idx++], pt.Y); if (err) { return err; } @@ -1045,74 +1051,74 @@ public: -class MccPointingTargetSerializer : public MccCoordinateSerializer -{ -public: - template - void operator()(const T& value, OR& bytes) - { - static MccEqtHrzCoordsSerializer eqhrz_ser; +// class MccPointingTargetSerializer : public MccCoordinateSerializer +// { +// public: +// template +// void operator()(const T& value, OR& bytes) +// { +// static MccEqtHrzCoordsSerializer eqhrz_ser; - // output format: RA_ICRS, DEC_ICRS, RA_APP, DEC_APP, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point - // in the case of sexagesimal output X,Y coordinates will be interpretated - // according to value.pair_kind field +// // output format: RA_ICRS, DEC_ICRS, RA_APP, DEC_APP, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point +// // in the case of sexagesimal output X,Y coordinates will be interpretated +// // according to value.pair_kind field - if (_currentFormat == SerializedCoordFormat::CFMT_DEGREES) { - toDegrees(bytes, value.RA_ICRS, value.DEC_ICRS); - } else if (_currentFormat == SerializedCoordFormat::CFMT_SGM) { - toSexagesimalHour(bytes, value.RA_ICRS); - std::format_to(std::back_inserter(bytes), "{}", _delimiter); +// if (_currentFormat == SerializedCoordFormat::CFMT_DEGREES) { +// toDegrees(bytes, value.RA_ICRS, value.DEC_ICRS); +// } else if (_currentFormat == SerializedCoordFormat::CFMT_SGM) { +// toSexagesimalHour(bytes, value.RA_ICRS); +// std::format_to(std::back_inserter(bytes), "{}", _delimiter); - toSexagesimalDeg(bytes, value.DEC_ICRS); - } +// toSexagesimalDeg(bytes, value.DEC_ICRS); +// } - std::format_to(std::back_inserter(bytes), "{}", _delimiter); +// std::format_to(std::back_inserter(bytes), "{}", _delimiter); - eqhrz_ser.setFormat(_currentFormat); - eqhrz_ser.setPrecision(_currentPrec); - eqhrz_ser(value, bytes); +// eqhrz_ser.setFormat(_currentFormat); +// eqhrz_ser.setPrecision(_currentPrec); +// eqhrz_ser(value, bytes); - // MccEqtHrzCoordsSerializer{}(value, bytes); - } -}; +// // MccEqtHrzCoordsSerializer{}(value, bytes); +// } +// }; -class MccPointingTargetDeserializer : public MccCoordinateDeserializer -{ -public: - template - std::error_code operator()(IR&& bytes, T& value) - { - // valid format: RA_ICRS, DEC_ICRS, RA_APP, DEC_APP, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point - // in the case of sexagesimal input the X,Y coordinates will be interpretated - // according to value.pair_kind field +// class MccPointingTargetDeserializer : public MccCoordinateDeserializer +// { +// public: +// template +// std::error_code operator()(IR&& bytes, T& value) +// { +// // valid format: RA_ICRS, DEC_ICRS, RA_APP, DEC_APP, HA, AZ, ZD, ALT, X, Y, pair-kind, time-point +// // in the case of sexagesimal input the X,Y coordinates will be interpretated +// // according to value.pair_kind field - auto els = splitToElements(std::forward(bytes)); - if (els.size() < 12) { - // return std::make_error_code(std::errc::invalid_argument); - return MccCoordinateConvErrorCode::ERROR_ARG_LEN; - } +// auto els = splitToElements(std::forward(bytes)); +// if (els.size() < 12) { +// // return std::make_error_code(std::errc::invalid_argument); +// return MccCoordinateConvErrorCode::ERROR_ARG_LEN; +// } - MccPointingTarget pt; - auto err = parseHourRepr(els[0], pt.RA_ICRS); - if (err) { - return err; - } +// MccPointingTarget pt; +// auto err = parseHourRepr(els[0], pt.RA_ICRS); +// if (err) { +// return err; +// } - err = parseDegreeRepr(els[1], pt.DEC_ICRS); - if (err) { - return err; - } +// err = parseDegreeRepr(els[1], pt.DEC_ICRS); +// if (err) { +// return err; +// } - err = MccEqtHrzCoordsDeserializer{}(std::string_view{els[2].begin(), els[11].end()}, pt); - if (err) { - return err; - } +// err = MccEqtHrzCoordsDeserializer{}(std::string_view{els[2].begin(), els[11].end()}, pt); +// if (err) { +// return err; +// } - mcc_copy_pointing_target_coord(pt, &value); +// mcc_copy_pointing_target_coord(pt, &value); - return {}; - } -}; +// return {}; +// } +// }; class MccTelemetryDataSerializer : public MccCoordinateSerializer @@ -1122,13 +1128,13 @@ public: void operator()(const T& value, OR& bytes) { static MccEqtHrzCoordsSerializer eqhrz_ser; - static MccPointingTargetSerializer pt_ser; + // static MccPointingTargetSerializer pt_ser; // output format: , speedX, speedY, pcmX, pcmY, refCorr (in arcsecs), - // RA-APP_mnt, DEC-APP_mnt, HA_mnt, AZ_mnt, ZD_mnt, ALT_mnt, X_mnt, Y_mnt, COO-PAIR_mnt, TIME-POINT_mnt, - // LST, EO, SPEED_X_mnt, SPEED_Y_mnt, PCM_X, PCM_Y, REFCORR, - // RA-ICRS_tag, DEC-ICRS_tag, RA-APP_tag, DEC-APP_tag, HA_tag, AZ_tag, ZD_tag, ALT_tag, X_tag, Y_tag, - // COO-PAIR_tag, TIME-POINT_tag + // RA-ICRS_mnt, DEC-ICRS_mnt, RA-APP_mnt, DEC-APP_mnt, HA_mnt, AZ_mnt, ZD_mnt, ALT_mnt, X_mnt, Y_mnt, + // COO-PAIR_mnt, TIME-POINT_mnt, LST, EO, SPEED_X_mnt, SPEED_Y_mnt, PCM_X, PCM_Y, REFCORR, RA-ICRS_tag, + // DEC-ICRS_tag, RA-APP_tag, DEC-APP_tag, HA_tag, AZ_tag, ZD_tag, ALT_tag, X_tag, Y_tag, COO-PAIR_tag, + // TIME-POINT_tag eqhrz_ser.setFormat(_currentFormat); eqhrz_ser.setPrecision(_currentPrec); @@ -1147,9 +1153,11 @@ public: toSexagesimalDeg(bytes, value.speedX, value.speedY, value.pcmX, value.pcmY, value.refCorr); std::format_to(std::back_inserter(bytes), "{}", _delimiter); - pt_ser.setFormat(_currentFormat); - pt_ser.setPrecision(_currentPrec); - pt_ser(value.target, bytes); + // pt_ser.setFormat(_currentFormat); + // pt_ser.setPrecision(_currentPrec); + // pt_ser(value.target, bytes); + + eqhrz_ser(value.target, bytes); } }; @@ -1165,18 +1173,18 @@ public: // valid format: , speedX, speedY, pcmX, pcmY, refCorr, auto els = splitToElements(std::forward(bytes)); - if (els.size() < 29) { + if (els.size() < 31) { // return std::make_error_code(std::errc::invalid_argument); return MccCoordinateConvErrorCode::ERROR_ARG_LEN; } MccTelemetryData tdata; - auto err = MccEqtHrzCoordsDeserializer{}(std::string_view{els[0].begin(), els[9].end()}, tdata); + auto err = MccEqtHrzCoordsDeserializer{}(std::string_view{els[0].begin(), els[11].end()}, tdata); if (err) { return err; } - size_t idx = 10; + size_t idx = 12; err = parseHourRepr(els[idx++], tdata.LST); if (err) { @@ -1213,7 +1221,8 @@ public: return err; } - err = MccPointingTargetDeserializer{}(std::string_view{els[idx].begin(), els.back().end()}, tdata.target); + // err = MccPointingTargetDeserializer{}(std::string_view{els[idx].begin(), els.back().end()}, tdata.target); + err = MccEqtHrzCoordsDeserializer{}(std::string_view{els[idx].begin(), els.back().end()}, tdata.target); if (err) { return err; } diff --git a/mcc/mcc_generics.h b/mcc/mcc_generics.h index fb8e06c..1b0528c 100644 --- a/mcc/mcc_generics.h +++ b/mcc/mcc_generics.h @@ -281,6 +281,9 @@ static constexpr void mcc_copy_celestial_point(mcc_celestial_point_c auto const& template concept mcc_eqt_hrz_coord_c = mcc_celestial_point_c && requires(T t) { + requires mcc_angle_c; // ICRS right ascention + requires mcc_angle_c; // ICRS declination + requires mcc_angle_c; // right ascension requires mcc_angle_c; // declination requires mcc_angle_c; // hour angle @@ -311,6 +314,9 @@ static constexpr void mcc_copy_eqt_hrz_coord(mcc_eqt_hrz_coord_c auto const& fro to_pt->X = (double)from_pt.X; to_pt->Y = (double)from_pt.Y; + to_pt->RA_ICRS = (double)from_pt.RA_ICRS; + to_pt->DEC_ICRS = (double)from_pt.DEC_ICRS; + to_pt->RA_APP = (double)from_pt.RA_APP; to_pt->DEC_APP = (double)from_pt.DEC_APP; @@ -582,47 +588,6 @@ concept mcc_hardware_c = requires(T t, const T t_const) { /* MOUNT TELEMETRY DATA CLASS CONCEPT */ -template -concept mcc_pointing_target_coord_c = mcc_eqt_hrz_coord_c && requires(T t) { - requires mcc_angle_c; // ICRS right ascention - requires mcc_angle_c; // ICRS declination -}; - - -static constexpr void mcc_copy_pointing_target_coord(mcc_pointing_target_coord_c auto const& from_pt, - mcc_pointing_target_coord_c auto* to_pt) -{ - if (to_pt == nullptr) { - return; - } - - using from_pt_t = std::remove_cvref_t; - using to_pt_t = std::remove_cvref_t; - - if constexpr (std::derived_from && std::copyable) { - *to_pt = from_pt; - return; - } - - to_pt->pair_kind = from_pt.pair_kind; - to_pt->time_point = - std::chrono::time_point_casttime_point)::duration>(from_pt.time_point); - to_pt->X = (double)from_pt.X; - to_pt->Y = (double)from_pt.Y; - - to_pt->RA_ICRS = (double)from_pt.RA_ICRS; - to_pt->DEC_ICRS = (double)from_pt.DEC_ICRS; - - to_pt->RA_APP = (double)from_pt.RA_APP; - to_pt->DEC_APP = (double)from_pt.DEC_APP; - - to_pt->HA = (double)from_pt.HA; - to_pt->AZ = (double)from_pt.AZ; - to_pt->ZD = (double)from_pt.ZD; - to_pt->ALT = (double)from_pt.ALT; -} - - template concept mcc_telemetry_data_c = mcc_eqt_hrz_coord_c && std::default_initializable && requires(T t) { @@ -630,7 +595,7 @@ concept mcc_telemetry_data_c = mcc_eqt_hrz_coord_c && std::default_initializa requires mcc_celestial_point_c; // target target coordinates - requires mcc_pointing_target_coord_c; + requires mcc_eqt_hrz_coord_c; // t.X and t.Y (from mcc_celestial_point_c) are encoder coordinates // t.* from mcc_eqt_hrz_coord_c are apparent mount pointing coordinates @@ -673,6 +638,9 @@ static constexpr void mcc_copy_telemetry_data(mcc_telemetry_data_c auto const& f to_pt->speedX = (double)from_pt.speedX; to_pt->speedY = (double)from_pt.speedY; + to_pt->RA_ICRS = (double)from_pt.RA_ICRS; + to_pt->DEC_ICRS = (double)from_pt.DEC_ICRS; + to_pt->RA_APP = (double)from_pt.RA_APP; to_pt->DEC_APP = (double)from_pt.DEC_APP; @@ -686,7 +654,9 @@ static constexpr void mcc_copy_telemetry_data(mcc_telemetry_data_c auto const& f to_pt->refCorr = (double)from_pt.refCorr; - mcc_copy_pointing_target_coord(from_pt.target, &to_pt->target); + mcc_copy_eqt_hrz_coord(from_pt.target, &to_pt->target); + + mcc_copy_celestial_point(from_pt.entered_target, &to_pt->entered_target); } diff --git a/mcc/mcc_telemetry.h b/mcc/mcc_telemetry.h index 49434b2..b06710b 100644 --- a/mcc/mcc_telemetry.h +++ b/mcc/mcc_telemetry.h @@ -10,7 +10,6 @@ #include #include #include -#include #include "mcc_defaults.h" @@ -181,12 +180,14 @@ public: return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM); } - if (_data.entered_target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { - _data.target.RA_ICRS = _data.entered_target.X; - _data.target.DEC_ICRS = _data.entered_target.Y; - } + // if (_data.entered_target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { + // _data.target.RA_ICRS = _data.entered_target.X; + // _data.target.DEC_ICRS = _data.entered_target.Y; + // } } + return MccTelemetryErrorCode::ERROR_OK; + if (stop_token.stop_requested()) { return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED; } @@ -232,8 +233,7 @@ public: double eo; - _data.time_point = - std::chrono::time_point_cast(hw_pos.time_point); + mcc_tp2tp(hw_pos.time_point, hw_pos.time_point); auto ccte_err = controls->timepointToJulday(_data.time_point, &_data.JD); if (!ccte_err) { @@ -261,6 +261,40 @@ public: _data.speedX = (double)hw_pos.speedX; _data.speedY = (double)hw_pos.speedY; + // 2025.12.18: according to addition RA/DEC_ICRS to mcc_eqt_hrz_coord_c ... + + MccCelestialPoint pt; + mcc_tp2tp(_data.time_point, pt.time_point); + + auto pcm_err = controls->computePCM(_data, &_data, &pt); + if (pcm_err) { + return mcc_deduce_error_code(pcm_err, MccTelemetryErrorCode::ERROR_PCM_COMP); + } + + if constexpr (mccIsEquatorialMount(pcm_t::mountType)) { + pt.pair_kind = MccCoordPairKind::COORDS_KIND_HADEC_APP; + _data.pair_kind = MccCoordPairKind::COORDS_KIND_HADEC_APP; + } else if constexpr (mccIsAltAzMount(pcm_t::mountType)) { + pt.pair_kind = MccCoordPairKind::COORDS_KIND_AZALT; + _data.pair_kind = MccCoordPairKind::COORDS_KIND_AZALT; + } else { + static_assert(false, "UNKNOWN MOUNT TYPE!"); + } + + ccte_err = controls->transformCoordinates(pt, &_data); + if (!ccte_err) { + ccte_err = controls->refractionCorrection(_data, &_data.refCorr); + if (!ccte_err) { + return _updateTargetFunc(stop_token); + } else { + return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM); + } + } else { + return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM); + } + + + /* // fill _data.pcmX, _data.pcmY and corresponded apparent coordinates auto pcm_err = controls->computePCM(_data, &_data, &_data); if (pcm_err) { @@ -276,8 +310,7 @@ public: if constexpr (mccIsEquatorialMount(pcm_t::mountType)) { // NOTE: now it are OBSERVED (NOT APPARENT) RA, HA, DEC!!! _data.RA_APP = - MccAngle((double)_data.LST - (double)_data.HA - eo).normalize(); - // MccAngle((double)_data.LST - (double)_data.HA + eo).normalize(); + MccAngle((double)_data.LST - (double)_data.HA + eo).normalize(); _data.X = _data.HA; _data.Y = _data.DEC_APP; @@ -304,8 +337,7 @@ public: _data.HA = pt.X; _data.DEC_APP = pt.Y; _data.RA_APP = - MccAngle((double)_data.LST - (double)_data.HA - eo).normalize(); - // MccAngle((double)_data.LST - (double)_data.HA + eo).normalize(); + MccAngle((double)_data.LST - (double)_data.HA + eo).normalize(); } } else { @@ -367,6 +399,8 @@ public: return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM); } + */ + return MccTelemetryErrorCode::ERROR_OK; }; @@ -741,4 +775,5 @@ protected: static_assert(mcc_telemetry_c, ""); + } // namespace mcc