#pragma once /* MOUNT CONTROL COMPONENTS LIBRARY */ #include #include "mcc_finite_state_machine.h" #include "mcc_mount_coord.h" #include "mcc_traits.h" /* SOME LIBRARY-WIDE DECLARATIONS */ namespace mcc { // mount construction type (only the most common ones) enum class MccMountType : uint8_t { GERMAN_TYPE, FORK_TYPE, CROSSAXIS_TYPE, ALTAZ_TYPE }; template static constexpr std::string_view MccMountTypeStr = TYPE == MccMountType::GERMAN_TYPE ? "GERMAN" : TYPE == MccMountType::FORK_TYPE ? "FORK" : TYPE == MccMountType::CROSSAXIS_TYPE ? "CROSSAXIS" : TYPE == MccMountType::ALTAZ_TYPE ? "ALTAZ" : "UNKNOWN"; template static constexpr bool mcc_is_equatorial_mount = TYPE == MccMountType::GERMAN_TYPE ? true : TYPE == MccMountType::FORK_TYPE ? true : TYPE == MccMountType::CROSSAXIS_TYPE ? true : TYPE == MccMountType::ALTAZ_TYPE ? false : false; template static constexpr bool mcc_is_altaz_mount = TYPE == MccMountType::GERMAN_TYPE ? false : TYPE == MccMountType::FORK_TYPE ? false : TYPE == MccMountType::CROSSAXIS_TYPE ? false : TYPE == MccMountType::ALTAZ_TYPE ? true : false; static consteval bool mccIsEquatorialMount(const MccMountType type) { return type == MccMountType::GERMAN_TYPE ? true : type == MccMountType::FORK_TYPE ? true : type == MccMountType::CROSSAXIS_TYPE ? true : type == MccMountType::ALTAZ_TYPE ? false : false; }; static consteval bool mccIsAltAzMount(const MccMountType type) { return type == MccMountType::GERMAN_TYPE ? false : type == MccMountType::FORK_TYPE ? false : type == MccMountType::CROSSAXIS_TYPE ? false : type == MccMountType::ALTAZ_TYPE ? true : false; }; /* NULL-LOGGER CLASS */ struct MccNullLogger { typedef int loglevel_t; void setLogLevel(loglevel_t){}; loglevel_t getLogLevel() const { return 0; }; void logMessage(loglevel_t, const std::string&) {}; void logError(const std::string&) {}; void logDebug(const std::string&) {}; void logWarn(const std::string&) {}; void logInfo(const std::string&) {}; }; } // namespace mcc /* MOUNT COMPONENTS CONCEPTS */ namespace mcc::traits { /* GENERIC LOGGER */ template concept mcc_logger_c = requires(T t, const T t_const) { typename T::loglevel_t; { t.setLogLevel(std::declval()) }; { t_const.getLogLevel() } -> std::same_as; { t.logMessage(std::declval(), std::declval()) }; { t.logError(std::declval()) }; { t.logDebug(std::declval()) }; { t.logWarn(std::declval()) }; { t.logInfo(std::declval()) }; }; /* ASTROMETRY-RELATED COMPUTATION ENGINE */ template concept mcc_astrom_engine_c = requires(T t, const T t_const) { requires mcc_error_c; // typename T::engine_state_t; // requires std::movable; typename T::coord_t; // type for coordinates representation typename T::time_point_t; // type to represent UTC time point typename T::juldate_t; // type to represent Julian date typename T::sideral_time_t; // type to represent sideral time typename T::eo_t; // equation of origins typename T::pa_t; // type to represent parallactic angle typename T::refract_result_t; /* coordinates conversional methods */ // ICRS RA and DEC to observed place: icrs2obs(ra, dec, jd, ra_app, dec_app, ha, az, alt, eo) { t.icrs2obs(std::declval(), std::declval(), std::declval(), std::declval(), std::declval(), std::declval(), std::declval(), std::declval(), std::declval()) } -> std::same_as; // observed place to ICRS RA and DEC: obs2icrs(type, x, y, jd, ra_icrs, dec_icrs) // (x,y) = (AZ, ZD) if type = MccCoordPairKind::COORDS_KIND_AZZD // (x,y) = (AZ, ALT) if type = MccCoordPairKind::COORDS_KIND_AZALT // (x,y) = (HA, DEC) if type = MccCoordPairKind::COORDS_KIND_HADEC_APP // (x,y) = (RA, DEC) if type = MccCoordPairKind::COORDS_KIND_RADEC_APP { t.obs2icrs(std::declval(), std::declval(), std::declval(), std::declval(), std::declval(), std::declval()) } -> std::same_as; // compute hour angle and declination from azimuth and altitude: hadec2azalt(ha, dec, az, alt) { t.hadec2azalt(std::declval(), std::declval(), std::declval(), std::declval()) } -> std::same_as; // compute azimuth and altitude from hour angle and declination: azalt2hadec(az, alt, ha, dec) { t.azalt2hadec(std::declval(), std::declval(), std::declval(), std::declval()) } -> std::same_as; // compute parallactic angle: hadec2pa(ha, dec, pa) { t.hadec2pa(std::declval(), std::declval(), std::declval()) } -> std::same_as; // compute equation of origins { t.eqOrigins(std::declval(), std::declval()) } -> std::same_as; /* time-related methods */ // this static method must return a current time point { T::timePointNow() } -> std::same_as; // Gregorian Calendar time point to Julian Date: greg2jul(time_point, jd) { t.greg2jul(std::declval(), std::declval()) } -> std::same_as; // apparent sideral time: apparentSiderTime(jd, st, islocal) // if islocal == false then the method must return the Greenwich apparent sideral time, otherwise - local one { t.apparentSiderTime(std::declval(), std::declval(), std::declval()) } -> std::same_as; /* atmospheric refraction-related methods */ // compute refraction-related quantities: refraction(refr_params) { t.refraction(std::declval()) } -> std::same_as; // compute refraction correction for given altitude: refractCorrection(alt, refr_params, refr_corr) { t.refractCorrection(std::declval(), std::declval(), std::declval()) } -> std::same_as; }; /* A VERY GENERIC MOUNT HARDWARE CONCEPT */ template concept mcc_mount_hardware_c = !std::copyable && std::movable && requires(T t, const T t_const) { requires mcc_error_c; typename T::time_point_t; typename T::coord_t; { t_const.id() } -> mcc_formattable; // a type that defines at least HW_STATE_STOP, HW_STATE_SLEW, HW_STATE_TRACK // compile-time constants // e.g. an implementations can be as follows: // enum class HW_STATE: int {HW_STATE_STOP, HW_STATE_SLEW, HW_STATE_TRACK} // // struct HW_STATE { // uint8_t HW_STATE_STOP = 100; // uint8_t HW_STATE_SLEW = 200; // uint8_t HW_STATE_TRACK = 300; // } requires requires(typename T::hw_state_t state) { []() { // hardware is in stop state (no any moving) static constexpr auto v1 = T::hw_state_t::HW_STATE_STOP; // hardware is in slew state (move to given celestial point) static constexpr auto v2 = T::hw_state_t::HW_STATE_SLEW; // hardware is in track state (track given celestial point) static constexpr auto v3 = T::hw_state_t::HW_STATE_TRACK; }(); }; // a class that contains at least time of measurement, coordinates for x,y axes and its moving rates requires requires(typename T::axes_pos_t pos) { requires std::same_as; // time point requires std::same_as; // co-longitude coordinate requires std::same_as; // co-latitude coordinate requires std::same_as; requires std::same_as; requires std::same_as; // hardware state }; { t.setPos(std::declval()) } -> std::same_as; { t.getPos(std::declval()) } -> std::same_as; { t_const.getState(std::declval()) } -> std::same_as; { t.stop() } -> std::same_as; // stop any moving { t.init() } -> std::same_as; // initialize hardware }; /* POINTING-ERROR CORRECTION */ template concept mcc_mount_pec_c = requires(T t, const T t_const) { requires mcc_error_c; typename T::coord_t; // the 'T' class must contain static constexpr member of 'MccMountType' type requires requires { requires std::same_as; []() { static constexpr MccMountType val = T::mountType; return val; }(); // to ensure 'mountType' can be used in compile-time context }; // a class that contains at least .dx and .dy public fields requires requires(typename T::pec_result_t res) { requires std::same_as; requires std::same_as; }; { t.compute(std::declval(), std::declval(), std::declval()) } -> std::same_as; }; /* MOUNT STATE TELEMETRY */ // a class that contains at least celestial (equatorial and horizontal) and harware coordinates template concept mcc_mount_telemetry_data_c = requires(T telemetry) { typename T::coord_t; typename T::time_point_t; // time point requires std::same_as; // mount current coordinates requires std::same_as; // apparent RA requires std::same_as; // apparent DEC requires std::same_as; // hour angle requires std::same_as; // azimuth requires std::same_as; // altitude requires std::same_as; // hardware encoder X-axis position requires std::same_as; // hardware encoder Y-axis position requires std::same_as; // hardware encoder X-axis rate requires std::same_as; // hardware encoder Y-axis rate }; template concept mcc_mount_telemetry_c = requires(T t, const T t_const) { requires mcc_error_c; // // a class that at least contains celestial (equatorial and horizontal) coordinates // requires requires(typename T::mount_telemetry_data_t telemetry) { // typename T::mount_telemetry_data_t::coord_t; // requires std::same_as; // // apparent RA requires std::same_as; // apparent DEC requires std::same_as; // // hour angle requires std::same_as; // // azimuth requires std::same_as; // altitude // }; requires mcc_mount_telemetry_data_c; { t_const.errorString(std::declval()) } -> mcc_formattable; { t.update() } -> std::same_as; { t.data(std::declval()) } -> std::same_as; }; /* A CONCEPT FOR CLASS TO REPRESENT CELESTIAL POINT */ template concept mcc_celestial_point_c = requires(T t) { // input coordinates pair type (e.g. IRCS RA,DEC, Az,Alt and so on) requires std::same_as; typename T::coord_t; // co-longitude (e.g. RA or Az) requires std::same_as; // co-latitude (e.g. DEC or ZD) requires std::same_as; }; // /* SLEW PARAMETERS */ // template // concept mcc_slew_params_c = std::movable && requires(T t) { // // input coordinates pair type (e.g. IRCS RA,DEC, Az,Alt and so on) // requires std::same_as; // typename T::coord_t; // // co-longitude (e.g. RA or Az) // requires std::same_as; // // co-latitude (e.g. DEC or ZD) // requires std::same_as; // // stop after slewing // requires std::convertible_to; // }; /* GENERIC SLEW AND GUIDING MODEL */ template concept mcc_slew_model_c = requires(T t) { requires mcc_error_c; // requires mcc_slew_params_c; requires mcc_celestial_point_c; // { t.slew(std::declval()) } -> std::same_as; { t.slew(std::declval()) } -> std::same_as; }; template concept mcc_guiding_model_c = requires(T t) { requires mcc_error_c; requires mcc_celestial_point_c; // start process of guiding { t.guiding(std::declval()) } -> std::same_as; }; /* MOUNT PROHIBITED ZONE */ template concept mcc_prohibited_zone_c = mcc_mount_telemetry_data_c && std::movable && requires(T t, const T t_const) { typename T::coord_t; typename T::time_point_t; requires mcc_time_duration_c; // static constexpr member to represent inifite duration requires requires { requires std::same_as; []() { constexpr auto val = T::infiniteDuration; return val; }; }; // the type 'T' must define a static constexpr member of type MccCoordPairKind // to declarate type of coordinate pair used to describe the zone. // This coordinate pair must be used as input in the 'inZone' class method. requires requires { requires std::same_as; []() { constexpr MccCoordPairKind val = T::zoneCoordPairKind; return val; }(); // to ensure that 'zoneCoordPairKind' can be used at compile-time context }; // return a name of the zone { t_const.name() } -> mcc_formattable; // check if given coordinates are into the zone. // input coordinates interpretation is in according to 'zoneCoordPairKind' static constexpr member { t.inZone(std::declval(), std::declval()) } -> std::convertible_to; // for given coordinates and time the method computes a time to reach the zone. // implementation of the method must assume that input coordinates are apparent RA and DEC at given time // point, while the time point is one from which computation should be performed (e.g. current time moment) { t.timeTo(std::declval(), std::declval(), std::declval()) } -> mcc_time_duration_c; // for given coordinates and time the method computes a time to exit from the zone { t.timeFrom(std::declval(), std::declval(), std::declval()) } -> mcc_time_duration_c; // requires for the methods above with the first argument of type // 'const mcc_mount_telemetry_data_c&' (const lvalue reference) { t.inZone(std::declval()) } -> std::convertible_to; // a time duration to reach the zone. // special values the method must return: // 'infiniteDuration' if the given sky point never reaches the zone // 0 (zero duration) if the given sky point is already in the zone or it never exits from the zone { t.timeTo(std::declval()) } -> std::same_as; // a time duration to exit from the zone. // special values the method must return: // 0 (zero duration) if the given sky point already exited from the zone or it never reaches the zone { t.timeFrom(std::declval()) } -> std::same_as; }; /* MOUNT GENERIC CONTROLS */ template concept mcc_mount_controls_c = std::move_constructible && std::movable && requires(T t) { requires mcc_astrom_engine_c; requires mcc_mount_pec_c; requires mcc_mount_hardware_c; requires mcc_mount_telemetry_c; requires mcc_slew_model_c; // requires mcc_slew_model_c; requires mcc_guiding_model_c; // requires mcc_guiding_model_c; // a std::tuple of prohibited zones []... Ts>(std::tuple) { }(t.prohibitedZones); }; /* GENERIC MOUNT CONCEPTS */ template concept mcc_mount_c = requires(T t) { // the class must define typename 'mount_controls_t' and it must be its base class requires mcc_mount_controls_c; requires std::derived_from; // deduced from 'mount_controls_t' typenames requires mcc_mount_telemetry_c; requires std::same_as; requires mcc_astrom_engine_c; requires mcc_mount_pec_c; requires mcc_mount_hardware_c; // requires mcc_slew_model_c; requires mcc_slew_model_c; // requires mcc_guiding_model_c; requires mcc_guiding_model_c; requires std::same_as; // public method { t.mountTelemetryData() } -> std::same_as; }; // generic with logging methods template concept mcc_log_mount_c = mcc_mount_c && mcc_logger_c; // a generic Finite State Machine mount with logging methods template concept mcc_fsm_log_mount_c = std::derived_from && mcc_log_mount_c; } // namespace mcc::traits /* CHECK LIBRARY-WIDE CLASS DECLARATIONS FOR ITS CONCEPTS SATISFACTION */ namespace mcc { static_assert(traits::mcc_logger_c, "MccNullLogger INVALID DECLARATION!"); } // namespace mcc