This commit is contained in:
2025-07-19 19:52:30 +03:00
parent 464c262e08
commit 9cd52267d6
11 changed files with 628 additions and 58 deletions

View File

@@ -28,6 +28,7 @@ class MccMountDefaultPEC final
public:
static constexpr MccMountType mountType = MOUNT_TYPE;
typedef std::error_code error_t;
typedef MccAngle coord_t;
struct pec_result_t {
@@ -117,11 +118,12 @@ public:
return _pecData.type;
}
// X and Y axis encoder coordinates
pec_result_t compute(const coord_t& x, const coord_t& y)
// The computed PEC quantities must be interpretated as:
// apparent_X = encoder_X + pec_result_t.dx
// apparent_Y = encoder_Y + pec_result_t.dy
// so, input x and y are assumed to be mount axis encoder coordinates
error_t compute(const coord_t& x, const coord_t& y, pec_result_t& res)
{
pec_result_t res{0.0, 0.0};
std::lock_guard lock(_pecDataMutex);
if constexpr (mcc_is_equatorial_mount<MOUNT_TYPE>) { // equatorial
@@ -163,7 +165,7 @@ public:
if (ret) {
res.dx = std::numeric_limits<double>::quiet_NaN();
res.dy = std::numeric_limits<double>::quiet_NaN();
return res;
return std::error_code(); // !!!!!!!!!!!!!!
}
@@ -173,7 +175,7 @@ public:
if (ret) {
res.dx = std::numeric_limits<double>::quiet_NaN();
res.dy = std::numeric_limits<double>::quiet_NaN();
return res;
return std::error_code(); // !!!!!!!!!!!!!!
}
@@ -185,9 +187,48 @@ public:
static_assert(false, "UNSUPPORTED");
}
return res;
return std::error_code();
}
// from celestial to encoder (use of iterative scheme)
error_t reverseCompute(const coord_t& x, const coord_t& y, pec_result_t& res, coord_t eps, size_t max_iter = 5)
{
coord_t e2 = eps * eps;
coord_t xi = x, yi = y;
coord_t xp, yp;
size_t iter = 1;
// the first iteration
auto err = compute(x, y, res);
if (!err) {
xp = x - res.dx;
yp = y - res.dy;
bool ok = ((xp - x) * (xp - x) + (yp - y) * (yp - y)) <= e2;
if (ok) {
return std::error_code();
}
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 = "exceed max iterations";!!!
}
return err;
}
private:
@@ -203,4 +244,7 @@ private:
typedef MccMountDefaultPEC<MccMountType::ALTAZ_TYPE> MccMountDefaultAltAzPec;
typedef MccMountDefaultPEC<MccMountType::FORK_TYPE> MccMountDefaultForkPec;
static_assert(traits::mcc_mount_pec_c<MccMountDefaultForkPec>, "");
} // namespace mcc