...
This commit is contained in:
parent
b0421972d1
commit
14f3bb7a83
352
cxx/mcc_guiding_model.h
Normal file
352
cxx/mcc_guiding_model.h
Normal file
@ -0,0 +1,352 @@
|
||||
#pragma once
|
||||
|
||||
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
||||
|
||||
|
||||
/* A VERY SIMPLE GUIDING MODEL GENERIC IMPLEMENTATION */
|
||||
|
||||
|
||||
#include "mcc_mount_concepts.h"
|
||||
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
|
||||
enum class MccSimpleGuidingModelErrorCode : int {
|
||||
ERROR_OK,
|
||||
ERROR_UNSUPPORTED_COORD_PAIR,
|
||||
ERROR_IN_PROHIBITED_ZONE,
|
||||
ERROR_ASTROM_COMP,
|
||||
ERROR_TELEMETRY_DATA,
|
||||
ERROR_PEC_COMP,
|
||||
ERROR_INVALID_CONTEXT_PARAM,
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <>
|
||||
class is_error_code_enum<mcc::MccSimpleGuidingModelErrorCode> : public true_type
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
|
||||
/* error category definition */
|
||||
|
||||
// error category
|
||||
struct MccSimpleGuidingModelCategory : public std::error_category {
|
||||
MccSimpleGuidingModelCategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "ADC_GENERIC_DEVICE";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
MccSimpleGuidingModelErrorCode err = static_cast<MccSimpleGuidingModelErrorCode>(ec);
|
||||
|
||||
switch (err) {
|
||||
case MccSimpleGuidingModelErrorCode::ERROR_OK:
|
||||
return "OK";
|
||||
case MccSimpleGuidingModelErrorCode::ERROR_ASTROM_COMP:
|
||||
return "guiding model: cannot perform astrometrical computations";
|
||||
case MccSimpleGuidingModelErrorCode::ERROR_TELEMETRY_DATA:
|
||||
return "guiding model: cannot get telemetry data";
|
||||
case MccSimpleGuidingModelErrorCode::ERROR_PEC_COMP:
|
||||
return "guiding model: cannot compute PEC corrections";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
static const MccSimpleGuidingModelCategory& get()
|
||||
{
|
||||
static const MccSimpleGuidingModelCategory constInst;
|
||||
return constInst;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline std::error_code make_error_code(MccSimpleGuidingModelErrorCode ec)
|
||||
{
|
||||
return std::error_code(static_cast<int>(ec), MccSimpleGuidingModelCategory::get());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
class MccCelestialPointTrack final
|
||||
{
|
||||
public:
|
||||
template <traits::mcc_astrom_engine_c ASTROM_ENGINE_T, traits::mcc_time_duration_c DT>
|
||||
MccCelestialPointTrack(ASTROM_ENGINE_T& astrom_engine,
|
||||
typename ASTROM_ENGINE_T::juldate_t start,
|
||||
DT step,
|
||||
size_t Npoints)
|
||||
{
|
||||
const auto p_astrom_engine = &astrom_engine;
|
||||
|
||||
_compFunc = []() {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<size_t()> _compFunc;
|
||||
};
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
template <traits::mcc_logger_c LoggerT = MccNullLogger>
|
||||
class MccSimpleGuidingModel : public LoggerT
|
||||
{
|
||||
template <traits::mcc_mount_controls_c T>
|
||||
using coord_t = typename decltype(T::astrometryEngine)::coord_t;
|
||||
|
||||
public:
|
||||
using LoggerT::logDebug;
|
||||
using LoggerT::logError;
|
||||
using LoggerT::logInfo;
|
||||
using LoggerT::logMessage;
|
||||
using LoggerT::logWarn;
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
struct guiding_context_t {
|
||||
double corrThresh{MccAngle("00:00:00.2"_dms)}; // correction threshold
|
||||
std::chrono::duration<double> predictedTrackDuration{10.0}; // 10 seconds
|
||||
std::chrono::duration<double> predictedTrackResolution{0.1}; // 0.1 seconds
|
||||
};
|
||||
|
||||
struct guiding_point_t {
|
||||
typedef double coord_t;
|
||||
|
||||
mcc::MccCoordPairKind coordPairKind{mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||
|
||||
coord_t x, y;
|
||||
};
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls, LoggerCtorArgTs&&... ctor_args)
|
||||
requires(!std::same_as<LoggerT, MccNullLogger>)
|
||||
: LoggerT(std::forward<LoggerCtorArgTs>(ctor_args)...)
|
||||
{
|
||||
logDebug(std::format("Create 'MccSimpleGuidingModel' class instance ({})", (void*)this));
|
||||
|
||||
init(mount_controls);
|
||||
}
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls)
|
||||
requires(std::same_as<LoggerT, MccNullLogger>)
|
||||
{
|
||||
init(mount_controls);
|
||||
}
|
||||
|
||||
virtual ~MccSimpleGuidingModel()
|
||||
{
|
||||
logDebug(std::format("Delete 'MccSimpleGuidingModel' class instance ({})", (void*)this));
|
||||
}
|
||||
|
||||
|
||||
error_t guiding(guiding_point_t guiding_point) {}
|
||||
|
||||
protected:
|
||||
std::function<error_t()> _guidingFunc{};
|
||||
std::atomic_bool _doCorrection{true};
|
||||
|
||||
|
||||
error_t init(auto& mount_controls, guiding_context_t context)
|
||||
{
|
||||
// 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>;
|
||||
|
||||
size_t predicted_Npoints = context.predictedTrackDuration / context.predictedTrackResolution;
|
||||
if (predicted_Npoints == 0) {
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_INVALID_CONTEXT_PARAM;
|
||||
}
|
||||
|
||||
const auto p_mount_controls = &mount_controls;
|
||||
|
||||
_guidingFunc = [p_mount_controls, context = std::move(context), predicted_Npoints](
|
||||
this auto&& self, guiding_point_t guiding_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;
|
||||
jd_t jd;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
// first, compute ICRS coordinates of given guiding point
|
||||
coord_t ra_icrs, dec_icrs;
|
||||
|
||||
const auto p_astrom_engine = &astrom_engine;
|
||||
const auto p_pec = &pec;
|
||||
|
||||
auto predictedPos = [p_astrom_engine, predicted_Npoints, &context, &ra_icrs, &dec_icrs](
|
||||
jd_t start, std::vector<guiding_point_t>& track) {
|
||||
if (track.size() < predicted_Npoints) {
|
||||
track.resize(predicted_Npoints);
|
||||
}
|
||||
|
||||
coord_t ha, ra_app, dec_app, az, alt, eo;
|
||||
typename astrom_engine_t::error_t ast_err;
|
||||
typename pec_t::error_t pec_err;
|
||||
typename pec_t::pec_result_t pec_res;
|
||||
|
||||
for (auto& g_point : track) {
|
||||
ast_err = p_astrom_engine->icrs2obs(ra_icrs, dec_icrs, start, ra_app, dec_app, ha, az, alt, eo);
|
||||
|
||||
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 MccSimpleGuidingModelErrorCode::ERROR_ASTROM_COMP;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) { // use of HA and DEC
|
||||
g_point.coordPairKind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||
g_point.x = ha;
|
||||
g_point.y = dec_app;
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) { // use of Az and Alt
|
||||
g_point.coordPairKind = MccCoordPairKind::COORDS_KIND_AZALT;
|
||||
g_point.x = az;
|
||||
g_point.y = alt;
|
||||
} else {
|
||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||
}
|
||||
|
||||
start.mjd += context.predictedTrackResolution.count() / 86400.0;
|
||||
}
|
||||
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_OK;
|
||||
}; // end of predictedPos lambda
|
||||
|
||||
if (guiding_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_XY) {
|
||||
typename pec_t::pec_result_t pec_res;
|
||||
|
||||
pec_err = pec.compute(guiding_point.x, guiding_point.y, pec_res);
|
||||
|
||||
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 MccSimpleGuidingModelErrorCode::ERROR_PEC_COMP;
|
||||
}
|
||||
}
|
||||
|
||||
guiding_point.x += pec_res.dx; // app HA
|
||||
guiding_point.y += pec_res.dy; // app DEC
|
||||
guiding_point.coordPairKind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||
|
||||
res_err = self(std::move(guiding_point));
|
||||
if (res_err) {
|
||||
return res_err;
|
||||
}
|
||||
} else if (guiding_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP) {
|
||||
} else if (guiding_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_RADEC_APP) {
|
||||
} else if (guiding_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZALT) {
|
||||
} else if (guiding_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZZD) {
|
||||
} else if (guiding_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||
ra_icrs = guiding_point.x;
|
||||
dec_icrs = guiding_point.y;
|
||||
} else {
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||
}
|
||||
|
||||
if (guiding_point.coordPairKind != mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||
ast_err = astrom_engine.greg2jul(std::chrono::system_clock::now(), jd);
|
||||
if (!ast_err) {
|
||||
ast_err = astrom_engine.obs2icrs(guiding_point.coordPairKind, guiding_point.x, guiding_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 MccSimpleGuidingModelErrorCode::ERROR_ASTROM_COMP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
coord_t ha, ra_app, dec_app, az, alt, eo;
|
||||
|
||||
while (true) {
|
||||
// check prohibited zones ...
|
||||
ast_err = astrom_engine.greg2jul(std::chrono::system_clock::now(), jd);
|
||||
ast_err = astrom_engine.icrs2obs(ra_icrs, dec_icrs, jd, ra_app, dec_app, ha, az, alt, eo);
|
||||
|
||||
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 MccSimpleGuidingModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
// compare t_data with computed coordinates ...
|
||||
}
|
||||
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_OK;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
@ -21,6 +21,7 @@ enum class MccMountAstromEngineERFAErrorCode : int {
|
||||
ERROR_INVALID_INPUT_ARG,
|
||||
ERROR_JULDATE_INVALID_YEAR,
|
||||
ERROR_JULDATE_INVALID_MONTH,
|
||||
ERROR_UNSUPPORTED_COORD_PAIR,
|
||||
ERROR_BULLETINA_OUT_OF_RANGE,
|
||||
ERROR_LEAPSECONDS_OUT_OF_RANGE,
|
||||
ERROR_DUBIOUS_YEAR,
|
||||
@ -75,6 +76,8 @@ struct MccMountAstromEngineERFACategory : public std::error_category {
|
||||
return "invalid year number";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_JULDATE_INVALID_MONTH:
|
||||
return "invalid month number";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_UNSUPPORTED_COORD_PAIR:
|
||||
return "unsupported coordinate pair";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_BULLETINA_OUT_OF_RANGE:
|
||||
return "time point is out of range";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_LEAPSECONDS_OUT_OF_RANGE:
|
||||
@ -449,6 +452,63 @@ public:
|
||||
}
|
||||
|
||||
|
||||
error_t obs2icrs(MccCoordPairKind coord_kind, coord_t x, coord_t y, juldate_t juldate, coord_t ra, coord_t dec)
|
||||
{
|
||||
std::lock_guard lock{_stateMutex};
|
||||
|
||||
auto dut1 = _currentState._bulletinA.DUT1(juldate.mjd);
|
||||
|
||||
if (!dut1.has_value()) {
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
auto pol_pos = _currentState._bulletinA.polarCoords(juldate.mjd);
|
||||
if (!pol_pos.has_value()) {
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
}
|
||||
const auto arcsec2rad = std::numbers::pi / 180 / 3600;
|
||||
pol_pos->x *= arcsec2rad;
|
||||
pol_pos->y *= arcsec2rad;
|
||||
|
||||
std::string type;
|
||||
switch (coord_kind) {
|
||||
case mcc::MccCoordPairKind::COORDS_KIND_AZZD:
|
||||
type = "A";
|
||||
break;
|
||||
case mcc::MccCoordPairKind::COORDS_KIND_AZALT:
|
||||
y = std::numbers::pi / 2.0 - y; // altitude to zenithal distance
|
||||
type = "A";
|
||||
break;
|
||||
case mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP:
|
||||
type = "H";
|
||||
break;
|
||||
case mcc::MccCoordPairKind::COORDS_KIND_RADEC_APP:
|
||||
type = "R";
|
||||
break;
|
||||
default:
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||
}
|
||||
|
||||
double ra_icrs, dec_icrs;
|
||||
|
||||
int ret = eraAtoc13(type.c_str(), x, y, juldate.MJD0, juldate.mjd, dut1->count(), _currentState.lon,
|
||||
_currentState.lat, _currentState.elev, pol_pos->x, pol_pos->y, _currentState.meteo.pressure,
|
||||
_currentState.meteo.temperature, _currentState.meteo.humidity, _currentState.wavelength,
|
||||
&ra_icrs, &dec_icrs);
|
||||
|
||||
if (ret == 1) {
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_DUBIOUS_YEAR;
|
||||
} else if (ret == -1) {
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_UNACCEPTABLE_DATE;
|
||||
}
|
||||
|
||||
ra = ra_icrs;
|
||||
dec = dec_icrs;
|
||||
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
error_t hadec2azalt(coord_t ha, coord_t dec, coord_t& az, coord_t& alt)
|
||||
{
|
||||
std::lock_guard lock{_stateMutex};
|
||||
|
||||
@ -127,6 +127,18 @@ concept mcc_astrom_engine_c = requires(T t, const T t_const) {
|
||||
std::declval<typename T::eo_t&>())
|
||||
} -> std::same_as<typename T::error_t>;
|
||||
|
||||
// observed place to ICRS RA and DEC: obs2icrs(type, x, y, jd, ra_icrs, dec_icrs)
|
||||
// (x,y) = (AZ, ZD) if type = MccCoordPairKind::COORDS_KIND_AZZD
|
||||
// (x,y) = (AZ, ALT) if type = MccCoordPairKind::COORDS_KIND_AZALT
|
||||
// (x,y) = (HA, DEC) if type = MccCoordPairKind::COORDS_KIND_HADEC_APP
|
||||
// (x,y) = (RA, DEC) if type = MccCoordPairKind::COORDS_KIND_RADEC_APP
|
||||
{
|
||||
t.obs2icrs(std::declval<MccCoordPairKind>(), std::declval<typename T::coord_t>(),
|
||||
std::declval<typename T::coord_t>(), std::declval<typename T::juldate_t>(),
|
||||
std::declval<typename T::coord_t&>(), std::declval<typename T::coord_t&>())
|
||||
} -> std::same_as<typename T::error_t>;
|
||||
|
||||
|
||||
// compute hour angle and declination from azimuth and altitude: hadec2azalt(ha, dec, az, alt)
|
||||
{
|
||||
t.hadec2azalt(std::declval<typename T::coord_t>(), std::declval<typename T::coord_t>(),
|
||||
|
||||
@ -15,6 +15,7 @@ namespace mcc
|
||||
|
||||
enum class MccSimpleSlewModelErrorCode : int {
|
||||
ERROR_OK,
|
||||
ERROR_UNSUPPORTED_COORD_PAIR,
|
||||
ERROR_IN_PROHIBITED_ZONE,
|
||||
ERROR_ASTROM_COMP,
|
||||
ERROR_TELEMETRY_DATA,
|
||||
@ -96,19 +97,19 @@ inline std::error_code make_error_code(MccSimpleSlewModelErrorCode ec)
|
||||
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;
|
||||
|
||||
public:
|
||||
typedef std::error_code error_t;
|
||||
|
||||
struct slew_params_t {
|
||||
typedef mcc::MccAngle coord_t;
|
||||
|
||||
mcc::MccCoordPairKind coordPairKind{mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP};
|
||||
mcc::MccCoordPairKind coordPairKind{mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||
|
||||
coord_t x{0.0};
|
||||
coord_t y{0.0};
|
||||
@ -371,6 +372,8 @@ protected:
|
||||
slew_pars.y = std::numbers::pi / 2.0 - slew_pars.y;
|
||||
|
||||
res_err = self(std::move(slew_pars));
|
||||
} else {
|
||||
return MccSimpleSlewModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||
}
|
||||
|
||||
if (res_err) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user