This commit is contained in:
Timur A. Fatkhullin 2025-10-20 00:36:00 +03:00
parent cbe106fe95
commit fc64642bd6

View File

@ -49,10 +49,7 @@ namespace mcc
struct MccTelemetryCategory : public std::error_category { struct MccTelemetryCategory : public std::error_category {
MccTelemetryCategory() : std::error_category() {} MccTelemetryCategory() : std::error_category() {}
const char* name() const noexcept const char* name() const noexcept { return "ALTITUDE-LIMIT-PZ"; }
{
return "ALTITUDE-LIMIT-PZ";
}
std::string message(int ec) const std::string message(int ec) const
{ {
@ -126,6 +123,109 @@ public:
using pcm_t = std::remove_cvref_t<decltype(*controls)>; using pcm_t = std::remove_cvref_t<decltype(*controls)>;
using hardware_t = std::remove_cvref_t<decltype(*controls)>; using hardware_t = std::remove_cvref_t<decltype(*controls)>;
_updateTargetFunc = [controls, this](std::stop_token stop_token) -> error_t {
MccPCMResult pcm_res;
mcc_tp2tp(_data.time_point, _data.target.time_point);
bool hw_coords = _data.target.pair_kind == MccCoordPairKind::COORDS_KIND_XY;
MccCelestialPoint hw_cp{.pair_kind = MccCoordPairKind::COORDS_KIND_XY};
mcc_tp2tp(_data.time_point, hw_cp.time_point);
if (hw_coords) { // compute corresponded apparent coordinates
hw_cp.X = _data.target.X;
hw_cp.Y = _data.target.Y;
auto pcm_err = controls->computePCM(_data.target, &pcm_res, &_data.target);
if (pcm_err) {
return mcc_deduce_error_code(pcm_err, MccTelemetryErrorCode::ERROR_PCM_COMP);
}
if (stop_token.stop_requested()) {
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
}
if constexpr (mccIsEquatorialMount(pcm_t::mountType)) {
_data.target.pair_kind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
} else if constexpr (mccIsAltAzMount(pcm_t::mountType)) {
_data.target.pair_kind = MccCoordPairKind::COORDS_KIND_AZZD;
} else {
static_assert(false, "UNKNOWN MOUNT TYPE!!!");
}
}
if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
_data.target.X = _data.target.RA_ICRS;
_data.target.Y = _data.target.DEC_ICRS;
}
auto ccte_err = controls->transformCoordinates(_data.target, &_data.target);
if (ccte_err) {
if (hw_coords) { // restore coordinates pair kind
_data.target.pair_kind = MccCoordPairKind::COORDS_KIND_XY;
}
return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM);
}
if (stop_token.stop_requested()) {
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
}
if (_data.target.pair_kind != MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
// fixed apparent coordinates (AZZD or HADEC)
// needs to compute ICRS
if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZZD) {
_data.target.X = _data.target.AZ;
_data.target.Y = _data.target.ZD;
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZALT) {
_data.target.X = _data.target.AZ;
_data.target.Y = _data.target.ALT;
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_HADEC_APP) {
_data.target.X = _data.target.HA;
_data.target.Y = _data.target.DEC_APP;
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_APP) {
_data.target.X = _data.target.RA_APP;
_data.target.Y = _data.target.DEC_APP;
} else {
return MccTelemetryErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
}
MccCelestialPoint pt{.pair_kind = MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
ccte_err = controls->transformCoordinates(_data.target, &pt);
if (ccte_err) {
if (hw_coords) { // restore coordinates pair kind
_data.target.pair_kind = MccCoordPairKind::COORDS_KIND_XY;
_data.target.X = hw_cp.X;
_data.target.Y = hw_cp.Y;
}
return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM);
}
_data.target.RA_ICRS = pt.X;
_data.target.DEC_ICRS = pt.Y;
} // from ICRS to apparent calculation is already performed above
if (stop_token.stop_requested()) {
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
}
// hardware coordinates
if (!hw_coords) {
auto pcm_err = controls->computeInversePCM(_data.target, &pcm_res, &_data.target);
if (pcm_err) {
return mcc_deduce_error_code(pcm_err, MccTelemetryErrorCode::ERROR_PCM_COMP);
}
} else { // restore coordinates pair kind
_data.target.pair_kind = MccCoordPairKind::COORDS_KIND_XY;
_data.target.X = hw_cp.X;
_data.target.Y = hw_cp.Y;
}
return MccTelemetryErrorCode::ERROR_OK;
};
/*
_updateTargetFunc = [controls, this](bool only_hw, std::stop_token stop_token) -> error_t { _updateTargetFunc = [controls, this](bool only_hw, std::stop_token stop_token) -> error_t {
if (!only_hw) { if (!only_hw) {
// //
@ -193,6 +293,7 @@ public:
return MccTelemetryErrorCode::ERROR_OK; return MccTelemetryErrorCode::ERROR_OK;
}; };
*/
_updateFunc = [controls, this](std::stop_token stop_token) { _updateFunc = [controls, this](std::stop_token stop_token) {
// first, update mount quantities // first, update mount quantities
@ -303,7 +404,9 @@ public:
// update target (assuming target ICRS coordinates are already set) // update target (assuming target ICRS coordinates are already set)
auto ret = _updateTargetFunc(false, stop_token); // auto ret = _updateTargetFunc(false, stop_token);
// update target according to its .pair_kind!
auto ret = _updateTargetFunc(stop_token);
if (ret) { if (ret) {
return ret; return ret;
} }
@ -327,6 +430,7 @@ public:
}; };
/*
_setTargetFunc = [controls, this](MccCelestialPoint const& pt) { _setTargetFunc = [controls, this](MccCelestialPoint const& pt) {
// in the case of apparent input coordinates // in the case of apparent input coordinates
// one must ensure the same time points // one must ensure the same time points
@ -359,6 +463,7 @@ public:
return mcc_deduce_error_code(ret, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM); return mcc_deduce_error_code(ret, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM);
}; };
*/
} }
@ -471,10 +576,7 @@ public:
} }
bool isInternalTelemetryDataUpdating() const bool isInternalTelemetryDataUpdating() const { return *_internalUpdating; }
{
return *_internalUpdating;
}
error_t updateTelemetryData(traits::mcc_time_duration_c auto const& timeout) error_t updateTelemetryData(traits::mcc_time_duration_c auto const& timeout)
@ -542,9 +644,40 @@ public:
error_t setPointingTarget(mcc_celestial_point_c auto pt) error_t setPointingTarget(mcc_celestial_point_c auto pt)
{ {
/*
* If apparent coordinates are specified (e.g. AZZD),
* they are assumed to be fixed in time,
* and other coordinates will be calculated from them
*/
std::lock_guard lock{*_updateMutex}; std::lock_guard lock{*_updateMutex};
return _setTargetFunc(pt); _data.target.pair_kind = pt.pair_kind;
if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_AZALT) {
_data.target.AZ = pt.X;
_data.target.ALT = pt.Y;
} else if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_AZZD) {
_data.target.AZ = pt.X;
_data.target.ZD = pt.Y;
} else if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_HADEC_APP) {
_data.target.HA = pt.X;
_data.target.DEC_APP = pt.Y;
} else if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_APP) {
_data.target.RA_APP = pt.X;
_data.target.DEC_APP = pt.Y;
} else if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
_data.target.RA_ICRS = pt.X;
_data.target.DEC_ICRS = pt.Y;
} else if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_XY) {
_data.target.X = pt.X;
_data.target.Y = pt.Y;
} else {
return MccTelemetryErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
}
return _updateTargetFunc({});
// return _setTargetFunc(pt);
} }
@ -603,7 +736,8 @@ protected:
std::future<error_t> _internalUpdatingFuture{}; std::future<error_t> _internalUpdatingFuture{};
std::stop_source _internalUpdatingStopSource{}; std::stop_source _internalUpdatingStopSource{};
std ::function<error_t(bool, std::stop_token)> _updateTargetFunc{}; std ::function<error_t(std::stop_token)> _updateTargetFunc{};
// std ::function<error_t(bool, std::stop_token)> _updateTargetFunc{};
std::function<error_t(std::stop_token)> _updateFunc{}; std::function<error_t(std::stop_token)> _updateFunc{};
std::function<error_t()> _setTargetFunc{}; std::function<error_t()> _setTargetFunc{};