...
This commit is contained in:
parent
052d4e2eb4
commit
4bf95c1043
@ -68,8 +68,9 @@ message(STATUS "BSPLINES_INCLUDE_DIR: " ${BSPLINES_INCLUDE_DIR})
|
||||
include_directories(${BSPLINES_INCLUDE_DIR})
|
||||
|
||||
set(MCC_LIBRARY_SRC1 mcc_generics.h mcc_defaults.h mcc_traits.h mcc_utils.h
|
||||
mcc_ccte_iers.h mcc_ccte_iers_default.h mcc_ccte_erfa.h mcc_telemetry.h
|
||||
mcc_angle.h mcc_pzone.h mcc_pzone_container.h mcc_finite_state_machine.h)
|
||||
mcc_ccte_iers.h mcc_ccte_iers_default.h mcc_ccte_erfa.h mcc_telemetry.h
|
||||
mcc_angle.h mcc_pzone.h mcc_pzone_container.h mcc_finite_state_machine.h
|
||||
mcc_generic_mount.h)
|
||||
|
||||
list(APPEND MCC_LIBRARY_SRC1 mcc_spdlog.h)
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
namespace mcc
|
||||
{
|
||||
|
||||
enum class MccGenericMountErrorCode : int { ERROR_OK, ERROR_HW_STOP, ERROR_HW_GETSTATE };
|
||||
enum class MccGenericMountErrorCode : int { ERROR_OK, ERROR_HW_INIT, ERROR_HW_STOP, ERROR_HW_GETSTATE };
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
@ -98,9 +98,22 @@ public:
|
||||
|
||||
return MccGenericMountErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
error_t initMount()
|
||||
{
|
||||
auto hw_err = this->hardwareInit();
|
||||
if (hw_err) {
|
||||
return mcc_deduce_error(hw_err, MccGenericMountErrorCode::ERROR_HW_STOP);
|
||||
}
|
||||
|
||||
return MccGenericMountErrorCode::ERROR_OK;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* GENERIC FINITE-STATE-MOCHINE MOUNT REFERENCE IMPLEMENTATION */
|
||||
|
||||
|
||||
template <mcc_hardware_c HardwareT,
|
||||
mcc_telemetry_c TelemetryT,
|
||||
mcc_pzone_container_c PZoneContT,
|
||||
@ -110,17 +123,173 @@ template <mcc_hardware_c HardwareT,
|
||||
mcc_logger_c LoggerT = MccNullLogger>
|
||||
class MccGenericMountFSM
|
||||
: public fsm::MccFiniteStateMachine,
|
||||
protected MccGenericMount<HardwareT, TelemetryT, PZoneContT, SlewModelT, TrackModelT, GuidingModelT, LoggerT>
|
||||
public MccGenericMount<HardwareT, TelemetryT, PZoneContT, SlewModelT, TrackModelT, GuidingModelT, LoggerT>
|
||||
{
|
||||
protected:
|
||||
typedef MccGenericMount<HardwareT, TelemetryT, PZoneContT, SlewModelT, TrackModelT, GuidingModelT, LoggerT>
|
||||
base_gmount_t;
|
||||
|
||||
public:
|
||||
struct MccGenericMountStateUninit {
|
||||
using transition_t = fsm::fsm_transition_table_t<>;
|
||||
/* EVENTS AND STATES DEFINITION */
|
||||
|
||||
|
||||
/* base class for events */
|
||||
|
||||
struct MccGenericMountBaseEvent {
|
||||
virtual ~MccGenericMountBaseEvent() = default;
|
||||
|
||||
MccGenericMountFSM& mount() const
|
||||
{
|
||||
return _mount;
|
||||
}
|
||||
|
||||
protected:
|
||||
MccGenericMountFSM& _mount;
|
||||
|
||||
MccGenericMountBaseEvent(MccGenericMountFSM& mount) : _mount(mount) {}
|
||||
};
|
||||
|
||||
// to IDLE state
|
||||
struct MccGenericMountEventIDLE : MccGenericMountBaseEvent {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-IDLE-EVENT";
|
||||
|
||||
// CTAD does not work for clang++ (at least till v. 20 and -std=c++23)!
|
||||
// so, one must explicitly define constructor here
|
||||
MccGenericMountEventIDLE(MccGenericMountFSM& mount) : MccGenericMountBaseEvent(mount) {}
|
||||
};
|
||||
|
||||
|
||||
// to error state
|
||||
struct MccGenericMountEventError : MccGenericMountBaseEvent {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-ERROR-EVENT";
|
||||
|
||||
typedef typename base_gmount_t::error_t error_t;
|
||||
|
||||
MccGenericMountEventError(MccGenericMountFSM& mount, const error_t& err)
|
||||
: MccGenericMountBaseEvent(mount), _error(err)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
error_t eventData() const
|
||||
{
|
||||
return _error;
|
||||
}
|
||||
|
||||
protected:
|
||||
error_t _error;
|
||||
};
|
||||
|
||||
|
||||
// to INIT state
|
||||
struct MccGenericMountEventInit : MccGenericMountBaseEvent {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-INIT-EVENT";
|
||||
|
||||
MccGenericMountEventInit(MccGenericMountFSM& mount) : MccGenericMountBaseEvent(mount) {}
|
||||
};
|
||||
|
||||
|
||||
// to slewing state
|
||||
struct MccGenericMountEventSlew : MccGenericMountBaseEvent {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-SLEWING-EVENT";
|
||||
|
||||
MccGenericMountEventSlew(MccGenericMountFSM& mount) : MccGenericMountBaseEvent(mount) {}
|
||||
};
|
||||
|
||||
|
||||
// to tracking state
|
||||
struct MccGenericMountEventTrack : MccGenericMountBaseEvent {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-TRACKING-EVENT";
|
||||
|
||||
MccGenericMountEventTrack(MccGenericMountFSM& mount) : MccGenericMountBaseEvent(mount) {}
|
||||
};
|
||||
|
||||
|
||||
// to guiding state
|
||||
struct MccGenericMountEventGuiding : MccGenericMountBaseEvent {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-GUIDING-EVENT";
|
||||
|
||||
MccGenericMountEventGuiding(MccGenericMountFSM& mount) : MccGenericMountBaseEvent(mount) {}
|
||||
};
|
||||
|
||||
|
||||
// to stoping state
|
||||
struct MccGenericMountEventStop : MccGenericMountBaseEvent {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-STOP-EVENT";
|
||||
|
||||
MccGenericMountEventStop(MccGenericMountFSM& mount) : MccGenericMountBaseEvent(mount) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* base class for states */
|
||||
|
||||
struct MccGenericMountBaseState {
|
||||
virtual ~MccGenericMountBaseState() = default;
|
||||
|
||||
protected:
|
||||
MccGenericMountBaseState() = default;
|
||||
|
||||
template <std::derived_from<MccGenericMountBaseEvent> EvT>
|
||||
void exitLog(this auto&& self, EvT& event)
|
||||
{
|
||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
|
||||
event.mount().logDebug(std::format("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID));
|
||||
}
|
||||
|
||||
template <std::derived_from<MccGenericMountBaseEvent> EvT>
|
||||
void enterLog(this auto&& self, EvT& event)
|
||||
{
|
||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
event.mount().logDebug(std::format("Enter to '{}' state due to '{}' event ...", self_t::ID, EvT::ID));
|
||||
}
|
||||
};
|
||||
|
||||
// forward declarations
|
||||
struct MccGenericMountStateInit;
|
||||
struct MccGenericMountStateIDLE;
|
||||
struct MccGenericMountStateError;
|
||||
struct MccGenericMountStateSlew;
|
||||
struct MccGenericMountStateTrack;
|
||||
struct MccGenericMountStateGuiding;
|
||||
struct MccGenericMountStateStopping;
|
||||
|
||||
struct MccGenericMountStateUninit : MccGenericMountBaseState {
|
||||
// from uninitialized state only INIT-event is permitted!
|
||||
using transition_t =
|
||||
fsm::fsm_transition_table_t<std::pair<MccGenericMountEventInit, MccGenericMountStateInit>,
|
||||
std::pair<MccGenericMountEventIDLE, MccGenericMountStateUninit>,
|
||||
std::pair<MccGenericMountEventError, MccGenericMountStateError>,
|
||||
std::pair<MccGenericMountEventStop, MccGenericMountStateUninit>,
|
||||
std::pair<MccGenericMountEventSlew, MccGenericMountStateUninit>,
|
||||
std::pair<MccGenericMountEventTrack, MccGenericMountStateUninit>,
|
||||
std::pair<MccGenericMountEventGuiding, MccGenericMountStateUninit>>;
|
||||
|
||||
template <std::derived_from<MccGenericMountBaseEvent> EvT>
|
||||
void exit(EvT& event)
|
||||
{
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
void enter(MccGenericMountEventInit& event)
|
||||
{
|
||||
error_t err = event.mount().initMount();
|
||||
if (err) {
|
||||
event.mount().dispatchEvent(MccGenericMountEventError{event.mount(), err});
|
||||
}
|
||||
}
|
||||
|
||||
template <std::derived_from<MccGenericMountBaseEvent> EvT>
|
||||
void enter(EvT& event)
|
||||
{
|
||||
this->enterLog(event);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* CONSTRUCTORS AND DESTRUCTOR */
|
||||
|
||||
MccGenericMountFSM(HardwareT hardware,
|
||||
TelemetryT telemetry,
|
||||
PZoneContT pzone_cont,
|
||||
@ -138,6 +307,14 @@ public:
|
||||
std::move(logger))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual ~MccGenericMountFSM() = default;
|
||||
|
||||
auto stopMount()
|
||||
{
|
||||
this->dispatchEvent(MccGenericMountEventStop{*this});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -847,6 +847,9 @@ concept mcc_generic_mount_c = mcc_telemetry_c<T> && mcc_pzone_container_c<T> &&
|
||||
|
||||
// stop any movement
|
||||
{ t.stopMount() } -> std::same_as<typename T::error_t>;
|
||||
|
||||
// init mount
|
||||
{ t.initMount() };
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user