...
This commit is contained in:
parent
14f3bb7a83
commit
fd67d04ca2
@ -125,7 +125,7 @@ add_library(${CNTR_PROTO_LIB} STATIC ${CNTR_PROTO_LIB_SRC})
|
|||||||
|
|
||||||
set(MCC_LIBRARY_SRC mcc_mount_concepts.h mcc_fsm_mount.h mcc_mount_coord.h mcc_mount_events_states.h mcc_finite_state_machine.h
|
set(MCC_LIBRARY_SRC mcc_mount_concepts.h mcc_fsm_mount.h mcc_mount_coord.h mcc_mount_events_states.h mcc_finite_state_machine.h
|
||||||
mcc_mount_pec.h mcc_mount_pz.h mcc_traits.h mcc_mount_telemetry.h mcc_mount_config.h mcc_mount_astro_erfa.h mcc_astrom_iers.h mcc_astrom_iers_default.h
|
mcc_mount_pec.h mcc_mount_pz.h mcc_traits.h mcc_mount_telemetry.h mcc_mount_config.h mcc_mount_astro_erfa.h mcc_astrom_iers.h mcc_astrom_iers_default.h
|
||||||
mcc_slew_model.h mcc_utils.h mcc_spdlog.h)
|
mcc_slew_model.h mcc_guiding_model.h mcc_utils.h mcc_spdlog.h)
|
||||||
set(MCC_LIBRARY mcc)
|
set(MCC_LIBRARY mcc)
|
||||||
add_library(${MCC_LIBRARY} INTERFACE ${MCC_LIBRARY_SRC})
|
add_library(${MCC_LIBRARY} INTERFACE ${MCC_LIBRARY_SRC})
|
||||||
target_compile_features(${MCC_LIBRARY} INTERFACE cxx_std_23)
|
target_compile_features(${MCC_LIBRARY} INTERFACE cxx_std_23)
|
||||||
|
|||||||
@ -108,19 +108,29 @@ AsibFM700Hardware::error_t AsibFM700Hardware::getPos(AsibFM700Hardware::axes_pos
|
|||||||
auto err = static_cast<AsibFM700HardwareErrorCode>(Mount.getMountData(&data));
|
auto err = static_cast<AsibFM700HardwareErrorCode>(Mount.getMountData(&data));
|
||||||
|
|
||||||
if (err == AsibFM700HardwareErrorCode::ERROR_OK) {
|
if (err == AsibFM700HardwareErrorCode::ERROR_OK) {
|
||||||
// time point from sidservo library is 'struct timeval', i.e., seconds and
|
// time point from sidservo library is 'double' number represented UNIXTIME with
|
||||||
// microseconds ellapsed from UNIX time epoch
|
// microseconds/nanoseconds precision (must be equal for encXposition and encYposition)
|
||||||
|
|
||||||
using secs_t = std::chrono::duration<double>;
|
using secs_t = std::chrono::duration<double>;
|
||||||
secs_t secs = secs_t{1.0 * data.encposition.msrtime.tv_sec + 1.0E-6 * data.encposition.msrtime.tv_usec};
|
|
||||||
|
|
||||||
|
secs_t secs = secs_t{data.encXposition.t};
|
||||||
pos.time_point = time_point_t{std::chrono::duration_cast<time_point_t::duration>(secs)};
|
pos.time_point = time_point_t{std::chrono::duration_cast<time_point_t::duration>(secs)};
|
||||||
|
|
||||||
// according to hardware configuration (encoders pins (Eddy said)) X is DEC-axis and Y is HA-axis
|
// according to "SiTech protocol notes" X is DEC-axis and Y is HA-axis
|
||||||
pos.x = data.encposition.Y;
|
pos.x = data.encYposition.val;
|
||||||
pos.y = data.encposition.X;
|
pos.y = data.encXposition.val;
|
||||||
|
|
||||||
// ERROR: how can I get rates?!!!!!!!!!!
|
pos.xrate = data.encYspeed.val;
|
||||||
|
pos.yrate = data.encXspeed.val;
|
||||||
|
|
||||||
|
// mount state
|
||||||
|
|
||||||
|
// are both motors stopped?
|
||||||
|
bool stop_motors = (data.extradata.ExtraBits & XMOTOR_STOP_BIT) && (data.extradata.ExtraBits & YMOTOR_STOP_BIT);
|
||||||
|
if (stop_motors) {
|
||||||
|
pos.state = hw_state_t::HW_STATE_STOP;
|
||||||
|
return AsibFM700HardwareErrorCode::ERROR_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
@ -61,15 +61,22 @@ namespace asibfm700
|
|||||||
class AsibFM700Hardware final
|
class AsibFM700Hardware final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static constexpr uint8_t XMOTOR_STOP_BIT = 0b00000001; // if 0th bit set then motor is stopped
|
||||||
|
static constexpr uint8_t YMOTOR_STOP_BIT = 0b00010000; // if 4th bit set then motor is stopped
|
||||||
|
|
||||||
// definitions from concept
|
// definitions from concept
|
||||||
typedef std::error_code error_t;
|
typedef std::error_code error_t;
|
||||||
typedef mcc::MccAngle coord_t;
|
typedef mcc::MccAngle coord_t;
|
||||||
typedef std::chrono::system_clock::time_point time_point_t; // UTC time
|
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 };
|
||||||
|
|
||||||
struct axes_pos_t {
|
struct axes_pos_t {
|
||||||
time_point_t time_point;
|
time_point_t time_point;
|
||||||
coord_t x, y;
|
coord_t x, y;
|
||||||
coord_t xrate, yrate;
|
coord_t xrate, yrate;
|
||||||
|
|
||||||
|
hw_state_t state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,10 @@ enum class MccSimpleGuidingModelErrorCode : int {
|
|||||||
ERROR_ASTROM_COMP,
|
ERROR_ASTROM_COMP,
|
||||||
ERROR_TELEMETRY_DATA,
|
ERROR_TELEMETRY_DATA,
|
||||||
ERROR_PEC_COMP,
|
ERROR_PEC_COMP,
|
||||||
|
ERROR_HARDWARE_SETPOS,
|
||||||
ERROR_INVALID_CONTEXT_PARAM,
|
ERROR_INVALID_CONTEXT_PARAM,
|
||||||
|
ERROR_INVALID_THRESH,
|
||||||
|
ERROR_INVALID_CORR_RANGE,
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mcc
|
} // namespace mcc
|
||||||
@ -56,12 +59,22 @@ struct MccSimpleGuidingModelCategory : public std::error_category {
|
|||||||
switch (err) {
|
switch (err) {
|
||||||
case MccSimpleGuidingModelErrorCode::ERROR_OK:
|
case MccSimpleGuidingModelErrorCode::ERROR_OK:
|
||||||
return "OK";
|
return "OK";
|
||||||
|
case MccSimpleGuidingModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR:
|
||||||
|
return "slew model: unsupported coordinate pair";
|
||||||
case MccSimpleGuidingModelErrorCode::ERROR_ASTROM_COMP:
|
case MccSimpleGuidingModelErrorCode::ERROR_ASTROM_COMP:
|
||||||
return "guiding model: cannot perform astrometrical computations";
|
return "guiding model: cannot perform astrometrical computations";
|
||||||
case MccSimpleGuidingModelErrorCode::ERROR_TELEMETRY_DATA:
|
case MccSimpleGuidingModelErrorCode::ERROR_TELEMETRY_DATA:
|
||||||
return "guiding model: cannot get telemetry data";
|
return "guiding model: cannot get telemetry data";
|
||||||
case MccSimpleGuidingModelErrorCode::ERROR_PEC_COMP:
|
case MccSimpleGuidingModelErrorCode::ERROR_PEC_COMP:
|
||||||
return "guiding model: cannot compute PEC corrections";
|
return "guiding model: cannot compute PEC corrections";
|
||||||
|
case MccSimpleGuidingModelErrorCode::ERROR_HARDWARE_SETPOS:
|
||||||
|
return "guiding model: cannot set position";
|
||||||
|
case MccSimpleGuidingModelErrorCode::ERROR_INVALID_CONTEXT_PARAM:
|
||||||
|
return "guiding model: invalid context parameter";
|
||||||
|
case MccSimpleGuidingModelErrorCode::ERROR_INVALID_THRESH:
|
||||||
|
return "guiding model: invalid guiding residual threshold";
|
||||||
|
case MccSimpleGuidingModelErrorCode::ERROR_INVALID_CORR_RANGE:
|
||||||
|
return "guiding model: invalid guiding correction range";
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
@ -124,33 +137,37 @@ public:
|
|||||||
|
|
||||||
struct guiding_context_t {
|
struct guiding_context_t {
|
||||||
double corrThresh{MccAngle("00:00:00.2"_dms)}; // correction threshold
|
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> predictedTrackDuration{10.0}; // 10 seconds
|
||||||
std::chrono::duration<double> predictedTrackResolution{0.1}; // 0.1 seconds
|
std::chrono::duration<double> predictedTrackResolution{0.1}; // 0.1 seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
struct guiding_point_t {
|
typedef MccCelestialPoint guiding_point_t;
|
||||||
typedef double coord_t;
|
|
||||||
|
|
||||||
mcc::MccCoordPairKind coordPairKind{mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
// struct guiding_point_t {
|
||||||
|
// typedef double coord_t;
|
||||||
|
|
||||||
coord_t x, y;
|
// mcc::MccCoordPairKind coordPairKind{mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||||
};
|
|
||||||
|
// coord_t x, y;
|
||||||
|
// };
|
||||||
|
|
||||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
||||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls, LoggerCtorArgTs&&... ctor_args)
|
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls, guiding_context_t context, LoggerCtorArgTs&&... ctor_args)
|
||||||
requires(!std::same_as<LoggerT, MccNullLogger>)
|
requires(!std::same_as<LoggerT, MccNullLogger>)
|
||||||
: LoggerT(std::forward<LoggerCtorArgTs>(ctor_args)...)
|
: LoggerT(std::forward<LoggerCtorArgTs>(ctor_args)...)
|
||||||
{
|
{
|
||||||
logDebug(std::format("Create 'MccSimpleGuidingModel' class instance ({})", (void*)this));
|
logDebug(std::format("Create 'MccSimpleGuidingModel' class instance ({})", (void*)this));
|
||||||
|
|
||||||
init(mount_controls);
|
init(mount_controls, std::move(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
||||||
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls)
|
MccSimpleGuidingModel(MOUNT_CONTROLS_T& mount_controls, guiding_context_t context)
|
||||||
requires(std::same_as<LoggerT, MccNullLogger>)
|
requires(std::same_as<LoggerT, MccNullLogger>)
|
||||||
{
|
{
|
||||||
init(mount_controls);
|
init(mount_controls, std::move(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~MccSimpleGuidingModel()
|
virtual ~MccSimpleGuidingModel()
|
||||||
@ -159,7 +176,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
error_t guiding(guiding_point_t guiding_point) {}
|
error_t guiding(guiding_point_t guiding_point)
|
||||||
|
{
|
||||||
|
return _guidingFunc(std::move(guiding_point));
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t stopGuiding(bool off)
|
||||||
|
{
|
||||||
|
_doCorrection = off;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool inGuiding()
|
||||||
|
{
|
||||||
|
return _doCorrection;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::function<error_t()> _guidingFunc{};
|
std::function<error_t()> _guidingFunc{};
|
||||||
@ -182,10 +212,63 @@ protected:
|
|||||||
return MccSimpleGuidingModelErrorCode::ERROR_INVALID_CONTEXT_PARAM;
|
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;
|
const auto p_mount_controls = &mount_controls;
|
||||||
|
|
||||||
_guidingFunc = [p_mount_controls, context = std::move(context), predicted_Npoints](
|
auto check_zones = [p_mount_controls, this]() {
|
||||||
|
return [this]<size_t... Is>(std::index_sequence<Is...>) {
|
||||||
|
error_t ret;
|
||||||
|
|
||||||
|
(
|
||||||
|
[&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) {
|
this auto&& self, guiding_point_t guiding_point) {
|
||||||
|
if (context.correctionRange[0] >= context.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& astrom_engine = p_mount_controls->astrometryEngine;
|
auto& astrom_engine = p_mount_controls->astrometryEngine;
|
||||||
auto& hardware = p_mount_controls->hardware;
|
auto& hardware = p_mount_controls->hardware;
|
||||||
auto& pec = p_mount_controls->PEC;
|
auto& pec = p_mount_controls->PEC;
|
||||||
@ -196,8 +279,6 @@ protected:
|
|||||||
jd_t jd;
|
jd_t jd;
|
||||||
|
|
||||||
|
|
||||||
typename hardware_t::axes_pos_t ax_pos;
|
|
||||||
|
|
||||||
error_t res_err;
|
error_t res_err;
|
||||||
typename astrom_engine_t::error_t ast_err;
|
typename astrom_engine_t::error_t ast_err;
|
||||||
typename pec_t::error_t pec_err;
|
typename pec_t::error_t pec_err;
|
||||||
@ -297,7 +378,7 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (guiding_point.coordPairKind != mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
if (guiding_point.coordPairKind != mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||||
ast_err = astrom_engine.greg2jul(std::chrono::system_clock::now(), jd);
|
ast_err = astrom_engine.greg2jul(astrom_engine_t::timePointNow(), jd);
|
||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
ast_err = astrom_engine.obs2icrs(guiding_point.coordPairKind, guiding_point.x, guiding_point.y, jd,
|
ast_err = astrom_engine.obs2icrs(guiding_point.coordPairKind, guiding_point.x, guiding_point.y, jd,
|
||||||
ra_icrs, dec_icrs);
|
ra_icrs, dec_icrs);
|
||||||
@ -321,11 +402,33 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
coord_t ha, ra_app, dec_app, az, alt, eo;
|
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) {
|
while (true) {
|
||||||
// check prohibited zones ...
|
// check prohibited zones ...
|
||||||
ast_err = astrom_engine.greg2jul(std::chrono::system_clock::now(), jd);
|
if ((res_err = check_zones())) {
|
||||||
|
return res_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
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.data(t_data);
|
t_err = telemetry.data(t_data);
|
||||||
if (t_err) {
|
if (t_err) {
|
||||||
@ -342,6 +445,50 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compare t_data with computed coordinates ...
|
// compare t_data with computed coordinates ...
|
||||||
|
if (_doCorrection) {
|
||||||
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
|
xr = t_data.mntHA - ha;
|
||||||
|
yr = t_data.mntDEC - dec_app;
|
||||||
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
|
xr = t_data.mntAZ - az;
|
||||||
|
yr = t_data.mntALT - alt;
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||||
|
}
|
||||||
|
|
||||||
|
coord_diff = xr * xr + yr * yr;
|
||||||
|
|
||||||
|
if (coord_diff < 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));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do correction
|
||||||
|
ax_pos.state = hardware_t::hw_state_t::HW_STATE_TRACK;
|
||||||
|
ax_pos.x = t_data.mntPosX;
|
||||||
|
ax_pos.y = t_data.mntPosY;
|
||||||
|
|
||||||
|
// asynchronous operation!
|
||||||
|
auto err = hardware.setPos(std::move(ax_pos));
|
||||||
|
if (err) {
|
||||||
|
if constexpr (std::same_as<decltype(err), error_t>) {
|
||||||
|
logError(
|
||||||
|
std::format("An hardware error occured: code = {} ({})", err.value(), err.message()));
|
||||||
|
return err;
|
||||||
|
} else {
|
||||||
|
if constexpr (traits::mcc_formattable<decltype(err)>) {
|
||||||
|
logError(std::format("An hardware error occured: code = {}", err));
|
||||||
|
}
|
||||||
|
return MccSimpleGuidingModelErrorCode::ERROR_HARDWARE_SETPOS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MccSimpleGuidingModelErrorCode::ERROR_OK;
|
return MccSimpleGuidingModelErrorCode::ERROR_OK;
|
||||||
|
|||||||
@ -251,6 +251,11 @@ public:
|
|||||||
|
|
||||||
/* time-related methods */
|
/* time-related methods */
|
||||||
|
|
||||||
|
static time_point_t timePointNow()
|
||||||
|
{
|
||||||
|
return time_point_t::clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
// templated generic version
|
// templated generic version
|
||||||
template <mcc::traits::mcc_systime_c TpT>
|
template <mcc::traits::mcc_systime_c TpT>
|
||||||
error_t greg2jul(TpT time_point, juldate_t& juldate)
|
error_t greg2jul(TpT time_point, juldate_t& juldate)
|
||||||
|
|||||||
@ -72,6 +72,15 @@ struct MccNullLogger {
|
|||||||
void logInfo(const std::string&) {};
|
void logInfo(const std::string&) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct MccCelestialPoint {
|
||||||
|
typedef double coord_t;
|
||||||
|
|
||||||
|
MccCoordPairKind coordPairKind{MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||||
|
coord_t x{0.0}, y{0.0};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace mcc
|
} // namespace mcc
|
||||||
|
|
||||||
|
|
||||||
@ -98,6 +107,7 @@ concept mcc_logger_c = requires(T t, const T t_const) {
|
|||||||
{ t.logInfo(std::declval<const std::string&>()) };
|
{ t.logInfo(std::declval<const std::string&>()) };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* ASTROMETRY-RELATED COMPUTATION ENGINE */
|
/* ASTROMETRY-RELATED COMPUTATION ENGINE */
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -165,6 +175,9 @@ concept mcc_astrom_engine_c = requires(T t, const T t_const) {
|
|||||||
|
|
||||||
/* time-related methods */
|
/* time-related methods */
|
||||||
|
|
||||||
|
// this static method must return a current time point
|
||||||
|
{ T::timePointNow() } -> std::same_as<typename T::time_point_t>;
|
||||||
|
|
||||||
// Gregorian Calendar time point to Julian Date: greg2jul(time_point, jd)
|
// Gregorian Calendar time point to Julian Date: greg2jul(time_point, jd)
|
||||||
{
|
{
|
||||||
t.greg2jul(std::declval<typename T::time_point_t>(), std::declval<typename T::juldate_t&>())
|
t.greg2jul(std::declval<typename T::time_point_t>(), std::declval<typename T::juldate_t&>())
|
||||||
@ -202,20 +215,48 @@ concept mcc_mount_hardware_c = !std::copyable<T> && std::movable<T> && requires(
|
|||||||
|
|
||||||
{ t_const.id() } -> mcc_formattable;
|
{ 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}
|
||||||
|
//
|
||||||
|
// struct HW_STATE {
|
||||||
|
// uint8_t HW_STATE_STOP = 100;
|
||||||
|
// uint8_t HW_STATE_SLEW = 200;
|
||||||
|
// uint8_t HW_STATE_TRACK = 300;
|
||||||
|
// }
|
||||||
|
requires requires(typename T::hw_state_t state) {
|
||||||
|
[]() {
|
||||||
|
// hardware is in stop state (no any moving)
|
||||||
|
static constexpr auto v1 = T::hw_state_t::HW_STATE_STOP;
|
||||||
|
// hardware is in slew state (move to given celestial point)
|
||||||
|
|
||||||
|
static constexpr auto v2 = T::hw_state_t::HW_STATE_SLEW;
|
||||||
|
|
||||||
|
// hardware is in track state (track given celestial point)
|
||||||
|
static constexpr auto v3 = T::hw_state_t::HW_STATE_TRACK;
|
||||||
|
}();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// a class that contains at least time of measurement, coordinates for x,y axes and its moving rates
|
// 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 requires(typename T::axes_pos_t pos) {
|
||||||
requires std::same_as<decltype(pos.time_point), typename T::time_point_t>;
|
requires std::same_as<decltype(pos.time_point), typename T::time_point_t>; // time point of measurement
|
||||||
|
|
||||||
requires std::same_as<decltype(pos.x), typename T::coord_t>;
|
requires std::same_as<decltype(pos.x), typename T::coord_t>; // co-longitude coordinate
|
||||||
requires std::same_as<decltype(pos.y), typename T::coord_t>;
|
requires std::same_as<decltype(pos.y), typename T::coord_t>; // co-latitude coordinate
|
||||||
|
|
||||||
requires std::same_as<decltype(pos.xrate), typename T::coord_t>;
|
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.yrate), typename T::coord_t>;
|
||||||
|
|
||||||
|
requires std::same_as<decltype(pos.state), typename T::hw_state_t>; // hardware state
|
||||||
};
|
};
|
||||||
|
|
||||||
{ t.setPos(std::declval<typename T::axes_pos_t>()) } -> std::same_as<typename T::error_t>;
|
{ 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.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>;
|
||||||
|
|
||||||
{ t.stop() } -> std::same_as<typename T::error_t>;
|
{ t.stop() } -> std::same_as<typename T::error_t>;
|
||||||
{ t.init() } -> std::same_as<typename T::error_t>;
|
{ t.init() } -> std::same_as<typename T::error_t>;
|
||||||
};
|
};
|
||||||
@ -302,11 +343,11 @@ concept mcc_mount_telemetry_c = requires(T t, const T t_const) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* A CONCEPT FOR CLASS TO REPRESENT CELESTIAL POINT */
|
||||||
|
|
||||||
/* SLEW PARAMETERS */
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept mcc_slew_params_c = std::movable<T> && requires(T t) {
|
concept mcc_celestial_point_c = requires(T t) {
|
||||||
// input coordinates pair type (e.g. IRCS RA,DEC, Az,Alt and so on)
|
// input coordinates pair type (e.g. IRCS RA,DEC, Az,Alt and so on)
|
||||||
requires std::same_as<decltype(t.coordPairKind), MccCoordPairKind>;
|
requires std::same_as<decltype(t.coordPairKind), MccCoordPairKind>;
|
||||||
|
|
||||||
@ -317,37 +358,49 @@ concept mcc_slew_params_c = std::movable<T> && requires(T t) {
|
|||||||
|
|
||||||
// co-latitude (e.g. DEC or ZD)
|
// co-latitude (e.g. DEC or ZD)
|
||||||
requires std::same_as<decltype(t.y), typename T::coord_t>;
|
requires std::same_as<decltype(t.y), typename T::coord_t>;
|
||||||
|
|
||||||
// stop after slewing
|
|
||||||
requires std::convertible_to<decltype(t.stop), bool>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// /* SLEW PARAMETERS */
|
||||||
|
|
||||||
|
// template <typename T>
|
||||||
|
// concept mcc_slew_params_c = std::movable<T> && requires(T t) {
|
||||||
|
// // input coordinates pair type (e.g. IRCS RA,DEC, Az,Alt and so on)
|
||||||
|
// requires std::same_as<decltype(t.coordPairKind), MccCoordPairKind>;
|
||||||
|
|
||||||
|
// typename T::coord_t;
|
||||||
|
|
||||||
|
// // co-longitude (e.g. RA or Az)
|
||||||
|
// requires std::same_as<decltype(t.x), typename T::coord_t>;
|
||||||
|
|
||||||
|
// // co-latitude (e.g. DEC or ZD)
|
||||||
|
// requires std::same_as<decltype(t.y), typename T::coord_t>;
|
||||||
|
|
||||||
|
// // stop after slewing
|
||||||
|
// requires std::convertible_to<decltype(t.stop), bool>;
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
/* GENERIC SLEW AND GUIDING MODEL */
|
/* GENERIC SLEW AND GUIDING MODEL */
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept mcc_slew_model_c = requires(T t) {
|
concept mcc_slew_model_c = requires(T t) {
|
||||||
requires mcc_error_c<typename T::error_t>;
|
requires mcc_error_c<typename T::error_t>;
|
||||||
requires mcc_slew_params_c<typename T::slew_params_t>;
|
// requires mcc_slew_params_c<typename T::slew_params_t>;
|
||||||
|
requires mcc_celestial_point_c<typename T::slew_point_t>;
|
||||||
|
|
||||||
{ t.slew(std::declval<typename T::slew_params_t>()) } -> std::same_as<typename T::error_t>;
|
// { t.slew(std::declval<typename T::slew_params_t>()) } -> std::same_as<typename T::error_t>;
|
||||||
|
{ t.slew(std::declval<typename T::slew_point_t>()) } -> std::same_as<typename T::error_t>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// template <typename T, typename TelemetryT>
|
|
||||||
// concept mcc_slew_model_c = mcc_mount_telemetry_c<TelemetryT> && requires(T t) {
|
|
||||||
// requires mcc_error_c<typename T::error_t>;
|
|
||||||
// requires mcc_slew_params_c<typename T::slew_params_t>;
|
|
||||||
|
|
||||||
// {
|
template <typename T>
|
||||||
// t.slew(std::declval<typename T::slew_params_t>(), std::declval<TelemetryT&>())
|
concept mcc_guiding_model_c = requires(T t) {
|
||||||
// } -> std::same_as<typename T::error_t>;
|
requires mcc_error_c<typename T::error_t>;
|
||||||
// };
|
requires mcc_celestial_point_c<typename T::guiding_point_t>;
|
||||||
|
|
||||||
template <typename T, typename TelemetryT>
|
// start process of guiding
|
||||||
concept mcc_guiding_model_c = mcc_mount_telemetry_c<TelemetryT> && requires(T t) {
|
{ t.guiding(std::declval<typename T::guiding_point_t>()) } -> std::same_as<typename T::error_t>;
|
||||||
typename T::error_t;
|
|
||||||
|
|
||||||
{ t.guiding(std::declval<TelemetryT&>()) } -> std::same_as<typename T::error_t>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -438,7 +491,8 @@ concept mcc_mount_controls_c = std::move_constructible<T> && std::movable<T> &&
|
|||||||
|
|
||||||
requires mcc_slew_model_c<decltype(t.slewModel)>;
|
requires mcc_slew_model_c<decltype(t.slewModel)>;
|
||||||
// requires mcc_slew_model_c<decltype(t.slewModel), decltype(t.telemetry)>;
|
// requires mcc_slew_model_c<decltype(t.slewModel), decltype(t.telemetry)>;
|
||||||
requires mcc_guiding_model_c<decltype(t.guidingModel), decltype(t.telemetry)>;
|
requires mcc_guiding_model_c<decltype(t.guidingModel)>;
|
||||||
|
// requires mcc_guiding_model_c<decltype(t.guidingModel), decltype(t.telemetry)>;
|
||||||
|
|
||||||
// a std::tuple of prohibited zones
|
// a std::tuple of prohibited zones
|
||||||
[]<mcc_prohibited_zone_c<typename decltype(t.telemetry)::mount_telemetry_data_t>... Ts>(std::tuple<Ts...>) {
|
[]<mcc_prohibited_zone_c<typename decltype(t.telemetry)::mount_telemetry_data_t>... Ts>(std::tuple<Ts...>) {
|
||||||
@ -463,7 +517,8 @@ concept mcc_mount_c = requires(T t) {
|
|||||||
requires mcc_mount_hardware_c<typename T::hardware_t>;
|
requires mcc_mount_hardware_c<typename T::hardware_t>;
|
||||||
// requires mcc_slew_model_c<typename T::slew_model_t, typename T::mount_telemetry_t>;
|
// requires mcc_slew_model_c<typename T::slew_model_t, typename T::mount_telemetry_t>;
|
||||||
requires mcc_slew_model_c<typename T::slew_model_t>;
|
requires mcc_slew_model_c<typename T::slew_model_t>;
|
||||||
requires mcc_guiding_model_c<typename T::guiding_model_t, typename T::mount_telemetry_t>;
|
// requires mcc_guiding_model_c<typename T::guiding_model_t, typename T::mount_telemetry_t>;
|
||||||
|
requires mcc_guiding_model_c<typename T::guiding_model_t>;
|
||||||
|
|
||||||
requires std::same_as<typename T::slew_params_t, typename T::slew_model_t::slew_params_t>;
|
requires std::same_as<typename T::slew_params_t, typename T::slew_model_t::slew_params_t>;
|
||||||
|
|
||||||
@ -481,3 +536,15 @@ template <typename T>
|
|||||||
concept mcc_fsm_log_mount_c = std::derived_from<T, fsm::MccFiniteStateMachine> && mcc_log_mount_c<T>;
|
concept mcc_fsm_log_mount_c = std::derived_from<T, fsm::MccFiniteStateMachine> && mcc_log_mount_c<T>;
|
||||||
|
|
||||||
} // namespace mcc::traits
|
} // namespace mcc::traits
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* CHECK LIBRARY-WIDE CLASS DECLARATIONS FOR ITS CONCEPTS SATISFACTION */
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
|
||||||
|
static_assert(traits::mcc_logger_c<MccNullLogger>, "MccNullLogger INVALID DECLARATION!");
|
||||||
|
static_assert(traits::mcc_celestial_point_c<MccCelestialPoint>, "MccCelestialPoint INVALID DECLARATION!");
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
|
|||||||
@ -98,18 +98,18 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// by default angle is in radians
|
// by default angle is in radians
|
||||||
MccAngle(const double& val, const MccRadianTag = MccRadianTag{}) : _angleInRads(val) {}
|
constexpr MccAngle(const double& val, const MccRadianTag = MccRadianTag{}) : _angleInRads(val) {}
|
||||||
|
|
||||||
// construct angle in degrees, e.g.:
|
// construct angle in degrees, e.g.:
|
||||||
// auto ang = MccAngle{180.0, mcc_degrees};
|
// auto ang = MccAngle{180.0, mcc_degrees};
|
||||||
MccAngle(const double& val, const MccDegreeTag) : _angleInRads(val * utils::deg2radCoeff) {}
|
constexpr MccAngle(const double& val, const MccDegreeTag) : _angleInRads(val * utils::deg2radCoeff) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// constuct angle from sexagesimal representation or floating-point number of degrees, e.g.:
|
// constuct angle from sexagesimal representation or floating-point number of degrees, e.g.:
|
||||||
// auto ang = MccAngle{"-12:34:56.789"}; // from degrees:minutes:seconds
|
// auto ang = MccAngle{"-12:34:56.789"}; // from degrees:minutes:seconds
|
||||||
// auto ang = MccAngle{"123.574698"}; // from degrees
|
// auto ang = MccAngle{"123.574698"}; // from degrees
|
||||||
MccAngle(traits::mcc_input_char_range auto const& val)
|
constexpr MccAngle(traits::mcc_input_char_range auto const& val)
|
||||||
{
|
{
|
||||||
auto res = utils::parsAngleString(val);
|
auto res = utils::parsAngleString(val);
|
||||||
if (res.has_value()) {
|
if (res.has_value()) {
|
||||||
@ -122,7 +122,7 @@ public:
|
|||||||
// construct angle from sexagesimal representation or floating-point number of degrees, e.g.:
|
// construct angle from sexagesimal representation or floating-point number of degrees, e.g.:
|
||||||
// auto ang = MccAngle{"01:23:45.6789", mcc_hms}; // from hours:minutes:seconds
|
// auto ang = MccAngle{"01:23:45.6789", mcc_hms}; // from hours:minutes:seconds
|
||||||
// auto ang = MccAngle{"123.574698"}; // from degrees
|
// auto ang = MccAngle{"123.574698"}; // from degrees
|
||||||
MccAngle(traits::mcc_input_char_range auto const& val, const MccHMSTag)
|
constexpr MccAngle(traits::mcc_input_char_range auto const& val, const MccHMSTag)
|
||||||
{
|
{
|
||||||
auto res = utils::parsAngleString(val, true);
|
auto res = utils::parsAngleString(val, true);
|
||||||
if (res.has_value()) {
|
if (res.has_value()) {
|
||||||
@ -135,7 +135,7 @@ public:
|
|||||||
virtual ~MccAngle() = default;
|
virtual ~MccAngle() = default;
|
||||||
|
|
||||||
template <std::derived_from<MccAngle> T>
|
template <std::derived_from<MccAngle> T>
|
||||||
auto& operator=(this T&& self, const T& other)
|
constexpr auto& operator=(this T&& self, const T& other)
|
||||||
{
|
{
|
||||||
std::forward<decltype(self)>(self)._angleInRads = other._angleInRads;
|
std::forward<decltype(self)>(self)._angleInRads = other._angleInRads;
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <std::derived_from<MccAngle> T>
|
template <std::derived_from<MccAngle> T>
|
||||||
auto& operator=(this T&& self, T&& other)
|
constexpr auto& operator=(this T&& self, T&& other)
|
||||||
{
|
{
|
||||||
std::forward<decltype(self)>(self)._angleInRads = std::move(other._angleInRads);
|
std::forward<decltype(self)>(self)._angleInRads = std::move(other._angleInRads);
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto& operator=(this auto&& self, const T& val)
|
constexpr auto& operator=(this auto&& self, const T& val)
|
||||||
requires std::is_arithmetic_v<T>
|
requires std::is_arithmetic_v<T>
|
||||||
{
|
{
|
||||||
std::forward<decltype(self)>(self)._angleInRads = val;
|
std::forward<decltype(self)>(self)._angleInRads = val;
|
||||||
@ -209,19 +209,19 @@ public:
|
|||||||
// return _angleInRads;
|
// return _angleInRads;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
operator double() const
|
constexpr operator double() const
|
||||||
{
|
{
|
||||||
return _angleInRads;
|
return _angleInRads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T degrees() const
|
constexpr T degrees() const
|
||||||
{
|
{
|
||||||
return _angleInRads * 180.0 / std::numbers::pi;
|
return _angleInRads * 180.0 / std::numbers::pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
double degrees() const
|
constexpr double degrees() const
|
||||||
{
|
{
|
||||||
return degrees<double>();
|
return degrees<double>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ enum class MccSimpleSlewModelErrorCode : int {
|
|||||||
ERROR_TELEMETRY_DATA,
|
ERROR_TELEMETRY_DATA,
|
||||||
ERROR_PEC_COMP,
|
ERROR_PEC_COMP,
|
||||||
ERROR_HARDWARE_SETPOS,
|
ERROR_HARDWARE_SETPOS,
|
||||||
|
ERROR_HARDWARE_GETPOS,
|
||||||
ERROR_SLEW_TIMEOUT
|
ERROR_SLEW_TIMEOUT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -59,6 +60,8 @@ struct MccSimpleSlewModelCategory : public std::error_category {
|
|||||||
switch (err) {
|
switch (err) {
|
||||||
case MccSimpleSlewModelErrorCode::ERROR_OK:
|
case MccSimpleSlewModelErrorCode::ERROR_OK:
|
||||||
return "OK";
|
return "OK";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR:
|
||||||
|
return "slew model: unsupported coordinate pair";
|
||||||
case MccSimpleSlewModelErrorCode::ERROR_IN_PROHIBITED_ZONE:
|
case MccSimpleSlewModelErrorCode::ERROR_IN_PROHIBITED_ZONE:
|
||||||
return "slew model: position is in prohibited zone";
|
return "slew model: position is in prohibited zone";
|
||||||
case MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP:
|
case MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP:
|
||||||
@ -69,6 +72,8 @@ struct MccSimpleSlewModelCategory : public std::error_category {
|
|||||||
return "slew model: cannot compute PEC corrections";
|
return "slew model: cannot compute PEC corrections";
|
||||||
case MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS:
|
case MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS:
|
||||||
return "slew model: cannot set position";
|
return "slew model: cannot set position";
|
||||||
|
case MccSimpleSlewModelErrorCode::ERROR_HARDWARE_GETPOS:
|
||||||
|
return "slew model: cannot get position";
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
@ -106,31 +111,26 @@ public:
|
|||||||
|
|
||||||
typedef std::error_code error_t;
|
typedef std::error_code error_t;
|
||||||
|
|
||||||
struct slew_params_t {
|
typedef MccCelestialPoint slew_point_t;
|
||||||
typedef mcc::MccAngle coord_t;
|
|
||||||
|
|
||||||
mcc::MccCoordPairKind coordPairKind{mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
// struct slew_params_t {
|
||||||
|
// typedef mcc::MccAngle coord_t;
|
||||||
|
|
||||||
coord_t x{0.0};
|
// mcc::MccCoordPairKind coordPairKind{mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||||
coord_t y{0.0};
|
|
||||||
|
|
||||||
// if <= 0 then hardware must assume default rate
|
// coord_t x{0.0};
|
||||||
coord_t xrate{-1};
|
// coord_t y{0.0};
|
||||||
coord_t yrate{-1};
|
|
||||||
|
|
||||||
bool stop{false};
|
// // if <= 0 then hardware must assume default rate
|
||||||
};
|
// coord_t xrate{-1};
|
||||||
|
// coord_t yrate{-1};
|
||||||
|
|
||||||
|
// bool stop{false};
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
struct context_t {
|
struct context_t {
|
||||||
// double eps{0.01};
|
bool stopAfterSlew{false};
|
||||||
// size_t maxIter{5};
|
|
||||||
|
|
||||||
slew_params_t::coord_t guidingRateX;
|
|
||||||
slew_params_t::coord_t guidingRateY;
|
|
||||||
slew_params_t::coord_t guidingRateEps;
|
|
||||||
size_t maxRateCycles{5};
|
|
||||||
|
|
||||||
std::chrono::seconds timeout{300};
|
std::chrono::seconds timeout{300};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public:
|
|||||||
logDebug(std::format("Delete 'MccSimpleSlewModel' class instance ({})", (void*)this));
|
logDebug(std::format("Delete 'MccSimpleSlewModel' class instance ({})", (void*)this));
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t slew(slew_params_t pars)
|
error_t slew(slew_point_t pars)
|
||||||
{
|
{
|
||||||
error_t res_err = _slewFunc(std::move(pars));
|
error_t res_err = _slewFunc(std::move(pars));
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::function<error_t(const slew_params_t&)> _slewFunc{};
|
std::function<error_t(const slew_point_t&)> _slewFunc{};
|
||||||
|
|
||||||
void init(auto& mount_controls, context_t context)
|
void init(auto& mount_controls, context_t context)
|
||||||
{
|
{
|
||||||
@ -215,7 +215,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
_slewFunc = [p_mount_controls, context = std::move(context), check_zones](this auto&& self,
|
_slewFunc = [p_mount_controls, context = std::move(context), check_zones](this auto&& self,
|
||||||
slew_params_t slew_pars) {
|
slew_point_t slew_point) {
|
||||||
auto& astrom_engine = p_mount_controls->astrometryEngine;
|
auto& astrom_engine = p_mount_controls->astrometryEngine;
|
||||||
auto& hardware = p_mount_controls->hardware;
|
auto& hardware = p_mount_controls->hardware;
|
||||||
auto& pec = p_mount_controls->PEC;
|
auto& pec = p_mount_controls->PEC;
|
||||||
@ -234,14 +234,14 @@ protected:
|
|||||||
typename telemetry_t::mount_telemetry_data_t t_data;
|
typename telemetry_t::mount_telemetry_data_t t_data;
|
||||||
|
|
||||||
|
|
||||||
if (slew_pars.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_XY) {
|
if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_XY) {
|
||||||
// trivial case (the pair is interpretated as raw encoder coordinates)
|
// trivial case (the pair is interpretated as raw encoder coordinates)
|
||||||
ax_pos.x = slew_pars.x;
|
ax_pos.x = slew_point.x;
|
||||||
ax_pos.y = slew_pars.y;
|
ax_pos.y = slew_point.y;
|
||||||
ax_pos.xrate = slew_pars.xrate;
|
// ax_pos.xrate = slew_point.xrate;
|
||||||
ax_pos.yrate = slew_pars.yrate;
|
// ax_pos.yrate = slew_point.yrate;
|
||||||
|
|
||||||
} else if (slew_pars.coordPairKind ==
|
} else if (slew_point.coordPairKind ==
|
||||||
mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { // catalog coordinates
|
mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { // catalog coordinates
|
||||||
jd_t jd;
|
jd_t jd;
|
||||||
coord_t ra_app, dec_app, ha, az, alt;
|
coord_t ra_app, dec_app, ha, az, alt;
|
||||||
@ -249,37 +249,38 @@ protected:
|
|||||||
|
|
||||||
logDebug("Input slew coordinates are ICRS RA-DEC: convert it to apparent ...");
|
logDebug("Input slew coordinates are ICRS RA-DEC: convert it to apparent ...");
|
||||||
|
|
||||||
ast_err = astrom_engine->greg2jul(std::chrono::system_clock::now(), jd);
|
|
||||||
|
ast_err = astrom_engine->greg2jul(astrom_engine_t::timePointNow(), jd);
|
||||||
|
|
||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
ast_err = astrom_engine->icrs2obs(slew_pars.x, slew_pars.y, jd, ra_app, dec_app, ha, az, alt, eo);
|
ast_err = astrom_engine->icrs2obs(slew_point.x, slew_point.y, jd, ra_app, dec_app, ha, az, alt, eo);
|
||||||
|
|
||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
slew_pars.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
slew_pars.x = ha;
|
slew_point.x = ha;
|
||||||
slew_pars.y = dec_app;
|
slew_point.y = dec_app;
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
slew_pars.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
||||||
slew_pars.x = az;
|
slew_point.x = az;
|
||||||
slew_pars.y = alt;
|
slew_point.y = alt;
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
} else {
|
} else {
|
||||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (slew_pars.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_RADEC_APP) { // apparent
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_RADEC_APP) { // apparent
|
||||||
jd_t jd;
|
jd_t jd;
|
||||||
typename astrom_engine_t::eo_t eo;
|
typename astrom_engine_t::eo_t eo;
|
||||||
|
|
||||||
logDebug("Input slew coordinates are apparent RA-DEC: convert it to apparent HA-DEC ...");
|
logDebug("Input slew coordinates are apparent RA-DEC: convert it to apparent HA-DEC ...");
|
||||||
|
|
||||||
ast_err = astrom_engine->greg2jul(std::chrono::system_clock::now(), jd);
|
ast_err = astrom_engine->greg2jul(astrom_engine_t::timePointNow(), jd);
|
||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
typename astrom_engine_t::sideral_time_t lst;
|
typename astrom_engine_t::sideral_time_t lst;
|
||||||
ast_err = astrom_engine->apparentSiderTime(jd, lst, true);
|
ast_err = astrom_engine->apparentSiderTime(jd, lst, true);
|
||||||
@ -287,14 +288,14 @@ protected:
|
|||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
ast_err = astrom_engine->eqOrigins(jd, eo);
|
ast_err = astrom_engine->eqOrigins(jd, eo);
|
||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
slew_pars.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
slew_pars.x = lst - slew_pars.x + eo; // HA = LST - RA_APP + EO
|
slew_point.x = lst - slew_point.x + eo; // HA = LST - RA_APP + EO
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (slew_pars.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP) { // apparent
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP) { // apparent
|
||||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) { // compute encoder coordinates
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) { // compute encoder coordinates
|
||||||
logDebug("Input slew coordinates are apparent HA-DEC: convert it to hardware encoder ones ...");
|
logDebug("Input slew coordinates are apparent HA-DEC: convert it to hardware encoder ones ...");
|
||||||
|
|
||||||
@ -302,46 +303,46 @@ protected:
|
|||||||
|
|
||||||
typename pec_t::pec_result_t pec_res;
|
typename pec_t::pec_result_t pec_res;
|
||||||
|
|
||||||
// pec_err = pec->reverseCompute(slew_pars.x, slew_pars.y, pec_res, context.eps, context.maxIter);
|
// pec_err = pec->reverseCompute(slew_point.x, slew_point.y, pec_res, context.eps, context.maxIter);
|
||||||
pec_err = pec->compute(slew_pars.x, slew_pars.y, pec_res);
|
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
||||||
if (!pec_err) {
|
if (!pec_err) {
|
||||||
slew_pars.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
||||||
slew_pars.x -= pec_res.dx;
|
slew_point.x -= pec_res.dx;
|
||||||
slew_pars.y -= pec_res.dy;
|
slew_point.y -= pec_res.dy;
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
}
|
}
|
||||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||||
coord_t az, alt;
|
coord_t az, alt;
|
||||||
|
|
||||||
logDebug("Input slew coordinates are apparent HA-DEC: convert it to AZ-ALT ...");
|
logDebug("Input slew coordinates are apparent HA-DEC: convert it to AZ-ALT ...");
|
||||||
|
|
||||||
ast_err = astrom_engine->hadec2azalt(slew_pars.x, slew_pars.y, az, alt);
|
ast_err = astrom_engine->hadec2azalt(slew_point.x, slew_point.y, az, alt);
|
||||||
|
|
||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
slew_pars.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_AZALT;
|
||||||
slew_pars.x = az;
|
slew_point.x = az;
|
||||||
slew_pars.y = alt;
|
slew_point.y = alt;
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||||
}
|
}
|
||||||
} else if (slew_pars.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZALT) {
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZALT) {
|
||||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||||
coord_t ha, dec;
|
coord_t ha, dec;
|
||||||
|
|
||||||
logDebug("Input slew coordinates are AZ-ALT: convert it to HA-DEC ...");
|
logDebug("Input slew coordinates are AZ-ALT: convert it to HA-DEC ...");
|
||||||
|
|
||||||
ast_err = astrom_engine->azalt2hadec(slew_pars.x, slew_pars.y, ha, dec);
|
ast_err = astrom_engine->azalt2hadec(slew_point.x, slew_point.y, ha, dec);
|
||||||
|
|
||||||
if (!ast_err) {
|
if (!ast_err) {
|
||||||
slew_pars.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
slew_pars.x = ha;
|
slew_point.x = ha;
|
||||||
slew_pars.y = dec;
|
slew_point.y = dec;
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
}
|
}
|
||||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) { // compute encoder coordinates
|
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) { // compute encoder coordinates
|
||||||
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
||||||
@ -350,28 +351,28 @@ protected:
|
|||||||
|
|
||||||
typename pec_t::pec_result_t pec_res;
|
typename pec_t::pec_result_t pec_res;
|
||||||
|
|
||||||
// pec_err = pec->reverseCompute(slew_pars.x, slew_pars.y, pec_res, context.eps, context.maxIter);
|
// pec_err = pec->reverseCompute(slew_point.x, slew_point.y, pec_res, context.eps, context.maxIter);
|
||||||
pec_err = pec->compute(slew_pars.x, slew_pars.y, pec_res);
|
pec_err = pec->compute(slew_point.x, slew_point.y, pec_res);
|
||||||
if (!pec_err) {
|
if (!pec_err) {
|
||||||
slew_pars.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
slew_point.coordPairKind = mcc::MccCoordPairKind::COORDS_KIND_XY;
|
||||||
slew_pars.x -= pec_res.dx;
|
slew_point.x -= pec_res.dx;
|
||||||
slew_pars.y -= pec_res.dy;
|
slew_point.y -= pec_res.dy;
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||||
}
|
}
|
||||||
} else if (slew_pars.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZZD) {
|
} else if (slew_point.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_AZZD) {
|
||||||
//
|
//
|
||||||
// WARNING: it is assumed that coordinates are in radians!
|
// WARNING: it is assumed that coordinates are in radians!
|
||||||
//
|
//
|
||||||
logDebug("Input slew coordinates are AZ-ZD: convert it to AZ-ALT ...");
|
logDebug("Input slew coordinates are AZ-ZD: convert it to AZ-ALT ...");
|
||||||
|
|
||||||
slew_pars.y = std::numbers::pi / 2.0 - slew_pars.y;
|
slew_point.y = std::numbers::pi / 2.0 - slew_point.y;
|
||||||
|
|
||||||
res_err = self(std::move(slew_pars));
|
res_err = self(std::move(slew_point));
|
||||||
} else {
|
} else {
|
||||||
return MccSimpleSlewModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
return MccSimpleSlewModelErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||||
}
|
}
|
||||||
@ -424,12 +425,13 @@ protected:
|
|||||||
|
|
||||||
size_t i_iter = 0;
|
size_t i_iter = 0;
|
||||||
|
|
||||||
context.guidingRateEps *= context.guidingRateEps;
|
// context.guidingRateEps *= context.guidingRateEps;
|
||||||
|
|
||||||
typename telemetry_t::mount_telemetry_data_t::time_point_t prev_time_point{};
|
typename hardware_t::axes_pos_t::time_point_t prev_time_point{};
|
||||||
typename telemetry_t::mount_telemetry_data_t::coord_t xrate, yrate, mount_rate2;
|
// typename telemetry_t::mount_telemetry_data_t::time_point_t prev_time_point{};
|
||||||
|
// typename telemetry_t::mount_telemetry_data_t::coord_t xrate, yrate, mount_rate2;
|
||||||
|
|
||||||
auto start_poll_tm = std::chrono::high_resolution_clock::now();
|
auto start_poll_tm = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// check prohibited zones
|
// check prohibited zones
|
||||||
@ -441,53 +443,75 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// it is assumed here that telemetry data is in actual state!
|
// it is assumed here that telemetry data is in actual state!
|
||||||
t_err = telemetry.data(t_data);
|
// t_err = telemetry.data(t_data);
|
||||||
if (t_err) {
|
// if (t_err) {
|
||||||
hardware.stop();
|
// hardware.stop();
|
||||||
|
|
||||||
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
// if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||||
logError(
|
// logError(
|
||||||
std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
// std::format("An telemetry error occured: code = {} ({})", t_err.value(),
|
||||||
return t_err;
|
// 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;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
err = hardware->getPos(ax_pos);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
if constexpr (std::same_as<decltype(err), error_t>) {
|
||||||
|
logError(std::format("An hardware error occured: code = {} ({})", err.value(), err.message()));
|
||||||
|
return err;
|
||||||
} else {
|
} else {
|
||||||
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
if constexpr (traits::mcc_formattable<decltype(err)>) {
|
||||||
logError(std::format("An telemetry error occured: code = {}", t_err));
|
logError(std::format("An hardware error occured: code = {}", err));
|
||||||
}
|
}
|
||||||
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
return MccSimpleSlewModelErrorCode::ERROR_HARDWARE_GETPOS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev_time_point == t_data.time_point) {
|
// if (prev_time_point == t_data.time_point) {
|
||||||
|
if (prev_time_point == ax_pos.time_point) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slew_pars.stop) { // slew and stop, so mount moving rate must be 0 at the end
|
if (context.stopAfterSlew) { // slew and stop, so mount moving rate must be 0 at the end
|
||||||
mount_rate2 = t_data.mntRateX * t_data.mntRateX + t_data.mntRateY * t_data.mntRateY;
|
if (ax_pos.state == hardware_t::hw_state_t::HW_STATE_STOP) {
|
||||||
|
|
||||||
if (utils::isEqual((double)mount_rate2, 0.0)) {
|
|
||||||
++i_iter;
|
|
||||||
} else {
|
|
||||||
i_iter = 0;
|
|
||||||
}
|
|
||||||
} else { // slew and guiding, so mount rate must be near guiding rate at the end
|
|
||||||
xrate = t_data.mntRateX - context.guidingRateX;
|
|
||||||
yrate = t_data.mntRateY - context.guidingRateY;
|
|
||||||
mount_rate2 = xrate * xrate + yrate * yrate;
|
|
||||||
|
|
||||||
if (mount_rate2 <= context.guidingRateEps) {
|
|
||||||
++i_iter;
|
|
||||||
} else {
|
|
||||||
i_iter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i_iter >= context.maxRateCycles) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// mount_rate2 = t_data.mntRateX * t_data.mntRateX + t_data.mntRateY * t_data.mntRateY;
|
||||||
|
|
||||||
|
// if (utils::isEqual((double)mount_rate2, 0.0)) {
|
||||||
|
// ++i_iter;
|
||||||
|
// } else {
|
||||||
|
// i_iter = 0;
|
||||||
|
// }
|
||||||
|
} else { // slew and guiding, so mount rate must be near tracking rate at the end
|
||||||
|
if (ax_pos.state == hardware_t::hw_state_t::HW_STATE_TRACK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// xrate = t_data.mntRateX - context.guidingRateX;
|
||||||
|
// yrate = t_data.mntRateY - context.guidingRateY;
|
||||||
|
// mount_rate2 = xrate * xrate + yrate * yrate;
|
||||||
|
|
||||||
|
// if (mount_rate2 <= context.guidingRateEps) {
|
||||||
|
// ++i_iter;
|
||||||
|
// } else {
|
||||||
|
// i_iter = 0;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (i_iter >= context.maxRateCycles) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
prev_time_point = t_data.time_point;
|
prev_time_point = t_data.time_point;
|
||||||
|
|
||||||
if ((std::chrono::high_resolution_clock::now() - start_poll_tm) > context.timeout) {
|
if ((std::chrono::steady_clock::now() - start_poll_tm) > context.timeout) {
|
||||||
logError("Waiting time for completion of slewing expired!");
|
logError("Waiting time for completion of slewing expired!");
|
||||||
return MccSimpleSlewModelErrorCode::ERROR_SLEW_TIMEOUT;
|
return MccSimpleSlewModelErrorCode::ERROR_SLEW_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user