...
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "mcc_mount_concepts.h"
|
||||
|
||||
#include "mcc_mount_telemetry.h"
|
||||
#include "mcc_slew_guiding_model_common.h"
|
||||
|
||||
namespace mcc
|
||||
@@ -165,6 +166,10 @@ protected:
|
||||
using hardware_t = decltype(mount_controls.hardware);
|
||||
using pec_t = decltype(mount_controls.PEC);
|
||||
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);
|
||||
|
||||
static constexpr size_t Nzones = std::tuple_size_v<tpl_pz_t>;
|
||||
@@ -172,7 +177,7 @@ protected:
|
||||
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& hardware = p_mount_controls->hardware;
|
||||
auto& pec = p_mount_controls->PEC;
|
||||
@@ -192,233 +197,26 @@ protected:
|
||||
|
||||
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;
|
||||
// first, compute encoder coordinates
|
||||
ax_pos.time_point = astrom_engine_t::timePointNow();
|
||||
t_err = telemetry.toHardware(slew_point, ax_pos.time_point, ax_pos.x, ax_pos.y);
|
||||
if (!t_err) {
|
||||
// setup target sky point
|
||||
t_err = telemetry.setTarget(slew_point);
|
||||
}
|
||||
|
||||
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;
|
||||
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(pec_err)>) {
|
||||
logError(std::format("An PEC error occured: code = {}", pec_err));
|
||||
if constexpr (traits::mcc_formattable<decltype(t_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!!!)
|
||||
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 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 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) {
|
||||
// check prohibited zones
|
||||
|
||||
|
||||
Reference in New Issue
Block a user