...
This commit is contained in:
parent
85e99151a8
commit
fc943abe03
@ -53,6 +53,25 @@ static consteval bool mccIsAltAzMount(const MccMountType type)
|
||||
: false;
|
||||
};
|
||||
|
||||
|
||||
/* NULL-LOGGER CLASS */
|
||||
|
||||
struct MccNullLogger {
|
||||
typedef int loglevel_t;
|
||||
|
||||
void setLogLevel(loglevel_t){};
|
||||
loglevel_t getLogLevel() const
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
void logMessage(loglevel_t, const std::string&) {};
|
||||
void logError(const std::string&) {};
|
||||
void logDebug(const std::string&) {};
|
||||
void logWarn(const std::string&) {};
|
||||
void logInfo(const std::string&) {};
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
|
||||
|
||||
@ -93,8 +93,15 @@ inline std::error_code make_error_code(MccSimpleSlewModelErrorCode ec)
|
||||
* [azimuth, zenithal distance] (see sources code below)
|
||||
*/
|
||||
|
||||
class MccSimpleSlewModel
|
||||
template <traits::mcc_logger_c LoggerT = MccNullLogger>
|
||||
class MccSimpleSlewModel : public LoggerT
|
||||
{
|
||||
using LoggerT::logDebug;
|
||||
using LoggerT::logError;
|
||||
using LoggerT::logInfo;
|
||||
using LoggerT::logMessage;
|
||||
using LoggerT::logWarn;
|
||||
|
||||
public:
|
||||
typedef std::error_code error_t;
|
||||
|
||||
@ -126,9 +133,39 @@ public:
|
||||
std::chrono::seconds timeout{300};
|
||||
};
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T, typename... LoggerCtorArgTs>
|
||||
MccSimpleSlewModel(MOUNT_CONTROLS_T& mount_controls, context_t context, LoggerCtorArgTs&&... ctor_args)
|
||||
requires(!std::same_as<LoggerT, MccNullLogger>)
|
||||
: LoggerT(std::forward<LoggerCtorArgTs>(ctor_args)...)
|
||||
{
|
||||
logDebug(std::format("Create 'MccSimpleSlewModel' class instance ({})", (void*)this));
|
||||
|
||||
init(mount_controls, std::move(context));
|
||||
}
|
||||
|
||||
template <traits::mcc_mount_controls_c MOUNT_CONTROLS_T>
|
||||
MccSimpleSlewModel(MOUNT_CONTROLS_T& mount_controls, context_t context)
|
||||
requires(std::same_as<LoggerT, MccNullLogger>)
|
||||
{
|
||||
init(mount_controls, std::move(context));
|
||||
}
|
||||
|
||||
virtual ~MccSimpleSlewModel()
|
||||
{
|
||||
logDebug(std::format("Delete 'MccSimpleSlewModel' class instance ({})", (void*)this));
|
||||
}
|
||||
|
||||
error_t slew(slew_params_t pars)
|
||||
{
|
||||
error_t res_err = _slewFunc(std::move(pars));
|
||||
|
||||
return res_err;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<error_t(const slew_params_t&)> _slewFunc{};
|
||||
|
||||
void init(auto& mount_controls, context_t context)
|
||||
{
|
||||
// deduce controls types
|
||||
using astrom_engine_t = decltype(mount_controls.astrometryEngine);
|
||||
@ -176,7 +213,6 @@ public:
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
_slewFunc = [p_mount_controls, context = std::move(context), check_zones](this auto&& self,
|
||||
slew_params_t slew_pars) {
|
||||
auto& astrom_engine = p_mount_controls->astrometryEngine;
|
||||
@ -193,6 +229,10 @@ public:
|
||||
typename astrom_engine_t::error_t ast_err;
|
||||
typename pec_t::error_t pec_err;
|
||||
|
||||
typename telemetry_t::error_t t_err;
|
||||
typename telemetry_t::mount_telemetry_data_t t_data;
|
||||
|
||||
|
||||
if (slew_pars.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_XY) {
|
||||
// trivial case (the pair is interpretated as raw encoder coordinates)
|
||||
ax_pos.x = slew_pars.x;
|
||||
@ -206,6 +246,8 @@ public:
|
||||
coord_t ra_app, dec_app, ha, az, alt;
|
||||
typename astrom_engine_t::eo_t eo;
|
||||
|
||||
logDebug("Input slew coordinates are ICRS RA-DEC: convert it to apparent ...");
|
||||
|
||||
ast_err = astrom_engine->greg2jul(std::chrono::system_clock::now(), jd);
|
||||
|
||||
if (!ast_err) {
|
||||
@ -234,6 +276,8 @@ public:
|
||||
jd_t jd;
|
||||
typename astrom_engine_t::eo_t eo;
|
||||
|
||||
logDebug("Input slew coordinates are apparent RA-DEC: convert it to apparent HA-DEC ...");
|
||||
|
||||
ast_err = astrom_engine->greg2jul(std::chrono::system_clock::now(), jd);
|
||||
if (!ast_err) {
|
||||
typename astrom_engine_t::sideral_time_t lst;
|
||||
@ -251,6 +295,8 @@ public:
|
||||
}
|
||||
} else if (slew_pars.coordPairKind == mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP) { // apparent
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) { // compute encoder coordinates
|
||||
logDebug("Input slew coordinates are apparent HA-DEC: convert it to hardware encoder ones ...");
|
||||
|
||||
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
||||
|
||||
typename pec_t::pec_result_t pec_res;
|
||||
@ -267,6 +313,8 @@ public:
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) {
|
||||
coord_t az, alt;
|
||||
|
||||
logDebug("Input slew coordinates are apparent HA-DEC: convert it to AZ-ALT ...");
|
||||
|
||||
ast_err = astrom_engine->hadec2azalt(slew_pars.x, slew_pars.y, az, alt);
|
||||
|
||||
if (!ast_err) {
|
||||
@ -283,6 +331,8 @@ public:
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
coord_t ha, dec;
|
||||
|
||||
logDebug("Input slew coordinates are AZ-ALT: convert it to HA-DEC ...");
|
||||
|
||||
ast_err = astrom_engine->azalt2hadec(slew_pars.x, slew_pars.y, ha, dec);
|
||||
|
||||
if (!ast_err) {
|
||||
@ -295,6 +345,8 @@ public:
|
||||
} else if constexpr (mccIsAltAzMount(pec_t::mountType)) { // compute encoder coordinates
|
||||
coord_t eps = 1.0 / 3600.0 * std::numbers::pi / 180.0;
|
||||
|
||||
logDebug("Input slew coordinates are AZ-ALT: convert it to hardware encoder ones ...");
|
||||
|
||||
typename pec_t::pec_result_t pec_res;
|
||||
|
||||
// pec_err = pec->reverseCompute(slew_pars.x, slew_pars.y, pec_res, context.eps, context.maxIter);
|
||||
@ -314,6 +366,8 @@ public:
|
||||
//
|
||||
// WARNING: it is assumed that coordinates are in radians!
|
||||
//
|
||||
logDebug("Input slew coordinates are AZ-ZD: convert it to AZ-ALT ...");
|
||||
|
||||
slew_pars.y = std::numbers::pi / 2.0 - slew_pars.y;
|
||||
|
||||
res_err = self(std::move(slew_pars));
|
||||
@ -325,30 +379,42 @@ public:
|
||||
|
||||
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 MccSimpleSlewModelErrorCode::ERROR_PEC_COMP;
|
||||
}
|
||||
}
|
||||
|
||||
if (ast_err) {
|
||||
if constexpr (std::same_as<decltype(ast_err), error_t>) {
|
||||
logError(std::format("An error occured while performing astrometry computations: code = {} ({})",
|
||||
ast_err.value(), ast_err.message()));
|
||||
return ast_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(ast_err)>) {
|
||||
logError(std::format("An error occured while performing astrometry computations: code = {}",
|
||||
ast_err));
|
||||
}
|
||||
return MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP;
|
||||
}
|
||||
}
|
||||
|
||||
typename telemetry_t::error_t t_err;
|
||||
typename telemetry_t::mount_telemetry_data_t t_data;
|
||||
|
||||
// move mount (it is assumed this is asynchronous operation!!!)
|
||||
typename hardware_t::error_t err = hardware->setPos(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 MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS;
|
||||
}
|
||||
}
|
||||
@ -377,8 +443,13 @@ public:
|
||||
hardware.stop();
|
||||
|
||||
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||
logError(
|
||||
std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
||||
return t_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||
}
|
||||
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
}
|
||||
@ -414,6 +485,7 @@ public:
|
||||
prev_time_point = t_data.time_point;
|
||||
|
||||
if ((std::chrono::high_resolution_clock::now() - start_poll_tm) > context.timeout) {
|
||||
logError("Waiting time for completion of slewing expired!");
|
||||
return MccSimpleSlewModelErrorCode::ERROR_SLEW_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@ -422,16 +494,6 @@ public:
|
||||
return MccSimpleSlewModelErrorCode::ERROR_OK;
|
||||
};
|
||||
}
|
||||
|
||||
error_t slew(slew_params_t pars)
|
||||
{
|
||||
error_t res_err = _slewFunc(std::move(pars));
|
||||
|
||||
return res_err;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<error_t(const slew_params_t&)> _slewFunc{};
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user