This commit is contained in:
2025-08-06 02:06:20 +03:00
parent 138e4bf84d
commit 6315d5e18e
15 changed files with 630 additions and 152 deletions

View File

@@ -23,10 +23,7 @@ enum class MccMountDefaultPECErrorCode : int { ERROR_OK, ERROR_INVALID_INPUTS_BI
struct MccMountDefaultPECCategory : public std::error_category {
MccMountDefaultPECCategory() : std::error_category() {}
const char* name() const noexcept
{
return "ADC_GENERIC_DEVICE";
}
const char* name() const noexcept { return "ADC_GENERIC_DEVICE"; }
std::string message(int ec) const
{
@@ -140,14 +137,41 @@ public:
: _pecData(std::move(pdata)),
_phi(_pecData.siteLatitude),
_geomCoeffs(_pecData.geomCoefficients),
_bsplCoeffs(_pecData.bsplineCoefficients)
_bsplCoeffs(_pecData.bsplineCoefficients),
_pecDataMutex(new std::mutex)
{
}
MccMountDefaultPEC(const MccMountDefaultPEC&) = delete;
MccMountDefaultPEC& operator=(const MccMountDefaultPEC&) = delete;
MccMountDefaultPEC(MccMountDefaultPEC&& other)
: _pecData(std::move(other._pecData)),
_phi(_pecData.siteLatitude),
_geomCoeffs(_pecData.geomCoefficients),
_bsplCoeffs(_pecData.bsplineCoefficients),
_pecDataMutex(std::move(other._pecDataMutex))
{
}
MccMountDefaultPEC& operator=(MccMountDefaultPEC&& other)
{
if (this == &other) {
return *this;
}
_pecData = std::move(other._pecData);
_phi = _pecData.siteLatitude;
_geomCoeffs = _pecData.geomCoefficients;
_bsplCoeffs = _pecData.bsplineCoefficients;
_pecDataMutex = std::move(other._pecDataMutex);
return *this;
}
void setData(pec_data_t pdata)
{
std::lock_guard lock(_pecDataMutex);
std::lock_guard lock(*_pecDataMutex);
_pecData = std::move(pdata);
_phi = _pecData.siteLatitude;
@@ -158,21 +182,21 @@ public:
pec_data_t getData() const
{
std::lock_guard lock(_pecDataMutex);
std::lock_guard lock(*_pecDataMutex);
return _pecData;
}
void setType(MccMountDefaultPECType type)
{
std::lock_guard lock(_pecDataMutex);
std::lock_guard lock(*_pecDataMutex);
_pecData.type = type;
}
MccMountDefaultPECType getType() const
{
std::lock_guard lock(_pecDataMutex);
std::lock_guard lock(*_pecDataMutex);
return _pecData.type;
}
@@ -183,7 +207,7 @@ public:
// 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)
{
std::lock_guard lock(_pecDataMutex);
std::lock_guard lock(*_pecDataMutex);
if constexpr (mcc_is_equatorial_mount<MOUNT_TYPE>) { // equatorial
if (_pecData.type == MccMountDefaultPECType::PEC_TYPE_GEOMETRY) {
@@ -249,70 +273,6 @@ public:
return MccMountDefaultPECErrorCode::ERROR_OK;
}
// 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 xe, ye;
size_t iter = 1;
// the first iteration
auto err = compute(x, y, res);
if (!err) {
// 'encoder' cocordinates
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;
auto rx = (x - xi);
auto ry = (y - yi);
auto d = rx * rx + ry * ry;
bool ok = d <= e2;
if (ok) {
return MccMountDefaultPECErrorCode::ERROR_OK;
}
while (iter < max_iter) {
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 = MccMountDefaultPECErrorCode::ERROR_EXCEED_MAX_ITERS;
}
return err;
}
private:
pec_data_t _pecData;
@@ -320,7 +280,7 @@ private:
pec_geom_coeffs_t& _geomCoeffs;
pec_bspline_coeffs_t& _bsplCoeffs;
mutable std::mutex _pecDataMutex;
std::unique_ptr<std::mutex> _pecDataMutex;
};
@@ -328,6 +288,7 @@ typedef MccMountDefaultPEC<MccMountType::ALTAZ_TYPE> MccMountDefaultAltAzPec;
typedef MccMountDefaultPEC<MccMountType::FORK_TYPE> MccMountDefaultForkPec;
static_assert(traits::mcc_mount_pec_c<MccMountDefaultForkPec>, "");
static_assert(std::movable<MccMountDefaultForkPec>);
} // namespace mcc