...
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
/* MOUNT TELEMETRY OBJECT CONCEPT AND POSSIBLE IMPLEMENTATION */
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
// #include "mcc_mount_config.h"
|
||||
@@ -32,73 +32,166 @@ namespace mcc
|
||||
|
||||
// } // namespace traits
|
||||
|
||||
|
||||
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T,
|
||||
traits::mcc_mount_pec_c PEC_T,
|
||||
traits::mcc_mount_hardware_c HARDWARE_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 };
|
||||
|
||||
// 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 astrom_engine_t::coord_t, typename pec_t::coord_t>,
|
||||
"ASTROMETRY ENGINE COORDINATE TYPE MUST BE CONVERTIBLE TO PEC ONE!");
|
||||
|
||||
static_assert(std::same_as<typename astrom_engine_t::time_point_t, typename hardware_t::time_point_t>,
|
||||
"TIME-POINT TYPE IN ASTROMETRY ENGINE AND HARDWARE MUST BE THE SAME!");
|
||||
|
||||
// mount current telemetry data: time, position and related quantities
|
||||
struct mount_telemetry_data_t {
|
||||
typedef double mnt_coord_t;
|
||||
typedef double mnt_speed_t;
|
||||
typedef double time_point_t;
|
||||
typedef std::vector<double> refr_coeff_t;
|
||||
typedef astrom_engine_t::coord_t mnt_coord_t;
|
||||
// typedef astrom_engine_t::coord_t mnt_speed_t;
|
||||
|
||||
// time-related
|
||||
std::chrono::system_clock::time_point utc;
|
||||
time_point_t mjd; // modified Julian date
|
||||
time_point_t ut1;
|
||||
time_point_t tt;
|
||||
time_point_t siderTime; // sideral time (in radians)
|
||||
typename astrom_engine_t::time_point_t utc; // time point of measurements, UTC
|
||||
typename astrom_engine_t::juldate_t jd; // Julian date
|
||||
typename astrom_engine_t::sideral_time_t siderTime; // local apperant sideral time
|
||||
// astrom_engine_t::time_point_t ut1; // Universal time
|
||||
// astrom_engine_t::time_point_t tt; // Terrestial time
|
||||
|
||||
// apparent target (user-input) current coordinates (in radians)
|
||||
mnt_coord_t tagRA, tagDEC;
|
||||
mnt_coord_t tagHA;
|
||||
mnt_coord_t tagAZ, tagZD;
|
||||
mnt_coord_t tagAZ, tagALT;
|
||||
mnt_coord_t tagPA; // paralactic angle
|
||||
|
||||
// encoder-measured current mount coordinates (in radians)
|
||||
mnt_coord_t mntRA, mntDEC;
|
||||
mnt_coord_t mntHA;
|
||||
mnt_coord_t mntAZ, mntZD;
|
||||
mnt_coord_t mntPA;
|
||||
mnt_coord_t mntAZ, mntALT;
|
||||
typename astrom_engine_t::pa_t mntPA;
|
||||
|
||||
// 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 - ZD for horizontal-type one
|
||||
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
||||
mnt_coord_t mntPosX, mntPosY;
|
||||
mnt_speed_t mntSpeedX, mntSpeedY;
|
||||
// mnt_speed_t mntSpeedX, mntSpeedY;
|
||||
|
||||
// current refraction coefficients
|
||||
refr_coeff_t currRefrCoeffs;
|
||||
// current refraction correction (for tagZD)
|
||||
typename pec_t::pec_result_t currRefrCoeffs;
|
||||
// current refraction correction (for mntALT)
|
||||
mnt_coord_t currRefr;
|
||||
|
||||
// PCS (pointing correction system) corrections
|
||||
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ZD for horizontal-type one
|
||||
mnt_coord_t pcsX, pcsY;
|
||||
// PEC (pointing error correction):
|
||||
// X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ALT for horizontal-type one
|
||||
mnt_coord_t pecX, pecY;
|
||||
};
|
||||
|
||||
template <MccMountType MOUNT_TYPE>
|
||||
MccMountTelemetry(MccMountConfig<MOUNT_TYPE>& mount_config)
|
||||
MccMountTelemetry(astrom_engine_t& astrom_engine, pec_t& pec, hardware_t& hardware)
|
||||
{
|
||||
// to be sure that mount_config is captured by reference
|
||||
const auto config_ptr = &mount_config;
|
||||
// to be sure that arguments are captured by reference
|
||||
const auto astrom_engine_ptr = &astrom_engine;
|
||||
const auto pec_ptr = &pec;
|
||||
const auto hardware_ptr = &hardware;
|
||||
|
||||
_updateImpl = [config_ptr, this]() {
|
||||
_updateImpl = [astrom_engine_ptr, pec_ptr, hardware_ptr, this]() {
|
||||
mount_telemetry_data_t current_data;
|
||||
|
||||
// computing ...
|
||||
|
||||
typename hardware_t::axes_pos_t ax_pos;
|
||||
|
||||
auto err = hardware_ptr->getPos(ax_pos);
|
||||
if (err) {
|
||||
// logging?!!!
|
||||
return TEL_ERROR_HARDWARE;
|
||||
}
|
||||
|
||||
_data.utc = ax_pos.time_point;
|
||||
_data.mntPosX = ax_pos.x;
|
||||
_data.mntPosY = ax_pos.y;
|
||||
|
||||
// compute Julian date
|
||||
auto ast_err = astrom_engine_ptr->greg2jul(_data.utc, _data.jd);
|
||||
if (ast_err) {
|
||||
return TEL_ERROR_ASTROMETRY_COMP;
|
||||
}
|
||||
|
||||
// compute local apparent sideral time
|
||||
ast_err = astrom_engine_ptr->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 = astrom_engine_ptr->eqOrigins(_data.jd, eo);
|
||||
if (ast_err) {
|
||||
return TEL_ERROR_ASTROMETRY_COMP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
typename pec_t::pec_result_t pec_res;
|
||||
pec_res = pec_ptr->compute(ax_pos.x, ax_pos.y);
|
||||
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
_data.mntHA = pec_res.x + ax_pos.x;
|
||||
_data.mntDEC = pec_res.y + ax_pos.y;
|
||||
|
||||
ast_err = astrom_engine_ptr->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 = pec_res.x + ax_pos.x;
|
||||
_data.mntALT = pec_res.y + ax_pos.x;
|
||||
|
||||
ast_err = astrom_engine_ptr->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 = astrom_engine_ptr->hadec2pa(_data.mntHA, _data.mntDEC, _data.mntPA);
|
||||
if (ast_err) {
|
||||
return TEL_ERROR_ASTROMETRY_COMP;
|
||||
}
|
||||
|
||||
ast_err = astrom_engine_ptr->refraction(_data.currRefrCoeffs);
|
||||
if (ast_err) {
|
||||
return TEL_ERROR_ASTROMETRY_COMP;
|
||||
}
|
||||
|
||||
ast_err = astrom_engine_ptr->refractCorrection(_data.mntALT, _data.currRefrCoeffs, _data.currRefr);
|
||||
if (ast_err) {
|
||||
return TEL_ERROR_ASTROMETRY_COMP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::lock_guard lock{_updateMutex};
|
||||
|
||||
_data = current_data;
|
||||
_data = std::move(current_data);
|
||||
};
|
||||
}
|
||||
|
||||
virtual ~MccMountTelemetry() = default;
|
||||
|
||||
// update current data method
|
||||
void update()
|
||||
error_t update()
|
||||
{
|
||||
_updateImpl();
|
||||
}
|
||||
@@ -116,7 +209,7 @@ public:
|
||||
protected:
|
||||
mount_telemetry_data_t _data{};
|
||||
|
||||
std::function<void()> _updateImpl{};
|
||||
std::function<error_t()> _updateImpl{};
|
||||
|
||||
std::mutex _updateMutex;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user