...
This commit is contained in:
parent
5a5854ccdd
commit
64a3544bd8
@ -490,12 +490,18 @@ public:
|
||||
}
|
||||
|
||||
template <traits::fsm_event_c EvT>
|
||||
auto dispatchEvent(EvT&& event = EvT())
|
||||
requires std::default_initializable<EvT>
|
||||
auto dispatchEvent(EvT&& event)
|
||||
{
|
||||
return dispatchEvent(event);
|
||||
}
|
||||
|
||||
template <traits::fsm_event_c EvT>
|
||||
auto dispatchEvent()
|
||||
requires std::default_initializable<EvT>
|
||||
{
|
||||
return dispatchEvent(EvT{});
|
||||
}
|
||||
|
||||
std::string_view currentStateID() const
|
||||
{
|
||||
return _currentStateID;
|
||||
|
||||
@ -271,7 +271,7 @@ public:
|
||||
// binary arithmetic operations
|
||||
|
||||
template <std::convertible_to<MccAngle> T1, std::convertible_to<MccAngle> T2>
|
||||
auto operator+(const T1& v1, const T2& v2)
|
||||
static auto operator+(const T1& v1, const T2& v2)
|
||||
{
|
||||
static_assert(std::convertible_to<T1, T2> || std::convertible_to<T2, T1>, "INCOMPATIBLE TYPES!");
|
||||
|
||||
@ -281,7 +281,7 @@ auto operator+(const T1& v1, const T2& v2)
|
||||
}
|
||||
|
||||
template <std::convertible_to<MccAngle> T1, std::convertible_to<MccAngle> T2>
|
||||
auto operator-(const T1& v1, const T2& v2)
|
||||
static auto operator-(const T1& v1, const T2& v2)
|
||||
{
|
||||
static_assert(std::convertible_to<T1, T2> || std::convertible_to<T2, T1>, "INCOMPATIBLE TYPES!");
|
||||
|
||||
@ -292,7 +292,7 @@ auto operator-(const T1& v1, const T2& v2)
|
||||
|
||||
|
||||
template <std::convertible_to<MccAngle> T1, std::convertible_to<MccAngle> T2>
|
||||
auto operator*(const T1& v1, const T2& v2)
|
||||
static auto operator*(const T1& v1, const T2& v2)
|
||||
{
|
||||
if constexpr (std::is_arithmetic_v<T1>) {
|
||||
return v2 *= v1;
|
||||
@ -304,7 +304,7 @@ auto operator*(const T1& v1, const T2& v2)
|
||||
}
|
||||
|
||||
template <std::convertible_to<MccAngle> T1, typename T2>
|
||||
auto operator/(const T1& v1, const T2& v2)
|
||||
static auto operator/(const T1& v1, const T2& v2)
|
||||
requires std::is_arithmetic_v<T2>
|
||||
{
|
||||
return v1 /= v2;
|
||||
@ -343,34 +343,19 @@ class MccAngleAZ : public MccAngle
|
||||
using MccAngle::MccAngle;
|
||||
};
|
||||
|
||||
class MccAngleALT; // just forward declaration
|
||||
|
||||
class MccAngleZD : public MccAngle
|
||||
{
|
||||
public:
|
||||
using MccAngle::MccAngle;
|
||||
|
||||
MccAngleZD(const MccAngleALT&);
|
||||
};
|
||||
|
||||
class MccAngleALT : public MccAngle
|
||||
{
|
||||
public:
|
||||
using MccAngle::MccAngle;
|
||||
|
||||
MccAngleALT(const MccAngleZD& zd)
|
||||
{
|
||||
_angleInRads = std::numbers::pi / 2.0 - (double)zd;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
MccAngleZD::MccAngleZD(const MccAngleALT& alt)
|
||||
{
|
||||
_angleInRads = std::numbers::pi / 2.0 - (double)alt;
|
||||
}
|
||||
|
||||
|
||||
class MccAngleX : public MccAngle // some co-longitude coordinate
|
||||
{
|
||||
using MccAngle::MccAngle;
|
||||
|
||||
@ -175,37 +175,53 @@ struct MccMountEventShutdown : public MccMountEventBase<MountT> {
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
struct MccMountStateBase {
|
||||
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
// void exit(this auto&& self, EvT& event)
|
||||
// {
|
||||
// using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
|
||||
// std::forward<decltype(self)>(self).exitImpl(event);
|
||||
|
||||
// event.mount().logDebug("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
|
||||
// }
|
||||
|
||||
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
// void enter(this auto&& self, EvT& event)
|
||||
// {
|
||||
// using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
|
||||
// event.mount().logDebug("Enter to '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
|
||||
|
||||
// std::forward<decltype(self)>(self).enterImpl(event);
|
||||
// }
|
||||
|
||||
protected:
|
||||
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
// void exitImpl(EvT& event)
|
||||
// {
|
||||
// event.mount().logWarn("Call an empty MccMountStateBase::exitImpl method!!! Event type is '{}'", EvT::ID);
|
||||
// }
|
||||
|
||||
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
// void enterImpl(EvT& event)
|
||||
// {
|
||||
// event.mount().logWarn("Call an empty MccMountStateBase::enterImpl method!!! Event type is '{}'", EvT::ID);
|
||||
// }
|
||||
|
||||
// MccMountStateBase() = default;
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void exit(this auto&& self, EvT& event)
|
||||
void exitLog(this auto&& self, EvT& event)
|
||||
{
|
||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
|
||||
std::forward<decltype(self)>(self).exitImpl(event);
|
||||
|
||||
event.mount().logDebug("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void enter(this auto&& self, EvT& event)
|
||||
void enterLog(this auto&& self, EvT& event)
|
||||
{
|
||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
|
||||
event.mount().logDebug("Enter to '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
|
||||
|
||||
std::forward<decltype(self)>(self).enterImpl(event);
|
||||
}
|
||||
|
||||
protected:
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void exitImpl(EvT& event)
|
||||
{
|
||||
event.mount().logWarn("Call an empty MccMountStateBase::exitImpl method!!! Event type is '{}'", EvT::ID);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void enterImpl(EvT& event)
|
||||
{
|
||||
event.mount().logWarn("Call an empty MccMountStateBase::enterImpl method!!! Event type is '{}'", EvT::ID);
|
||||
}
|
||||
};
|
||||
|
||||
@ -242,25 +258,30 @@ struct MccMountStateStop : MccMountStateBase<MountT> {
|
||||
|
||||
using transition_t = fsm::fsm_transition_table_t<std::pair<MccMountEventIDLE<MountT>, MccMountStateIDLE<MountT>>>;
|
||||
|
||||
protected:
|
||||
void exitImpl(MccMountEventIDLE<MountT>& event)
|
||||
// protected:
|
||||
void exit(MccMountEventIDLE<MountT>& event)
|
||||
{
|
||||
// normal exit from the state
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
// normal bihavior (transit to IDLE state after stopping)
|
||||
void enterImpl(MccMountEventStop<MountT>& event)
|
||||
{
|
||||
auto mount = event.mount();
|
||||
mount.stopMount();
|
||||
// normal behavior (transit to IDLE state after stopping)
|
||||
// void enter(MccMountEventStop<MountT>& event)
|
||||
// {
|
||||
// this->enterLog(event);
|
||||
|
||||
// switch to IDLE state
|
||||
mount.template dispatchEvent<MccMountEventIDLE<MountT>>({mount});
|
||||
}
|
||||
// auto mount = event.mount();
|
||||
// mount.stopMount();
|
||||
|
||||
// // switch to IDLE state
|
||||
// mount.template dispatchEvent<MccMountEventIDLE<MountT>>({mount});
|
||||
// }
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void enterImpl(EvT& event)
|
||||
void enter(EvT& event)
|
||||
{
|
||||
this->enterLog(event);
|
||||
|
||||
auto mount = event.mount();
|
||||
|
||||
mount.stopMount();
|
||||
@ -268,7 +289,7 @@ protected:
|
||||
if constexpr (std::same_as<EvT, MccMountEventStop<MountT>>) {
|
||||
mount.logInfo("Stop reason: {}", event.reason());
|
||||
|
||||
// normal bihavior (transit to IDLE state after stopping)
|
||||
// normal behavior (transit to IDLE state after stopping)
|
||||
mount.template dispatchEvent<MccMountEventIDLE<MountT>>({mount});
|
||||
} else {
|
||||
mount.logInfo("Stop reason: special state");
|
||||
@ -285,15 +306,18 @@ struct MccMountStateInit : MccMountStateBase<MountT> {
|
||||
|
||||
using transition_t = fsm::fsm_transition_table_t<std::pair<MccMountEventIDLE<MountT>, MccMountStateIDLE<MountT>>>;
|
||||
|
||||
protected:
|
||||
void exitImpl(MccMountEventIDLE<MountT>& event)
|
||||
// protected:
|
||||
void exit(MccMountEventIDLE<MountT>& event)
|
||||
{
|
||||
// normal exit from the state
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void enterImpl(EvT& event)
|
||||
void enter(EvT& event)
|
||||
{
|
||||
this->enterLog(event);
|
||||
|
||||
auto mount = event.mount();
|
||||
mount.initMount();
|
||||
|
||||
@ -318,33 +342,50 @@ struct MccMountStateError : MccMountStateBase<MountT> {
|
||||
std::pair<MccMountEventStop<MountT>, MccMountStateError<MountT>>,
|
||||
std::pair<MccMountEventShutdown<MountT>, MccMountStateShutdown<MountT>>>;
|
||||
|
||||
protected:
|
||||
// protected:
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void exitImpl(EvT& event)
|
||||
void exit(EvT& event)
|
||||
{
|
||||
this->exitLog(event);
|
||||
|
||||
event.mount().logWarn(
|
||||
"The mount is in the error state!!! One must correct it before transit to any states! Event type is '{}'",
|
||||
EvT::ID);
|
||||
}
|
||||
|
||||
void exitImpl(MccMountEventIDLE<MountT>& event)
|
||||
void exit(MccMountEventIDLE<MountT>& event)
|
||||
{
|
||||
event.mount().logWarning("Suppose the error was corrected!");
|
||||
this->exitLog(event);
|
||||
|
||||
event.mount().logWarn("Suppose the error was corrected!");
|
||||
}
|
||||
|
||||
void exitImpl(MccMountEventInit<MountT>& event)
|
||||
void exit(MccMountEventInit<MountT>& event)
|
||||
{
|
||||
// normal exit from the state
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void enterImpl(EvT& event)
|
||||
void enter(MccMountEventError<MountT>& event)
|
||||
{
|
||||
this->enterLog(event);
|
||||
|
||||
auto err = event.eventData();
|
||||
|
||||
event.mount().logError("The mount is in the error state: code = {}, category = {}, message = '{}'", err.value(),
|
||||
err.category().name(), err.message());
|
||||
}
|
||||
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
// void enter(EvT& event)
|
||||
// {
|
||||
// this->enterLog(event);
|
||||
|
||||
// auto err = event.eventData();
|
||||
|
||||
// event.mount().logError("The mount is in the error state: code = {}, category = {}, message = '{}'",
|
||||
// err.value(),
|
||||
// err.category().name(), err.message());
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
@ -361,6 +402,18 @@ struct MccMountStateIDLE : MccMountStateBase<MountT> {
|
||||
std::pair<MccMountEventGuiding<MountT>, MccMountStateGuiding<MountT>>,
|
||||
std::pair<MccMountEventStop<MountT>, MccMountStateIDLE<MountT>>,
|
||||
std::pair<MccMountEventShutdown<MountT>, MccMountStateShutdown<MountT>>>;
|
||||
|
||||
template <std::derived_from<MccMountStateBase<MountT>> EvT>
|
||||
void exit(EvT& event)
|
||||
{
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountStateBase<MountT>> EvT>
|
||||
void enter(EvT& event)
|
||||
{
|
||||
this->enterLog(event);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -373,15 +426,18 @@ struct MccMountStateShutdown : MccMountStateBase<MountT> {
|
||||
// only initialization
|
||||
using transition_t = fsm::fsm_transition_table_t<std::pair<MccMountEventInit<MountT>, MccMountStateInit<MountT>>>;
|
||||
|
||||
protected:
|
||||
void exitImpl(MccMountEventInit<MountT>& event)
|
||||
// protected:
|
||||
void exit(MccMountEventInit<MountT>& event)
|
||||
{
|
||||
// normal exit from the state
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void enterImpl(EvT& event)
|
||||
void enter(EvT& event)
|
||||
{
|
||||
this->enterLog(event);
|
||||
|
||||
event.mount().shutdownMount();
|
||||
}
|
||||
};
|
||||
@ -402,16 +458,19 @@ struct MccMountStateSlew : MccMountStateBase<MountT> {
|
||||
std::pair<MccMountEventStop<MountT>, MccMountStateStop<MountT>>,
|
||||
std::pair<MccMountEventShutdown<MountT>, MccMountStateStop<MountT>>>;
|
||||
|
||||
protected:
|
||||
// protected:
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void exitImpl(EvT& event)
|
||||
void exit(EvT& event)
|
||||
{
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventSlew<MountT>> EvT>
|
||||
void enterImpl(EvT& event)
|
||||
void enter(EvT& event)
|
||||
{
|
||||
event.mount().slewMount(/* params here ...*/);
|
||||
this->enterLog(event);
|
||||
|
||||
event.mount().slewMount(event.eventData());
|
||||
}
|
||||
};
|
||||
|
||||
@ -432,16 +491,19 @@ struct MccMountStateGuiding : MccMountStateBase<MountT> {
|
||||
std::pair<MccMountEventStop<MountT>, MccMountStateStop<MountT>>,
|
||||
std::pair<MccMountEventShutdown<MountT>, MccMountStateStop<MountT>>>;
|
||||
|
||||
protected:
|
||||
// protected:
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void exitImpl(EvT& event)
|
||||
void exit(EvT& event)
|
||||
{
|
||||
this->exitLog(event);
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventSlew<MountT>> EvT>
|
||||
void enterImpl(EvT& event)
|
||||
void enter(EvT& event)
|
||||
{
|
||||
event.mount().slewMount(/* params here ...*/);
|
||||
this->enterLog(event);
|
||||
|
||||
event.mount().startGuiding();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -16,11 +16,11 @@ int tests_coord(int argc, char* argv[])
|
||||
std::cout << "ang_degs = " << ang.degrees() << "\n";
|
||||
std::cout << "ang_rads = " << (float)ang << "\n";
|
||||
|
||||
MccAngleALT alt(30.0_degs);
|
||||
MccAngleZD zd(alt);
|
||||
// MccAngleALT alt(30.0_degs);
|
||||
// MccAngleZD zd(alt);
|
||||
|
||||
std::cout << "alt = " << alt.degrees() << "\n";
|
||||
std::cout << "zd (from alt) = " << zd.degrees() << "\n";
|
||||
// std::cout << "alt = " << alt.degrees() << "\n";
|
||||
// std::cout << "zd (from alt) = " << zd.degrees() << "\n";
|
||||
|
||||
std::cout << "\n";
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user