This commit is contained in:
2025-11-13 17:56:51 +03:00
parent b3a257fab6
commit 94fb4c6a48
7 changed files with 182 additions and 197 deletions

View File

@@ -53,7 +53,7 @@ struct MccSimpleSlewingModelCategory : public std::error_category {
const char* name() const noexcept
{
return "SIMPLE-TRACKING-MODEL";
return "SIMPLE-SLEWING-MODEL";
}
std::string message(int ec) const
@@ -214,7 +214,9 @@ public:
start_slewing_tp = std::chrono::steady_clock::now();
last_adjust_tp = start_slewing_tp;
while (true) {
// main loop (simply monitors the current position taking into account the prohibited zones, as well as the
// timeout of the entire process)
while (!*_stopSlewing) {
// wait for updated telemetry data
{
std::lock_guard lock{*_currentParamsMutex};
@@ -263,91 +265,115 @@ public:
}
}
hw_err = controls->hardwareGetState(&hw_state);
if (hw_err) {
*_stopSlewing = true;
return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_GETSTATE);
}
t_err = controls->targetToMountDist(&dist);
if (t_err) {
*_stopSlewing = true;
return mcc_deduce_error_code(t_err, MccSimpleSlewingModelErrorCode::ERROR_DIST_TELEMETRY);
}
if (*_stopSlewing) {
return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
}
{
std::lock_guard lock{*_currentParamsMutex};
// if (adjust_mode && !_currentParams.slewAndStop) {
if (adjust_mode && !slew_and_stop) {
// do not allow mount speed fall below sideral
if constexpr (mccIsEquatorialMount(CONTROLS_T::mountType)) {
// turn on sideral rate only if the current position point catches up with the target
if ((tdata.target.HA - tdata.HA) <= 0.0 && tdata.speedX < slewing_params_t::sideralRate) {
hw_state.X = (double)tdata.target.X;
hw_state.Y = (double)tdata.target.Y;
hw_state.speedX = slewing_params_t::sideralRate;
hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_TRACKING;
hw_err = controls->hardwareSetState(hw_state);
if (hw_err) {
*_stopSlewing = true;
return mcc_deduce_error_code(hw_err,
MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
}
}
} else if constexpr (mccIsAltAzMount(CONTROLS_T::mountType)) {
} else {
static_assert(false, "UNKNOWN MOUNT TYPE!!");
}
if (slew_and_stop) {
if (hw_state.moving_state == CONTROLS_T::hardware_moving_state_t::HW_MOVE_STOPPED) {
break;
}
} else { // just wait for mount to be stopped
t_err = controls->targetToMountDist(&dist);
if (t_err) {
*_stopSlewing = true;
return mcc_deduce_error_code(t_err, MccSimpleSlewingModelErrorCode::ERROR_DIST_TELEMETRY);
}
if (dist <= _currentParams.slewToleranceRadius) { // stop slewing and exit from cycle
if (hw_state.moving_state ==
CONTROLS_T::hardware_moving_state_t::HW_MOVE_STOPPED) { // mount was stopped
*_stopSlewing = true;
break;
}
break;
}
if (dist <= _currentParams.adjustCoordDiff) { // adjust mount pointing
auto now = std::chrono::steady_clock::now();
if ((now - last_adjust_tp) < _currentParams.adjustCycleInterval) {
continue;
}
hw_state.X = (double)tdata.target.X;
hw_state.Y = (double)tdata.target.Y;
// resend new position since target coordinates are changed in time
hw_state.X = (double)tdata.target.X;
hw_state.Y = (double)tdata.target.Y;
hw_state.speedX = _currentParams.adjustRateX;
hw_state.speedY = _currentParams.adjustRateY;
hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_ADJUSTING;
hw_err = controls->hardwareSetState(hw_state);
if (hw_err) {
*_stopSlewing = true;
return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
}
last_adjust_tp = now;
adjust_mode = true;
} else {
adjust_mode = false;
hw_err = controls->hardwareSetState(hw_state);
if (hw_err) {
*_stopSlewing = true;
return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
}
}
if (*_stopSlewing) {
return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
}
// if (*_stopSlewing) {
// return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
// }
// {
// std::lock_guard lock{*_currentParamsMutex};
// // if (adjust_mode && !_currentParams.slewAndStop) {
// if (adjust_mode && !slew_and_stop) {
// // do not allow mount speed fall below sideral
// if constexpr (mccIsEquatorialMount(CONTROLS_T::mountType)) {
// // turn on sideral rate only if the current position point catches up with the target
// if ((tdata.target.HA - tdata.HA) <= 0.0 && tdata.speedX < slewing_params_t::sideralRate)
// {
// hw_state.X = (double)tdata.target.X;
// hw_state.Y = (double)tdata.target.Y;
// hw_state.speedX = slewing_params_t::sideralRate;
// hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_TRACKING;
// hw_err = controls->hardwareSetState(hw_state);
// if (hw_err) {
// *_stopSlewing = true;
// return mcc_deduce_error_code(hw_err,
// MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
// }
// }
// } else if constexpr (mccIsAltAzMount(CONTROLS_T::mountType)) {
// } else {
// static_assert(false, "UNKNOWN MOUNT TYPE!!");
// }
// }
// if (dist <= _currentParams.slewToleranceRadius) { // stop slewing and exit from cycle
// if (hw_state.moving_state ==
// CONTROLS_T::hardware_moving_state_t::HW_MOVE_STOPPED) { // mount was stopped
// *_stopSlewing = true;
// break;
// }
// }
// if (dist <= _currentParams.adjustCoordDiff) { // adjust mount pointing
// auto now = std::chrono::steady_clock::now();
// if ((now - last_adjust_tp) < _currentParams.adjustCycleInterval) {
// continue;
// }
// hw_state.X = (double)tdata.target.X;
// hw_state.Y = (double)tdata.target.Y;
// hw_state.speedX = _currentParams.adjustRateX;
// hw_state.speedY = _currentParams.adjustRateY;
// hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_ADJUSTING;
// hw_err = controls->hardwareSetState(hw_state);
// if (hw_err) {
// *_stopSlewing = true;
// return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
// }
// last_adjust_tp = now;
// adjust_mode = true;
// } else {
// adjust_mode = false;
// }
// }
// if (*_stopSlewing) {
// return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
// }
}
return MccSimpleSlewingModelErrorCode::ERROR_OK;