This commit is contained in:
Timur A. Fatkhullin 2025-07-21 18:26:39 +03:00
parent 6d65efd0af
commit 743ade7916

View File

@ -9,9 +9,82 @@
#include "mcc_mount_concepts.h" #include "mcc_mount_concepts.h"
namespace mcc namespace mcc
{ {
enum class MccSimpleSlewModelErrorCode : int {
ERROR_OK,
ERROR_IN_PROHIBITED_ZONE,
ERROR_ASTROM_COMP,
ERROR_TELEMETRY_DATA,
ERROR_PEC_COMP,
ERROR_HARDWARE_SETPOS
};
} // namespace mcc
namespace std
{
template <>
class is_error_code_enum<mcc::MccSimpleSlewModelErrorCode> : public true_type
{
};
} // namespace std
namespace mcc
{
/* error category definition */
// error category
struct MccSimpleSlewModelCategory : public std::error_category {
MccSimpleSlewModelCategory() : std::error_category() {}
const char* name() const noexcept
{
return "ADC_GENERIC_DEVICE";
}
std::string message(int ec) const
{
MccSimpleSlewModelErrorCode err = static_cast<MccSimpleSlewModelErrorCode>(ec);
switch (err) {
case MccSimpleSlewModelErrorCode::ERROR_OK:
return "OK";
case MccSimpleSlewModelErrorCode::ERROR_IN_PROHIBITED_ZONE:
return "slew model: position is in prohibited zone";
case MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP:
return "slew model: cannot perform astrometrical computations";
case MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA:
return "slew model: cannot get telemetry data";
case MccSimpleSlewModelErrorCode::ERROR_PEC_COMP:
return "slew model: cannot compute PEC corrections";
case MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS:
return "slew model: cannot set position";
default:
return "UNKNOWN";
}
}
static const MccSimpleSlewModelCategory& get()
{
static const MccSimpleSlewModelCategory constInst;
return constInst;
}
};
inline std::error_code make_error_code(MccSimpleSlewModelErrorCode ec)
{
return std::error_code(static_cast<int>(ec), MccSimpleSlewModelCategory::get());
}
/* /*
* WARNING: it is assumed that coordinates are in radians! * WARNING: it is assumed that coordinates are in radians!
@ -51,19 +124,42 @@ public:
const auto p_mount_controls = &mount_controls; const auto p_mount_controls = &mount_controls;
// prohibited zones related lambdas // prohibited zones related lambdas
auto check_zones = [p_mount_controls]<size_t... Is>(std::array<bool, sizeof...(Is)>& result, auto check_zones = [p_mount_controls]<size_t... Is>(std::index_sequence<Is...>) {
std::index_sequence<Is...>) { // std::array<std::error_code, sizeof...(Is)> result{};
((result[Is] = std::get<Is>(p_mount_controls->prohibitedZones).inZone(p_mount_controls->telemetry.data())),
...);
bool flag = false; error_t ret;
((flag |= result[Is]), ...);
return flag; (
[&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 = MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
}
} else {
ret = std::get<Is>(p_mount_controls->prohibitedZones).inZone(tdata)
? MccSimpleSlewModelErrorCode::ERROR_IN_PROHIBITED_ZONE
: MccSimpleSlewModelErrorCode::ERROR_OK;
}
}(),
...);
return ret;
}; };
_slewFunc = [p_mount_controls](this auto&& self, const slew_params_t& slew_pars) { _slewFunc = [p_mount_controls, check_zones](this auto&& self, const slew_params_t& slew_pars) {
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;
@ -199,37 +295,62 @@ public:
} }
if (pec_err) { if (pec_err) {
// ??????????? if constexpr (std::same_as<decltype(pec_err), error_t>) {
return std::error_code(); // !!!!!!!!!!!!!!! return pec_err;
} else {
return MccSimpleSlewModelErrorCode::ERROR_PEC_COMP;
}
} }
if (!ast_err) { if (ast_err) {
typename telemetry_t::error_t t_err; if constexpr (std::same_as<decltype(ast_err), error_t>) {
typename telemetry_t::mount_telemetry_data_t t_data; return ast_err;
} else {
return MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP;
}
}
// move mount (it is assumed this is asynchronous operation!!!) typename telemetry_t::error_t t_err;
typename hardware_t::error_t err = hardware->setPos(std::move(ax_pos)); typename telemetry_t::mount_telemetry_data_t t_data;
std::array<bool, Nzones> pz_result; // move mount (it is assumed this is asynchronous operation!!!)
typename hardware_t::error_t err = hardware->setPos(ax_pos);
if (!err) { if (err) {
// if constexpr (std::same_as<decltype(err), error_t>) {
// what is the condition for mount reaches given position?!! return err;
// } else {
while (true) { return MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS;
t_err = telemetry.data(t_data); }
if (t_err) { }
// ?????????!!!!!!!!!!
}
// check prohibited zones //
if (check_zones(pz_result, std::make_index_sequence<Nzones>{})) { // what is the condition for mount reaches given position?!!
// stop mount ?!!!!!!!!!!!!!!!!!!!!! //
// return in-zone-error-code while (true) {
} // check prohibited zones
res_err = check_zones(std::make_index_sequence<Nzones>{});
if (res_err) {
hardware.stop();
return res_err;
}
// it is assumed here that telemetry data is in actual state!
t_err = telemetry.data(t_data);
if (t_err) {
hardware.stop();
if constexpr (std::same_as<decltype(t_err), error_t>) {
return t_err;
} else {
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
} }
} }
} }
return MccSimpleSlewModelErrorCode::ERROR_OK;
}; };
} }