Compare commits

...

2 Commits

Author SHA1 Message Date
d1e91e1c96 ... 2025-02-26 17:49:18 +03:00
c64baf6e35 ... 2025-02-26 09:51:21 +03:00
4 changed files with 169 additions and 9 deletions

View File

@ -185,12 +185,12 @@ public:
fst << "#\n";
for (auto& [key, value] : _currentConfig) {
fst << key << " = ";
fst << key;
if (auto v_str = std::get_if<1>(&value)) {
fst << *v_str;
fst << " = " << *v_str;
} else if (auto v_vec = std::get_if<2>(&value)) {
fst << (*v_vec)[0];
fst << " = " << (*v_vec)[0];
for (size_t i = 1; i < v_vec->size(); ++i) {
fst << ", " << (*v_vec)[i];
}

View File

@ -5,6 +5,7 @@
#include <concepts>
#include <cstdint>
#include <functional>
#include <string_view>
namespace mcc
{
@ -15,8 +16,7 @@ enum class MccMountType : uint8_t { GERMAN_TYPE, FORK_TYPE, CROSSAXIS_TYPE, ALTA
// mount state type concept
template <typename T>
concept mcc_mount_state_c = requires(T t, const T t_const) {
typename T::state_id_t;
{ t.ident() } -> std::same_as<typename T::state_id_t>;
{ t_const.ident() } -> std::same_as<std::string_view>;
typename T::context_t;
{ t.enter(std::declval<const typename T::context_t&>()) } -> std::same_as<void>;
@ -29,9 +29,37 @@ concept mcc_mount_state_c = requires(T t, const T t_const) {
template <MccMountType MOUNT_TYPE>
class MccMount
{
typedef double coord_t;
typedef double time_point_t;
public:
static constexpr MccMountType mountType = MOUNT_TYPE;
/* mount main-cycle variable quantities */
struct mount_state_t {
// time-related
time_point_t siderTime; // sideral time
// target (user-input) current coordinates (in radians)
coord_t tagRA, tagDEC;
coord_t tagHA;
coord_t tagAZ, tagZD;
// encoder-measured current mount coordinates (in radians)
coord_t mntRA, mntDEC;
coord_t mntHA;
coord_t mntAZ, mntZD;
// current refraction coefficient
coord_t currRefr;
// PCS (pointing correction system) corrections
coord_t pcsX, pcsY; // X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ZD for horizontal-type one
// mount current state
};
MccMount()
{

View File

@ -1,5 +1,4 @@
#include <iostream>
#include <strstream>
#include "../comm_server_configfile.h"
@ -14,10 +13,11 @@ int main(int argc, char* argv[])
auto print_cfg = [](auto const& cfg) {
for (auto& [key, v] : cfg.config()) {
std::cout << key << " = ";
std::cout << key;
if (auto v_str = std::get_if<1>(&v)) {
std::cout << *v_str;
std::cout << " = " << *v_str;
} else if (auto v_vec = std::get_if<2>(&v)) {
std::cout << " = ";
for (auto& el : *v_vec) {
std::cout << "<" << el << "> ";
}
@ -36,7 +36,8 @@ int main(int argc, char* argv[])
vec_key = 1,2,3 , 345, 4576, 79
)--";
std::istrstream ist(str.c_str());
std::stringstream ist;
ist << str;
cfg.load(ist);
std::cout << "From input stream: \n";

View File

@ -1,6 +1,8 @@
#pragma once
#include <charconv>
#include <cmath>
#include <numbers>
#include <ranges>
#include <regex>
@ -140,4 +142,133 @@ static std::optional<double> parsAngleString(R&& r, bool hms = false)
return std::nullopt;
}
static constexpr auto deg2radCoeff = std::numbers::pi / 180.0;
// radians to degrees
template <bool NORM = false>
static double rad2deg(double ang)
{
auto r = ang / deg2radCoeff;
if constexpr (NORM) {
return std::fmod(r, 360.0);
} else {
return r;
}
}
template <std::ranges::output_range<char> R, bool NORM = false>
static R rad2deg_str(double ang, int prec = 2)
{
R res;
std::string fmt = "{:0." + std::to_string(prec) + "f}";
auto degs = rad2deg<NORM>(ang);
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, degs);
}
template <bool NORM = false>
static std::string rad2deg_str(double ang, int prec = 2)
{
return rad2deg_str<std::string, NORM>(ang, prec);
}
template <std::ranges::output_range<char> R, bool NORM = false>
static R rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 2, int prec2 = 2)
{
R res = rad2deg_str<R, NORM>(ang1, prec1);
R r = rad2deg_str<R, NORM>(ang2, prec2);
std::ranges::copy(std::back_inserter(res), delim);
std::ranges::copy(std::back_inserter(res), r);
return res;
}
template <bool NORM = false>
static std::string rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 2, int prec2 = 2)
{
return rad2deg_str<std::string, NORM>(ang1, ang2, delim, prec1, prec2);
}
// radians to sexagesimal
template <std::ranges::output_range<char> R, bool NORM = false>
static R rad2sxg(double ang, bool hms = false, int prec = 2)
{
R res;
std::string fmt = "{:02d}:{:02d}:{:0" + std::to_string(prec + 3) + "." + std::to_string(prec) + "f}";
auto degs = rad2deg<NORM>(std::abs(ang));
if (hms) {
degs /= 15.0;
}
auto d = std::trunc(degs);
auto s = (degs - d) * 60.0;
auto m = std::trunc(s);
s = (s - m) * 60.0;
if (ang < 0) {
std::ranges::copy(std::string_view("-"), std::back_inserter(res));
}
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, d, m, s);
return res;
}
template <bool NORM = false>
static std::string rad2sxg(double ang, bool hms = false, int prec = 2)
{
return rad2sxg<std::string, NORM>(ang, hms, prec);
}
template <std::ranges::output_range<char> R, bool NORM = false>
static R RADEC_rad2sxg(double ra, double dec, std::string_view delim = ",", int ra_prec = 2, int dec_prec = 1)
{
R res = rad2sxg<R, NORM>(ra, true, ra_prec);
R r = rad2sxg(dec, false, dec_prec);
std::ranges::copy(std::back_inserter(res), delim);
std::ranges::copy(std::back_inserter(res), r);
return res;
}
template <bool NORM = false>
static std::string RADEC_rad2sxg(double ra, double dec, std::string_view delim = ",", int ra_prec = 2, int dec_prec = 1)
{
return RADEC_rad2sxg<std::string, NORM>(ra, dec, delim, ra_prec, dec_prec);
}
template <std::ranges::output_range<char> R, bool NORM = false>
static R AZZD_rad2sxg(double az, double zd, std::string_view delim = ",", int az_prec = 2, int zd_prec = 1)
{
R res = rad2sxg<R, NORM>(az, false, az_prec);
R r = rad2sxg(zd, false, zd_prec);
std::ranges::copy(std::back_inserter(res), delim);
std::ranges::copy(std::back_inserter(res), r);
return res;
}
template <bool NORM = false>
static std::string AZZD_rad2sxg(double az, double zd, std::string_view delim = ",", int az_prec = 2, int zd_prec = 1)
{
return AZZD_rad2sxg<std::string, NORM>(az, zd, delim, az_prec, zd_prec);
}
} // namespace mcc::utils