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"
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!
@ -51,19 +124,42 @@ public:
const auto p_mount_controls = &mount_controls;
// prohibited zones related lambdas
auto check_zones = [p_mount_controls]<size_t... Is>(std::array<bool, sizeof...(Is)>& result,
std::index_sequence<Is...>) {
((result[Is] = std::get<Is>(p_mount_controls->prohibitedZones).inZone(p_mount_controls->telemetry.data())),
...);
auto check_zones = [p_mount_controls]<size_t... Is>(std::index_sequence<Is...>) {
// std::array<std::error_code, sizeof...(Is)> result{};
bool flag = false;
((flag |= result[Is]), ...);
error_t ret;
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& hardware = p_mount_controls->hardware;
auto& pec = p_mount_controls->PEC;
@ -199,37 +295,62 @@ public:
}
if (pec_err) {
// ???????????
return std::error_code(); // !!!!!!!!!!!!!!!
if constexpr (std::same_as<decltype(pec_err), error_t>) {
return pec_err;
} else {
return MccSimpleSlewModelErrorCode::ERROR_PEC_COMP;
}
}
if (!ast_err) {
typename telemetry_t::error_t t_err;
typename telemetry_t::mount_telemetry_data_t t_data;
if (ast_err) {
if constexpr (std::same_as<decltype(ast_err), error_t>) {
return ast_err;
} else {
return MccSimpleSlewModelErrorCode::ERROR_ASTROM_COMP;
}
}
// move mount (it is assumed this is asynchronous operation!!!)
typename hardware_t::error_t err = hardware->setPos(std::move(ax_pos));
typename telemetry_t::error_t t_err;
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) {
//
// what is the condition for mount reaches given position?!!
//
while (true) {
t_err = telemetry.data(t_data);
if (t_err) {
// ?????????!!!!!!!!!!
}
if (err) {
if constexpr (std::same_as<decltype(err), error_t>) {
return err;
} else {
return MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS;
}
}
// check prohibited zones
if (check_zones(pz_result, std::make_index_sequence<Nzones>{})) {
// stop mount ?!!!!!!!!!!!!!!!!!!!!!
// return in-zone-error-code
}
//
// what is the condition for mount reaches given position?!!
//
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;
};
}