...
This commit is contained in:
parent
8da923f9e7
commit
a5bdf87a9b
79
cxx/mount.h
79
cxx/mount.h
@ -3,10 +3,21 @@
|
||||
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <concepts>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
#include "spdlog/sinks/null_sink.h"
|
||||
|
||||
|
||||
// low-level functions
|
||||
namespace lowlevel
|
||||
{
|
||||
#include "../LibSidServo/sidservo.h"
|
||||
} // namespace lowlevel
|
||||
|
||||
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
@ -19,9 +30,8 @@ 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>;
|
||||
{ t.enter() } -> std::same_as<void>;
|
||||
{ t.exit() } -> std::same_as<void>;
|
||||
};
|
||||
|
||||
|
||||
@ -37,12 +47,19 @@ class MccMount
|
||||
public:
|
||||
static constexpr MccMountType mountType = MOUNT_TYPE;
|
||||
|
||||
/* mount main-cycle variable quantities */
|
||||
struct mount_state_t {
|
||||
// time-related
|
||||
time_point_t siderTime; // sideral time
|
||||
/* low-level hardware related constants */
|
||||
|
||||
// target (user-input) current coordinates (in radians)
|
||||
// number of attempts to get low-level hardware data before emit an error
|
||||
static constexpr uint8_t LOWLEVEL_HW_POLL_ATTEMPTS = 10;
|
||||
|
||||
/* mount main-cycle variable quantities (mount orientation) */
|
||||
struct mount_orient_t {
|
||||
// time-related
|
||||
std::chrono::system_clock::time_point utc;
|
||||
time_point_t mjd; // modified Julian date
|
||||
time_point_t siderTime; // sideral time (in radians)
|
||||
|
||||
// apparent target (user-input) current coordinates (in radians)
|
||||
mnt_coord_t tagRA, tagDEC;
|
||||
mnt_coord_t tagHA;
|
||||
mnt_coord_t tagAZ, tagZD;
|
||||
@ -66,10 +83,15 @@ public:
|
||||
};
|
||||
|
||||
|
||||
struct mount_config_t {
|
||||
uint8_t hw_poll_attempts = LOWLEVEL_HW_POLL_ATTEMPTS;
|
||||
};
|
||||
|
||||
MccMount()
|
||||
|
||||
|
||||
MccMount(std::shared_ptr<spdlog::logger> logger = spdlog::null_logger_mt("NULL"))
|
||||
: _mountLogger(logger), _exitCurrentState([]() {})
|
||||
{
|
||||
_exitCurrentState = []() {}; // do nothing
|
||||
}
|
||||
|
||||
virtual ~MccMount() {}
|
||||
@ -78,17 +100,46 @@ public:
|
||||
void setMountState(StateT& state)
|
||||
{
|
||||
_exitCurrentState(); // exit from current state
|
||||
_exitCurrentState = [&state, this]() { state.exit(this); };
|
||||
_exitCurrentState = [&state]() { state.exit(); };
|
||||
|
||||
state.enter(this);
|
||||
state.enter();
|
||||
}
|
||||
|
||||
|
||||
mount_orient_t getMountData() const noexcept
|
||||
{
|
||||
return _currentMountOrient.load();
|
||||
}
|
||||
|
||||
protected:
|
||||
mount_config_t _mountCurrentConfig;
|
||||
|
||||
std::shared_ptr<spdlog::logger> _mountLogger;
|
||||
std::function<void()> _exitCurrentState;
|
||||
|
||||
std::atomic<mount_state_t> _mountCurrentState;
|
||||
std::atomic<mount_orient_t> _currentMountOrient;
|
||||
|
||||
void updateMountState() {}
|
||||
void updateMountState()
|
||||
{
|
||||
mount_orient_t orient;
|
||||
lowlevel::mountdata_t hw_mdata;
|
||||
|
||||
// get data from encoders
|
||||
decltype(mount_config_t::hw_poll_attempts) n_attempts = 0;
|
||||
do {
|
||||
auto ret_code = lowlevel::Mount.getMountData(&hw_mdata);
|
||||
if (ret_code != lowlevel::MCC_E_OK) {
|
||||
++n_attempts;
|
||||
}
|
||||
} while (n_attempts < _mountCurrentConfig.hw_poll_attempts);
|
||||
|
||||
if (n_attempts >= _mountCurrentConfig.hw_poll_attempts) {
|
||||
// log error heres
|
||||
return;
|
||||
}
|
||||
|
||||
_currentMountOrient.store(orient);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user