This commit is contained in:
2025-10-29 15:07:53 +03:00
parent 78e4bb182c
commit bc300bb3de
6 changed files with 508 additions and 166 deletions

View File

@@ -19,7 +19,8 @@ enum class MccGenericMountErrorCode : int {
ERROR_HW_STOP,
ERROR_HW_GETSTATE,
ERROR_SET_TARGET,
ERROR_MOUNT_SLEW
ERROR_MOUNT_SLEW,
ERROR_MOUNT_TRACK
};
enum class MccGenericFsmMountErrorCode : int { ERROR_OK, ERROR_INVALID_OPERATION, ERROR_UNKNOWN_EVENT };
@@ -152,6 +153,9 @@ public:
using typename SlewModelT::slewing_params_t;
using typename TrackModelT::tracking_params_t;
enum class mount_status_t : int { IDLE, INITIALIZATION, STOPPED, SLEWING, ADJUSTING, TRACKING, ERROR };
MccGenericMount(HardwareT hardware,
TelemetryT telemetry,
PZoneContT pzone_cont,
@@ -163,8 +167,10 @@ public:
PZoneContT(std::move(pzone_cont)),
SlewModelT(std::move(slew_model)),
TrackModelT(std::move(track_model)),
LoggerT(std::move(logger))
LoggerT(std::move(logger)),
_mountStatus(new mount_status_t)
{
*_mountStatus = mount_status_t::IDLE;
}
MccGenericMount(MccGenericMount&&) = default;
@@ -173,7 +179,10 @@ public:
MccGenericMount& operator=(MccGenericMount&&) = default;
MccGenericMount& operator=(const MccGenericMount&) = delete;
virtual ~MccGenericMount() = default;
virtual ~MccGenericMount()
{
stopMount();
};
error_t stopMount()
{
@@ -184,11 +193,15 @@ public:
auto hw_err = this->hardwareStop();
if (hw_err) {
*_mountStatus = mount_status_t::ERROR;
return mcc_deduce_error_code(hw_err, MccGenericMountErrorCode::ERROR_HW_STOP);
}
logInfo("Stop command was sent");
*_mountStatus = mount_status_t::STOPPED;
return MccGenericMountErrorCode::ERROR_OK;
}
@@ -196,13 +209,19 @@ public:
{
logInfo("Start generic mount initialization ...");
*_mountStatus = mount_status_t::INITIALIZATION;
auto hw_err = this->hardwareInit();
if (hw_err) {
*_mountStatus = mount_status_t::ERROR;
return mcc_deduce_error_code(hw_err, MccGenericMountErrorCode::ERROR_HW_STOP);
}
logInfo("Generic mount initialization was performed");
*_mountStatus = mount_status_t::IDLE;
return MccGenericMountErrorCode::ERROR_OK;
}
@@ -231,17 +250,66 @@ public:
// re-implements SlewModelT::slewToTarget to fetch input target coordinates from intermediate buffer
error_t slewToTarget(bool slew_and_stop = false)
{
*_mountStatus = mount_status_t::SLEWING;
auto err = TelemetryT::setPointingTarget(_enteredTargetCoordiniates);
if (err) {
*_mountStatus = mount_status_t::ERROR;
return mcc_deduce_error_code(err, MccGenericMountErrorCode::ERROR_SET_TARGET);
}
if (slew_and_stop) {
*_mountStatus = mount_status_t::IDLE;
}
return mcc_deduce_error_code(SlewModelT::slewToTarget(slew_and_stop),
MccGenericMountErrorCode::ERROR_MOUNT_SLEW);
}
error_t trackTarget()
{
auto err = TrackModelT::traclTarget();
if (err) {
*_mountStatus = mount_status_t::ERROR;
return mcc_deduce_error_code(err, MccGenericMountErrorCode::ERROR_MOUNT_TRACK);
}
*_mountStatus = mount_status_t::TRACKING;
return MccGenericMountErrorCode::ERROR_OK;
}
error_t stopSlewing()
{
*_mountStatus = mount_status_t::IDLE;
SlewModelT::stopSlewing();
return MccGenericMountErrorCode::ERROR_OK;
}
error_t stopTracking()
{
*_mountStatus = mount_status_t::IDLE;
TrackModelT::stopTracking();
return MccGenericMountErrorCode::ERROR_OK;
}
MccGenericMount::mount_status_t mountStatus() const
{
return _mountStatus.get();
}
protected:
MccCelestialPoint _enteredTargetCoordiniates;
MccCelestialPoint _enteredTargetCoordiniates{};
std::unique_ptr<std::atomic<MccGenericMount::mount_status_t>> _mountStatus;
};