From 1087e043a8a2f7e48161fa8d44c909ea695ca964 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Wed, 17 Sep 2025 18:21:32 +0300 Subject: [PATCH] ... --- asibfm700/asibfm700_common.h | 16 ++++++++++++---- asibfm700/asibfm700_mount.cpp | 24 ++++++++++++++++++++++++ asibfm700/asibfm700_mount.h | 3 ++- mcc/mcc_generic_mount.h | 22 ++++++++++++++++------ mcc/mcc_generics.h | 18 ++++++++++++------ mcc/mcc_pzone.h | 15 +++++++++++++-- mcc/mcc_pzone_container.h | 2 -- mcc/mcc_slewing_model.h | 11 ++++++----- mcc/mcc_telemetry.h | 2 +- 9 files changed, 86 insertions(+), 27 deletions(-) diff --git a/asibfm700/asibfm700_common.h b/asibfm700/asibfm700_common.h index ce036df..82f6ba5 100644 --- a/asibfm700/asibfm700_common.h +++ b/asibfm700/asibfm700_common.h @@ -27,10 +27,10 @@ struct Asibfm700MountConfig { std::chrono::milliseconds hardwarePollingPeriod{100}; // main cycle period // CCTE-related configuration - double siteLatitude{43.646711_degs}; - double siteLongitude{41.440732_degs}; - double siteElevation{2100.0}; - double refractWavelength{0.55}; + mcc::MccAngle siteLatitude{43.646711_degs}; // in radians + mcc::MccAngle siteLongitude{41.440732_degs}; // in radians + double siteElevation{2070.0}; // in meters + double refractWavelength{0.55}; // in mkm std::string leapSecondFilename{}; std::string bulletinAFilename{}; @@ -41,8 +41,16 @@ struct Asibfm700MountConfig { .siteLatitude = siteLatitude, .geomCoefficients = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}; + // servo controller configuration AsibFM700ServoController::hardware_config_t servoControllerConfig{}; + + // slew and track parameters mcc::MccSimpleMovingModelParams movingModelParams{}; + + // prohibited zones parameters + mcc::MccAngle pzMinAltitude{10.0_degs}; // in radians + mcc::MccAngle pzLimitSwitchHAMin{}; // in radians + mcc::MccAngle pzLimitSwitchHAMax{}; // in radians }; } // namespace asibfm700 diff --git a/asibfm700/asibfm700_mount.cpp b/asibfm700/asibfm700_mount.cpp index ac53054..ab1df0e 100644 --- a/asibfm700/asibfm700_mount.cpp +++ b/asibfm700/asibfm700_mount.cpp @@ -1,5 +1,7 @@ #include "asibfm700_mount.h" +#include + namespace asibfm700 { @@ -20,8 +22,30 @@ Asibfm700Mount::Asibfm700Mount(Asibfm700MountConfig const& config, Asibfm700StartState{}) { logDebug("Create Asibfm700Mount class instance ({})", this->getThreadId()); + + logInfo("Init AstroSib FM-700 mount with configuration:"); + logInfo(" site latitude: {}", config.siteLatitude.sexagesimal()); + logInfo(" site longitude: {}", config.siteLongitude.sexagesimal()); + logInfo(" site elevation: {} meters", config.siteElevation); + logInfo(" refraction wavelength: {} mkm", config.refractWavelength); + logInfo(" leap seconds filename: {}", config.leapSecondFilename); + logInfo(" IERS Bulletin A filename: {}", config.bulletinAFilename); + + logInfo("Add prohibited zones ..."); + + logInfo("Add MccAltLimitPZ zone: min alt = {}, lat = {}", config.pzMinAltitude.degrees(), + config.siteLatitude.degrees()); + addPZone(mcc::MccAltLimitPZ{config.pzMinAltitude, config.siteLatitude, this}); + + logInfo("Add MccAxisLimitSwitchPZ zone: min value = {}, max value = {}", config.pzLimitSwitchHAMin, + config.pzLimitSwitchHAMax); + size_t pz_num = addPZone(mcc::MccAxisLimitSwitchPZ{ + config.pzLimitSwitchHAMin, config.pzLimitSwitchHAMax, this}); + + logInfo("{} prohibited zones were added", pz_num); } + Asibfm700Mount::~Asibfm700Mount() { logDebug("Delete Asibfm700Mount class instance ({})", this->getThreadId()); diff --git a/asibfm700/asibfm700_mount.h b/asibfm700/asibfm700_mount.h index 85d4efd..1a32218 100644 --- a/asibfm700/asibfm700_mount.h +++ b/asibfm700/asibfm700_mount.h @@ -93,6 +93,8 @@ public: using Asibfm700Logger::logInfo; using Asibfm700Logger::logWarn; + // using Asibfm700PZoneContainer::addPZone; + Asibfm700Mount(Asibfm700MountConfig const& config, std::shared_ptr logger, const auto& pattern_range = mcc::utils::MccSpdlogLogger::LOGGER_DEFAULT_FORMAT); @@ -104,6 +106,5 @@ static_assert(mcc::mcc_position_controls_c, ""); static_assert(mcc::mcc_all_controls_c, ""); static_assert(mcc::mcc_generic_mount_c, ""); -// static_assert(mcc::mcc_generic_fsm_log_mount_c, ""); } // namespace asibfm700 diff --git a/mcc/mcc_generic_mount.h b/mcc/mcc_generic_mount.h index 804ed87..1fcc9fc 100644 --- a/mcc/mcc_generic_mount.h +++ b/mcc/mcc_generic_mount.h @@ -279,7 +279,18 @@ protected: struct MccGenericFsmMountSlewEvent : MccGenericFsmMountBaseEvent { static constexpr std::string_view ID{"GENERIC-MOUNT-SLEW-EVENT"}; - MccGenericFsmMountSlewEvent(MccGenericFsmMount* mount) : MccGenericFsmMountBaseEvent(mount) {} + MccGenericFsmMountSlewEvent(MccGenericFsmMount* mount, bool slew_and_stop) + : MccGenericFsmMountBaseEvent(mount), _slewAndStop(slew_and_stop) + { + } + + bool eventData() const noexcept + { + return _slewAndStop; + } + + protected: + bool _slewAndStop{}; }; struct MccGenericFsmMountTrackEvent : MccGenericFsmMountBaseEvent { @@ -473,9 +484,8 @@ protected: } - MccGenericFsmMount::slewing_params_t params; - mount_ptr->getSlewingParams(¶ms); - if (params.slewAndStop) { // after slewing switch to IDLE state + bool slew_and_stop = event.eventData(); + if (slew_and_stop) { // after slewing switch to IDLE state mount_ptr->dispatchEvent(MccGenericFsmMountIdleEvent{mount_ptr}); } else { // after slewing switch to tracking state mount_ptr->dispatchEvent(MccGenericFsmMountTrackEvent{mount_ptr}); @@ -674,10 +684,10 @@ public: return _lastError; } - auto slewToTarget() + auto slewToTarget(bool slew_and_stop = false) { try { - this->dispatchEvent(MccGenericFsmMountSlewEvent{this}); + this->dispatchEvent(MccGenericFsmMountSlewEvent{this, slew_and_stop}); } catch (std::system_error const& exc) { if (exc.code().category() == fsm::MccFiniteStateMachineCategory::get()) { _lastError = MccGenericFsmMountErrorCode::ERROR_INVALID_OPERATION; diff --git a/mcc/mcc_generics.h b/mcc/mcc_generics.h index 810398e..de683b1 100644 --- a/mcc/mcc_generics.h +++ b/mcc/mcc_generics.h @@ -836,14 +836,20 @@ concept mcc_slewing_model_c = requires(T t) { // requires mcc_error_c; // a class of slewing process parameters - requires requires(typename T::slewing_params_t pars) { - // slew mount to target and stop - requires std::convertible_to; - }; + typename T::slewing_params_t; + // requires requires(typename T::slewing_params_t pars) { + // // slew mount to target and stop + // requires std::convertible_to; + // }; // { t.slewToTarget() } -> std::same_as; // { t.stopSlewing() } -> std::same_as; - { t.slewToTarget() } -> mcc_error_c; + + // the method signature: + // slewToTarget(bool slew_and_stop) + // slew_and_stop == true, slew mount and stop + // slew_and_stop == false, slew mount and track + { t.slewToTarget(std::declval()) } -> mcc_error_c; { t.stopSlewing() } -> mcc_error_c; { t.setSlewingParams(std::declval()) } -> mcc_error_c; @@ -912,7 +918,7 @@ template concept mcc_generic_mount_c = mcc_telemetry_c && mcc_pzone_container_c && requires(T t) { // requires mcc_error_c; - // slew mount to target (target coordinates were defined in telemetry data) + // slew mount to target (it is assumed that the target coordinates are determined in the telemetry data) { t.slewToTarget() }; // { t.slewToTarget() } -> std::same_as; diff --git a/mcc/mcc_pzone.h b/mcc/mcc_pzone.h index 27d050e..7d1a8b2 100644 --- a/mcc/mcc_pzone.h +++ b/mcc/mcc_pzone.h @@ -12,7 +12,7 @@ namespace mcc { -enum MccAltLimitPZErrorCode : int { ERROR_OK, ERROR_NULLPTR, ERROR_COORD_TRANSFROM, ERROR_PCM_COMP }; +enum class MccAltLimitPZErrorCode : int { ERROR_OK, ERROR_NULLPTR, ERROR_COORD_TRANSFROM, ERROR_PCM_COMP }; } // namespace mcc @@ -621,7 +621,7 @@ public: } - consteval std::string_view name() + consteval std::string_view name() const { return axisKind == MccCoordKind::COORDS_KIND_AZ ? "AZ_AXIS-LIMITSWITCH_ZONE" : axisKind == MccCoordKind::COORDS_KIND_HA ? "HA_AXIS-LIMITSWITCH_ZONE" @@ -750,6 +750,17 @@ public: requires((mcc_eqt_hrz_coord_c || mcc_celestial_point_c) && (mcc_eqt_hrz_coord_c || mcc_celestial_point_c)) { + if (point == nullptr) { + return MccAltLimitPZErrorCode::ERROR_NULLPTR; + } + + point->X = _minLimit; + // if constexpr (mcc_eqt_hrz_coord_c) { + // point->X = _minLimit; + // } else { // mcc_celestial_point_c + // point->X = _minLimit; + // } + return MccAltLimitPZErrorCode::ERROR_OK; } diff --git a/mcc/mcc_pzone_container.h b/mcc/mcc_pzone_container.h index e7b6f45..221936a 100644 --- a/mcc/mcc_pzone_container.h +++ b/mcc/mcc_pzone_container.h @@ -1,7 +1,5 @@ #pragma once -#pragma once - /* MOUNT CONTROL COMPONENTS LIBRARY */ diff --git a/mcc/mcc_slewing_model.h b/mcc/mcc_slewing_model.h index 528ff97..3582680 100644 --- a/mcc/mcc_slewing_model.h +++ b/mcc/mcc_slewing_model.h @@ -122,7 +122,7 @@ public: { *_stopSlewing = true; - _slewingFunc = [controls, this]() -> error_t { + _slewingFunc = [controls, this](bool slew_and_stop) -> error_t { // first, check target coordinates typename CONTROLS_T::error_t t_err; MccTelemetryData tdata; @@ -278,7 +278,8 @@ public: { std::lock_guard lock{*_currentParamsMutex}; - if (adjust_mode && !_currentParams.slewAndStop) { + // if (adjust_mode && !_currentParams.slewAndStop) { + if (adjust_mode && !slew_and_stop) { // do not allow mount speed fall below sideral if constexpr (mccIsEquatorialMount(CONTROLS_T::mountType)) { // turn on sideral rate only if the current position point catches up with the target @@ -359,7 +360,7 @@ public: virtual ~MccSimpleSlewingModel() = default; - error_t slewToTarget() + error_t slewToTarget(bool slew_and_stop = false) { if (!(*_stopSlewing)) { return MccSimpleSlewingModelErrorCode::ERROR_ALREADY_SLEW; @@ -367,7 +368,7 @@ public: *_stopSlewing = false; - return _slewingFunc(); + return _slewingFunc(slew_and_stop); } @@ -401,7 +402,7 @@ public: } protected: - std::function _slewingFunc{}; + std::function _slewingFunc{}; std::unique_ptr _stopSlewing; slewing_params_t _currentParams{}; diff --git a/mcc/mcc_telemetry.h b/mcc/mcc_telemetry.h index d82c3ed..3575bf9 100644 --- a/mcc/mcc_telemetry.h +++ b/mcc/mcc_telemetry.h @@ -16,7 +16,7 @@ namespace mcc { -enum MccTelemetryErrorCode : int { +enum class MccTelemetryErrorCode : int { ERROR_OK, ERROR_NULLPTR, ERROR_COORD_TRANSFORM,