diff --git a/mcc/mcc_ccte_erfa.h b/mcc/mcc_ccte_erfa.h index 4155092..a40293f 100644 --- a/mcc/mcc_ccte_erfa.h +++ b/mcc/mcc_ccte_erfa.h @@ -123,7 +123,6 @@ inline std::error_code make_error_code(MccCCTE_ERFAErrorCode ec) } - class MccCCTE_ERFA : public mcc_CCTE_interface_t { static constexpr double PI_2 = std::numbers::pi / 2.0; @@ -183,28 +182,28 @@ public: virtual ~MccCCTE_ERFA() = default; - std::string_view name() const + std::string_view nameCCTE() const { return "ERFA-CCTE-ENGINE"; } // engine state related methods - void setState(engine_state_t state) + void setStateERFA(engine_state_t state) { std::lock_guard lock{*_stateMutex}; _currentState = std::move(state); } - engine_state_t getState() const + engine_state_t getStateERFA() const { std::lock_guard lock{*_stateMutex}; return _currentState; } - void updateMeteo(meteo_t meteo) + void updateMeteoERFA(meteo_t meteo) { std::lock_guard lock{*_stateMutex}; diff --git a/mcc/mcc_generic_mount.h b/mcc/mcc_generic_mount.h index 187c34f..3cb6840 100644 --- a/mcc/mcc_generic_mount.h +++ b/mcc/mcc_generic_mount.h @@ -8,50 +8,137 @@ #include "mcc_generics.h" + namespace mcc { -template -class MccGenericMount : public TelemetryT, public PZoneContT, public LoggerT +enum class MccGenericMountErrorCode : int { ERROR_OK, ERROR_HW_STOP, ERROR_HW_GETSTATE }; + +} // namespace mcc + + +namespace std +{ + +template <> +class is_error_code_enum : public true_type +{ +}; + +} // namespace std + + + +namespace mcc +{ + +template +class MccGenericMount : public HardwareT, + public TelemetryT, + public PZoneContT, + public SlewModelT, + public TrackModelT, + public GuidingModelT, + public LoggerT { public: - MccGenericMount(TelemetryT telemetry, PZoneContT pzone_cont, LoggerT logger) - : TelemetryT(std::move(telemetry)), PZoneContT(std::move(pzone_cont)), LoggerT(std::move(logger)) + typedef std::error_code error_t; + + using LoggerT::logDebug; + using LoggerT::logError; + using LoggerT::logInfo; + using LoggerT::logWarn; + + + using typename GuidingModelT::guiding_params_t; + using typename SlewModelT::slewing_params_t; + using typename TrackModelT::tracking_params_t; + + MccGenericMount(HardwareT hardware, + TelemetryT telemetry, + PZoneContT pzone_cont, + SlewModelT slew_model, + TrackModelT track_model, + GuidingModelT guiding_model, + LoggerT logger = MccNullLogger{}) + : HardwareT(std::move(hardware)), + TelemetryT(std::move(telemetry)), + PZoneContT(std::move(pzone_cont)), + SlewModelT(std::move(slew_model)), + TrackModelT(std::move(track_model)), + GuidingModelT(std::move(guiding_model)), + LoggerT(std::move(logger)) { } virtual ~MccGenericMount() = default; - - template SelfT> - auto slewToTarget(this SelfT&& self) + error_t stopMount() { - return std::forward(self).slewToTarget(); - } + logInfo("stop any movements ..."); - template SelfT> - auto trackTarget(this SelfT&& self) - { - return std::forward(self).trackTarget(); - } + this->stopGuidingTarget(); + this->stopTracking(); + this->stopSlewing(); - template SelfT> - auto startGuidingTarget(this SelfT&& self) - { - return std::forward(self).startGuidingTarget(); - } + auto hw_err = this->hardwareStop(); + if (hw_err) { + return mcc_deduce_error(hw_err, MccGenericMountErrorCode::ERROR_HW_STOP); + } - template SelfT> - auto stopGuidingTarget(this SelfT&& self) - { - return std::forward(self).stopGuidingTarget(); - } + // poll hardware till stopped-state detected ... - template SelfT> - auto stopMount(this SelfT&& self) - { - return std::forward(self).stopMount(); + logInfo("mount was stopped"); + + return MccGenericMountErrorCode::ERROR_OK; } }; + +template +class MccGenericMountFSM + : public fsm::MccFiniteStateMachine, + protected MccGenericMount +{ +protected: + typedef MccGenericMount + base_gmount_t; + +public: + struct MccGenericMountStateUninit { + using transition_t = fsm::fsm_transition_table_t<>; + }; + + MccGenericMountFSM(HardwareT hardware, + TelemetryT telemetry, + PZoneContT pzone_cont, + SlewModelT slew_model, + TrackModelT track_model, + GuidingModelT guiding_model, + LoggerT logger = MccNullLogger{}) + : fsm::MccFiniteStateMachine(MccGenericMountStateUninit{}), + base_gmount_t(std::move(hardware), + std::move(telemetry), + std::move(pzone_cont), + std::move(slew_model), + std::move(track_model), + std::move(guiding_model), + std::move(logger)) + { + } +}; + + } // namespace mcc diff --git a/mcc/mcc_generics.h b/mcc/mcc_generics.h index 6a1a109..ff7d248 100644 --- a/mcc/mcc_generics.h +++ b/mcc/mcc_generics.h @@ -314,7 +314,7 @@ protected: template concept mcc_ccte_c = std::derived_from> && requires(const T t_const, T t) { - { t_const.name() } -> std::formattable; + { t_const.nameCCTE() } -> std::formattable; requires mcc_refract_model_c; @@ -532,31 +532,73 @@ concept mcc_PCM_c = template concept mcc_hardware_c = requires(T t, const T t_const) { - typename T::error_t; + requires mcc_error_c; - { t_const.name() } -> std::formattable; + { t_const.hardwareName() } -> std::formattable; - // a class that contains at least time point of measurement, coordinates for x,y axes and its moving rates - requires requires(typename T::axes_pos_t pos) { - requires mcc_time_point_c; // time point + // a type that defines at least HW_MOVE_STOPPED, HW_MOVE_SLEWING, HW_MOVE_ADJUSTING, HW_MOVE_TRACKING + // and HW_MOVE_GUIDING compile-time constants. The main purpose of this type is a + // possible tunning of hardware hardwareSetState-related commands and detect stop-state + // + // e.g. an implementations can be as follows: + // enum class hardware_moving_state_t: int {HW_MOVE_STOPPED, HW_MOVE_SLEWING, HW_MOVE_ADJUSTING, + // HW_MOVE_TRACKING, HW_MOVE_GUIDING} + // + // struct hardware_moving_state_t { + // uint16_t HW_MOVE_STOPPED = 0; + // uint16_t HW_MOVE_SLEWING = 111; + // uint16_t HW_MOVE_ADJUSTING = 222; + // uint16_t HW_MOVE_TRACKING = 333; + // uint16_t HW_MOVE_GUIDING = 444; + // } + requires requires(typename T::hardware_moving_state_t type) { + []() { + // mount axes were stopped + static constexpr auto v0 = T::hardware_moving_state_t::HW_MOVE_STOPPED; - requires mcc_angle_c; // target or current co-longitude coordinate - requires mcc_angle_c; // target or current co-latitude coordinate + // hardware was asked for slewing (move to given celestial point) + static constexpr auto v1 = T::hardware_moving_state_t::HW_MOVE_SLEWING; - requires mcc_angle_c; - requires mcc_angle_c; + // hardware was asked for adjusting after slewing + // (adjusting actual mount position to align with target celestial point at the end of slewing process) + static constexpr auto v2 = T::hardware_moving_state_t::HW_MOVE_ADJUSTING; + + // hardware was asked for tracking (track target celestial point) + static constexpr auto v3 = T::hardware_moving_state_t::HW_MOVE_TRACKING; + + // hardware was asked for guiding + // (small corrections to align actual mount position with target celestial point) + static constexpr auto v4 = T::hardware_moving_state_t::HW_MOVE_GUIDING; + }(); }; - // set positions (angles) of mount axes with given speeds + + + // a class that contains at least time point of measurement, coordinates for x,y axes, its moving rates and moving + // type + requires requires(typename T::hardware_state_t state) { + requires mcc_time_point_c; // time point + + requires mcc_angle_c; // target or current co-longitude coordinate + requires mcc_angle_c; // target or current co-latitude coordinate + + requires mcc_angle_c; // moving speed along co-longitude coordinate + requires mcc_angle_c; // moving speed along co-latitude coordinate + + std::same_as; + }; + + // set hardware state: + // i.g. set positions (angles) of mount axes with given speeds // NOTE: exact interpretation (or even ignoring) of the given moving speeds is subject of a hardware-class // implementation, e.g. it can be maximal speeds at slewing ramp - { t.setPos(std::declval()) } -> std::same_as; + { t.hardwareSetState(std::declval()) } -> std::same_as; - // get current positions and speeds (angles) of mount axes - { t.getPos(std::declval()) } -> std::same_as; + // get current state + { t.hardwareGetState(std::declval()) } -> std::same_as; - { t.stop() } -> std::same_as; // stop any moving - { t.init() } -> std::same_as; // initialize hardware + { t.hardwareStop() } -> std::same_as; // stop any moving + { t.hardwareInit() } -> std::same_as; // initialize hardware }; @@ -684,8 +726,10 @@ template concept mcc_pzone_container_c = std::derived_from>; +/* MOUNT MOVING MODEL CONCEPT */ + template -concept mcc_slewing_model_c = requires(T t, const T t_const) { +concept mcc_slewing_model_c = requires(T t) { requires mcc_error_c; // a class of slewing process parameters @@ -694,8 +738,6 @@ concept mcc_slewing_model_c = requires(T t, const T t_const) { std::convertible_to; }; - { t_const.name() } -> std::formattable; - { t.slewToTarget() } -> std::same_as; { t.stopSlewing() } -> std::same_as; @@ -705,7 +747,7 @@ concept mcc_slewing_model_c = requires(T t, const T t_const) { template -concept mcc_tracking_model_c = requires(T t, const T t_const) { +concept mcc_tracking_model_c = requires(T t) { requires mcc_error_c; // a class of tracking process parameters @@ -714,8 +756,6 @@ concept mcc_tracking_model_c = requires(T t, const T t_const) { requires mcc_angle_c; }; - { t_const.name() } -> std::formattable; - { t.trackTarget() } -> std::same_as; { t.stopTracking() } -> std::same_as; @@ -724,7 +764,7 @@ concept mcc_tracking_model_c = requires(T t, const T t_const) { }; template -concept mcc_guiding_model_c = requires(T t, const T t_const) { +concept mcc_guiding_model_c = requires(T t) { requires mcc_error_c; // a class of guiding process parameters @@ -733,8 +773,6 @@ concept mcc_guiding_model_c = requires(T t, const T t_const) { std::convertible_to; }; - { t_const.name() } -> std::formattable; - { t.startGuidingTarget() } -> std::same_as; { t.stopGuidingTarget() } -> std::same_as; @@ -796,7 +834,6 @@ concept mcc_guiding_model_c = requires(T t, const T t_const) { template concept mcc_generic_mount_c = mcc_telemetry_c && mcc_pzone_container_c && requires(T t) { requires mcc_error_c; - typename T::stop_reason_t; // slew mount to target (target coordinates were defined in telemetry data) { t.slewToTarget() } -> std::same_as; @@ -809,7 +846,7 @@ concept mcc_generic_mount_c = mcc_telemetry_c && mcc_pzone_container_c && { t.stopGuidingTarget() } -> std::same_as; // stop any movement - { t.stopMount(std::declval()) } -> std::same_as; + { t.stopMount() } -> std::same_as; }; diff --git a/mcc/mcc_telemetry.h b/mcc/mcc_telemetry.h index 46505bf..0db678f 100644 --- a/mcc/mcc_telemetry.h +++ b/mcc/mcc_telemetry.h @@ -201,8 +201,8 @@ public: _updateFunc = [ccte, pcm, hardware, this](std::stop_token stop_token) { // first, update mount quantities - typename hardware_t::axes_pos_t hw_pos; - auto hw_err = hardware->getPos(&hw_pos); + typename hardware_t::hardware_state_t hw_pos; + auto hw_err = hardware->hardwareGetState(&hw_pos); if (hw_err) { return mcc_deduce_error(hw_err, MccTelemetryErrorCode::ERROR_HARDWARE_GETPOS); }