125 lines
3.2 KiB
C++
125 lines
3.2 KiB
C++
#pragma once
|
|
|
|
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
|
|
|
|
|
/* MOUNT TELEMETRY OBJECT CONCEPT AND POSSIBLE IMPLEMENTATION */
|
|
|
|
#include <chrono>
|
|
#include <mutex>
|
|
|
|
// #include "mcc_mount_config.h"
|
|
#include "mcc_mount_concepts.h"
|
|
|
|
namespace mcc
|
|
{
|
|
|
|
|
|
// namespace traits
|
|
// {
|
|
|
|
// template <typename T>
|
|
// concept mcc_mount_telemetry_c = requires(T t, const T t_const) {
|
|
// typename T::error_t;
|
|
// typename T::mount_telemetry_data_t;
|
|
|
|
// { t_const.errorString(std::declval<typename T::error_t>()) } -> mcc_formattable;
|
|
|
|
// { t.update() } -> std::same_as<typename T::error_t>;
|
|
|
|
// { t_const.data() } -> std::same_as<typename T::mount_telemetry_data_t>;
|
|
// };
|
|
|
|
// } // namespace traits
|
|
|
|
|
|
class MccMountTelemetry
|
|
{
|
|
public:
|
|
// 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;
|
|
|
|
// 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)
|
|
|
|
// 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 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;
|
|
|
|
// 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
|
|
mnt_coord_t mntPosX, mntPosY;
|
|
mnt_speed_t mntSpeedX, mntSpeedY;
|
|
|
|
// current refraction coefficients
|
|
refr_coeff_t currRefrCoeffs;
|
|
// current refraction correction (for tagZD)
|
|
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;
|
|
};
|
|
|
|
template <MccMountType MOUNT_TYPE>
|
|
MccMountTelemetry(MccMountConfig<MOUNT_TYPE>& mount_config)
|
|
{
|
|
// to be sure that mount_config is captured by reference
|
|
const auto config_ptr = &mount_config;
|
|
|
|
_updateImpl = [config_ptr, this]() {
|
|
mount_telemetry_data_t current_data;
|
|
|
|
// computing ...
|
|
|
|
|
|
std::lock_guard lock{_updateMutex};
|
|
|
|
_data = current_data;
|
|
};
|
|
}
|
|
|
|
virtual ~MccMountTelemetry() = default;
|
|
|
|
// update current data method
|
|
void update()
|
|
{
|
|
_updateImpl();
|
|
}
|
|
|
|
mount_telemetry_data_t data(this auto&& self)
|
|
{
|
|
using self_t = decltype(self);
|
|
|
|
std::lock_guard lock{std::forward<self_t>(self)._updateMutex};
|
|
|
|
return std::move(std::forward<self_t>(self)._data);
|
|
}
|
|
|
|
|
|
protected:
|
|
mount_telemetry_data_t _data{};
|
|
|
|
std::function<void()> _updateImpl{};
|
|
|
|
std::mutex _updateMutex;
|
|
};
|
|
|
|
} // namespace mcc
|