...
This commit is contained in:
@@ -174,7 +174,8 @@ public:
|
||||
}
|
||||
|
||||
bool in_zone;
|
||||
auto pz_err = controls->inPZone(tdata.target, &in_zone);
|
||||
std::vector<bool> in_zone_vec;
|
||||
auto pz_err = controls->inPZone(tdata.target, &in_zone, &in_zone_vec);
|
||||
if (pz_err) {
|
||||
*_stopSlewing = true;
|
||||
return mcc_deduce_error_code(pz_err, MccSimpleSlewingModelErrorCode::ERROR_PZONE_CONTAINER_COMP);
|
||||
@@ -183,7 +184,14 @@ public:
|
||||
if (in_zone) {
|
||||
*_stopSlewing = true;
|
||||
|
||||
logger.logError("target point is in prohibited zone! Entered target coordinates:");
|
||||
size_t i = 0;
|
||||
for (; i < in_zone_vec.size(); ++i) {
|
||||
if (in_zone_vec[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.logError("target point is in prohibited zone (zone index: {})! Entered target coordinates:", i);
|
||||
logger.logError(std::format(" RA-APP, DEC-APP, HA, LST: {}, {}, {}, {}",
|
||||
mcc::MccAngle{tdata.target.RA_APP}.sexagesimal(true),
|
||||
mcc::MccAngle{tdata.target.DEC_APP}.sexagesimal(),
|
||||
@@ -193,6 +201,9 @@ public:
|
||||
mcc::MccAngle{tdata.target.ZD}.sexagesimal(),
|
||||
mcc::MccAngle{tdata.target.ALT}.sexagesimal()));
|
||||
|
||||
logger.logError(std::format(" X-enc, Y-enc: {}, {}", mcc::MccAngle{tdata.target.X}.sexagesimal(),
|
||||
mcc::MccAngle{tdata.target.Y}.sexagesimal()));
|
||||
|
||||
return MccSimpleSlewingModelErrorCode::ERROR_TARGET_IN_PZONE;
|
||||
}
|
||||
|
||||
@@ -310,6 +321,20 @@ public:
|
||||
|
||||
std::pair<double, double> distXY;
|
||||
|
||||
|
||||
if constexpr (mccIsEquatorialMount(CONTROLS_T::mountType)) {
|
||||
if (tdata.target.pair_kind != MccCoordPairKind::COORDS_KIND_HADEC_APP) {
|
||||
// here, HA and DEC are changed during slewing process!!
|
||||
slew_and_stop = false;
|
||||
}
|
||||
} else if constexpr (mccIsAltAzMount(CONTROLS_T::mountType)) {
|
||||
if (!(tdata.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZALT &&
|
||||
tdata.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZZD)) {
|
||||
slew_and_stop = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// main loop (simply monitors the current position taking into account the prohibited zones, as well as the
|
||||
// timeout of the entire process)
|
||||
while (!*_stopSlewing) {
|
||||
@@ -442,8 +467,15 @@ public:
|
||||
return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
|
||||
}
|
||||
|
||||
logger.logDebug(" the 'hardwareSetState' method performed successfully!");
|
||||
|
||||
{
|
||||
std::lock_guard lock{*_currentParamsMutex};
|
||||
logger.logDebug(" the 'hardwareSetState' method performed successfully!");
|
||||
}
|
||||
}
|
||||
|
||||
// sleep here
|
||||
std::this_thread::sleep_for(_currentParams.slewingTelemetryInterval);
|
||||
}
|
||||
|
||||
*_stopSlewing = true;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <stop_token>
|
||||
#include <thread>
|
||||
|
||||
#include "mcc_defaults.h"
|
||||
@@ -150,7 +151,7 @@ public:
|
||||
MccCelestialPoint hw_cp{.pair_kind = MccCoordPairKind::COORDS_KIND_XY};
|
||||
mcc_tp2tp(_data.time_point, hw_cp.time_point);
|
||||
|
||||
if (hw_coords) { // compute corresponded apparent coordinates
|
||||
if (hw_coords) { // compute corresponded observed coordinates
|
||||
hw_cp.X = _data.target.X;
|
||||
hw_cp.Y = _data.target.Y;
|
||||
|
||||
@@ -318,6 +319,7 @@ public:
|
||||
MccCelestialPoint pt{.pair_kind = MccCoordPairKind::COORDS_KIND_AZALT, .time_point = _data.time_point};
|
||||
|
||||
if constexpr (mccIsEquatorialMount(pcm_t::mountType)) {
|
||||
// NOTE: now it are OBSERVED (NOT APPARENT) RA, HA, DEC!!!
|
||||
_data.RA_APP =
|
||||
MccAngle((double)_data.LST - (double)_data.HA - eo).normalize<MccAngle::NORM_KIND_0_360>();
|
||||
// MccAngle((double)_data.LST - (double)_data.HA + eo).normalize<MccAngle::NORM_KIND_0_360>();
|
||||
@@ -367,18 +369,32 @@ public:
|
||||
|
||||
ccte_err = controls->refractionCorrection(_data, &_data.refCorr);
|
||||
if (!ccte_err) {
|
||||
// // compute APPARENT RA, HA and DEC from observer AZ, ZD
|
||||
// _data.Y += _data.refCorr; // zenithal distance corrected for the refraction
|
||||
|
||||
// pt.pair_kind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||
|
||||
// ccte_err = controls->transformCoordinates(_data, &pt);
|
||||
// if (!ccte_err) {
|
||||
// _data.HA = pt.X;
|
||||
// _data.DEC_APP = pt.Y;
|
||||
// _data.RA_APP =
|
||||
// MccAngle((double)_data.LST - (double)_data.HA -
|
||||
// eo).normalize<MccAngle::NORM_KIND_0_360>();
|
||||
|
||||
|
||||
// restore hardware encoders coordinates
|
||||
_data.X = (double)hw_pos.X;
|
||||
_data.Y = (double)hw_pos.Y;
|
||||
|
||||
// update target (assuming target ICRS coordinates are already set)
|
||||
|
||||
// auto ret = _updateTargetFunc(false, stop_token);
|
||||
|
||||
// update target according to its .pair_kind!
|
||||
auto ret = _updateTargetFunc(stop_token);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,32 +423,35 @@ public:
|
||||
_dataUpdatingRequested->clear();
|
||||
_dataUpdatingStart->clear();
|
||||
|
||||
_updatingFuture = std::async(
|
||||
std::launch::async,
|
||||
[controls, this](std::stop_token stoken) {
|
||||
bool stop_flag = stoken.stop_requested();
|
||||
// controls->logTrace(std::format("stop_requested() = {}", stop_flag));
|
||||
// while (!stoken.stop_requested()) {
|
||||
while (!stop_flag) {
|
||||
_dataUpdatingRequested->wait(false);
|
||||
_updatingFuture =
|
||||
std::async(std::launch::async, &MccTelemetry::updateLoop, this, _internalUpdatingStopSource.get_token());
|
||||
|
||||
stop_flag = stoken.stop_requested();
|
||||
if (!stop_flag) {
|
||||
// if (!stoken.stop_requested()) {
|
||||
*_internalUpdating = true;
|
||||
std::lock_guard lock{*_timeoutMutex};
|
||||
// _updatingFuture = std::async(
|
||||
// std::launch::async,
|
||||
// [controls, this](std::stop_token stoken) {
|
||||
// bool stop_flag = stoken.stop_requested();
|
||||
// // controls->logTrace(std::format("stop_requested() = {}", stop_flag));
|
||||
// // while (!stoken.stop_requested()) {
|
||||
// while (!stop_flag) {
|
||||
// _dataUpdatingRequested->wait(false);
|
||||
|
||||
_dataUpdatingStart->test_and_set();
|
||||
_dataUpdatingStart->notify_all();
|
||||
// stop_flag = stoken.stop_requested();
|
||||
// if (!stop_flag) {
|
||||
// // if (!stoken.stop_requested()) {
|
||||
// *_internalUpdating = true;
|
||||
// std::lock_guard lock{*_timeoutMutex};
|
||||
|
||||
_lastUpdateError = _updateFunc(stoken);
|
||||
// _dataUpdatingStart->test_and_set();
|
||||
// _dataUpdatingStart->notify_all();
|
||||
|
||||
_dataUpdatingStart->clear();
|
||||
_dataUpdatingRequested->clear();
|
||||
}
|
||||
}
|
||||
},
|
||||
_internalUpdatingStopSource.get_token());
|
||||
// _lastUpdateError = _updateFunc(stoken);
|
||||
|
||||
// _dataUpdatingStart->clear();
|
||||
// _dataUpdatingRequested->clear();
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// _internalUpdatingStopSource.get_token());
|
||||
}
|
||||
|
||||
|
||||
@@ -511,11 +530,14 @@ public:
|
||||
_lastUpdateError = MccTelemetryErrorCode::ERROR_UPDATE_LOOP_WAIT;
|
||||
}
|
||||
|
||||
startInternalTelemetryDataUpdating();
|
||||
_updatingFuture = std::async(std::launch::async, &MccTelemetry::updateLoop, this,
|
||||
_internalUpdatingStopSource.get_token());
|
||||
|
||||
|
||||
*_internalUpdating = true;
|
||||
} else {
|
||||
startInternalTelemetryDataUpdating();
|
||||
_updatingFuture = std::async(std::launch::async, &MccTelemetry::updateLoop, this,
|
||||
_internalUpdatingStopSource.get_token());
|
||||
|
||||
*_internalUpdating = true;
|
||||
}
|
||||
@@ -728,6 +750,31 @@ protected:
|
||||
std::unique_ptr<std::timed_mutex> _timeoutMutex{new std::timed_mutex()};
|
||||
|
||||
error_t _lastUpdateError{MccTelemetryErrorCode::ERROR_OK};
|
||||
|
||||
void updateLoop(std::stop_token stoken)
|
||||
{
|
||||
bool stop_flag = stoken.stop_requested();
|
||||
// controls->logTrace(std::format("stop_requested() = {}", stop_flag));
|
||||
while (!stoken.stop_requested()) {
|
||||
// while (!stop_flag) {
|
||||
_dataUpdatingRequested->wait(false);
|
||||
|
||||
// stop_flag = stoken.stop_requested();
|
||||
// if (!stop_flag) {
|
||||
if (!stoken.stop_requested()) {
|
||||
*_internalUpdating = true;
|
||||
std::lock_guard lock{*_timeoutMutex};
|
||||
|
||||
_dataUpdatingStart->test_and_set();
|
||||
_dataUpdatingStart->notify_all();
|
||||
|
||||
_lastUpdateError = _updateFunc(stoken);
|
||||
|
||||
_dataUpdatingStart->clear();
|
||||
_dataUpdatingRequested->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user