...
This commit is contained in:
@@ -124,21 +124,30 @@ public:
|
||||
using slew_point_t = MccSlewAndGuidingPoint;
|
||||
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
||||
MccSimpleSlewModel(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, // std::tuple of prohibited zones
|
||||
typename... LoggerCtorArgTs>
|
||||
MccSimpleSlewModel(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 'MccSimpleSlewModel' class instance ({})", (void*)this));
|
||||
|
||||
init(mount_controls);
|
||||
init(telemetry, hardware, prohibited_zone);
|
||||
}
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
||||
MccSimpleSlewModel(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 // std::tuple of prohibited zones
|
||||
>
|
||||
MccSimpleSlewModel(TELEMETRY_T& telemetry, HARDWARE_T& hardware, PZ_T& prohibited_zone)
|
||||
requires(std::same_as<LoggerT, MccNullLogger>)
|
||||
{
|
||||
init(mount_controls);
|
||||
init(telemetry, hardware, prohibited_zone);
|
||||
}
|
||||
|
||||
MccSimpleSlewModel(MccSimpleSlewModel&&) = default;
|
||||
@@ -169,56 +178,43 @@ protected:
|
||||
std::atomic_bool _stopRequested{false};
|
||||
std::function<error_t(const slew_point_t&)> _slewFunc{};
|
||||
|
||||
void init(auto& mount_controls)
|
||||
void 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);
|
||||
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 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'!");
|
||||
|
||||
using tpl_pz_t = decltype(mount_controls.prohibitedZones);
|
||||
using astrom_engine_t = typename telemetry_t::astrom_engine_t;
|
||||
|
||||
static constexpr size_t Nzones = std::tuple_size_v<tpl_pz_t>;
|
||||
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;
|
||||
|
||||
|
||||
_slewFunc = [p_mount_controls, this](slew_point_t slew_point) {
|
||||
_slewFunc = [p_telemetry, p_hardware, p_prohibited_zones, this](slew_point_t slew_point) {
|
||||
_stopRequested = false;
|
||||
|
||||
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;
|
||||
|
||||
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 astrom_engine_t::error_t ast_err;
|
||||
|
||||
typename telemetry_t::error_t t_err;
|
||||
typename telemetry_t::mount_telemetry_data_t t_data;
|
||||
|
||||
coord_t ra_icrs, dec_icrs;
|
||||
|
||||
if (slew_point.withinToleranceCycleNumber == 0) {
|
||||
slew_point.withinToleranceCycleNumber = MccSlewAndGuidingPoint::defaultWithinToleranceCycleNumber;
|
||||
}
|
||||
|
||||
// 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);
|
||||
t_err = p_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);
|
||||
t_err = p_telemetry->setTarget(slew_point);
|
||||
}
|
||||
|
||||
if (t_err) {
|
||||
@@ -237,7 +233,7 @@ protected:
|
||||
ax_pos.xrate = slew_point.slewXRate;
|
||||
ax_pos.yrate = slew_point.slewYRate;
|
||||
ax_pos.moving_type = hardware_t::hw_moving_type_t::HW_MOVE_SLEWING;
|
||||
typename hardware_t::error_t hw_err = hardware->setPos(ax_pos);
|
||||
typename hardware_t::error_t hw_err = p_hardware->setPos(ax_pos);
|
||||
|
||||
if (hw_err) {
|
||||
if constexpr (std::same_as<decltype(hw_err), error_t>) {
|
||||
@@ -260,9 +256,10 @@ protected:
|
||||
adj_ax_pos.yrate = slew_point.adjustYRate;
|
||||
adj_ax_pos.moving_type = hardware_t::hw_moving_type_t::HW_MOVE_ADJUSTING;
|
||||
|
||||
typename telemetry_t::mount_telemetry_data_t::coord_t xr, yr, coord_diff2,
|
||||
adj_rad2 = slew_point.adjustCoordDiff * slew_point.adjustCoordDiff,
|
||||
tol_rad2 = slew_point.slewToleranceRadius * slew_point.slewToleranceRadius;
|
||||
typename telemetry_t::mount_telemetry_data_t::coord_t adj_rad2 = slew_point.adjustCoordDiff *
|
||||
slew_point.adjustCoordDiff,
|
||||
tol_rad2 = slew_point.slewToleranceRadius *
|
||||
slew_point.slewToleranceRadius;
|
||||
|
||||
std::array<bool, Nzones> in_zone_flag;
|
||||
|
||||
@@ -271,34 +268,34 @@ protected:
|
||||
bool in_adj_mode = false;
|
||||
|
||||
// compute new hardware coordinate of target
|
||||
auto compute_new_coord = [](auto const& t_data, typename hardware_t::axes_pos_t& hw_pos) {
|
||||
// current celestial position of target is already computed for given time point
|
||||
// so one needs only correct apparent coordinates for PEC corrections
|
||||
hw_pos.time_point = t_data.time_point;
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
hw_pos.x = t_data.tagHA - t_data.pecX;
|
||||
hw_pos.y = t_data.tagDEC - t_data.pecY;
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||
hw_pos.x = t_data.tagAZ - t_data.pecX;
|
||||
hw_pos.y = t_data.tagALT - t_data.pecY;
|
||||
} else {
|
||||
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||
}
|
||||
};
|
||||
// auto compute_new_coord = [](auto const& t_data, typename hardware_t::axes_pos_t& hw_pos) {
|
||||
// // current celestial position of target is already computed for given time point
|
||||
// // so one needs only correct apparent coordinates for PEC corrections
|
||||
// hw_pos.time_point = t_data.time_point;
|
||||
// if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
// hw_pos.x = t_data.tagHA - t_data.pecX;
|
||||
// hw_pos.y = t_data.tagDEC - t_data.pecY;
|
||||
// } else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||
// hw_pos.x = t_data.tagAZ - t_data.pecX;
|
||||
// hw_pos.y = t_data.tagALT - t_data.pecY;
|
||||
// } else {
|
||||
// static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||
// }
|
||||
// };
|
||||
|
||||
auto cycle_func = [&](auto t_data) mutable {
|
||||
auto cycle_func = [&](auto& t_data) mutable {
|
||||
if (_stopRequested) {
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_SLEW_STOPPED;
|
||||
}
|
||||
|
||||
// check for prohibited zones
|
||||
if (mccCheckInZonePZTuple(t_data, p_mount_controls->prohibitedZones, in_zone_flag)) {
|
||||
if (mccCheckInZonePZTuple(t_data, *p_prohibited_zones, in_zone_flag)) {
|
||||
return MccSimpleSlewModelErrorCode::ERROR_IN_PROHIBITED_ZONE;
|
||||
};
|
||||
|
||||
|
||||
// t_data was updated in caller!!!
|
||||
auto coord_diff = telemetry.targetToMountDiff();
|
||||
auto coord_diff = p_telemetry->targetToMountDiff();
|
||||
|
||||
if (_stopRequested) {
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_SLEW_STOPPED;
|
||||
@@ -307,9 +304,13 @@ protected:
|
||||
if (coord_diff.r2 < adj_rad2) { // adjusting mode
|
||||
in_adj_mode = true;
|
||||
|
||||
compute_new_coord(t_data, adj_ax_pos);
|
||||
// compute_new_coord(t_data, adj_ax_pos);
|
||||
|
||||
hw_err = hardware->setPos(adj_ax_pos);
|
||||
adj_ax_pos.time_point = t_data.time_point;
|
||||
adj_ax_pos.x += coord_diff.xdiff;
|
||||
adj_ax_pos.y += coord_diff.ydiff;
|
||||
|
||||
hw_err = p_hardware->setPos(adj_ax_pos);
|
||||
|
||||
if (!hw_err) {
|
||||
++i_adj_cycle;
|
||||
@@ -343,12 +344,26 @@ protected:
|
||||
|
||||
} else { // continue to slewing
|
||||
if (in_adj_mode) { // ?!!!!!!!!!!!!! slew again?!!!
|
||||
logWarn(std::format(
|
||||
"The slewing is in adjusting mode but computed target-to-mount coordinate difference "
|
||||
"'{}' is greater than limit '{}' for adjusting mode!",
|
||||
coord_diff.r2, adj_rad2));
|
||||
|
||||
in_adj_mode = false;
|
||||
i_adj_cycle = 0;
|
||||
i_in_tol_cycle = 0;
|
||||
|
||||
compute_new_coord(t_data, ax_pos);
|
||||
typename hardware_t::error_t hw_err = hardware->setPos(ax_pos);
|
||||
// compute_new_coord(t_data, ax_pos);
|
||||
adj_ax_pos.time_point = t_data.time_point;
|
||||
adj_ax_pos.x += coord_diff.xdiff;
|
||||
adj_ax_pos.y += coord_diff.ydiff;
|
||||
|
||||
ax_pos.time_point = t_data.time_point;
|
||||
ax_pos.x = adj_ax_pos.x;
|
||||
ax_pos.y = adj_ax_pos.y;
|
||||
// send command for slewing
|
||||
typename hardware_t::error_t hw_err = p_hardware->setPos(ax_pos);
|
||||
|
||||
|
||||
if (hw_err) {
|
||||
if constexpr (std::same_as<decltype(hw_err), error_t>) {
|
||||
@@ -372,7 +387,7 @@ protected:
|
||||
// NOTE: TARGET COORDINATES WILL BE UPDATED FOR CURRENT TIME-POINT IN TELEMETRY-CLASS!!!
|
||||
|
||||
while (true) {
|
||||
t_err = telemetry.waitForUpdatedData(t_data, slew_point.telemetryUpdateTimeout);
|
||||
t_err = p_telemetry->waitForUpdatedData(t_data, slew_point.telemetryUpdateTimeout);
|
||||
|
||||
if (t_err) {
|
||||
std::string err_str = "An error occured while waiting for updated telemetry";
|
||||
|
||||
Reference in New Issue
Block a user