...
This commit is contained in:
parent
1033506c11
commit
7c8bf5bb0b
@ -5,66 +5,74 @@
|
|||||||
|
|
||||||
/* MOUNT TELEMETRY OBJECT POSSIBLE GENERIC IMPLEMENTATION */
|
/* MOUNT TELEMETRY OBJECT POSSIBLE GENERIC IMPLEMENTATION */
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "mcc_mount_concepts.h"
|
#include "mcc_mount_telemetry_astrom.h"
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
enum class MccMountTelemetryErrorCode : int { ERROR_OK, ERROR_HARDWARE };
|
||||||
|
|
||||||
|
/* error category definition */
|
||||||
|
|
||||||
|
// error category
|
||||||
|
struct MccMountTelemetryCategory : public std::error_category {
|
||||||
|
MccMountTelemetryCategory() : std::error_category() {}
|
||||||
|
|
||||||
|
const char* name() const noexcept
|
||||||
|
{
|
||||||
|
return "ADC_GENERIC_DEVICE";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string message(int ec) const
|
||||||
|
{
|
||||||
|
MccMountTelemetryErrorCode err = static_cast<MccMountTelemetryErrorCode>(ec);
|
||||||
|
|
||||||
|
switch (err) {
|
||||||
|
case MccMountTelemetryErrorCode::ERROR_OK:
|
||||||
|
return "OK";
|
||||||
|
case MccMountTelemetryErrorCode::ERROR_HARDWARE:
|
||||||
|
return "hardware request failed";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const MccMountTelemetryAstromTransformCategory& get()
|
||||||
|
{
|
||||||
|
static const MccMountTelemetryAstromTransformCategory constInst;
|
||||||
|
return constInst;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline std::error_code make_error_code(MccMountTelemetryErrorCode ec)
|
||||||
|
{
|
||||||
|
return std::error_code(static_cast<int>(ec), MccMountTelemetryCategory::get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
|
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class is_error_code_enum<mcc::MccMountTelemetryErrorCode> : public true_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
namespace mcc
|
namespace mcc
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
namespace traits
|
/* DEFAULT TELEMETRY DATA CLASS */
|
||||||
{
|
|
||||||
|
|
||||||
/* enhanced telemetry data concept */
|
|
||||||
/* in general it correspond to definitions used in astrometry engine (see its concept) */
|
|
||||||
|
|
||||||
template <typename T, typename ASTROM_ENGINE_T, typename PEC_T>
|
|
||||||
concept mcc_mount_telemetry_enh_data_c = mcc_mount_telemetry_data_c<T> && requires(T t) {
|
|
||||||
requires traits::mcc_astrom_engine_c<ASTROM_ENGINE_T>;
|
|
||||||
requires traits::mcc_mount_pec_c<PEC_T>;
|
|
||||||
|
|
||||||
// check for types definitions and its consistency
|
|
||||||
requires std::same_as<typename T::coord_t, typename ASTROM_ENGINE_T::coord_t>;
|
|
||||||
|
|
||||||
requires std::same_as<typename T::time_point_t, typename ASTROM_ENGINE_T::time_point_t>;
|
|
||||||
|
|
||||||
requires std::same_as<typename T::juldate_t,
|
|
||||||
typename ASTROM_ENGINE_T::juldate_t>; // a type to represent Julian date
|
|
||||||
|
|
||||||
requires std::same_as<typename T::sideral_time_t,
|
|
||||||
typename ASTROM_ENGINE_T::sideral_time_t>; // a type to represent sideral time
|
|
||||||
|
|
||||||
requires std::same_as<typename T::pa_t,
|
|
||||||
typename ASTROM_ENGINE_T::pa_t>; // a type to represent parallactic angle
|
|
||||||
// typename T::eo_t; // a type to represent equation of origins
|
|
||||||
|
|
||||||
requires std::same_as<decltype(t.jd), typename T::juldate_t>; // Julian date
|
|
||||||
requires std::same_as<decltype(t.siderTime), typename T::sideral_time_t>; // sideral time
|
|
||||||
requires std::same_as<decltype(t.mntRA), typename T::pa_t>; // parallactic angle
|
|
||||||
|
|
||||||
// encoder-measured (non-corrected for PCS) current mount position and moving speed (in radians, radians/s)
|
|
||||||
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
|
||||||
requires std::same_as<decltype(t.mntPosX), typename T::coord_t>;
|
|
||||||
requires std::same_as<decltype(t.mntPosY), typename T::coord_t>;
|
|
||||||
requires std::same_as<decltype(t.mntRateX), typename T::coord_t>;
|
|
||||||
requires std::same_as<decltype(t.mntRateY), typename T::coord_t>;
|
|
||||||
|
|
||||||
// current refraction coefficients
|
|
||||||
requires std::same_as<decltype(t.currRefrCoeffs), typename PEC_T::pec_result_t>;
|
|
||||||
// current refraction correction (for mntALT)
|
|
||||||
requires std::same_as<decltype(t.currRefr), typename T::coord_t>;
|
|
||||||
|
|
||||||
// PEC (pointing error correction):
|
|
||||||
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
|
||||||
requires std::same_as<decltype(t.pecX), typename T::coord_t>;
|
|
||||||
requires std::same_as<decltype(t.pecY), typename T::coord_t>;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace traits
|
|
||||||
|
|
||||||
|
|
||||||
// default generic telemetry data definition
|
|
||||||
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T, traits::mcc_mount_pec_c PEC_T>
|
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T, traits::mcc_mount_pec_c PEC_T>
|
||||||
struct MccMountTelemetryData {
|
struct MccMountTelemetryData {
|
||||||
typedef typename ASTROM_ENGINE_T::coord_t coord_t;
|
typedef typename ASTROM_ENGINE_T::coord_t coord_t;
|
||||||
@ -78,6 +86,13 @@ struct MccMountTelemetryData {
|
|||||||
juldate_t jd; // Julian date
|
juldate_t jd; // Julian date
|
||||||
sideral_time_t siderTime; // local apperant sideral time
|
sideral_time_t siderTime; // local apperant sideral time
|
||||||
|
|
||||||
|
// target sky point ICRS and current coordinates
|
||||||
|
coord_t tagRA_ICRS, tagDEC_ICRS;
|
||||||
|
coord_t tagRA, tagDEC;
|
||||||
|
coord_t tagHA;
|
||||||
|
coord_t tagAZ, tagALT;
|
||||||
|
pa_t tagPA;
|
||||||
|
|
||||||
// encoder-measured current mount coordinates
|
// encoder-measured current mount coordinates
|
||||||
coord_t mntRA, mntDEC;
|
coord_t mntRA, mntDEC;
|
||||||
coord_t mntHA;
|
coord_t mntHA;
|
||||||
@ -100,57 +115,58 @@ struct MccMountTelemetryData {
|
|||||||
coord_t pecX, pecY;
|
coord_t pecX, pecY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* DEFAULT TELEMETRY MANAGER CLASS */
|
||||||
|
|
||||||
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T,
|
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T,
|
||||||
traits::mcc_mount_pec_c PEC_T,
|
traits::mcc_mount_pec_c PEC_T,
|
||||||
traits::mcc_mount_hardware_c HARDWARE_T,
|
traits::mcc_mount_hardware_c HARDWARE_T,
|
||||||
traits::mcc_mount_telemetry_enh_data_c<ASTROM_ENGINE_T, PEC_T> DATA_T =
|
std::derived_from<MccMountTelemetryData<ASTROM_ENGINE_T, PEC_T>> DATA_T =
|
||||||
MccMountTelemetryData<ASTROM_ENGINE_T, PEC_T>>
|
MccMountTelemetryData<ASTROM_ENGINE_T, PEC_T>>
|
||||||
class MccMountTelemetry
|
class MccMountTelemetry : public MccMountTelemetryAstromTransform<ASTROM_ENGINE_T, PEC_T>
|
||||||
{
|
{
|
||||||
|
typedef MccMountTelemetryAstromTransform<ASTROM_ENGINE_T, PEC_T> base_t;
|
||||||
|
|
||||||
|
struct point_t {
|
||||||
|
MccCoordPairKind coordPairKind;
|
||||||
|
typename ASTROM_ENGINE_T::coord_t x, y;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef ASTROM_ENGINE_T astrom_engine_t;
|
typedef ASTROM_ENGINE_T astrom_engine_t;
|
||||||
typedef PEC_T pec_t;
|
typedef PEC_T pec_t;
|
||||||
typedef HARDWARE_T hardware_t;
|
typedef HARDWARE_T hardware_t;
|
||||||
|
|
||||||
enum error_t : int { TEL_ERROR_OK = 0, TEL_ERROR_HARDWARE, TEL_ERROR_ASTROMETRY_COMP, TEL_ERROR_PEC };
|
|
||||||
|
|
||||||
// check for coordinate types consistency
|
|
||||||
static_assert(std::convertible_to<typename hardware_t::coord_t, typename astrom_engine_t::coord_t>,
|
|
||||||
"HARDWARE COORDINATE TYPE MUST BE CONVERTIBLE TO ASTROMETRY ENGINE ONE!");
|
|
||||||
|
|
||||||
static_assert(std::convertible_to<typename hardware_t::coord_t, typename pec_t::coord_t>,
|
|
||||||
"HARDWARE COORDINATE TYPE MUST BE CONVERTIBLE TO PEC ONE!");
|
|
||||||
|
|
||||||
// static_assert(std::convertible_to<typename pec_t::coord_t, typename astrom_engine_t::coord_t>,
|
|
||||||
// "ASTROMETRY ENGINE COORDINATE TYPE MUST BE CONVERTIBLE TO PEC ONE!");
|
|
||||||
|
|
||||||
// mandatory arithmetic operations
|
|
||||||
static_assert( // for CIO-based apparent RA computation and PEC correction addition (see below)
|
|
||||||
requires(typename astrom_engine_t::coord_t v1,
|
|
||||||
typename astrom_engine_t::coord_t v2,
|
|
||||||
typename pec_t::coord_t v3) {
|
|
||||||
{ v1 + v2 } -> std::convertible_to<typename astrom_engine_t::coord_t>;
|
|
||||||
{ v1 - v2 } -> std::convertible_to<typename astrom_engine_t::coord_t>;
|
|
||||||
v1 += v3;
|
|
||||||
},
|
|
||||||
"ASTROMETRY ENGINE COORDINATE TYPE MUST DEFINE '+', '+=' AND '-' ARITHMETIC OPERATIONS!");
|
|
||||||
|
|
||||||
|
|
||||||
// check for time point types consistency
|
|
||||||
static_assert(std::convertible_to<typename hardware_t::time_point_t, typename astrom_engine_t::time_point_t>,
|
|
||||||
"HARDWARE TIME-POINT TYPE MUST BE CONVERTIBLE TO ASTROMETRY ENGINE ONE!");
|
|
||||||
|
|
||||||
typedef DATA_T mount_telemetry_data_t;
|
typedef DATA_T mount_telemetry_data_t;
|
||||||
|
|
||||||
|
typedef std::error_code error_t;
|
||||||
|
|
||||||
|
typedef std::function<void(mount_telemetry_data_t)> update_callback_func_t;
|
||||||
|
typedef std::list<update_callback_func_t> update_callback_container_t;
|
||||||
|
|
||||||
MccMountTelemetry(astrom_engine_t& astrom_engine, pec_t& pec, hardware_t& hardware)
|
MccMountTelemetry(astrom_engine_t& astrom_engine, pec_t& pec, hardware_t& hardware)
|
||||||
: _astromEngine(astrom_engine), _pec(pec), _hardware(hardware)
|
: base_t(astrom_engine, pec), _hardware(hardware)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~MccMountTelemetry() = default;
|
virtual ~MccMountTelemetry() = default;
|
||||||
|
|
||||||
// update current data method
|
|
||||||
|
// set current target sky point coordinates (update all data)
|
||||||
|
template <traits::mcc_celestial_point_c PointT>
|
||||||
|
error_t setTarget(PointT tag_point)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{_updateMutex};
|
||||||
|
|
||||||
|
auto err = this->toICRS(tag_point, _data.utc, _data.tagRA_ICRS, _data.tagDEC_ICRS);
|
||||||
|
if (!err) {
|
||||||
|
err = update();
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
error_t update()
|
error_t update()
|
||||||
{
|
{
|
||||||
mount_telemetry_data_t current_data;
|
mount_telemetry_data_t current_data;
|
||||||
@ -159,91 +175,133 @@ public:
|
|||||||
|
|
||||||
auto err = _hardware.getPos(ax_pos);
|
auto err = _hardware.getPos(ax_pos);
|
||||||
if (err) {
|
if (err) {
|
||||||
// logging?!!!
|
if constexpr (std::same_as<error_t, decltype(err)>) {
|
||||||
return TEL_ERROR_HARDWARE;
|
return err;
|
||||||
}
|
|
||||||
|
|
||||||
_data.utc = ax_pos.time_point;
|
|
||||||
_data.mntPosX = static_cast<typename astrom_engine_t::coord_t>(ax_pos.x);
|
|
||||||
_data.mntPosY = static_cast<typename astrom_engine_t::coord_t>(ax_pos.y);
|
|
||||||
_data.mntRateX = static_cast<typename astrom_engine_t::coord_t>(ax_pos.xrate);
|
|
||||||
_data.mntRateY = static_cast<typename astrom_engine_t::coord_t>(ax_pos.yrate);
|
|
||||||
|
|
||||||
// compute Julian date
|
|
||||||
auto ast_err = _astromEngine.greg2jul(_data.time_point, _data.jd);
|
|
||||||
if (ast_err) {
|
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// compute local apparent sideral time
|
|
||||||
ast_err = _astromEngine.apparentSiderTime(_data.jd, _data.siderTime, true);
|
|
||||||
if (ast_err) {
|
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// compute equation of origins
|
|
||||||
typename astrom_engine_t::eo_t eo;
|
|
||||||
ast_err = _astromEngine.eqOrigins(_data.jd, eo);
|
|
||||||
if (ast_err) {
|
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typename pec_t::pec_result_t pec_res;
|
|
||||||
auto pec_err = _pec.compute(ax_pos.x, ax_pos.y, pec_res);
|
|
||||||
if (pec_err) {
|
|
||||||
return TEL_ERROR_PEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
|
||||||
_data.mntHA = _data.mntPosX;
|
|
||||||
_data.mntDEC = _data.mntPosY;
|
|
||||||
_data.mntHA += pec_res.dx;
|
|
||||||
_data.mntDEC += pec_res.dy;
|
|
||||||
|
|
||||||
ast_err = _astromEngine.hadec2azalt(_data.mntHA, _data.mntDEC, _data.mntAZ, _data.mntALT);
|
|
||||||
if (ast_err) {
|
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
|
||||||
}
|
}
|
||||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
return MccMountTelemetryErrorCode::ERROR_HARDWARE;
|
||||||
_data.mntAZ = _data.mntPosX;
|
}
|
||||||
_data.mntALT = _data.mntPosY;
|
|
||||||
_data.mntAZ += pec_res.dx;
|
|
||||||
_data.mntALT += pec_res.dy;
|
|
||||||
|
|
||||||
ast_err = _astromEngine.azalt2hadec(_data.mntAZ, _data.mntALT, _data.mntHA, _data.mntDEC);
|
error_t res_err;
|
||||||
if (ast_err) {
|
typename astrom_engine_t::error_t ast_err{};
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
|
||||||
|
// times
|
||||||
|
current_data.utc = ax_pos.time_point;
|
||||||
|
// Julian date
|
||||||
|
ast_err = this->_astromEngine.greg2jul(current_data.time_point, current_data.jd);
|
||||||
|
if (!ast_err) {
|
||||||
|
// local apparent sideral time
|
||||||
|
ast_err = this->_astromEngine.apparentSiderTime(current_data.jd, current_data.siderTime, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_err) {
|
||||||
|
if constexpr (std::same_as<typename astrom_engine_t::error_t, error_t>) {
|
||||||
|
return ast_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// encoder coordinates
|
||||||
|
current_data.mntPosX = static_cast<typename astrom_engine_t::coord_t>(ax_pos.x);
|
||||||
|
current_data.mntPosY = static_cast<typename astrom_engine_t::coord_t>(ax_pos.y);
|
||||||
|
current_data.mntRateX = static_cast<typename astrom_engine_t::coord_t>(ax_pos.xrate);
|
||||||
|
current_data.mntRateY = static_cast<typename astrom_engine_t::coord_t>(ax_pos.yrate);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// correction for PEC
|
||||||
|
if constexpr (base_t::equatorialMount) {
|
||||||
|
res_err = this->toApparent(point_t{.coordPairKind = MccCoordPairKind::COORDS_KIND_XY,
|
||||||
|
.x = current_data.mntPosX,
|
||||||
|
.y = current_data.mntPosY},
|
||||||
|
current_data.utc, current_data.mntHA, current_data.mntDEC);
|
||||||
|
if (!res_err) {
|
||||||
|
ast_err = this->_astromEngine.hadec2azalt(current_data.mntHA, current_data.mntDEC, current_data.mntAZ,
|
||||||
|
current_data.mntALT);
|
||||||
|
}
|
||||||
|
} else if constexpr (base_t::altAzMount) {
|
||||||
|
res_err = this->toApparent(point_t{.coordPairKind = MccCoordPairKind::COORDS_KIND_XY,
|
||||||
|
.x = current_data.mntPosX,
|
||||||
|
.y = current_data.mntPosY},
|
||||||
|
current_data.utc, current_data.mntAZ, current_data.mntALT);
|
||||||
|
if (!res_err) {
|
||||||
|
ast_err = this->_astromEngine.azalt2hadec(current_data.mntAZ, current_data.mntALT, current_data.mntHA,
|
||||||
|
current_data.mntDEC);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute CIO-based apparent RA
|
if (res_err) {
|
||||||
_data.mntRA = _data.siderTime - _data.mntHA + eo;
|
return res_err;
|
||||||
|
|
||||||
// compute PA
|
|
||||||
ast_err = _astromEngine.hadec2pa(_data.mntHA, _data.mntDEC, _data.mntPA);
|
|
||||||
if (ast_err) {
|
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_err = _astromEngine.refraction(_data.currRefrCoeffs);
|
// PA angle
|
||||||
if (ast_err) {
|
if (!ast_err) {
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
ast_err = this->_astromEngine.hadec2pa(current_data.mntHA, current_data.mntDEC, current_data.mntPA);
|
||||||
|
if (!ast_err) {
|
||||||
|
// target coordinates (assuming its ICRS RA-DEC are already given or computed)
|
||||||
|
typename mount_telemetry_data_t::eo_t eo;
|
||||||
|
ast_err = this->_astromEngine.icrs2obs(current_data.tagRA_ICRS, current_data.tagDEC_ICRS,
|
||||||
|
current_data.jd, current_data.tagRA, current_data.tagDEC,
|
||||||
|
current_data.tagHA, current_data.tagAZ, current_data.tagALT, eo);
|
||||||
|
|
||||||
|
if (!ast_err) {
|
||||||
|
current_data.mntRA = current_data.siderTime - current_data.mntHA + eo; // CIO based mount RA
|
||||||
|
ast_err = this->_astromEngine.hadec2pa(current_data.tagHA, current_data.tagDEC, current_data.tagPA);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_err = _astromEngine.refractCorrection(_data.mntALT, _data.currRefrCoeffs, _data.currRefr);
|
|
||||||
if (ast_err) {
|
if (ast_err) {
|
||||||
return TEL_ERROR_ASTROMETRY_COMP;
|
if constexpr (std::same_as<typename astrom_engine_t::error_t, error_t>) {
|
||||||
|
return ast_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_ASTROMETRY_COMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard lock{_updateMutex};
|
std::lock_guard lock{_updateMutex};
|
||||||
|
|
||||||
_data = std::move(current_data);
|
_data = std::move(current_data);
|
||||||
|
|
||||||
return TEL_ERROR_OK;
|
std::lock_guard cl_lock{_callbackMutex};
|
||||||
|
|
||||||
|
// callbacks will be invoked with its own copy of telemetry data!
|
||||||
|
for (auto& func : _callbackFuncs) {
|
||||||
|
std::thread t([this, &func] {
|
||||||
|
auto d = _data;
|
||||||
|
func(std::move(d));
|
||||||
|
});
|
||||||
|
t.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
return MccMountTelemetryErrorCode::ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
update_callback_container_t::iterator addCallbackFunc(update_callback_func_t func)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{_callbackMutex};
|
||||||
|
|
||||||
|
return _callbackFuncs.emplace_back(std::move(func));
|
||||||
|
}
|
||||||
|
|
||||||
|
void delCallbackFunc(update_callback_container_t::iterator iter)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{_callbackMutex};
|
||||||
|
|
||||||
|
if (_callbackFuncs.size()) {
|
||||||
|
_callbackFuncs.erase(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearCallbackFuncs()
|
||||||
|
{
|
||||||
|
std::lock_guard lock{_callbackMutex};
|
||||||
|
|
||||||
|
_callbackFuncs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t data(mount_telemetry_data_t& data)
|
error_t data(mount_telemetry_data_t& data)
|
||||||
@ -252,32 +310,16 @@ public:
|
|||||||
|
|
||||||
data = std::move(_data);
|
data = std::move(_data);
|
||||||
|
|
||||||
return TEL_ERROR_OK;
|
return MccMountTelemetryErrorCode::ERROR_OK;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string_view errorString(error_t err) const
|
|
||||||
{
|
|
||||||
if (err == TEL_ERROR_OK) {
|
|
||||||
return "OK";
|
|
||||||
} else if (err == TEL_ERROR_ASTROMETRY_COMP) {
|
|
||||||
return "astrometry computation error";
|
|
||||||
} else if (err == TEL_ERROR_PEC) {
|
|
||||||
return "PEC computation error";
|
|
||||||
} else if (err == TEL_ERROR_HARDWARE) {
|
|
||||||
return "hardware request error";
|
|
||||||
} else {
|
|
||||||
return "unknown error";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mount_telemetry_data_t _data{};
|
mount_telemetry_data_t _data{};
|
||||||
astrom_engine_t& _astromEngine;
|
|
||||||
pec_t& _pec;
|
|
||||||
hardware_t& _hardware;
|
hardware_t& _hardware;
|
||||||
|
update_callback_container_t _callbackFuncs{};
|
||||||
|
|
||||||
std::mutex _updateMutex;
|
std::mutex _updateMutex;
|
||||||
|
std::mutex _callbackMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
284
cxx/mcc_mount_telemetry.h.old
Normal file
284
cxx/mcc_mount_telemetry.h.old
Normal file
@ -0,0 +1,284 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
||||||
|
|
||||||
|
|
||||||
|
/* MOUNT TELEMETRY OBJECT POSSIBLE GENERIC IMPLEMENTATION */
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "mcc_mount_concepts.h"
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
namespace traits
|
||||||
|
{
|
||||||
|
|
||||||
|
/* enhanced telemetry data concept */
|
||||||
|
/* in general it correspond to definitions used in astrometry engine (see its concept) */
|
||||||
|
|
||||||
|
template <typename T, typename ASTROM_ENGINE_T, typename PEC_T>
|
||||||
|
concept mcc_mount_telemetry_enh_data_c = mcc_mount_telemetry_data_c<T> && requires(T t) {
|
||||||
|
requires traits::mcc_astrom_engine_c<ASTROM_ENGINE_T>;
|
||||||
|
requires traits::mcc_mount_pec_c<PEC_T>;
|
||||||
|
|
||||||
|
// check for types definitions and its consistency
|
||||||
|
requires std::same_as<typename T::coord_t, typename ASTROM_ENGINE_T::coord_t>;
|
||||||
|
|
||||||
|
requires std::same_as<typename T::time_point_t, typename ASTROM_ENGINE_T::time_point_t>;
|
||||||
|
|
||||||
|
requires std::same_as<typename T::juldate_t,
|
||||||
|
typename ASTROM_ENGINE_T::juldate_t>; // a type to represent Julian date
|
||||||
|
|
||||||
|
requires std::same_as<typename T::sideral_time_t,
|
||||||
|
typename ASTROM_ENGINE_T::sideral_time_t>; // a type to represent sideral time
|
||||||
|
|
||||||
|
requires std::same_as<typename T::pa_t,
|
||||||
|
typename ASTROM_ENGINE_T::pa_t>; // a type to represent parallactic angle
|
||||||
|
// typename T::eo_t; // a type to represent equation of origins
|
||||||
|
|
||||||
|
requires std::same_as<decltype(t.jd), typename T::juldate_t>; // Julian date
|
||||||
|
requires std::same_as<decltype(t.siderTime), typename T::sideral_time_t>; // sideral time
|
||||||
|
requires std::same_as<decltype(t.mntRA), typename T::pa_t>; // parallactic angle
|
||||||
|
|
||||||
|
// encoder-measured (non-corrected for PCS) current mount position and moving speed (in radians, radians/s)
|
||||||
|
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
||||||
|
requires std::same_as<decltype(t.mntPosX), typename T::coord_t>;
|
||||||
|
requires std::same_as<decltype(t.mntPosY), typename T::coord_t>;
|
||||||
|
requires std::same_as<decltype(t.mntRateX), typename T::coord_t>;
|
||||||
|
requires std::same_as<decltype(t.mntRateY), typename T::coord_t>;
|
||||||
|
|
||||||
|
// current refraction coefficients
|
||||||
|
requires std::same_as<decltype(t.currRefrCoeffs), typename PEC_T::pec_result_t>;
|
||||||
|
// current refraction correction (for mntALT)
|
||||||
|
requires std::same_as<decltype(t.currRefr), typename T::coord_t>;
|
||||||
|
|
||||||
|
// PEC (pointing error correction):
|
||||||
|
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
||||||
|
requires std::same_as<decltype(t.pecX), typename T::coord_t>;
|
||||||
|
requires std::same_as<decltype(t.pecY), typename T::coord_t>;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace traits
|
||||||
|
|
||||||
|
|
||||||
|
// default generic telemetry data definition
|
||||||
|
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T, traits::mcc_mount_pec_c PEC_T>
|
||||||
|
struct MccMountTelemetryData {
|
||||||
|
typedef typename ASTROM_ENGINE_T::coord_t coord_t;
|
||||||
|
typedef typename ASTROM_ENGINE_T::time_point_t time_point_t;
|
||||||
|
typedef typename ASTROM_ENGINE_T::juldate_t juldate_t;
|
||||||
|
typedef typename ASTROM_ENGINE_T::sideral_time_t sideral_time_t;
|
||||||
|
typedef typename ASTROM_ENGINE_T::pa_t pa_t;
|
||||||
|
|
||||||
|
// time-related
|
||||||
|
time_point_t time_point; // time point of measurements, UTC
|
||||||
|
juldate_t jd; // Julian date
|
||||||
|
sideral_time_t siderTime; // local apperant sideral time
|
||||||
|
|
||||||
|
// encoder-measured current mount coordinates
|
||||||
|
coord_t mntRA, mntDEC;
|
||||||
|
coord_t mntHA;
|
||||||
|
coord_t mntAZ, mntALT;
|
||||||
|
pa_t mntPA;
|
||||||
|
|
||||||
|
// encoder-measured (non-corrected for PCS) current mount position and axes rates
|
||||||
|
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
||||||
|
coord_t mntPosX, mntPosY;
|
||||||
|
coord_t mntRateX, mntRateY;
|
||||||
|
|
||||||
|
// current refraction coefficients
|
||||||
|
typename PEC_T::pec_result_t currRefrCoeffs;
|
||||||
|
|
||||||
|
// current refraction correction (for mntALT)
|
||||||
|
coord_t currRefr;
|
||||||
|
|
||||||
|
// PEC (pointing error correction):
|
||||||
|
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
||||||
|
coord_t pecX, pecY;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T,
|
||||||
|
traits::mcc_mount_pec_c PEC_T,
|
||||||
|
traits::mcc_mount_hardware_c HARDWARE_T,
|
||||||
|
traits::mcc_mount_telemetry_enh_data_c<ASTROM_ENGINE_T, PEC_T> DATA_T =
|
||||||
|
MccMountTelemetryData<ASTROM_ENGINE_T, PEC_T>>
|
||||||
|
class MccMountTelemetry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef ASTROM_ENGINE_T astrom_engine_t;
|
||||||
|
typedef PEC_T pec_t;
|
||||||
|
typedef HARDWARE_T hardware_t;
|
||||||
|
|
||||||
|
enum error_t : int { TEL_ERROR_OK = 0, TEL_ERROR_HARDWARE, TEL_ERROR_ASTROMETRY_COMP, TEL_ERROR_PEC };
|
||||||
|
|
||||||
|
// check for coordinate types consistency
|
||||||
|
static_assert(std::convertible_to<typename hardware_t::coord_t, typename astrom_engine_t::coord_t>,
|
||||||
|
"HARDWARE COORDINATE TYPE MUST BE CONVERTIBLE TO ASTROMETRY ENGINE ONE!");
|
||||||
|
|
||||||
|
static_assert(std::convertible_to<typename hardware_t::coord_t, typename pec_t::coord_t>,
|
||||||
|
"HARDWARE COORDINATE TYPE MUST BE CONVERTIBLE TO PEC ONE!");
|
||||||
|
|
||||||
|
// static_assert(std::convertible_to<typename pec_t::coord_t, typename astrom_engine_t::coord_t>,
|
||||||
|
// "ASTROMETRY ENGINE COORDINATE TYPE MUST BE CONVERTIBLE TO PEC ONE!");
|
||||||
|
|
||||||
|
// mandatory arithmetic operations
|
||||||
|
static_assert( // for CIO-based apparent RA computation and PEC correction addition (see below)
|
||||||
|
requires(typename astrom_engine_t::coord_t v1,
|
||||||
|
typename astrom_engine_t::coord_t v2,
|
||||||
|
typename pec_t::coord_t v3) {
|
||||||
|
{ v1 + v2 } -> std::convertible_to<typename astrom_engine_t::coord_t>;
|
||||||
|
{ v1 - v2 } -> std::convertible_to<typename astrom_engine_t::coord_t>;
|
||||||
|
v1 += v3;
|
||||||
|
},
|
||||||
|
"ASTROMETRY ENGINE COORDINATE TYPE MUST DEFINE '+', '+=' AND '-' ARITHMETIC OPERATIONS!");
|
||||||
|
|
||||||
|
|
||||||
|
// check for time point types consistency
|
||||||
|
static_assert(std::convertible_to<typename hardware_t::time_point_t, typename astrom_engine_t::time_point_t>,
|
||||||
|
"HARDWARE TIME-POINT TYPE MUST BE CONVERTIBLE TO ASTROMETRY ENGINE ONE!");
|
||||||
|
|
||||||
|
typedef DATA_T mount_telemetry_data_t;
|
||||||
|
|
||||||
|
|
||||||
|
MccMountTelemetry(astrom_engine_t& astrom_engine, pec_t& pec, hardware_t& hardware)
|
||||||
|
: _astromEngine(astrom_engine), _pec(pec), _hardware(hardware)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~MccMountTelemetry() = default;
|
||||||
|
|
||||||
|
// update current data method
|
||||||
|
error_t update()
|
||||||
|
{
|
||||||
|
mount_telemetry_data_t current_data;
|
||||||
|
|
||||||
|
typename hardware_t::axes_pos_t ax_pos;
|
||||||
|
|
||||||
|
auto err = _hardware.getPos(ax_pos);
|
||||||
|
if (err) {
|
||||||
|
// logging?!!!
|
||||||
|
return TEL_ERROR_HARDWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
_data.utc = ax_pos.time_point;
|
||||||
|
_data.mntPosX = static_cast<typename astrom_engine_t::coord_t>(ax_pos.x);
|
||||||
|
_data.mntPosY = static_cast<typename astrom_engine_t::coord_t>(ax_pos.y);
|
||||||
|
_data.mntRateX = static_cast<typename astrom_engine_t::coord_t>(ax_pos.xrate);
|
||||||
|
_data.mntRateY = static_cast<typename astrom_engine_t::coord_t>(ax_pos.yrate);
|
||||||
|
|
||||||
|
// compute Julian date
|
||||||
|
auto ast_err = _astromEngine.greg2jul(_data.time_point, _data.jd);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute local apparent sideral time
|
||||||
|
ast_err = _astromEngine.apparentSiderTime(_data.jd, _data.siderTime, true);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute equation of origins
|
||||||
|
typename astrom_engine_t::eo_t eo;
|
||||||
|
ast_err = _astromEngine.eqOrigins(_data.jd, eo);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typename pec_t::pec_result_t pec_res;
|
||||||
|
auto pec_err = _pec.compute(ax_pos.x, ax_pos.y, pec_res);
|
||||||
|
if (pec_err) {
|
||||||
|
return TEL_ERROR_PEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
|
_data.mntHA = _data.mntPosX;
|
||||||
|
_data.mntDEC = _data.mntPosY;
|
||||||
|
_data.mntHA += pec_res.dx;
|
||||||
|
_data.mntDEC += pec_res.dy;
|
||||||
|
|
||||||
|
ast_err = _astromEngine.hadec2azalt(_data.mntHA, _data.mntDEC, _data.mntAZ, _data.mntALT);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
|
_data.mntAZ = _data.mntPosX;
|
||||||
|
_data.mntALT = _data.mntPosY;
|
||||||
|
_data.mntAZ += pec_res.dx;
|
||||||
|
_data.mntALT += pec_res.dy;
|
||||||
|
|
||||||
|
ast_err = _astromEngine.azalt2hadec(_data.mntAZ, _data.mntALT, _data.mntHA, _data.mntDEC);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute CIO-based apparent RA
|
||||||
|
_data.mntRA = _data.siderTime - _data.mntHA + eo;
|
||||||
|
|
||||||
|
// compute PA
|
||||||
|
ast_err = _astromEngine.hadec2pa(_data.mntHA, _data.mntDEC, _data.mntPA);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_err = _astromEngine.refraction(_data.currRefrCoeffs);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_err = _astromEngine.refractCorrection(_data.mntALT, _data.currRefrCoeffs, _data.currRefr);
|
||||||
|
if (ast_err) {
|
||||||
|
return TEL_ERROR_ASTROMETRY_COMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard lock{_updateMutex};
|
||||||
|
|
||||||
|
_data = std::move(current_data);
|
||||||
|
|
||||||
|
return TEL_ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t data(mount_telemetry_data_t& data)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{_updateMutex};
|
||||||
|
|
||||||
|
data = std::move(_data);
|
||||||
|
|
||||||
|
return TEL_ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string_view errorString(error_t err) const
|
||||||
|
{
|
||||||
|
if (err == TEL_ERROR_OK) {
|
||||||
|
return "OK";
|
||||||
|
} else if (err == TEL_ERROR_ASTROMETRY_COMP) {
|
||||||
|
return "astrometry computation error";
|
||||||
|
} else if (err == TEL_ERROR_PEC) {
|
||||||
|
return "PEC computation error";
|
||||||
|
} else if (err == TEL_ERROR_HARDWARE) {
|
||||||
|
return "hardware request error";
|
||||||
|
} else {
|
||||||
|
return "unknown error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mount_telemetry_data_t _data{};
|
||||||
|
astrom_engine_t& _astromEngine;
|
||||||
|
pec_t& _pec;
|
||||||
|
hardware_t& _hardware;
|
||||||
|
|
||||||
|
std::mutex _updateMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
@ -9,6 +9,74 @@
|
|||||||
|
|
||||||
#include "mcc_mount_concepts.h"
|
#include "mcc_mount_concepts.h"
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
|
||||||
|
enum class MccMountTelemetryAstromTransformErrorCode : int {
|
||||||
|
ERROR_OK = 0,
|
||||||
|
ERROR_COORD_PAIR_KIND,
|
||||||
|
ERROR_ASTROMETRY_COMP,
|
||||||
|
ERROR_PEC
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* error category definition */
|
||||||
|
|
||||||
|
// error category
|
||||||
|
struct MccMountTelemetryAstromTransformCategory : public std::error_category {
|
||||||
|
MccMountTelemetryAstromTransformCategory() : std::error_category() {}
|
||||||
|
|
||||||
|
const char* name() const noexcept
|
||||||
|
{
|
||||||
|
return "ADC_GENERIC_DEVICE";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string message(int ec) const
|
||||||
|
{
|
||||||
|
MccMountTelemetryAstromTransformErrorCode err = static_cast<MccMountTelemetryAstromTransformErrorCode>(ec);
|
||||||
|
|
||||||
|
switch (err) {
|
||||||
|
case MccMountTelemetryAstromTransformErrorCode::ERROR_OK:
|
||||||
|
return "OK";
|
||||||
|
case MccMountTelemetryAstromTransformErrorCode::ERROR_COORD_PAIR_KIND:
|
||||||
|
return "unsupported coordinate pair kind";
|
||||||
|
case MccMountTelemetryAstromTransformErrorCode::ERROR_ASTROMETRY_COMP:
|
||||||
|
return "astrometry engine error";
|
||||||
|
case MccMountTelemetryAstromTransformErrorCode::ERROR_PEC:
|
||||||
|
return "PEC computation error";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const MccMountTelemetryAstromTransformCategory& get()
|
||||||
|
{
|
||||||
|
static const MccMountTelemetryAstromTransformCategory constInst;
|
||||||
|
return constInst;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline std::error_code make_error_code(MccMountTelemetryAstromTransformErrorCode ec)
|
||||||
|
{
|
||||||
|
return std::error_code(static_cast<int>(ec), MccMountTelemetryAstromTransformCategory::get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class is_error_code_enum<mcc::MccMountTelemetryAstromTransformErrorCode> : public true_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace mcc
|
namespace mcc
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -18,13 +86,23 @@ class MccMountTelemetryAstromTransform
|
|||||||
static typename ASTROM_ENGINE_T::coord_t dummyCoord{};
|
static typename ASTROM_ENGINE_T::coord_t dummyCoord{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef ASTROM_ENGINE_T astrom_engine_t;
|
||||||
|
typedef PEC_T pec_t;
|
||||||
|
|
||||||
|
// check for coordinate types consistency
|
||||||
|
static_assert(
|
||||||
|
requires(typename astrom_engine_t::coord_t ac, typename pec_t::coord_t pc) {
|
||||||
|
// to compute PEC-corrected values
|
||||||
|
{ ac += pc };
|
||||||
|
{ ac = ac + pc };
|
||||||
|
{ ac = ac - pc };
|
||||||
|
},
|
||||||
|
"ASTROMETRY ENGINE AND PEC COORDINATES TYPE MUST BE CONSISTENT!");
|
||||||
|
|
||||||
// deduce mount type
|
// deduce mount type
|
||||||
static constexpr bool equatorialMount = mccIsEquatorialMount(PEC_T::mountType);
|
static constexpr bool equatorialMount = mccIsEquatorialMount(PEC_T::mountType);
|
||||||
static constexpr bool altAzMount = mccIsAltAzMount(PEC_T::mountType);
|
static constexpr bool altAzMount = mccIsAltAzMount(PEC_T::mountType);
|
||||||
|
|
||||||
typedef ASTROM_ENGINE_T astrom_engine_t;
|
|
||||||
typedef PEC_T pec_t;
|
|
||||||
|
|
||||||
typedef typename astrom_engine_t::coord_t coord_t;
|
typedef typename astrom_engine_t::coord_t coord_t;
|
||||||
|
|
||||||
typedef std::error_code error_t;
|
typedef std::error_code error_t;
|
||||||
@ -153,14 +231,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_COORD_PAIR_KIND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pec_err) {
|
if (pec_err) {
|
||||||
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
||||||
return pec_err;
|
return pec_err;
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_PEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,11 +246,11 @@ public:
|
|||||||
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
||||||
return ast_err;
|
return ast_err;
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_ASTROMETRY_COMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -211,9 +289,9 @@ public:
|
|||||||
RA = coord.x;
|
RA = coord.x;
|
||||||
DEC = coord.y;
|
DEC = coord.y;
|
||||||
|
|
||||||
return {};
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_OK;
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_COORD_PAIR_KIND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coord.coordPairKind != MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
if (coord.coordPairKind != MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||||
@ -229,7 +307,7 @@ public:
|
|||||||
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
||||||
return pec_err;
|
return pec_err;
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_PEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,11 +315,11 @@ public:
|
|||||||
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
||||||
return ast_err;
|
return ast_err;
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_ASTROMETRY_COMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -277,7 +355,7 @@ public:
|
|||||||
X = coord.x;
|
X = coord.x;
|
||||||
Y = coord.y;
|
Y = coord.y;
|
||||||
|
|
||||||
return {};
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_OK;
|
||||||
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_RADEC_APP) { // from app RA-DEC
|
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_RADEC_APP) { // from app RA-DEC
|
||||||
ast_err = get_jd_lst_eo(jd, lst, eo);
|
ast_err = get_jd_lst_eo(jd, lst, eo);
|
||||||
|
|
||||||
@ -296,7 +374,7 @@ public:
|
|||||||
X = coord.x - pec_res.dx;
|
X = coord.x - pec_res.dx;
|
||||||
Y = coord.y - pec_res.dy;
|
Y = coord.y - pec_res.dy;
|
||||||
|
|
||||||
return {};
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_OK;
|
||||||
}
|
}
|
||||||
} else if constexpr (altAzMount) {
|
} else if constexpr (altAzMount) {
|
||||||
coord_t az, alt;
|
coord_t az, alt;
|
||||||
@ -312,20 +390,65 @@ public:
|
|||||||
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
}
|
}
|
||||||
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_AZALT) { // from app AZ-ALT
|
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_AZALT) { // from app AZ-ALT
|
||||||
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_AZZD) { // from app AZ-ZD
|
if constexpr (equatorialMount) {
|
||||||
|
coord_t ha, dec;
|
||||||
|
ast_err = _astromEngine.azalt2hadec(coord.x, coord.y, ha, dec);
|
||||||
|
if (!ast_err) {
|
||||||
|
coord.coordPairKind == MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
|
coord.x = ha;
|
||||||
|
coord.y = dec;
|
||||||
|
|
||||||
|
ast_err = toHardware(std::move(coord), std::move(time_point), X, Y);
|
||||||
|
}
|
||||||
|
} else if constexpr (altAzMount) {
|
||||||
|
typename pec_t::pec_result_t pec_res;
|
||||||
|
|
||||||
|
pec_err = _pec.compute(coord.x, coord.y, pec_res);
|
||||||
|
if (!pec_err) {
|
||||||
|
X = coord.x - pec_res.dx;
|
||||||
|
Y = coord.y - pec_res.dy;
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_AZZD) { // from app AZ-ZD
|
||||||
coord.coordPairKind == MccCoordPairKind::COORDS_KIND_AZALT;
|
coord.coordPairKind == MccCoordPairKind::COORDS_KIND_AZALT;
|
||||||
coord.y = std::numbers::pi / 2.0 - coord.y;
|
coord.y = std::numbers::pi / 2.0 - coord.y;
|
||||||
ast_err = toICRS(std::move(coord), std::move(time_point), X, Y);
|
ast_err = toICRS(std::move(coord), std::move(time_point), X, Y);
|
||||||
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { // from ICRS RA-DEC
|
} else if (coord.coordPairKind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { // from ICRS RA-DEC
|
||||||
|
coord_t ra, dec, ha, az, alt;
|
||||||
|
eo_t eo;
|
||||||
|
|
||||||
|
ast_err = _astromEngine.greg2jul(time_point, jd);
|
||||||
|
if (!ast_err) {
|
||||||
|
ast_err = icrs2obs(coord.x, coord.y, jd, ra, dec, ha, az, alt, eo);
|
||||||
|
if (!ast_err) {
|
||||||
|
if constexpr (equatorialMount) {
|
||||||
|
coord.coordPairKind == MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
|
coord.x = ha;
|
||||||
|
coord.y = dec;
|
||||||
|
} else if constexpr (altAzMount) {
|
||||||
|
coord.coordPairKind == MccCoordPairKind::COORDS_KIND_AZALT;
|
||||||
|
coord.x = az;
|
||||||
|
coord.y = alt;
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_err = toHardware(std::move(coord), std::move(time_point), X, Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_COORD_PAIR_KIND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pec_err) {
|
if (pec_err) {
|
||||||
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
||||||
return pec_err;
|
return pec_err;
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_PEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,11 +456,11 @@ public:
|
|||||||
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
||||||
return ast_err;
|
return ast_err;
|
||||||
} else {
|
} else {
|
||||||
return std::make_error_code(std::errc::operation_canceled);
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_ASTROMETRY_COMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return MccMountTelemetryAstromTransformErrorCode::ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "mcc_mount_concepts.h"
|
#include "mcc_mount_concepts.h"
|
||||||
|
|
||||||
|
#include "mcc_mount_telemetry.h"
|
||||||
#include "mcc_slew_guiding_model_common.h"
|
#include "mcc_slew_guiding_model_common.h"
|
||||||
|
|
||||||
namespace mcc
|
namespace mcc
|
||||||
@ -165,6 +166,10 @@ protected:
|
|||||||
using hardware_t = decltype(mount_controls.hardware);
|
using hardware_t = decltype(mount_controls.hardware);
|
||||||
using pec_t = decltype(mount_controls.PEC);
|
using pec_t = decltype(mount_controls.PEC);
|
||||||
using telemetry_t = decltype(mount_controls.telemetry);
|
using telemetry_t = decltype(mount_controls.telemetry);
|
||||||
|
static_assert(std::derived_from<telemetry_t, MccMountTelemetry<astrom_engine_t, pec_t, hardware_t,
|
||||||
|
typename telemetry_t::mount_telemetry_data_t>>,
|
||||||
|
"TELEMETRY CLASS MUST BE A DESCENDANT OF 'MccMountTelemetry' ONE!");
|
||||||
|
|
||||||
using tpl_pz_t = decltype(mount_controls.prohibitedZones);
|
using tpl_pz_t = decltype(mount_controls.prohibitedZones);
|
||||||
|
|
||||||
static constexpr size_t Nzones = std::tuple_size_v<tpl_pz_t>;
|
static constexpr size_t Nzones = std::tuple_size_v<tpl_pz_t>;
|
||||||
@ -172,7 +177,7 @@ protected:
|
|||||||
const auto p_mount_controls = &mount_controls;
|
const auto p_mount_controls = &mount_controls;
|
||||||
|
|
||||||
|
|
||||||
_slewFunc = [p_mount_controls](this auto&& self, slew_point_t slew_point) {
|
_slewFunc = [p_mount_controls, this](slew_point_t slew_point) {
|
||||||
auto& astrom_engine = p_mount_controls->astrometryEngine;
|
auto& astrom_engine = p_mount_controls->astrometryEngine;
|
||||||
auto& hardware = p_mount_controls->hardware;
|
auto& hardware = p_mount_controls->hardware;
|
||||||
auto& pec = p_mount_controls->PEC;
|
auto& pec = p_mount_controls->PEC;
|
||||||
@ -192,233 +197,26 @@ protected:
|
|||||||
|
|
||||||
coord_t ra_icrs, dec_icrs;
|
coord_t ra_icrs, dec_icrs;
|
||||||
|
|
||||||
|
// first, compute encoder coordinates
|
||||||
if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_XY) {
|
ax_pos.time_point = astrom_engine_t::timePointNow();
|
||||||
// the pair is interpretated as raw encoder coordinates
|
t_err = telemetry.toHardware(slew_point, ax_pos.time_point, ax_pos.x, ax_pos.y);
|
||||||
if (slew_point.stopAfterSlew) {
|
if (!t_err) {
|
||||||
ax_pos.x = slew_point.x;
|
// setup target sky point
|
||||||
ax_pos.y = slew_point.y;
|
t_err = telemetry.setTarget(slew_point);
|
||||||
} else { // very strange but should be processed! forward to compute ICRS RA AND DEC
|
|
||||||
typename pec_t::pec_result_t pec_res;
|
|
||||||
|
|
||||||
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
|
||||||
if (!pec_err) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
|
||||||
slew_point.x += pec_res.dx;
|
|
||||||
slew_point.y += pec_res.dy;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (slew_point.coordPairKind ==
|
|
||||||
mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { // catalog coordinates
|
|
||||||
if (slew_point.stopAfterSlew) {
|
|
||||||
jd_t jd;
|
|
||||||
coord_t ra_app, dec_app, ha, az, alt;
|
|
||||||
typename astrom_engine_t::eo_t eo;
|
|
||||||
|
|
||||||
logDebug("Input slew coordinates are ICRS RA-DEC: convert it to apparent ...");
|
|
||||||
|
|
||||||
|
|
||||||
ast_err = astrom_engine->greg2jul(astrom_engine_t::timePointNow(), jd);
|
|
||||||
|
|
||||||
if (!ast_err) {
|
|
||||||
ast_err =
|
|
||||||
astrom_engine->icrs2obs(slew_point.x, slew_point.y, jd, ra_app, dec_app, ha, az, alt, eo);
|
|
||||||
|
|
||||||
if (!ast_err) {
|
|
||||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
|
||||||
slew_point.x = ha;
|
|
||||||
slew_point.y = dec_app;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
|
||||||
slew_point.x = az;
|
|
||||||
slew_point.y = alt;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
} else {
|
|
||||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // OK, here one should stop with coordinates converting
|
|
||||||
ra_icrs = slew_point.x;
|
|
||||||
dec_icrs = slew_point.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_RADEC_APP) { // apparent
|
|
||||||
if (slew_point.stopAfterSlew) {
|
|
||||||
jd_t jd;
|
|
||||||
typename astrom_engine_t::eo_t eo;
|
|
||||||
|
|
||||||
logDebug("Input slew coordinates are apparent RA-DEC: convert it to apparent HA-DEC ...");
|
|
||||||
|
|
||||||
ast_err = astrom_engine->greg2jul(astrom_engine_t::timePointNow(), jd);
|
|
||||||
if (!ast_err) {
|
|
||||||
typename astrom_engine_t::sideral_time_t lst;
|
|
||||||
ast_err = astrom_engine->apparentSiderTime(jd, lst, true);
|
|
||||||
|
|
||||||
if (!ast_err) {
|
|
||||||
ast_err = astrom_engine->eqOrigins(jd, eo);
|
|
||||||
if (!ast_err) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
|
||||||
slew_point.x = lst - slew_point.x + eo; // HA = LST - RA_APP + EO
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP) { // apparent
|
|
||||||
if (slew_point.stopAfterSlew) {
|
|
||||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) { // compute encoder coordinates
|
|
||||||
logDebug("Input slew coordinates are apparent HA-DEC: convert it to hardware encoder ones ...");
|
|
||||||
|
|
||||||
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
|
||||||
|
|
||||||
typename pec_t::pec_result_t pec_res;
|
|
||||||
|
|
||||||
// pec_err = pec->reverseCompute(slew_point.x, slew_point.y, pec_res, context.eps,
|
|
||||||
// context.maxIter);
|
|
||||||
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
|
||||||
if (!pec_err) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
|
||||||
slew_point.x -= pec_res.dx;
|
|
||||||
slew_point.y -= pec_res.dy;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
}
|
|
||||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
|
||||||
coord_t az, alt;
|
|
||||||
|
|
||||||
logDebug("Input slew coordinates are apparent HA-DEC: convert it to AZ-ALT ...");
|
|
||||||
|
|
||||||
ast_err = astrom_engine->hadec2azalt(slew_point.x, slew_point.y, az, alt);
|
|
||||||
|
|
||||||
if (!ast_err) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
|
||||||
slew_point.x = az;
|
|
||||||
slew_point.y = alt;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZALT) {
|
|
||||||
if (slew_point.stopAfterSlew) {
|
|
||||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
|
||||||
coord_t ha, dec;
|
|
||||||
|
|
||||||
logDebug("Input slew coordinates are AZ-ALT: convert it to HA-DEC ...");
|
|
||||||
|
|
||||||
ast_err = astrom_engine->azalt2hadec(slew_point.x, slew_point.y, ha, dec);
|
|
||||||
|
|
||||||
if (!ast_err) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
|
||||||
slew_point.x = ha;
|
|
||||||
slew_point.y = dec;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
}
|
|
||||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) { // compute encoder coordinates
|
|
||||||
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
|
||||||
|
|
||||||
logDebug("Input slew coordinates are AZ-ALT: convert it to hardware encoder ones ...");
|
|
||||||
|
|
||||||
typename pec_t::pec_result_t pec_res;
|
|
||||||
|
|
||||||
// pec_err = pec->reverseCompute(slew_point.x, slew_point.y, pec_res, context.eps,
|
|
||||||
// context.maxIter);
|
|
||||||
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
|
||||||
if (!pec_err) {
|
|
||||||
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
|
||||||
slew_point.x -= pec_res.dx;
|
|
||||||
slew_point.y -= pec_res.dy;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZZD) {
|
|
||||||
//
|
|
||||||
// WARNING: it is assumed that coordinates are in radians!
|
|
||||||
//
|
|
||||||
logDebug("Input slew coordinates are AZ-ZD: convert it to AZ-ALT ...");
|
|
||||||
|
|
||||||
slew_point.y = std::numbers::pi / 2.0 - slew_point.y;
|
|
||||||
|
|
||||||
res_err = self(std::move(slew_point));
|
|
||||||
} else {
|
|
||||||
return MccSimpleSlewModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res_err) {
|
if (t_err) {
|
||||||
return res_err;
|
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||||
}
|
logError(std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
||||||
|
return t_err;
|
||||||
if (pec_err) {
|
|
||||||
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
|
||||||
logError(std::format("An PEC error occured: code = {} ({})", pec_err.value(), pec_err.message()));
|
|
||||||
return pec_err;
|
|
||||||
} else {
|
} else {
|
||||||
if constexpr (traits::mcc_formattable<decltype(pec_err)>) {
|
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||||
logError(std::format("An PEC error occured: code = {}", pec_err));
|
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||||
}
|
}
|
||||||
return MccSimpleSlewModelErrorCode::ERROR_PEC_COMP;
|
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ast_err) {
|
|
||||||
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
|
||||||
logError(std::format("An error occured while performing astrometry computations: code = {} ({})",
|
|
||||||
ast_err.value(), ast_err.message()));
|
|
||||||
return ast_err;
|
|
||||||
} else {
|
|
||||||
if constexpr (traits::mcc_formattable<decltype(ast_err)>) {
|
|
||||||
logError(std::format("An error occured while performing astrometry computations: code = {}",
|
|
||||||
ast_err));
|
|
||||||
}
|
|
||||||
return MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// compute ICRS RA and DEC if needed
|
|
||||||
if (!slew_point.stopAfterSlew) {
|
|
||||||
if (slew_point.coordPairKind != mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
|
||||||
jd_t jd;
|
|
||||||
ast_err = astrom_engine.greg2jul(astrom_engine_t::timePointNow(), jd);
|
|
||||||
if (!ast_err) {
|
|
||||||
ast_err = astrom_engine.obs2icrs(slew_point.coordPairKind, slew_point.x, slew_point.y, jd,
|
|
||||||
ra_icrs, dec_icrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ast_err) {
|
|
||||||
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
|
||||||
logError(
|
|
||||||
std::format("An error occured while performing astrometry computations: code = {} ({})",
|
|
||||||
ast_err.value(), ast_err.message()));
|
|
||||||
return ast_err;
|
|
||||||
} else {
|
|
||||||
if constexpr (traits::mcc_formattable<decltype(ast_err)>) {
|
|
||||||
logError(std::format(
|
|
||||||
"An error occured while performing astrometry computations: code = {}", ast_err));
|
|
||||||
}
|
|
||||||
return MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// move mount (it is assumed this is asynchronous operation!!!)
|
// move mount (it is assumed this is asynchronous operation!!!)
|
||||||
typename hardware_t::error_t err = hardware->setPos(ax_pos);
|
typename hardware_t::error_t err = hardware->setPos(ax_pos);
|
||||||
|
|
||||||
@ -434,8 +232,6 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t i_iter = 0;
|
|
||||||
|
|
||||||
|
|
||||||
typename hardware_t::axes_pos_t::time_point_t prev_time_point{};
|
typename hardware_t::axes_pos_t::time_point_t prev_time_point{};
|
||||||
// typename telemetry_t::mount_telemetry_data_t::time_point_t prev_time_point{};
|
// typename telemetry_t::mount_telemetry_data_t::time_point_t prev_time_point{};
|
||||||
@ -446,6 +242,45 @@ protected:
|
|||||||
auto start_poll_tm = std::chrono::steady_clock::now();
|
auto start_poll_tm = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
|
||||||
|
auto iter = telemetry.addCallbackFunc([slew_point = std::move(slew_point), this](auto t_data) {
|
||||||
|
// check prohibited zones
|
||||||
|
|
||||||
|
std::array<bool, Nzones> in_zone_flag;
|
||||||
|
auto t_err = mccCheckInZonePZTuple(*telemetry, p_mount_controls->prohibitedZones, in_zone_flag);
|
||||||
|
|
||||||
|
if (t_err) {
|
||||||
|
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||||
|
logError(
|
||||||
|
std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
||||||
|
return t_err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||||
|
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||||
|
}
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typename telemetry_t::mount_telemetry_data_t::coord_t xr, yr, coord_diff2,
|
||||||
|
adjRad2 = slew_point.adjustCoordDiff * slew_point.adjustCoordDiff;
|
||||||
|
|
||||||
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
|
xr = t_data.tagRA - t_data.mntHA;
|
||||||
|
yr = t_data.tagDEC - t_data.mntDEC;
|
||||||
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
|
xr = t_data.tagAZ - t_data.mntAZ;
|
||||||
|
yr = t_data.tagALT - t_data.mntALT;
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
|
||||||
|
coord_diff2 = xr * xr + yr * yr;
|
||||||
|
|
||||||
|
if (coord_diff2 < adjRad2) { // switch to adjusting mode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// check prohibited zones
|
// check prohibited zones
|
||||||
|
|
||||||
|
|||||||
550
cxx/mcc_slew_model.h.old
Normal file
550
cxx/mcc_slew_model.h.old
Normal file
@ -0,0 +1,550 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
||||||
|
|
||||||
|
|
||||||
|
/* A VERY SIMPLE SLEW MODEL GENERIC IMPLEMENTATION */
|
||||||
|
|
||||||
|
|
||||||
|
#include "mcc_mount_concepts.h"
|
||||||
|
|
||||||
|
#include "mcc_slew_guiding_model_common.h"
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
|
||||||
|
enum class MccSimpleSlewModelErrorCode : int {
|
||||||
|
ERROR_OK,
|
||||||
|
ERROR_UNSUPPORTED_COORD_PAIR,
|
||||||
|
ERROR_IN_PROHIBITED_ZONE,
|
||||||
|
ERROR_ASTROM_COMP,
|
||||||
|
ERROR_TELEMETRY_DATA,
|
||||||
|
ERROR_PEC_COMP,
|
||||||
|
ERROR_HARDWARE_SETPOS,
|
||||||
|
ERROR_HARDWARE_GETPOS,
|
||||||
|
ERROR_SLEW_TIMEOUT
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class is_error_code_enum<mcc::MccSimpleSlewModelErrorCode> : public true_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/* error category definition */
|
||||||
|
|
||||||
|
// error category
|
||||||
|
struct MccSimpleSlewModelCategory : public std::error_category {
|
||||||
|
MccSimpleSlewModelCategory() : std::error_category() {}
|
||||||
|
|
||||||
|
const char* name() const noexcept
|
||||||
|
{
|
||||||
|
return "ADC_GENERIC_DEVICE";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string message(int ec) const
|
||||||
|
{
|
||||||
|
MccSimpleSlewModelErrorCode err = static_cast<MccSimpleSlewModelErrorCode>(ec);
|
||||||
|
|
||||||
|
switch (err) {
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_OK:
|
||||||
|
return "OK";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR:
|
||||||
|
return "slew model: unsupported coordinate pair";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_IN_PROHIBITED_ZONE:
|
||||||
|
return "slew model: position is in prohibited zone";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP:
|
||||||
|
return "slew model: cannot perform astrometrical computations";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA:
|
||||||
|
return "slew model: cannot get telemetry data";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_PEC_COMP:
|
||||||
|
return "slew model: cannot compute PEC corrections";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS:
|
||||||
|
return "slew model: cannot set position";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_HARDWARE_GETPOS:
|
||||||
|
return "slew model: cannot get position";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const MccSimpleSlewModelCategory& get()
|
||||||
|
{
|
||||||
|
static const MccSimpleSlewModelCategory constInst;
|
||||||
|
return constInst;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline std::error_code make_error_code(MccSimpleSlewModelErrorCode ec)
|
||||||
|
{
|
||||||
|
return std::error_code(static_cast<int>(ec), MccSimpleSlewModelCategory::get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING: it is assumed that coordinates are in radians!
|
||||||
|
* but this fact is only used if slew coordinate pair are given as
|
||||||
|
* [azimuth, zenithal distance] (see sources code below)
|
||||||
|
*/
|
||||||
|
|
||||||
|
template <traits::mcc_logger_c LoggerT = MccNullLogger>
|
||||||
|
class MccSimpleSlewModel : public LoggerT
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using LoggerT::logDebug;
|
||||||
|
using LoggerT::logError;
|
||||||
|
using LoggerT::logInfo;
|
||||||
|
using LoggerT::logMessage;
|
||||||
|
using LoggerT::logWarn;
|
||||||
|
|
||||||
|
typedef std::error_code error_t;
|
||||||
|
|
||||||
|
struct slew_point_t : MccCelestialPoint {
|
||||||
|
// target-mount coordinate difference to start adjusting slewing (in radians)
|
||||||
|
coord_t adjustCoordDiff{(double)MccAngle{10.0_degs}};
|
||||||
|
|
||||||
|
// coordinates difference to stop slewing (in radians)
|
||||||
|
coord_t slewPrecision{(double)MccAngle{5.0_arcsecs}};
|
||||||
|
|
||||||
|
// coordinates polling interval in seconds
|
||||||
|
std::chrono::duration<double> coordPollingInterval{0.1};
|
||||||
|
bool stopAfterSlew{false};
|
||||||
|
std::chrono::seconds timeout{3600};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
||||||
|
MccSimpleSlewModel(MOUNT_CONTROLS_T& mount_controls, LoggerCtorArgTs&&... ctor_args)
|
||||||
|
requires(!std::same_as<LoggerT, MccNullLogger>)
|
||||||
|
: LoggerT(std::forward<LoggerCtorArgTs>(ctor_args)...)
|
||||||
|
{
|
||||||
|
logDebug(std::format("Create 'MccSimpleSlewModel' class instance ({})", (void*)this));
|
||||||
|
|
||||||
|
init(mount_controls);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
||||||
|
MccSimpleSlewModel(MOUNT_CONTROLS_T& mount_controls)
|
||||||
|
requires(std::same_as<LoggerT, MccNullLogger>)
|
||||||
|
{
|
||||||
|
init(mount_controls);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~MccSimpleSlewModel()
|
||||||
|
{
|
||||||
|
logDebug(std::format("Delete 'MccSimpleSlewModel' class instance ({})", (void*)this));
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t slew(slew_point_t pars)
|
||||||
|
{
|
||||||
|
error_t res_err = _slewFunc(std::move(pars));
|
||||||
|
|
||||||
|
return res_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::function<error_t(const slew_point_t&)> _slewFunc{};
|
||||||
|
|
||||||
|
void init(auto& mount_controls)
|
||||||
|
{
|
||||||
|
// deduce controls types
|
||||||
|
using astrom_engine_t = decltype(mount_controls.astrometryEngine);
|
||||||
|
using hardware_t = decltype(mount_controls.hardware);
|
||||||
|
using pec_t = decltype(mount_controls.PEC);
|
||||||
|
using telemetry_t = decltype(mount_controls.telemetry);
|
||||||
|
using tpl_pz_t = decltype(mount_controls.prohibitedZones);
|
||||||
|
|
||||||
|
static constexpr size_t Nzones = std::tuple_size_v<tpl_pz_t>;
|
||||||
|
|
||||||
|
const auto p_mount_controls = &mount_controls;
|
||||||
|
|
||||||
|
|
||||||
|
_slewFunc = [p_mount_controls](this auto&& self, slew_point_t slew_point) {
|
||||||
|
auto& astrom_engine = p_mount_controls->astrometryEngine;
|
||||||
|
auto& hardware = p_mount_controls->hardware;
|
||||||
|
auto& pec = p_mount_controls->PEC;
|
||||||
|
auto& telemetry = p_mount_controls->telemetry;
|
||||||
|
|
||||||
|
using coord_t = typename astrom_engine_t::coord_t;
|
||||||
|
using jd_t = typename astrom_engine_t::juldate_t;
|
||||||
|
|
||||||
|
typename hardware_t::axes_pos_t ax_pos;
|
||||||
|
|
||||||
|
error_t res_err;
|
||||||
|
typename astrom_engine_t::error_t ast_err;
|
||||||
|
typename pec_t::error_t pec_err;
|
||||||
|
|
||||||
|
typename telemetry_t::error_t t_err;
|
||||||
|
typename telemetry_t::mount_telemetry_data_t t_data;
|
||||||
|
|
||||||
|
coord_t ra_icrs, dec_icrs;
|
||||||
|
|
||||||
|
|
||||||
|
if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_XY) {
|
||||||
|
// the pair is interpretated as raw encoder coordinates
|
||||||
|
if (slew_point.stopAfterSlew) {
|
||||||
|
ax_pos.x = slew_point.x;
|
||||||
|
ax_pos.y = slew_point.y;
|
||||||
|
} else { // very strange but should be processed! forward to compute ICRS RA AND DEC
|
||||||
|
typename pec_t::pec_result_t pec_res;
|
||||||
|
|
||||||
|
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
||||||
|
if (!pec_err) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
||||||
|
slew_point.x += pec_res.dx;
|
||||||
|
slew_point.y += pec_res.dy;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (slew_point.coordPairKind ==
|
||||||
|
mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { // catalog coordinates
|
||||||
|
if (slew_point.stopAfterSlew) {
|
||||||
|
jd_t jd;
|
||||||
|
coord_t ra_app, dec_app, ha, az, alt;
|
||||||
|
typename astrom_engine_t::eo_t eo;
|
||||||
|
|
||||||
|
logDebug("Input slew coordinates are ICRS RA-DEC: convert it to apparent ...");
|
||||||
|
|
||||||
|
|
||||||
|
ast_err = astrom_engine->greg2jul(astrom_engine_t::timePointNow(), jd);
|
||||||
|
|
||||||
|
if (!ast_err) {
|
||||||
|
ast_err =
|
||||||
|
astrom_engine->icrs2obs(slew_point.x, slew_point.y, jd, ra_app, dec_app, ha, az, alt, eo);
|
||||||
|
|
||||||
|
if (!ast_err) {
|
||||||
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
|
slew_point.x = ha;
|
||||||
|
slew_point.y = dec_app;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
||||||
|
slew_point.x = az;
|
||||||
|
slew_point.y = alt;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // OK, here one should stop with coordinates converting
|
||||||
|
ra_icrs = slew_point.x;
|
||||||
|
dec_icrs = slew_point.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_RADEC_APP) { // apparent
|
||||||
|
if (slew_point.stopAfterSlew) {
|
||||||
|
jd_t jd;
|
||||||
|
typename astrom_engine_t::eo_t eo;
|
||||||
|
|
||||||
|
logDebug("Input slew coordinates are apparent RA-DEC: convert it to apparent HA-DEC ...");
|
||||||
|
|
||||||
|
ast_err = astrom_engine->greg2jul(astrom_engine_t::timePointNow(), jd);
|
||||||
|
if (!ast_err) {
|
||||||
|
typename astrom_engine_t::sideral_time_t lst;
|
||||||
|
ast_err = astrom_engine->apparentSiderTime(jd, lst, true);
|
||||||
|
|
||||||
|
if (!ast_err) {
|
||||||
|
ast_err = astrom_engine->eqOrigins(jd, eo);
|
||||||
|
if (!ast_err) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
|
slew_point.x = lst - slew_point.x + eo; // HA = LST - RA_APP + EO
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP) { // apparent
|
||||||
|
if (slew_point.stopAfterSlew) {
|
||||||
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) { // compute encoder coordinates
|
||||||
|
logDebug("Input slew coordinates are apparent HA-DEC: convert it to hardware encoder ones ...");
|
||||||
|
|
||||||
|
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
||||||
|
|
||||||
|
typename pec_t::pec_result_t pec_res;
|
||||||
|
|
||||||
|
// pec_err = pec->reverseCompute(slew_point.x, slew_point.y, pec_res, context.eps,
|
||||||
|
// context.maxIter);
|
||||||
|
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
||||||
|
if (!pec_err) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
||||||
|
slew_point.x -= pec_res.dx;
|
||||||
|
slew_point.y -= pec_res.dy;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
}
|
||||||
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
|
coord_t az, alt;
|
||||||
|
|
||||||
|
logDebug("Input slew coordinates are apparent HA-DEC: convert it to AZ-ALT ...");
|
||||||
|
|
||||||
|
ast_err = astrom_engine->hadec2azalt(slew_point.x, slew_point.y, az, alt);
|
||||||
|
|
||||||
|
if (!ast_err) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
||||||
|
slew_point.x = az;
|
||||||
|
slew_point.y = alt;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZALT) {
|
||||||
|
if (slew_point.stopAfterSlew) {
|
||||||
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
|
coord_t ha, dec;
|
||||||
|
|
||||||
|
logDebug("Input slew coordinates are AZ-ALT: convert it to HA-DEC ...");
|
||||||
|
|
||||||
|
ast_err = astrom_engine->azalt2hadec(slew_point.x, slew_point.y, ha, dec);
|
||||||
|
|
||||||
|
if (!ast_err) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
|
slew_point.x = ha;
|
||||||
|
slew_point.y = dec;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
}
|
||||||
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) { // compute encoder coordinates
|
||||||
|
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
||||||
|
|
||||||
|
logDebug("Input slew coordinates are AZ-ALT: convert it to hardware encoder ones ...");
|
||||||
|
|
||||||
|
typename pec_t::pec_result_t pec_res;
|
||||||
|
|
||||||
|
// pec_err = pec->reverseCompute(slew_point.x, slew_point.y, pec_res, context.eps,
|
||||||
|
// context.maxIter);
|
||||||
|
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
||||||
|
if (!pec_err) {
|
||||||
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
||||||
|
slew_point.x -= pec_res.dx;
|
||||||
|
slew_point.y -= pec_res.dy;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZZD) {
|
||||||
|
//
|
||||||
|
// WARNING: it is assumed that coordinates are in radians!
|
||||||
|
//
|
||||||
|
logDebug("Input slew coordinates are AZ-ZD: convert it to AZ-ALT ...");
|
||||||
|
|
||||||
|
slew_point.y = std::numbers::pi / 2.0 - slew_point.y;
|
||||||
|
|
||||||
|
res_err = self(std::move(slew_point));
|
||||||
|
} else {
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res_err) {
|
||||||
|
return res_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pec_err) {
|
||||||
|
if constexpr (std::same_as<decltype(pec_err), error_t>) {
|
||||||
|
logError(std::format("An PEC error occured: code = {} ({})", pec_err.value(), pec_err.message()));
|
||||||
|
return pec_err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(pec_err)>) {
|
||||||
|
logError(std::format("An PEC error occured: code = {}", pec_err));
|
||||||
|
}
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_PEC_COMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_err) {
|
||||||
|
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
||||||
|
logError(std::format("An error occured while performing astrometry computations: code = {} ({})",
|
||||||
|
ast_err.value(), ast_err.message()));
|
||||||
|
return ast_err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(ast_err)>) {
|
||||||
|
logError(std::format("An error occured while performing astrometry computations: code = {}",
|
||||||
|
ast_err));
|
||||||
|
}
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute ICRS RA and DEC if needed
|
||||||
|
if (!slew_point.stopAfterSlew) {
|
||||||
|
if (slew_point.coordPairKind != mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||||
|
jd_t jd;
|
||||||
|
ast_err = astrom_engine.greg2jul(astrom_engine_t::timePointNow(), jd);
|
||||||
|
if (!ast_err) {
|
||||||
|
ast_err = astrom_engine.obs2icrs(slew_point.coordPairKind, slew_point.x, slew_point.y, jd,
|
||||||
|
ra_icrs, dec_icrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_err) {
|
||||||
|
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
||||||
|
logError(
|
||||||
|
std::format("An error occured while performing astrometry computations: code = {} ({})",
|
||||||
|
ast_err.value(), ast_err.message()));
|
||||||
|
return ast_err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(ast_err)>) {
|
||||||
|
logError(std::format(
|
||||||
|
"An error occured while performing astrometry computations: code = {}", ast_err));
|
||||||
|
}
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// move mount (it is assumed this is asynchronous operation!!!)
|
||||||
|
typename hardware_t::error_t err = hardware->setPos(ax_pos);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
if constexpr (std::same_as<decltype(err), error_t>) {
|
||||||
|
logError(std::format("An hardware error occured: code = {} ({})", err.value(), err.message()));
|
||||||
|
return err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(err)>) {
|
||||||
|
logError(std::format("An hardware error occured: code = {}", err));
|
||||||
|
}
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t i_iter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
typename hardware_t::axes_pos_t::time_point_t prev_time_point{};
|
||||||
|
// typename telemetry_t::mount_telemetry_data_t::time_point_t prev_time_point{};
|
||||||
|
typename telemetry_t::mount_telemetry_data_t::coord_t xr, yr, coord_diff2,
|
||||||
|
adjRad2 = slew_point.adjustCoordDiff * slew_point.adjustCoordDiff;
|
||||||
|
|
||||||
|
std::array<bool, Nzones> in_zone_flag;
|
||||||
|
auto start_poll_tm = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
// check prohibited zones
|
||||||
|
|
||||||
|
t_err = mccCheckInZonePZTuple(*telemetry, p_mount_controls->prohibitedZones, in_zone_flag);
|
||||||
|
|
||||||
|
// it is assumed here that telemetry data is in actual state!
|
||||||
|
// t_err = telemetry.data(t_data);
|
||||||
|
if (t_err) {
|
||||||
|
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||||
|
logError(
|
||||||
|
std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
||||||
|
return t_err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||||
|
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||||
|
}
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hardware->getPos(ax_pos);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
if constexpr (std::same_as<decltype(err), error_t>) {
|
||||||
|
logError(std::format("An hardware error occured: code = {} ({})", err.value(), err.message()));
|
||||||
|
return err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(err)>) {
|
||||||
|
logError(std::format("An hardware error occured: code = {}", err));
|
||||||
|
}
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_HARDWARE_GETPOS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
|
xr = slew_point.x - t_data.mntHA;
|
||||||
|
yr = slew_point.y - t_data.mntDEC;
|
||||||
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
|
xr = slew_point.x - t_data.mntAZ;
|
||||||
|
yr = slew_point.y - t_data.mntALT;
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
|
||||||
|
coord_diff2 = xr * xr + yr * yr;
|
||||||
|
|
||||||
|
if (coord_diff2 < adjRad2) { // switch to adjusting mode
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (prev_time_point == t_data.time_point) {
|
||||||
|
if (prev_time_point == ax_pos.time_point) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slew_point.stopAfterSlew) { // slew and stop, so mount moving rate must be 0 at the end
|
||||||
|
if (ax_pos.state == hardware_t::hw_state_t::HW_STATE_STOP) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// mount_rate2 = t_data.mntRateX * t_data.mntRateX + t_data.mntRateY * t_data.mntRateY;
|
||||||
|
|
||||||
|
// if (utils::isEqual((double)mount_rate2, 0.0)) {
|
||||||
|
// ++i_iter;
|
||||||
|
// } else {
|
||||||
|
// i_iter = 0;
|
||||||
|
// }
|
||||||
|
} else { // slew and guiding, so mount rate must be near tracking rate at the end
|
||||||
|
if (ax_pos.state == hardware_t::hw_state_t::HW_STATE_TRACK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// xrate = t_data.mntRateX - context.guidingRateX;
|
||||||
|
// yrate = t_data.mntRateY - context.guidingRateY;
|
||||||
|
// mount_rate2 = xrate * xrate + yrate * yrate;
|
||||||
|
|
||||||
|
// if (mount_rate2 <= context.guidingRateEps) {
|
||||||
|
// ++i_iter;
|
||||||
|
// } else {
|
||||||
|
// i_iter = 0;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (i_iter >= context.maxRateCycles) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
prev_time_point = t_data.time_point;
|
||||||
|
|
||||||
|
if ((std::chrono::steady_clock::now() - start_poll_tm) > slew_point.timeout) {
|
||||||
|
logError("Waiting time for completion of slewing expired!");
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_SLEW_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return MccSimpleSlewModelErrorCode::ERROR_OK;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// static_assert(traits::mcc_slew_model_c<>);
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
Loading…
x
Reference in New Issue
Block a user