Compare commits
No commits in common. "ca9dcdfa68bf67f0f12ee7600d2cb93d20268b9b" and "a96682bc12526e1676757f344a6991d7d3e1462a" have entirely different histories.
ca9dcdfa68
...
a96682bc12
@ -60,7 +60,10 @@ struct MccNullLogger {
|
||||
typedef int loglevel_t;
|
||||
|
||||
void setLogLevel(loglevel_t){};
|
||||
loglevel_t getLogLevel() const { return 0; };
|
||||
loglevel_t getLogLevel() const
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
void logMessage(loglevel_t, const std::string&) {};
|
||||
void logError(const std::string&) {};
|
||||
@ -381,7 +384,6 @@ concept mcc_slew_model_c = requires(T t) {
|
||||
|
||||
// { t.slew(std::declval<typename T::slew_params_t>()) } -> std::same_as<typename T::error_t>;
|
||||
{ t.slew(std::declval<typename T::slew_point_t>()) } -> std::same_as<typename T::error_t>;
|
||||
{ t.stop() } -> std::same_as<typename T::error_t>;
|
||||
};
|
||||
|
||||
|
||||
@ -392,7 +394,6 @@ concept mcc_guiding_model_c = requires(T t) {
|
||||
|
||||
// start process of guiding
|
||||
{ t.guiding(std::declval<typename T::guiding_point_t>()) } -> std::same_as<typename T::error_t>;
|
||||
{ t.stop() } -> std::same_as<typename T::error_t>;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
enum class MccMountTelemetryErrorCode : int { ERROR_OK, ERROR_HARDWARE, ERROR_DATA_TIMEOUT };
|
||||
enum class MccMountTelemetryErrorCode : int { ERROR_OK, ERROR_HARDWARE };
|
||||
|
||||
/* error category definition */
|
||||
|
||||
@ -20,7 +20,10 @@ enum class MccMountTelemetryErrorCode : int { ERROR_OK, ERROR_HARDWARE, ERROR_DA
|
||||
struct MccMountTelemetryCategory : public std::error_category {
|
||||
MccMountTelemetryCategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept { return "ADC_GENERIC_DEVICE"; }
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "ADC_GENERIC_DEVICE";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
@ -31,8 +34,6 @@ struct MccMountTelemetryCategory : public std::error_category {
|
||||
return "OK";
|
||||
case MccMountTelemetryErrorCode::ERROR_HARDWARE:
|
||||
return "hardware request failed";
|
||||
case MccMountTelemetryErrorCode::ERROR_DATA_TIMEOUT:
|
||||
return "an timeout occured while waiting for new data";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
@ -104,7 +105,7 @@ struct MccMountTelemetryData {
|
||||
coord_t mntRateX, mntRateY;
|
||||
|
||||
// current refraction coefficients
|
||||
typename ASTROM_ENGINE_T::refract_result_t currRefrCoeffs;
|
||||
typename PEC_T::pec_result_t currRefrCoeffs;
|
||||
|
||||
// current refraction correction (for mntALT)
|
||||
coord_t currRefr;
|
||||
@ -140,6 +141,9 @@ public:
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
typedef std::function<void(mount_telemetry_data_t)> update_callback_func_t;
|
||||
typedef std::list<update_callback_func_t> update_callback_container_t;
|
||||
|
||||
MccMountTelemetry(astrom_engine_t& astrom_engine, pec_t& pec, hardware_t& hardware)
|
||||
: base_t(astrom_engine, pec), _hardware(hardware)
|
||||
{
|
||||
@ -262,37 +266,49 @@ public:
|
||||
|
||||
_data = std::move(current_data);
|
||||
|
||||
// notify all threads for new telemetry data
|
||||
_updateCondVar.notify_all();
|
||||
std::lock_guard cl_lock{_callbackMutex};
|
||||
|
||||
// callbacks will be invoked with its own copy of telemetry data!
|
||||
for (auto& func : _callbackFuncs) {
|
||||
std::thread t([this, &func] {
|
||||
auto d = _data;
|
||||
func(std::move(d));
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
|
||||
return MccMountTelemetryErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
update_callback_container_t::iterator addCallbackFunc(update_callback_func_t func)
|
||||
{
|
||||
std::lock_guard lock{_callbackMutex};
|
||||
|
||||
return _callbackFuncs.emplace_back(std::move(func));
|
||||
}
|
||||
|
||||
void delCallbackFunc(update_callback_container_t::iterator iter)
|
||||
{
|
||||
std::lock_guard lock{_callbackMutex};
|
||||
|
||||
if (_callbackFuncs.size()) {
|
||||
_callbackFuncs.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
void clearCallbackFuncs()
|
||||
{
|
||||
std::lock_guard lock{_callbackMutex};
|
||||
|
||||
_callbackFuncs.clear();
|
||||
}
|
||||
|
||||
error_t data(mount_telemetry_data_t& data)
|
||||
{
|
||||
std::lock_guard lock{_updateMutex};
|
||||
|
||||
data = _data;
|
||||
|
||||
return MccMountTelemetryErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
// wait until data is updated or given timeout occurs
|
||||
template <traits::mcc_time_duration_c DT>
|
||||
error_t waitForUpdatedData(mount_telemetry_data_t& data, const DT& timeout)
|
||||
{
|
||||
auto timeout_tp = std::chrono::steady_clock::now() + timeout;
|
||||
|
||||
std::unique_lock lk(_updateMutex);
|
||||
|
||||
auto res = _updateCondVar.wait_until(
|
||||
lk, timeout_tp, [last_time_point = _data.time_point, this]() { return last_time_point < _data.timepoint; });
|
||||
if (res == std::cv_status::timeout) {
|
||||
return MccMountTelemetryErrorCode::ERROR_DATA_TIMEOUT;
|
||||
}
|
||||
|
||||
data = _data;
|
||||
data = std::move(_data);
|
||||
|
||||
return MccMountTelemetryErrorCode::ERROR_OK;
|
||||
}
|
||||
@ -300,9 +316,10 @@ public:
|
||||
protected:
|
||||
mount_telemetry_data_t _data{};
|
||||
hardware_t& _hardware;
|
||||
update_callback_container_t _callbackFuncs{};
|
||||
|
||||
std::mutex _updateMutex;
|
||||
std::condition_variable _updateCondVar;
|
||||
std::mutex _callbackMutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -24,8 +24,6 @@ enum class MccSimpleSlewModelErrorCode : int {
|
||||
ERROR_PEC_COMP,
|
||||
ERROR_HARDWARE_SETPOS,
|
||||
ERROR_HARDWARE_GETPOS,
|
||||
ERROR_SLEW_STOPPED,
|
||||
ERROR_SLEW_ADJ_MAXITER,
|
||||
ERROR_SLEW_TIMEOUT
|
||||
};
|
||||
|
||||
@ -52,7 +50,10 @@ namespace mcc
|
||||
struct MccSimpleSlewModelCategory : public std::error_category {
|
||||
MccSimpleSlewModelCategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept { return "ADC_GENERIC_DEVICE"; }
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "ADC_GENERIC_DEVICE";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
@ -75,12 +76,6 @@ struct MccSimpleSlewModelCategory : public std::error_category {
|
||||
return "slew model: cannot set position";
|
||||
case MccSimpleSlewModelErrorCode::ERROR_HARDWARE_GETPOS:
|
||||
return "slew model: cannot get position";
|
||||
case MccSimpleSlewModelErrorCode::ERROR_SLEW_STOPPED:
|
||||
return "slew model: stopped";
|
||||
case MccSimpleSlewModelErrorCode::ERROR_SLEW_ADJ_MAXITER:
|
||||
return "slew model: max number of adjusting iteration was exceeded";
|
||||
case MccSimpleSlewModelErrorCode::ERROR_SLEW_TIMEOUT:
|
||||
return "slew model: timeout occured while slewing";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
@ -172,22 +167,13 @@ public:
|
||||
|
||||
error_t slew(slew_point_t pars)
|
||||
{
|
||||
_stopRequested = false;
|
||||
error_t res_err = _slewFunc(std::move(pars));
|
||||
|
||||
return res_err;
|
||||
}
|
||||
|
||||
error_t stop()
|
||||
{
|
||||
_stopRequested = true;
|
||||
return MccSimpleSlewModelErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::atomic_bool _stopRequested{false};
|
||||
std::function<error_t(const slew_point_t&)> _slewFunc{};
|
||||
std::mutex _updateMutex{};
|
||||
|
||||
void init(auto& mount_controls)
|
||||
{
|
||||
@ -302,10 +288,6 @@ protected:
|
||||
};
|
||||
|
||||
auto cycle_func = [&](auto t_data) mutable {
|
||||
if (_stopRequested) {
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_SLEW_STOPPED;
|
||||
}
|
||||
|
||||
// check for prohibited zones
|
||||
auto t_err = mccCheckInZonePZTuple(*telemetry, p_mount_controls->prohibitedZones, in_zone_flag);
|
||||
|
||||
@ -326,10 +308,6 @@ protected:
|
||||
// t_data was updated in caller!!!
|
||||
coord_diff2 = coord_diff_func(t_data);
|
||||
|
||||
if (_stopRequested) {
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_SLEW_STOPPED;
|
||||
}
|
||||
|
||||
if (coord_diff2 < adj_rad2) { // adjusting mode
|
||||
in_adj_mode = true;
|
||||
hw_err = hardware->setPos(adj_ax_pos);
|
||||
@ -346,7 +324,7 @@ protected:
|
||||
}
|
||||
|
||||
if (i_adj_cycle == slew_point.maxAdjustingCycleNumber) {
|
||||
// res_err = max iter number was exceeded
|
||||
// res_err = max iter namber was exceeded
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -372,35 +350,13 @@ protected:
|
||||
|
||||
|
||||
auto start_poll_tm = std::chrono::steady_clock::now();
|
||||
// auto timeout_point = std::chrono::steady_clock::now() + slew_point.slewTimeout;
|
||||
auto wait_timeout = slew_point.slewTimeout / 5;
|
||||
if (wait_timeout < std::chrono::seconds(1)) {
|
||||
wait_timeout = std::chrono::seconds(1);
|
||||
}
|
||||
|
||||
// NOTE: TARGET COORDINATES WILL BE UPDATED FOR CURRENT TIME-POINT IN TELEMETRY-CLASS!!!
|
||||
|
||||
auto iter = telemetry.addCallbackFunc(cycle_func);
|
||||
|
||||
|
||||
while (true) {
|
||||
t_err = telemetry.waitForUpdatedData(t_data, wait_timeout);
|
||||
|
||||
if (t_err) {
|
||||
std::string err_str = "An error occured while waiting for updated telemetry";
|
||||
logError(std::format("An error occured while waiting for updated telemetry: {}", t_err));
|
||||
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||
std::format_to(std::back_inserter(err_str), ": code = {} ({})", t_err.value(), t_err.message());
|
||||
logError(err_str);
|
||||
return t_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||
std::format_to(std::back_inserter(err_str), ": code = {}", t_err.value());
|
||||
}
|
||||
logError(err_str);
|
||||
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
cycle_func(t_data);
|
||||
|
||||
if ((std::chrono::steady_clock::now() - start_poll_tm) > slew_point.slewTimeout) {
|
||||
logError("Waiting time for completion of slewing expired!");
|
||||
return MccSimpleSlewModelErrorCode::ERROR_SLEW_TIMEOUT;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user