...
This commit is contained in:
parent
9fbd858086
commit
750d29ceb9
@ -18,13 +18,7 @@ typedef mcc::astrom::erfa::MccMountAstromEngineERFA<mcc::MccAngle> AsibFM700Astr
|
||||
|
||||
typedef mcc::MccMountDefaultPEC<mcc::MccMountType::FORK_TYPE> AsibFM700PointingErrorCorrection;
|
||||
|
||||
struct AsibFM700TelemetryData : mcc::MccMountTelemetryData<AsibFM700AstromEngine, AsibFM700PointingErrorCorrection> {
|
||||
// apparent target (user-input) current coordinates
|
||||
coord_t tagRA, tagDEC;
|
||||
coord_t tagHA;
|
||||
coord_t tagAZ, tagALT;
|
||||
coord_t tagPA;
|
||||
};
|
||||
typedef mcc::MccMountTelemetryData<AsibFM700AstromEngine, AsibFM700PointingErrorCorrection> AsibFM700TelemetryData;
|
||||
|
||||
typedef mcc::MccMountTelemetry<AsibFM700AstromEngine,
|
||||
AsibFM700PointingErrorCorrection,
|
||||
|
||||
@ -69,33 +69,6 @@ AsibFM700Hardware::AsibFM700Hardware(const hardware_config_t& conf)
|
||||
_hardwareConfig.devConfig.EncoderDevPath = const_cast<char*>(_hardwareConfig.EncoderDevPath.c_str());
|
||||
_hardwareConfig.devConfig.EncoderXDevPath = const_cast<char*>(_hardwareConfig.EncoderXDevPath.c_str());
|
||||
_hardwareConfig.devConfig.EncoderYDevPath = const_cast<char*>(_hardwareConfig.EncoderYDevPath.c_str());
|
||||
|
||||
_sideralRate2 *= _sideralRate2;
|
||||
_sideralRateEps2 = 0.01; // 1%
|
||||
|
||||
// start state polling
|
||||
|
||||
_statePollingThread = std::jthread([this](std::stop_token stoken) {
|
||||
mountdata_t data;
|
||||
|
||||
while (true) {
|
||||
if (stoken.stop_requested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
error_t err = static_cast<AsibFM700HardwareErrorCode>(Mount.getMountData(&data));
|
||||
|
||||
|
||||
if (err == AsibFM700HardwareErrorCode::ERROR_OK) {
|
||||
// are both motors stopped?
|
||||
bool stop_motors =
|
||||
(data.extradata.ExtraBits & XMOTOR_STOP_BIT) && (data.extradata.ExtraBits & YMOTOR_STOP_BIT);
|
||||
if (stop_motors) {
|
||||
_state = hw_state_t::HW_STATE_STOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// AsibFM700Hardware::AsibFM700Hardware(AsibFM700Hardware&& other)
|
||||
@ -118,52 +91,28 @@ std::string_view AsibFM700Hardware::id() const
|
||||
}
|
||||
|
||||
|
||||
AsibFM700Hardware::error_t AsibFM700Hardware::getState(AsibFM700Hardware::hw_state_t& state) const
|
||||
{
|
||||
mountdata_t data;
|
||||
error_t err = static_cast<AsibFM700HardwareErrorCode>(Mount.getMountData(&data));
|
||||
|
||||
if (err == AsibFM700HardwareErrorCode::ERROR_OK) {
|
||||
// are both motors stopped?
|
||||
bool stop_motors = (data.extradata.ExtraBits & XMOTOR_STOP_BIT) && (data.extradata.ExtraBits & YMOTOR_STOP_BIT);
|
||||
if (stop_motors) {
|
||||
state = hw_state_t::HW_STATE_STOP;
|
||||
return AsibFM700HardwareErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
// compute current speed
|
||||
auto rate2 = data.encXspeed.val * data.encXspeed.val + data.encYspeed.val * data.encYspeed.val;
|
||||
auto ratio2 = rate2 / _sideralRate2;
|
||||
if (ratio2 <= _sideralRateEps2) { // tracking
|
||||
state = hw_state_t::HW_STATE_TRACK;
|
||||
} else {
|
||||
state = hw_state_t::HW_STATE_SLEW;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
AsibFM700Hardware::error_t AsibFM700Hardware::setPos(AsibFM700Hardware::axes_pos_t pos)
|
||||
{
|
||||
error_t err;
|
||||
|
||||
// according to"SiTech protocol notes" X is DEC-axis and Y is HA-axis
|
||||
coordpair_t hw_pos{.X = pos.y, .Y = pos.x};
|
||||
double tp = std::chrono::duration<double>(pos.time_point.time_since_epoch()).count();
|
||||
coordval_pair_t hw_posval{.X{.val = pos.x, .t = tp}, .Y{.val = pos.y, .t = tp}};
|
||||
|
||||
if (!pos.flags.slewNguide) {
|
||||
return static_cast<AsibFM700HardwareErrorCode>(Mount.slewTo(&hw_pos, pos.flags));
|
||||
}
|
||||
|
||||
switch (pos.state) {
|
||||
case hw_state_t::HW_STATE_SLEW: // slew mount
|
||||
err = static_cast<AsibFM700HardwareErrorCode>(Mount.slewTo(&hw_pos, pos.flags));
|
||||
switch (pos.moving_type) {
|
||||
case hw_moving_type_t::HW_MOVE_SLEWING: // slew mount
|
||||
if (pos.moveAndStop) {
|
||||
err = static_cast<AsibFM700HardwareErrorCode>(Mount.moveTo(&hw_pos));
|
||||
} else {
|
||||
err = static_cast<AsibFM700HardwareErrorCode>(Mount.slewTo(&hw_pos, pos.flags));
|
||||
}
|
||||
break;
|
||||
case hw_state_t::HW_STATE_TRACK: // interpretate as guiding correction
|
||||
err = static_cast<AsibFM700HardwareErrorCode>(Mount.correctBy(&hw_pos));
|
||||
case hw_moving_type_t::HW_MOVE_ADJUSTING: // corrections at the end of slewing
|
||||
err = static_cast<AsibFM700HardwareErrorCode>(Mount.correctTo(&hw_posval));
|
||||
break;
|
||||
case hw_state_t::HW_STATE_STOP:
|
||||
case hw_moving_type_t::HW_MOVE_GUIDING: // interpretate as guiding correction
|
||||
err = static_cast<AsibFM700HardwareErrorCode>(Mount.correctTo(&hw_posval));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -194,9 +143,6 @@ AsibFM700Hardware::error_t AsibFM700Hardware::getPos(AsibFM700Hardware::axes_pos
|
||||
|
||||
pos.xrate = data.encYspeed.val;
|
||||
pos.yrate = data.encXspeed.val;
|
||||
|
||||
// mount state
|
||||
err = getState(pos.state);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
||||
@ -71,15 +71,16 @@ public:
|
||||
typedef mcc::MccAngle coord_t;
|
||||
typedef std::chrono::system_clock::time_point time_point_t; // UTC time
|
||||
|
||||
enum class hw_state_t : int { HW_STATE_STOP, HW_STATE_SLEW, HW_STATE_TRACK };
|
||||
enum class hw_moving_type_t : int { HW_MOVE_SLEWING, HW_MOVE_ADJUSTING, HW_MOVE_TRACKING, HW_MOVE_GUIDING };
|
||||
|
||||
struct axes_pos_t {
|
||||
time_point_t time_point;
|
||||
coord_t x, y;
|
||||
coord_t xrate, yrate;
|
||||
|
||||
hw_state_t state;
|
||||
hw_moving_type_t moving_type{hw_moving_type_t::HW_MOVE_TRACKING};
|
||||
slewflags_t flags;
|
||||
bool moveAndStop{false};
|
||||
};
|
||||
|
||||
|
||||
@ -108,7 +109,6 @@ public:
|
||||
|
||||
std::string_view id() const;
|
||||
|
||||
error_t getState(hw_state_t&) const;
|
||||
error_t setPos(axes_pos_t);
|
||||
error_t getPos(axes_pos_t&);
|
||||
|
||||
@ -119,7 +119,6 @@ private:
|
||||
hardware_config_t _hardwareConfig;
|
||||
|
||||
std::jthread _statePollingThread;
|
||||
hw_state_t _state;
|
||||
|
||||
double _sideralRate2; // square of sideral rate
|
||||
double _sideralRateEps2;
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
|
||||
#include "mcc_mount_concepts.h"
|
||||
#include "mcc_mount_telemetry.h"
|
||||
#include "mcc_slew_guiding_model_common.h"
|
||||
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
|
||||
@ -24,6 +24,7 @@ enum class MccSimpleGuidingModelErrorCode : int {
|
||||
ERROR_INVALID_CONTEXT_PARAM,
|
||||
ERROR_INVALID_THRESH,
|
||||
ERROR_INVALID_CORR_RANGE,
|
||||
ERROR_GUIDING_STOPPED
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
@ -48,10 +49,7 @@ namespace mcc
|
||||
struct MccSimpleGuidingModelCategory : public std::error_category {
|
||||
MccSimpleGuidingModelCategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "ADC_GENERIC_DEVICE";
|
||||
}
|
||||
const char* name() const noexcept { return "ADC_GENERIC_DEVICE"; }
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
@ -76,6 +74,8 @@ struct MccSimpleGuidingModelCategory : public std::error_category {
|
||||
return "guiding model: invalid guiding residual threshold";
|
||||
case MccSimpleGuidingModelErrorCode::ERROR_INVALID_CORR_RANGE:
|
||||
return "guiding model: invalid guiding correction range";
|
||||
case MccSimpleGuidingModelErrorCode::ERROR_GUIDING_STOPPED:
|
||||
return "guiding model: stopped";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
@ -136,34 +136,30 @@ public:
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
struct guiding_context_t {
|
||||
double corrThresh{MccAngle("00:00:00.2"_dms)}; // correction threshold
|
||||
double correctionRange[2]{MccAngle("00:00:00.5"_dms), MccAngle("00:00:05"_dms)};
|
||||
|
||||
std::chrono::duration<double> predictedTrackDuration{10.0}; // 10 seconds
|
||||
std::chrono::duration<double> predictedTrackResolution{0.1}; // 0.1 seconds
|
||||
};
|
||||
|
||||
struct guiding_point_t : MccCelestialPoint {
|
||||
coord_t corrThresh{(double)MccAngle("00:00:00.2"_dms)}; // correction threshold
|
||||
coord_t correctionRange[2]{(double)MccAngle(0.5_arcsecs), (double)MccAngle(5.0_arcsecs)};
|
||||
|
||||
// timeout to wait telemetry update (in seconds, as floating-point)
|
||||
std::chrono::duration<double> telemetryUpdateTimeout{1.0};
|
||||
};
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls, guiding_context_t context, LoggerCtorArgTs&&... ctor_args)
|
||||
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, std::move(context));
|
||||
init(mount_controls);
|
||||
}
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls, guiding_context_t context)
|
||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls)
|
||||
requires(std::same_as<LoggerT, MccNullLogger>)
|
||||
{
|
||||
init(mount_controls, std::move(context));
|
||||
init(mount_controls);
|
||||
}
|
||||
|
||||
virtual ~MccSimpleGuidingModel()
|
||||
@ -172,98 +168,46 @@ public:
|
||||
}
|
||||
|
||||
|
||||
error_t guiding(guiding_point_t guiding_point)
|
||||
{
|
||||
return _guidingFunc(std::move(guiding_point));
|
||||
}
|
||||
error_t guiding(guiding_point_t guiding_point) { return _guidingFunc(std::move(guiding_point)); }
|
||||
|
||||
error_t stopGuiding(bool off)
|
||||
{
|
||||
_doCorrection = off;
|
||||
}
|
||||
error_t stopGuiding(bool off) { _doCorrection = off; }
|
||||
|
||||
bool inGuiding()
|
||||
{
|
||||
return _doCorrection;
|
||||
}
|
||||
bool inGuiding() { return _doCorrection; }
|
||||
|
||||
error_t stop() { return MccSimpleGuidingModelErrorCode::ERROR_OK; }
|
||||
|
||||
protected:
|
||||
std::function<error_t(guiding_point_t)> _guidingFunc{};
|
||||
std::atomic_bool _doCorrection{true};
|
||||
std::atomic_bool _stopRequested{false};
|
||||
|
||||
|
||||
error_t init(auto& mount_controls, guiding_context_t context)
|
||||
|
||||
error_t init(auto& mount_controls)
|
||||
{
|
||||
// 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 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;
|
||||
}
|
||||
|
||||
auto resi_thresh2 = context.corrThresh * context.corrThresh;
|
||||
|
||||
if (utils::isEqual(resi_thresh2, 0.0)) {
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_INVALID_THRESH;
|
||||
}
|
||||
|
||||
const auto p_mount_controls = &mount_controls;
|
||||
|
||||
auto check_zones = [p_mount_controls, this]() {
|
||||
return [this]<size_t... Is>(std::index_sequence<Is...>) {
|
||||
error_t ret;
|
||||
_guidingFunc = [p_mount_controls, this](guiding_point_t guiding_point) {
|
||||
_stopRequested = false;
|
||||
|
||||
(
|
||||
[&ret]() {
|
||||
if constexpr (Is > 0) {
|
||||
if (ret) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
typename telemetry_t::mount_telemetry_data_t tdata;
|
||||
|
||||
auto tel_err = p_mount_controls->telemetry.data(tdata);
|
||||
if (tel_err) {
|
||||
if constexpr (std::same_as<decltype(tel_err), error_t>) {
|
||||
ret = tel_err;
|
||||
} else {
|
||||
ret = MccSimpleGuidingModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
} else {
|
||||
ret = std::get<Is>(p_mount_controls->prohibitedZones).inZone(tdata)
|
||||
? MccSimpleGuidingModelErrorCode::ERROR_IN_PROHIBITED_ZONE
|
||||
: MccSimpleGuidingModelErrorCode::ERROR_OK;
|
||||
if (ret) {
|
||||
auto log_str = std::format("given coordinates are in prohibited zone '{}'",
|
||||
std::get<Is>(p_mount_controls->prohibitedZones).name());
|
||||
logError(log_str);
|
||||
}
|
||||
}
|
||||
}(),
|
||||
...);
|
||||
|
||||
|
||||
return ret;
|
||||
}(std::make_index_sequence<Nzones>{});
|
||||
};
|
||||
|
||||
|
||||
_guidingFunc = [p_mount_controls, context = std::move(context), predicted_Npoints, this](
|
||||
this auto&& self, guiding_point_t guiding_point) {
|
||||
if (context.correctionRange[0] >= context.correctionRange[1]) {
|
||||
if (guiding_point.correctionRange[0] >= guiding_point.correctionRange[1]) {
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_INVALID_THRESH;
|
||||
}
|
||||
|
||||
auto low_corr_limit = context.correctionRange[0] * context.correctionRange[0];
|
||||
auto high_corr_limit = context.correctionRange[1] * context.correctionRange[1];
|
||||
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;
|
||||
@ -283,206 +227,91 @@ protected:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) { // use of HA and DEC
|
||||
guiding_point.coordPairKind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) { // use of Az and Alt
|
||||
guiding_point.coordPairKind = MccCoordPairKind::COORDS_KIND_AZALT;
|
||||
} else {
|
||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||
}
|
||||
|
||||
guiding_point.x += pec_res.dx; // app HA/Az
|
||||
guiding_point.y += pec_res.dy; // app DEC/Alt
|
||||
|
||||
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(astrom_engine_t::timePointNow(), 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;
|
||||
coord_t xr, yr, coord_diff;
|
||||
typename hardware_t::axes_pos_t ax_pos;
|
||||
|
||||
while (true) {
|
||||
// check prohibited zones ...
|
||||
if ((res_err = check_zones())) {
|
||||
return res_err;
|
||||
}
|
||||
ax_pos.moving_type = hardware_t::hw_moving_type_t::HW_MOVE_GUIDING;
|
||||
|
||||
ast_err = astrom_engine.greg2jul(astrom_engine_t::timePointNow(), jd);
|
||||
if (!ast_err) {
|
||||
ast_err = astrom_engine.icrs2obs(ra_icrs, dec_icrs, jd, 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;
|
||||
t_err = 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()));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
std::array<bool, std::tuple_size_v<tpl_pz_t>> in_zone_flag;
|
||||
|
||||
while (true) {
|
||||
if (_stopRequested) {
|
||||
res_err = MccSimpleGuidingModelErrorCode::ERROR_GUIDING_STOPPED;
|
||||
}
|
||||
|
||||
t_err = telemetry.data(t_data);
|
||||
// check prohibited zones ...
|
||||
if (mccCheckInZonePZTuple(t_data, p_mount_controls->prohibitedZones, in_zone_flag)) {
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_IN_PROHIBITED_ZONE;
|
||||
};
|
||||
|
||||
|
||||
// suspend the thread here until telemetry data is updated
|
||||
t_err = telemetry.waitForUpdatedData(t_data, guiding_point.telemetryUpdateTimeout);
|
||||
|
||||
if (t_err) {
|
||||
std::string err_str = "An error occured while waiting for updated telemetry";
|
||||
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||
logError(
|
||||
std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
||||
std::format_to(std::back_inserter(err_str), ": code = {} ({})", t_err.value(), t_err.message());
|
||||
logError(err_str);
|
||||
return t_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||
std::format_to(std::back_inserter(err_str), ": code = {}", t_err.value());
|
||||
}
|
||||
logError(err_str);
|
||||
return MccSimpleGuidingModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
if (_stopRequested) {
|
||||
res_err = MccSimpleGuidingModelErrorCode::ERROR_GUIDING_STOPPED;
|
||||
}
|
||||
|
||||
// compare t_data with computed coordinates ...
|
||||
if (_doCorrection) {
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
xr = ha - t_data.mntHA;
|
||||
yr = dec_app - t_data.mntDEC;
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||
xr = az - t_data.mntAZ;
|
||||
yr = alt - t_data.mntALT;
|
||||
} else {
|
||||
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||
}
|
||||
auto coord_diff = telemetry.targetToMountDiff();
|
||||
|
||||
coord_diff = xr * xr + yr * yr;
|
||||
|
||||
if (coord_diff < low_corr_limit) {
|
||||
if (coord_diff.r2 < low_corr_limit) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (coord_diff > high_corr_limit) {
|
||||
logWarn(std::format(
|
||||
"guiding model: the 'mount-target' difference exceeds the limit (diff = {}; lim = {})",
|
||||
(double)coord_diff, (double)high_corr_limit));
|
||||
if (coord_diff.r2 > high_corr_limit) {
|
||||
logWarn(
|
||||
std::format("guiding model: the 'mount-target' square of difference exceeds the limit "
|
||||
"(diff = {}; lim = {})",
|
||||
(double)coord_diff.r2, (double)high_corr_limit));
|
||||
continue;
|
||||
}
|
||||
|
||||
// do correction
|
||||
ax_pos.state = hardware_t::hw_state_t::HW_STATE_TRACK; // indicates to hardware level
|
||||
ax_pos.x = xr;
|
||||
ax_pos.y = yr;
|
||||
// ax_pos.x = t_data.mntPosX;
|
||||
// ax_pos.y = t_data.mntPosY;
|
||||
// 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!");
|
||||
}
|
||||
|
||||
|
||||
// asynchronous operation!
|
||||
auto err = hardware.setPos(std::move(ax_pos));
|
||||
auto err = hardware.setPos(ax_pos);
|
||||
if (err) {
|
||||
if constexpr (std::same_as<decltype(err), error_t>) {
|
||||
logError(
|
||||
|
||||
@ -205,30 +205,38 @@ concept mcc_mount_hardware_c = !std::copyable<T> && std::movable<T> && requires(
|
||||
|
||||
{ t_const.id() } -> mcc_formattable;
|
||||
|
||||
// a type that defines at least HW_STATE_STOP, HW_STATE_SLEW, HW_STATE_TRACK
|
||||
// compile-time constants
|
||||
// e.g. an implementations can be as follows:
|
||||
// enum class HW_STATE: int {HW_STATE_STOP, HW_STATE_SLEW, HW_STATE_TRACK}
|
||||
// a type that defines at least HW_MOVE_SLEWING, HW_MOVE_ADJUSTING, HW_MOVE_TRACKING
|
||||
// and HW_MOVE_GUIDING compile-time constants. The main purpose of this type is a
|
||||
// possible tunning of hardware setPos-related commands
|
||||
//
|
||||
// struct HW_STATE {
|
||||
// uint8_t HW_STATE_STOP = 100;
|
||||
// uint8_t HW_STATE_SLEW = 200;
|
||||
// uint8_t HW_STATE_TRACK = 300;
|
||||
// e.g. an implementations can be as follows:
|
||||
// enum class hw_moving_type_t: int {HW_MOVE_SLEWING, HW_MOVE_ADJUSTING, HW_MOVE_TRACKING, HW_MOVE_GUIDING}
|
||||
//
|
||||
// struct hw_moving_type_t {
|
||||
// uint16_t HW_MOVE_SLEWING = 111;
|
||||
// uint16_t HW_MOVE_ADJUSTING = 222;
|
||||
// uint16_t HW_MOVE_TRACKING = 333;
|
||||
// uint16_t HW_MOVE_GUIDING = 444;
|
||||
// }
|
||||
requires requires(typename T::hw_state_t state) {
|
||||
requires requires(typename T::hw_moving_type_t state) {
|
||||
[]() {
|
||||
// hardware is in stop state (no any moving)
|
||||
static constexpr auto v1 = T::hw_state_t::HW_STATE_STOP;
|
||||
// hardware was asked for slewing (move to given celestial point)
|
||||
static constexpr auto v1 = T::hw_moving_type_t::HW_MOVE_SLEWING;
|
||||
|
||||
// hardware is in slew state (move to given celestial point)
|
||||
static constexpr auto v2 = T::hw_state_t::HW_STATE_SLEW;
|
||||
// hardware was asked for adjusting after slewing ("seeking" given celestial point at the end of slewing
|
||||
// process)
|
||||
static constexpr auto v2 = T::hw_moving_type_t::HW_MOVE_ADJUSTING;
|
||||
|
||||
// hardware is in track state (track given celestial point)
|
||||
static constexpr auto v3 = T::hw_state_t::HW_STATE_TRACK;
|
||||
// hardware was asked for tracking (track given celestial point)
|
||||
static constexpr auto v3 = T::hw_moving_type_t::HW_MOVE_TRACKING;
|
||||
|
||||
// hardware was asked for guiding (small corrections to track given celestial point)
|
||||
static constexpr auto v4 = T::hw_moving_type_t::HW_MOVE_GUIDING;
|
||||
}();
|
||||
};
|
||||
|
||||
|
||||
|
||||
// a class that contains at least time of measurement, coordinates for x,y axes and its moving rates
|
||||
requires requires(typename T::axes_pos_t pos) {
|
||||
requires std::same_as<decltype(pos.time_point), typename T::time_point_t>; // time point
|
||||
@ -239,13 +247,17 @@ concept mcc_mount_hardware_c = !std::copyable<T> && std::movable<T> && requires(
|
||||
requires std::same_as<decltype(pos.xrate), typename T::coord_t>;
|
||||
requires std::same_as<decltype(pos.yrate), typename T::coord_t>;
|
||||
|
||||
requires std::same_as<decltype(pos.state), typename T::hw_state_t>; // hardware state
|
||||
requires std::same_as<decltype(pos.moving_type), typename T::hw_moving_type_t>; // a 'hint' to hardware
|
||||
};
|
||||
|
||||
// set positions (angles) of mount axes with given speeds
|
||||
// NOTE: exact interpretation (or even ignoring) of the given moving speeds is subject of a hardware-class
|
||||
// implementation.
|
||||
// e.g. it can be maximal speeds at slewing ramp
|
||||
{ t.setPos(std::declval<typename T::axes_pos_t>()) } -> std::same_as<typename T::error_t>;
|
||||
{ t.getPos(std::declval<typename T::axes_pos_t&>()) } -> std::same_as<typename T::error_t>;
|
||||
|
||||
{ t_const.getState(std::declval<typename T::hw_state_t&>()) } -> std::same_as<typename T::error_t>;
|
||||
// get current positions and speeds (angles) of mount axes
|
||||
{ t.getPos(std::declval<typename T::axes_pos_t&>()) } -> std::same_as<typename T::error_t>;
|
||||
|
||||
{ t.stop() } -> std::same_as<typename T::error_t>; // stop any moving
|
||||
{ t.init() } -> std::same_as<typename T::error_t>; // initialize hardware
|
||||
@ -292,6 +304,13 @@ concept mcc_mount_telemetry_data_c = requires(T telemetry) {
|
||||
// time point
|
||||
requires std::same_as<decltype(telemetry.time_point), typename T::time_point_t>;
|
||||
|
||||
// target sky point ICRS and current coordinates
|
||||
requires std::same_as<decltype(telemetry.tagRA), typename T::coord_t>; // apparent RA
|
||||
requires std::same_as<decltype(telemetry.tagDEC), typename T::coord_t>; // apparent DEC
|
||||
requires std::same_as<decltype(telemetry.tagHA), typename T::coord_t>; // hour angle
|
||||
requires std::same_as<decltype(telemetry.tagAZ), typename T::coord_t>; // azimuth
|
||||
requires std::same_as<decltype(telemetry.tagALT), typename T::coord_t>; // altitude
|
||||
|
||||
// mount current coordinates
|
||||
requires std::same_as<decltype(telemetry.mntRA), typename T::coord_t>; // apparent RA
|
||||
requires std::same_as<decltype(telemetry.mntDEC), typename T::coord_t>; // apparent DEC
|
||||
@ -303,6 +322,11 @@ concept mcc_mount_telemetry_data_c = requires(T telemetry) {
|
||||
requires std::same_as<decltype(telemetry.mntPosY), typename T::coord_t>; // hardware encoder Y-axis position
|
||||
requires std::same_as<decltype(telemetry.mntRateX), typename T::coord_t>; // hardware encoder X-axis rate
|
||||
requires std::same_as<decltype(telemetry.mntRateY), typename T::coord_t>; // hardware encoder Y-axis rate
|
||||
|
||||
// corrections to transform mount hardware coordinates to apparent
|
||||
// (pointing error corrections)
|
||||
requires std::same_as<decltype(telemetry.pecX), typename T::coord_t>;
|
||||
requires std::same_as<decltype(telemetry.pecY), typename T::coord_t>;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -138,8 +138,13 @@ public:
|
||||
typedef HARDWARE_T hardware_t;
|
||||
typedef DATA_T mount_telemetry_data_t;
|
||||
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
struct coord_diff_t {
|
||||
typename ASTROM_ENGINE_T::coord_t xdiff, ydiff, r2;
|
||||
};
|
||||
|
||||
MccMountTelemetry(astrom_engine_t& astrom_engine, pec_t& pec, hardware_t& hardware)
|
||||
: base_t(astrom_engine, pec), _hardware(hardware)
|
||||
{
|
||||
@ -162,7 +167,30 @@ public:
|
||||
return err;
|
||||
}
|
||||
|
||||
// target - mount coordinate difference
|
||||
auto targetToMountDiff()
|
||||
{
|
||||
std::lock_guard lk(_updateMutex);
|
||||
|
||||
coord_diff_t result;
|
||||
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
result.xdiff = _data.tagRA - _data.mntHA;
|
||||
result.ydiff = _data.tagDEC - _data.mntDEC;
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||
result.xdiff = _data.tagAZ - _data.mntAZ;
|
||||
result.ydiff = _data.tagALT - _data.mntALT;
|
||||
} else {
|
||||
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||
}
|
||||
|
||||
result.r2 = result.xdiff * result.xdiff + result.ydiff * result.ydiff;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// update telemetry right now
|
||||
error_t update()
|
||||
{
|
||||
mount_telemetry_data_t current_data;
|
||||
@ -278,7 +306,7 @@ public:
|
||||
return MccMountTelemetryErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
// wait until data is updated or given timeout occurs
|
||||
// wait (block current thread) until data is updated or given timeout occurs
|
||||
template <traits::mcc_time_duration_c DT>
|
||||
error_t waitForUpdatedData(mount_telemetry_data_t& data, const DT& timeout)
|
||||
{
|
||||
|
||||
@ -27,39 +27,21 @@ static_assert(traits::mcc_celestial_point_c<MccCelestialPoint>, "MccCelestialPoi
|
||||
|
||||
/* CHECK FOR CURRENT MOUNT POSITION IN PROHIBITED ZONES */
|
||||
|
||||
/*
|
||||
* WARNING: if an error occured during telemetry data request
|
||||
* result 'in zone' flags cannot be interpretated correctly!
|
||||
*/
|
||||
template <traits::mcc_mount_telemetry_c TelemetryT,
|
||||
traits::mcc_prohibited_zone_c<typename TelemetryT::mount_telemetry_data_t>... ZTs>
|
||||
auto mccCheckInZonePZTuple(TelemetryT& telemetry,
|
||||
std::tuple<ZTs...>& tuple_zones,
|
||||
template <traits::mcc_mount_telemetry_data_c TelemetryDataT, traits::mcc_prohibited_zone_c<TelemetryDataT>... ZTs>
|
||||
auto mccCheckInZonePZTuple(const TelemetryDataT& telemetry_data,
|
||||
const std::tuple<ZTs...>& tuple_zones,
|
||||
std::array<bool, sizeof...(ZTs)>& in_zone)
|
||||
{
|
||||
const auto p_telemetry = &telemetry;
|
||||
const auto p_tdata = &telemetry_data;
|
||||
const auto p_tuple_zones = &tuple_zones;
|
||||
const auto p_in_zone = &in_zone;
|
||||
|
||||
return [p_telemetry, p_tuple_zones, p_in_zone]<size_t... Is>(std::index_sequence<Is...>) {
|
||||
typename TelemetryT::error_t t_err;
|
||||
(
|
||||
[&t_err]() {
|
||||
if constexpr (Is) {
|
||||
if (t_err) {
|
||||
(*p_in_zone)[Is] = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
[p_tdata, p_tuple_zones, p_in_zone]<size_t... Is>(std::index_sequence<Is...>) {
|
||||
(((*p_in_zone)[Is] = std::get<Is>(*p_tuple_zones).inZone(*p_tdata)), ...);
|
||||
}(std::make_index_sequence<sizeof...(ZTs)>{});
|
||||
|
||||
typename TelemetryT::mount_telemetry_data_t tdata;
|
||||
t_err = p_telemetry->data(tdata);
|
||||
|
||||
if (!t_err) {
|
||||
(*p_in_zone)[Is] = std::get<Is>(p_tuple_zones).inZone(tdata);
|
||||
}
|
||||
}(),
|
||||
...);
|
||||
return [p_in_zone]<size_t... Is>(std::index_sequence<Is...>) {
|
||||
return ((*p_in_zone)[Is] || ...);
|
||||
}(std::make_index_sequence<sizeof...(ZTs)>{});
|
||||
}
|
||||
|
||||
|
||||
@ -128,11 +128,14 @@ public:
|
||||
// coordinates difference to stop slewing (in radians)
|
||||
coord_t slewToleranceRadius{(double)MccAngle{5.0_arcsecs}};
|
||||
|
||||
// coordinates polling interval in seconds
|
||||
std::chrono::duration<double> coordPollingInterval{0.1};
|
||||
bool stopAfterSlew{false};
|
||||
// slew process timeout
|
||||
std::chrono::seconds slewTimeout{3600};
|
||||
|
||||
std::chrono::duration<double> telemetryPollingInterval{0.1};
|
||||
|
||||
// if true - stop mount after the slewing
|
||||
bool stopAfterSlew{false};
|
||||
|
||||
coord_t slewXRate{0.0}; // maximal slewing rate (0 means move with maximal allowed rate)
|
||||
coord_t slewYRate{0.0}; // maximal slewing rate (0 means move with maximal allowed rate)
|
||||
|
||||
@ -141,8 +144,9 @@ public:
|
||||
coord_t adjustYRate{
|
||||
(double)MccAngle{5.0_arcmins}}; // maximal adjusting rate (a rate at the final slewing stage)
|
||||
|
||||
// number of consecutive measurements within slewPrecision radius to stop adjusting of slewing
|
||||
// number of consecutive measurements within slewToleranceRadius radius to stop adjusting of slewing
|
||||
size_t withinToleranceCycleNumber{10};
|
||||
|
||||
// maximal allowed number of adjusting cycles
|
||||
size_t maxAdjustingCycleNumber{100};
|
||||
};
|
||||
@ -208,6 +212,8 @@ protected:
|
||||
|
||||
|
||||
_slewFunc = [p_mount_controls, 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;
|
||||
@ -254,6 +260,7 @@ protected:
|
||||
// start moving the mount (it is assumed this is asynchronous operation!!!)
|
||||
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);
|
||||
|
||||
if (hw_err) {
|
||||
@ -270,11 +277,12 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
typename hardware_t::axes_pos_t::time_point_t prev_time_point{};
|
||||
// typename hardware_t::axes_pos_t::time_point_t prev_time_point{};
|
||||
|
||||
auto adj_ax_pos = ax_pos; // to prevent possible effects in hardware 'setPos' method
|
||||
adj_ax_pos.xrate = slew_point.adjustXRate;
|
||||
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,
|
||||
@ -286,19 +294,20 @@ protected:
|
||||
size_t i_in_tol_cycle = 0;
|
||||
bool in_adj_mode = false;
|
||||
|
||||
auto coord_diff_func = [](auto& t_data) {
|
||||
typename telemetry_t::mount_telemetry_data_t::coord_t xr, yr;
|
||||
// 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)) {
|
||||
xr = t_data.tagRA - t_data.mntHA;
|
||||
yr = t_data.tagDEC - t_data.mntDEC;
|
||||
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)) {
|
||||
xr = t_data.tagAZ - t_data.mntAZ;
|
||||
yr = t_data.tagALT - t_data.mntALT;
|
||||
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!");
|
||||
}
|
||||
|
||||
return xr * xr + yr * yr;
|
||||
};
|
||||
|
||||
auto cycle_func = [&](auto t_data) mutable {
|
||||
@ -307,36 +316,28 @@ protected:
|
||||
}
|
||||
|
||||
// check for prohibited zones
|
||||
auto t_err = mccCheckInZonePZTuple(*telemetry, p_mount_controls->prohibitedZones, in_zone_flag);
|
||||
if (mccCheckInZonePZTuple(t_data, p_mount_controls->prohibitedZones, in_zone_flag)) {
|
||||
return MccSimpleSlewModelErrorCode::ERROR_IN_PROHIBITED_ZONE;
|
||||
};
|
||||
|
||||
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()));
|
||||
res_err = t_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||
}
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// t_data was updated in caller!!!
|
||||
coord_diff2 = coord_diff_func(t_data);
|
||||
auto coord_diff = telemetry.targetToMountDiff();
|
||||
|
||||
if (_stopRequested) {
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_SLEW_STOPPED;
|
||||
}
|
||||
|
||||
if (coord_diff2 < adj_rad2) { // adjusting mode
|
||||
if (coord_diff.r2 < adj_rad2) { // adjusting mode
|
||||
in_adj_mode = true;
|
||||
|
||||
compute_new_coord(t_data, adj_ax_pos);
|
||||
|
||||
hw_err = hardware->setPos(adj_ax_pos);
|
||||
|
||||
if (!hw_err) {
|
||||
++i_adj_cycle;
|
||||
if (coord_diff2 < tol_rad2) {
|
||||
if (coord_diff.r2 < tol_rad2) {
|
||||
++i_in_tol_cycle;
|
||||
|
||||
if (i_in_tol_cycle == slew_point.withinToleranceCycleNumber) {
|
||||
@ -346,7 +347,7 @@ protected:
|
||||
}
|
||||
|
||||
if (i_adj_cycle == slew_point.maxAdjustingCycleNumber) {
|
||||
// res_err = max iter number was exceeded
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_SLEW_ADJ_MAXITER;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -364,8 +365,27 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (in_adj_mode) { // ?!!!!!!!!!!!!!
|
||||
} else { // continue to slewing
|
||||
if (in_adj_mode) { // ?!!!!!!!!!!!!! slew again?!!!
|
||||
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);
|
||||
|
||||
if (hw_err) {
|
||||
if constexpr (std::same_as<decltype(hw_err), error_t>) {
|
||||
logError(std::format("An hardware error occured: code = {} ({})", hw_err.value(),
|
||||
hw_err.message()));
|
||||
return hw_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(hw_err)>) {
|
||||
logError(std::format("An hardware error occured: code = {}", hw_err));
|
||||
}
|
||||
return MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -385,7 +405,6 @@ protected:
|
||||
|
||||
if (t_err) {
|
||||
std::string err_str = "An error occured while waiting for updated telemetry";
|
||||
logError(std::format("An error occured while waiting for updated telemetry: {}", t_err));
|
||||
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||
std::format_to(std::back_inserter(err_str), ": code = {} ({})", t_err.value(), t_err.message());
|
||||
logError(err_str);
|
||||
@ -401,6 +420,10 @@ protected:
|
||||
|
||||
cycle_func(t_data);
|
||||
|
||||
if (res_err) {
|
||||
return res_err;
|
||||
}
|
||||
|
||||
if ((std::chrono::steady_clock::now() - start_poll_tm) > slew_point.slewTimeout) {
|
||||
logError("Waiting time for completion of slewing expired!");
|
||||
return MccSimpleSlewModelErrorCode::ERROR_SLEW_TIMEOUT;
|
||||
@ -414,6 +437,6 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
// static_assert(traits::mcc_slew_model_c<>);
|
||||
static_assert(traits::mcc_slew_model_c<MccSimpleSlewModel<>>, "");
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user