This commit is contained in:
Timur A. Fatkhullin
2025-09-01 01:15:23 +03:00
parent c2627ecd89
commit 218da42a1d
6 changed files with 408 additions and 13 deletions

View File

@@ -64,25 +64,23 @@ public:
mcc_PCM_c PcmT,
mcc_pzone_container_c PZoneContT>
MccSimpleTrackingModel(TelemetryT* telemetry, HardwareT* hardware, PcmT* pcm, PZoneContT* pz_cont)
: _stopTracking(new std::atomic_bool())
: _stopTracking(new std::atomic_bool()), _currentTrackParamsMutex(new std::mutex)
{
*_stopTracking = false;
// set default values
if constexpr (mccIsEquatorialMount(PcmT::mountType)) {
_currentTrackParams.trackSpeedX = tracking_params_t::sideralRate; // move along HA-axis with sideral rate
_currentTrackParams.trackSpeedY = 0.0;
_currentTrackParams.telemetryTimeout = std::chrono::seconds(3);
_currentTrackParams.minTimeToPZone = std::chrono::seconds(10);
}
_trackingFunc = [telemetry, hardware, pcm, pz_cont, this]() -> error_t {
MccCelestialPoint cpt;
typename HardwareT::hardware_state_t hw_state;
// compute position in future
auto err = hardware->hardwareGetState(&hw_state);
if (err) {
return mcc_deduce_error<error_t>(err, MccSimpleTrackingModelErrorCode::ERROR_HW_GETSTATE);
}
if constexpr (mccIsEquatorialMount(PcmT::mountType)) {
cpt.pair_kind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
} else if constexpr (mccIsAltAzMount(PcmT::mountType)) {
@@ -138,6 +136,12 @@ public:
cpt.Y = tdata.DEC_APP;
}
// compute position in future
auto err = hardware->hardwareGetState(&hw_state);
if (err) {
return mcc_deduce_error<error_t>(err, MccSimpleTrackingModelErrorCode::ERROR_HW_GETSTATE);
}
MccPCMResult pcm_inv_res;
// endpoint of the mount moving
@@ -148,8 +152,12 @@ public:
// just set sideral rate once
mcc_tp2tp(cpt.time_point, hw_state.time_point);
hw_state.speedX = _currentTrackParams.trackSpeedX;
hw_state.speedY = _currentTrackParams.trackSpeedY;
{
std::lock_guard lock{*_currentTrackParamsMutex};
hw_state.speedX = _currentTrackParams.trackSpeedX;
hw_state.speedY = _currentTrackParams.trackSpeedY;
}
hw_state.moving_type = HardwareT::hardware_moving_state_t::HW_MOVE_TRACKING;
// start tracking
@@ -169,7 +177,7 @@ public:
min_time = std::chrono::duration<double>{0};
for (size_t i = 0; i < pz_cont->sizePZones(); ++i) {
if (pz_timeto[i] <= _currentTrackParams.minTimeToPZone) {
if (pz_timeto[i] < _currentTrackParams.minTimeToPZone) {
return MccSimpleTrackingModelErrorCode::ERROR_NEAR_PZONE;
}
if (pz_timeto[i] < min_time) {
@@ -222,11 +230,17 @@ public:
error_t setTrackingParams(tracking_params_t params)
{
std::lock_guard lock{*_currentTrackParamsMutex};
_currentTrackParams = std::move(params);
return MccSimpleTrackingModelErrorCode::ERROR_OK;
}
tracking_params_t getTrackingParams()
tracking_params_t getTrackingParams() const
{
std::lock_guard lock{*_currentTrackParamsMutex};
return _currentTrackParams;
}
@@ -235,6 +249,7 @@ protected:
std::unique_ptr<std::atomic_bool> _stopTracking{};
tracking_params_t _currentTrackParams;
std::unique_ptr<std::mutex> _currentTrackParamsMutex;
};
} // namespace mcc