mountcontrol/cxx/mount.h
2025-02-27 17:33:11 +03:00

88 lines
2.0 KiB
C++

#pragma once
/* MOUNT CONTROL COMPONENTS LIBRARY */
#include <concepts>
#include <cstdint>
#include <functional>
#include <string_view>
namespace mcc
{
enum class MccMountType : uint8_t { GERMAN_TYPE, FORK_TYPE, CROSSAXIS_TYPE, ALTAZ_TYPE };
// mount state type concept
template <typename T>
concept mcc_mount_state_c = requires(T t, const T t_const) {
{ 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>;
{ t.exit(std::declval<const typename T::context_t&>()) } -> std::same_as<void>;
};
// implements a Finite State Machine Pattern
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()
{
_exitCurrentState = []() {}; // do nothing
}
virtual ~MccMount() {}
template <mcc_mount_state_c StateT>
void setMountState(StateT& state)
{
_exitCurrentState(); // exit from current state
_exitCurrentState = [&state, this]() { state.exit(this); };
state.enter(this);
}
protected:
std::function<void()> _exitCurrentState;
void updateMountState() {}
};
} // namespace mcc