...
This commit is contained in:
@@ -139,21 +139,29 @@ public:
|
||||
|
||||
using guiding_point_t = MccSlewAndGuidingPoint;
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls, LoggerCtorArgTs&&... ctor_args)
|
||||
template <traits::mcc_mount_telemetry_c TELEMETRY_T,
|
||||
traits::mcc_mount_hardware_c HARDWARE_T,
|
||||
traits::mcc_tuple_c PZ_T,
|
||||
typename... LoggerCtorArgTs>
|
||||
MccSimpleGuidingModel(TELEMETRY_T& telemetry,
|
||||
HARDWARE_T& hardware,
|
||||
PZ_T& prohibited_zone,
|
||||
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);
|
||||
init(telemetry, hardware, prohibited_zone);
|
||||
}
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls)
|
||||
template <traits::mcc_mount_telemetry_c TELEMETRY_T,
|
||||
traits::mcc_mount_hardware_c HARDWARE_T,
|
||||
traits::mcc_tuple_c PZ_T>
|
||||
MccSimpleGuidingModel(TELEMETRY_T& telemetry, HARDWARE_T& hardware, PZ_T& prohibited_zone)
|
||||
requires(std::same_as<LoggerT, MccNullLogger>)
|
||||
{
|
||||
init(mount_controls);
|
||||
init(telemetry, hardware, prohibited_zone);
|
||||
}
|
||||
|
||||
virtual ~MccSimpleGuidingModel()
|
||||
@@ -177,23 +185,24 @@ protected:
|
||||
|
||||
|
||||
|
||||
error_t init(auto& mount_controls)
|
||||
error_t init(auto& telemetry, auto& hardware, auto& prohibited_zones)
|
||||
{
|
||||
// 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);
|
||||
// deduce controls types
|
||||
using hardware_t = decltype(hardware);
|
||||
using telemetry_t = decltype(telemetry);
|
||||
static_assert(traits::mcc_mount_default_telemetry_c<telemetry_t>,
|
||||
"TELEMETRY CLASS MUST BE A DESCENDANT OF 'MccMountTelemetry'!");
|
||||
|
||||
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 astrom_engine_t = typename telemetry_t::astrom_engine_t;
|
||||
|
||||
using tpl_pz_t = decltype(mount_controls.prohibitedZones);
|
||||
static constexpr size_t Nzones = std::tuple_size_v<decltype(prohibited_zones)>;
|
||||
|
||||
const auto p_mount_controls = &mount_controls;
|
||||
const auto p_telemetry = &telemetry;
|
||||
const auto p_hardware = &hardware;
|
||||
const auto p_prohibited_zones = &prohibited_zones;
|
||||
|
||||
_guidingFunc = [p_mount_controls, this](guiding_point_t guiding_point) {
|
||||
_guidingFunc = [p_telemetry, p_hardware, p_prohibited_zones, this](guiding_point_t guiding_point) {
|
||||
_stopRequested = false;
|
||||
|
||||
if (guiding_point.correctionRange[0] >= guiding_point.correctionRange[1]) {
|
||||
@@ -203,19 +212,14 @@ protected:
|
||||
auto low_corr_limit = guiding_point.correctionRange[0] * guiding_point.correctionRange[0];
|
||||
auto high_corr_limit = guiding_point.correctionRange[1] * guiding_point.correctionRange[1];
|
||||
|
||||
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;
|
||||
// using coord_t = typename astrom_engine_t::coord_t;
|
||||
// using jd_t = typename astrom_engine_t::juldate_t;
|
||||
// jd_t jd;
|
||||
|
||||
|
||||
error_t res_err;
|
||||
typename astrom_engine_t::error_t ast_err;
|
||||
typename pec_t::error_t pec_err;
|
||||
// typename pec_t::error_t pec_err;
|
||||
|
||||
typename telemetry_t::error_t t_err;
|
||||
typename telemetry_t::mount_telemetry_data_t t_data;
|
||||
@@ -225,7 +229,7 @@ protected:
|
||||
|
||||
ax_pos.moving_type = hardware_t::hw_moving_type_t::HW_MOVE_GUIDING;
|
||||
|
||||
t_err = telemetry.setTarget(guiding_point);
|
||||
t_err = p_telemetry->setTarget(guiding_point);
|
||||
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()));
|
||||
@@ -238,7 +242,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
std::array<bool, std::tuple_size_v<tpl_pz_t>> in_zone_flag;
|
||||
std::array<bool, Nzones> in_zone_flag;
|
||||
|
||||
while (true) {
|
||||
if (_stopRequested) {
|
||||
@@ -249,10 +253,13 @@ protected:
|
||||
|
||||
|
||||
// suspend the thread here until telemetry data is updated
|
||||
t_err = telemetry.waitForUpdatedData(t_data, guiding_point.telemetryUpdateTimeout);
|
||||
t_err = p_telemetry->waitForUpdatedData(t_data, guiding_point.telemetryUpdateTimeout);
|
||||
|
||||
ax_pos.x = t_data.mntPosX;
|
||||
ax_pos.y = t_data.mntPosY;
|
||||
|
||||
// check prohibited zones ...
|
||||
if (mccCheckInZonePZTuple(t_data, p_mount_controls->prohibitedZones, in_zone_flag)) {
|
||||
if (mccCheckInZonePZTuple(t_data, *p_prohibited_zones, in_zone_flag)) {
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_IN_PROHIBITED_ZONE;
|
||||
};
|
||||
|
||||
@@ -279,9 +286,13 @@ protected:
|
||||
|
||||
// compare t_data with computed coordinates ...
|
||||
if (_doCorrection) {
|
||||
auto coord_diff = telemetry.targetToMountDiff();
|
||||
auto coord_diff = p_telemetry->targetToMountDiff();
|
||||
|
||||
if (coord_diff.r2 < low_corr_limit) {
|
||||
logWarn(
|
||||
std::format("guiding model: the 'mount-target' square of difference is less than the limit "
|
||||
"(diff = {}; lim = {}). Do not perfrom the corrections!",
|
||||
(double)coord_diff.r2, (double)high_corr_limit));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -294,22 +305,14 @@ protected:
|
||||
}
|
||||
|
||||
// do correction
|
||||
// current celestial position of target is already computed for current time point
|
||||
// so one needs only correct apparent coordinates for PEC corrections
|
||||
ax_pos.time_point = t_data.time_point;
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
ax_pos.x = t_data.tagHA - t_data.pecX;
|
||||
ax_pos.y = t_data.tagDEC - t_data.pecY;
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||
ax_pos.x = t_data.tagAZ - t_data.pecX;
|
||||
ax_pos.y = t_data.tagALT - t_data.pecY;
|
||||
} else {
|
||||
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||
ax_pos.x += coord_diff.xdiff;
|
||||
if (guiding_point.dualAxisGuiding) {
|
||||
ax_pos.y += coord_diff.ydiff;
|
||||
}
|
||||
|
||||
|
||||
// asynchronous operation!
|
||||
auto err = hardware.setPos(ax_pos);
|
||||
auto err = p_hardware->setPos(ax_pos);
|
||||
if (err) {
|
||||
if constexpr (std::same_as<decltype(err), error_t>) {
|
||||
logError(
|
||||
|
||||
Reference in New Issue
Block a user