This commit is contained in:
Timur A. Fatkhullin
2025-07-21 00:33:06 +03:00
parent 9cd52267d6
commit 6d65efd0af
6 changed files with 323 additions and 181 deletions

View File

@@ -12,6 +12,65 @@
#include "mcc_mount_concepts.h"
#include "mcc_mount_coord.h"
namespace mcc
{
enum class MccMountDefaultPECErrorCode : int { ERROR_OK, ERROR_INVALID_INPUTS_BISPLEV, ERROR_EXCEED_MAX_ITERS };
/* error category definition */
// error category
struct MccMountDefaultPECCategory : public std::error_category {
MccMountDefaultPECCategory() : std::error_category() {}
const char* name() const noexcept
{
return "ADC_GENERIC_DEVICE";
}
std::string message(int ec) const
{
MccMountDefaultPECErrorCode err = static_cast<MccMountDefaultPECErrorCode>(ec);
switch (err) {
case MccMountDefaultPECErrorCode::ERROR_OK:
return "OK";
case MccMountDefaultPECErrorCode::ERROR_INVALID_INPUTS_BISPLEV:
return "invalid input arguments for bispev";
case MccMountDefaultPECErrorCode::ERROR_EXCEED_MAX_ITERS:
return "exceed maximum of iterations number";
default:
return "UNKNOWN";
}
}
static const MccMountDefaultPECCategory& get()
{
static const MccMountDefaultPECCategory constInst;
return constInst;
}
};
inline std::error_code make_error_code(MccMountDefaultPECErrorCode ec)
{
return std::error_code(static_cast<int>(ec), MccMountDefaultPECCategory::get());
}
} // namespace mcc
namespace std
{
template <>
class is_error_code_enum<mcc::MccMountDefaultPECErrorCode> : public true_type
{
};
} // namespace std
namespace mcc
{
@@ -165,7 +224,7 @@ public:
if (ret) {
res.dx = std::numeric_limits<double>::quiet_NaN();
res.dy = std::numeric_limits<double>::quiet_NaN();
return std::error_code(); // !!!!!!!!!!!!!!
return MccMountDefaultPECErrorCode::ERROR_INVALID_INPUTS_BISPLEV;
}
@@ -175,7 +234,7 @@ public:
if (ret) {
res.dx = std::numeric_limits<double>::quiet_NaN();
res.dy = std::numeric_limits<double>::quiet_NaN();
return std::error_code(); // !!!!!!!!!!!!!!
return MccMountDefaultPECErrorCode::ERROR_INVALID_INPUTS_BISPLEV;
}
@@ -187,7 +246,7 @@ public:
static_assert(false, "UNSUPPORTED");
}
return std::error_code();
return MccMountDefaultPECErrorCode::ERROR_OK;
}
// from celestial to encoder (use of iterative scheme)
@@ -196,35 +255,59 @@ public:
coord_t e2 = eps * eps;
coord_t xi = x, yi = y;
coord_t xp, yp;
coord_t xe, ye;
size_t iter = 1;
// the first iteration
auto err = compute(x, y, res);
if (!err) {
xp = x - res.dx;
yp = y - res.dy;
// 'encoder' cocordinates
xe = x - res.dx;
ye = y - res.dy;
bool ok = ((xp - x) * (xp - x) + (yp - y) * (yp - y)) <= e2;
err = compute(xe, ye, res); // to celestial
if (err) {
return MccMountDefaultPECErrorCode::ERROR_INVALID_INPUTS_BISPLEV;
}
xi = xe + res.dx; // celestial
yi = ye + res.dy;
auto rx = (x - xi);
auto ry = (y - yi);
auto d = rx * rx + ry * ry;
bool ok = d <= e2;
if (ok) {
return std::error_code();
return MccMountDefaultPECErrorCode::ERROR_OK;
}
while (iter < max_iter) {
xi = xp;
yi = xp;
err = compute(xi, yi, res);
xp -= res.dx;
yp -= res.dy;
ok = ((xp - xi) * (xp - xi) + (yp - yi) * (yp - yi)) <= e2;
if (ok) {
return std::error_code();
err = compute(xi, yi, res); // to encoder
if (err) {
return MccMountDefaultPECErrorCode::ERROR_INVALID_INPUTS_BISPLEV;
}
xe = x - res.dx;
ye = y - res.dy;
err = compute(xe, ye, res); // to celestial
if (err) {
return MccMountDefaultPECErrorCode::ERROR_INVALID_INPUTS_BISPLEV;
}
xi = xe + res.dx; // celestial
yi = ye + res.dy;
ok = ((x - xi) * (x - xi) + (y - yi) * (y - yi)) <= e2;
if (ok) {
return MccMountDefaultPECErrorCode::ERROR_OK;
}
++iter;
}
// err = "exceed max iterations";!!!
err = MccMountDefaultPECErrorCode::ERROR_EXCEED_MAX_ITERS;
}
return err;