...
This commit is contained in:
parent
88d4b30a58
commit
f03e38466e
73
cxx/mount.h
73
cxx/mount.h
@ -43,6 +43,12 @@ concept mcc_mount_state_c = requires(T t, const T t_const) {
|
||||
{ t.enter() } -> std::same_as<void>;
|
||||
{ t.exit() } -> std::same_as<void>;
|
||||
{ t.stop() } -> std::same_as<void>;
|
||||
|
||||
typename T::state_data_t;
|
||||
|
||||
{ t.stateData() } -> std::same_as<typename T::state_data_t>;
|
||||
|
||||
requires std::movable<T>;
|
||||
};
|
||||
|
||||
} // namespace traits
|
||||
@ -51,6 +57,46 @@ concept mcc_mount_state_c = requires(T t, const T t_const) {
|
||||
|
||||
/* SOME BASIC DATA STRUCTURES DEFINITIONS */
|
||||
|
||||
// coordinate system related constants
|
||||
enum class MccCoordKind : uint8_t {
|
||||
COORDS_KIND_RA_IRCS, // IRCS right ascension
|
||||
COORDS_KIND_RA_APP, // apparent right ascension
|
||||
COORDS_KIND_HA, // hour angle
|
||||
COORDS_KIND_AZ, // azimuth
|
||||
COORDS_KIND_X, // co-longitude coordinate
|
||||
COORDS_KIND_DEC_IRCS, // IRCS declination
|
||||
COORDS_KIND_DEC_APP, // apparent declination
|
||||
COORDS_KIND_ALT, // altitude
|
||||
COORDS_KIND_ZD, // zenithal distance
|
||||
COORDS_KIND_Y // co-latitude coordinate
|
||||
};
|
||||
|
||||
enum class MccCoordPairKind : uint16_t {
|
||||
// catalog's
|
||||
COORDS_KIND_RADEC_IRCS = (int)MccCoordKind::COORDS_KIND_RA_IRCS + ((int)MccCoordKind::COORDS_KIND_DEC_IRCS << 8),
|
||||
// apparent RA and DEC
|
||||
COORDS_KIND_RADEC_APP = (int)MccCoordKind::COORDS_KIND_RA_APP + ((int)MccCoordKind::COORDS_KIND_DEC_APP << 8),
|
||||
// apparent HA (hour angle) and DEC
|
||||
COORDS_KIND_HADEC_APP = (int)MccCoordKind::COORDS_KIND_HA + ((int)MccCoordKind::COORDS_KIND_DEC_APP << 8),
|
||||
// Azimuth and Altitude
|
||||
COORDS_KIND_AZALT = (int)MccCoordKind::COORDS_KIND_AZ + ((int)MccCoordKind::COORDS_KIND_ALT << 8),
|
||||
// Azimuth and Zenithal distance
|
||||
COORDS_KIND_AZZD = (int)MccCoordKind::COORDS_KIND_AZ + ((int)MccCoordKind::COORDS_KIND_ZD << 8),
|
||||
// co-longitude and co-latitude (e.g. mount hardware drive/axis encoders)
|
||||
COORDS_KIND_XY = (int)MccCoordKind::COORDS_KIND_X + ((int)MccCoordKind::COORDS_KIND_Y << 8),
|
||||
};
|
||||
|
||||
template <MccCoordPairKind KIND>
|
||||
static constexpr std::string_view MccCoordPairKindStr =
|
||||
KIND == MccCoordPairKind::COORDS_KIND_RADEC_IRCS ? "RADEC-IRCS"
|
||||
: KIND == MccCoordPairKind::COORDS_KIND_RADEC_APP ? "RADEC-APP"
|
||||
: KIND == MccCoordPairKind::COORDS_KIND_HADEC_APP ? "HADEC-APP"
|
||||
: KIND == MccCoordPairKind::COORDS_KIND_AZALT ? "Azimuth-Altitude"
|
||||
: KIND == MccCoordPairKind::COORDS_KIND_AZZD ? "AzimuthZendist"
|
||||
: KIND == MccCoordPairKind::COORDS_KIND_XY ? "XY"
|
||||
: "UNKNOWN";
|
||||
|
||||
|
||||
// meteo parameters (e.g. to compute refraction)
|
||||
struct MccMountMeteo {
|
||||
typedef double temp_t;
|
||||
@ -201,6 +247,31 @@ public:
|
||||
DT time_from{DT::min()};
|
||||
};
|
||||
|
||||
|
||||
/* mount state base class */
|
||||
|
||||
class MccMountState
|
||||
{
|
||||
public:
|
||||
MccMountState(MccMount& mount) : _mount(mount) {}
|
||||
|
||||
virtual ~MccMountState() = default;
|
||||
|
||||
void enter(this std::derived_from<MccMountState> auto&& self)
|
||||
{
|
||||
std::forward<decltype(self)>(self).enter();
|
||||
}
|
||||
|
||||
void exit(std::derived_from<MccMountState> auto next_state)
|
||||
requires std::movable<decltype(next_state)>
|
||||
{
|
||||
_mount.setMountState(std::move(next_state));
|
||||
}
|
||||
|
||||
protected:
|
||||
MccMount& _mount;
|
||||
};
|
||||
|
||||
/* Constructors and destructor */
|
||||
|
||||
MccMount(traits::mcc_input_char_range auto const& logger_mark = "[MOUNT]",
|
||||
@ -229,7 +300,7 @@ public:
|
||||
/* Public methods */
|
||||
|
||||
template <traits::mcc_mount_state_c StateT>
|
||||
void setMountState(StateT& state)
|
||||
void setMountState(StateT state)
|
||||
{
|
||||
_exitCurrentState(); // exit from current state
|
||||
_exitCurrentState = [&state]() { state.exit(); };
|
||||
|
||||
@ -36,9 +36,12 @@ public:
|
||||
static constexpr auto mcc_noop_callback = [](const mount_state_error_t&) {};
|
||||
|
||||
MccMountAbstractState(traits::mcc_mount_c auto* mount_ptr,
|
||||
std::convertible_to<enter_callback_t> auto&& enter_callback,
|
||||
std::convertible_to<exit_callback_t> auto&& exit_callback,
|
||||
std::convertible_to<error_callback_t> auto&& error_callback)
|
||||
std::convertible_to<enter_callback_t> auto&& enter_callback = mcc_noop_callback,
|
||||
std::convertible_to<exit_callback_t> auto&& exit_callback = mcc_noop_callback,
|
||||
std::convertible_to<error_callback_t> auto&& error_callback = mcc_noop_callback)
|
||||
: _enterCallback(std::forward<enter_callback_t>(enter_callback)),
|
||||
_exitCallback(std::forward<exit_callback_t>(exit_callback)),
|
||||
_errorCallback(std::forward<error_callback_t>(error_callback))
|
||||
{
|
||||
_getMountDataFunc = [&mount_ptr, this]() { auto mstate = mount_ptr->getMountData(); };
|
||||
}
|
||||
@ -81,26 +84,108 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/* */
|
||||
class MccMountStateStoping
|
||||
{
|
||||
public:
|
||||
typedef std::string state_data_t;
|
||||
|
||||
MccMountStateStoping(traits::mcc_input_char_range auto const& reason) : _reason({reason.begin(), reason.end()}) {}
|
||||
|
||||
MccMountStateStoping(const char* reason) : MccMountStateStoping(std::string_view{reason}) {}
|
||||
|
||||
|
||||
std::string_view ident() const
|
||||
{
|
||||
return "MCC-MOUNT-STATE-STOPING";
|
||||
}
|
||||
|
||||
void enter() {}
|
||||
|
||||
void exit() {}
|
||||
|
||||
void stop() {}
|
||||
|
||||
state_data_t stateData()
|
||||
{
|
||||
return _reason;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string _reason;
|
||||
};
|
||||
|
||||
|
||||
/* */
|
||||
class MccMountStateStopped
|
||||
{
|
||||
public:
|
||||
typedef std::string state_data_t;
|
||||
|
||||
MccMountStateStopped(traits::mcc_input_char_range auto const& reason) : _reason({reason.begin(), reason.end()}) {}
|
||||
|
||||
MccMountStateStopped(const char* reason) : MccMountStateStopped(std::string_view{reason}) {}
|
||||
|
||||
|
||||
std::string_view ident() const
|
||||
{
|
||||
return "MCC-MOUNT-STATE-STOPPED";
|
||||
}
|
||||
|
||||
void enter() {}
|
||||
|
||||
void exit() {}
|
||||
|
||||
void stop() {}
|
||||
|
||||
state_data_t stateData()
|
||||
{
|
||||
return _reason;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string _reason;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* */
|
||||
class MccMountStateSlew
|
||||
{
|
||||
public:
|
||||
enum coords_kind_t { COORDS_KIND_RADEC_IRCS, COORDS_KIND_RADEC_APP, COORDS_KIND_HADEC_APP, COORDS_KIND_AZALT };
|
||||
|
||||
struct slew_state_params_t {
|
||||
coords_kind_t coordKind{COORDS_KIND_RADEC_APP};
|
||||
MccCoordPairKind coordKind{MccCoordPairKind::COORDS_KIND_RADEC_APP};
|
||||
MccAngle x, y; // according to 'coordKind'
|
||||
|
||||
bool stop{false}; // stop after
|
||||
};
|
||||
|
||||
MccMountStateSlew() {}
|
||||
MccMountStateSlew(traits::mcc_mount_c auto& mount,
|
||||
const slew_state_params_t& params,
|
||||
std::string_view ident = "MCC-MOUNT-STATE-SLEW")
|
||||
: _ident(ident)
|
||||
{
|
||||
_stopFunc = [&mount]() {
|
||||
//
|
||||
mount.setMountState(MccMountStateStopped("stop pointing"));
|
||||
};
|
||||
}
|
||||
|
||||
std::string_view ident() const
|
||||
{
|
||||
return "MCC-MOUNT-STATE-SLEW";
|
||||
return _ident;
|
||||
}
|
||||
|
||||
void enter() {}
|
||||
|
||||
void exit() {}
|
||||
|
||||
void stop() {}
|
||||
|
||||
protected:
|
||||
std::string_view _ident;
|
||||
|
||||
std::function<void()> _stopFunc;
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user