Compare commits
2 Commits
1d49077d7b
...
2ff2c24e52
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ff2c24e52 | |||
| c71cf98dd9 |
@ -222,8 +222,8 @@ concept mcc_mount_hardware_c = !std::copyable<T> && std::movable<T> && requires(
|
||||
[]() {
|
||||
// hardware is in stop state (no any moving)
|
||||
static constexpr auto v1 = T::hw_state_t::HW_STATE_STOP;
|
||||
// hardware is in slew state (move to given celestial point)
|
||||
|
||||
// hardware is in slew state (move to given celestial point)
|
||||
static constexpr auto v2 = T::hw_state_t::HW_STATE_SLEW;
|
||||
|
||||
// hardware is in track state (track given celestial point)
|
||||
@ -234,7 +234,7 @@ concept mcc_mount_hardware_c = !std::copyable<T> && std::movable<T> && requires(
|
||||
|
||||
// a class that contains at least time of measurement, coordinates for x,y axes and its moving rates
|
||||
requires requires(typename T::axes_pos_t pos) {
|
||||
requires std::same_as<decltype(pos.time_point), typename T::time_point_t>; // time point of measurement
|
||||
requires std::same_as<decltype(pos.time_point), typename T::time_point_t>; // time point
|
||||
|
||||
requires std::same_as<decltype(pos.x), typename T::coord_t>; // co-longitude coordinate
|
||||
requires std::same_as<decltype(pos.y), typename T::coord_t>; // co-latitude coordinate
|
||||
|
||||
@ -96,9 +96,10 @@ inline std::error_code make_error_code(MccSimpleSlewModelErrorCode ec)
|
||||
|
||||
|
||||
/*
|
||||
* WARNING: it is assumed that coordinates are in radians!
|
||||
* but this fact is only used if slew coordinate pair are given as
|
||||
* [azimuth, zenithal distance] (see sources code below)
|
||||
* It is very simple slew model!
|
||||
* There are no any complex routes (bypass of prohibited),
|
||||
* just a strait path from current point to target
|
||||
*
|
||||
*/
|
||||
|
||||
template <traits::mcc_logger_c LoggerT = MccNullLogger>
|
||||
@ -113,17 +114,32 @@ public:
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
static constexpr size_t defaultAdjustSuccessCycles = 5;
|
||||
|
||||
struct slew_point_t : MccCelestialPoint {
|
||||
// target-mount coordinate difference to start adjusting slewing (in radians)
|
||||
// target-mount coordinate difference to start adjusting of slewing (in radians)
|
||||
coord_t adjustCoordDiff{(double)MccAngle{10.0_degs}};
|
||||
|
||||
// coordinates difference to stop slewing (in radians)
|
||||
coord_t slewPrecision{(double)MccAngle{5.0_arcsecs}};
|
||||
coord_t slewToleranceRadius{(double)MccAngle{5.0_arcsecs}};
|
||||
|
||||
// coordinates polling interval in seconds
|
||||
std::chrono::duration<double> coordPollingInterval{0.1};
|
||||
bool stopAfterSlew{false};
|
||||
std::chrono::seconds timeout{3600};
|
||||
std::chrono::seconds slewTimeout{3600};
|
||||
|
||||
coord_t slewXRate{0.0}; // maximal slewing rate (0 means move with maximal allowed rate)
|
||||
coord_t slewYRate{0.0}; // maximal slewing rate (0 means move with maximal allowed rate)
|
||||
|
||||
coord_t adjustXRate{
|
||||
(double)MccAngle{5.0_arcmins}}; // maximal adjusting rate (a rate at the final slewing stage)
|
||||
coord_t adjustYRate{
|
||||
(double)MccAngle{5.0_arcmins}}; // maximal adjusting rate (a rate at the final slewing stage)
|
||||
|
||||
// number of consecutive measurements within slewPrecision radius to stop adjusting of slewing
|
||||
size_t withinToleranceCycleNumber{10};
|
||||
// maximal allowed number of adjusting cycles
|
||||
size_t maxAdjustingCycleNumber{100};
|
||||
};
|
||||
|
||||
|
||||
@ -197,11 +213,15 @@ protected:
|
||||
|
||||
coord_t ra_icrs, dec_icrs;
|
||||
|
||||
if (slew_point.adjustSuccessCycles == 0) {
|
||||
slew_point.adjustSuccessCycles = 5;
|
||||
}
|
||||
|
||||
// first, compute encoder coordinates
|
||||
ax_pos.time_point = astrom_engine_t::timePointNow();
|
||||
t_err = telemetry.toHardware(slew_point, ax_pos.time_point, ax_pos.x, ax_pos.y);
|
||||
if (!t_err) {
|
||||
// setup target sky point
|
||||
// SETUP TARGET SKY POINT
|
||||
t_err = telemetry.setTarget(slew_point);
|
||||
}
|
||||
|
||||
@ -217,16 +237,19 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// move mount (it is assumed this is asynchronous operation!!!)
|
||||
typename hardware_t::error_t err = hardware->setPos(ax_pos);
|
||||
// start moving the mount (it is assumed this is asynchronous operation!!!)
|
||||
ax_pos.xrate = slew_point.slewXRate;
|
||||
ax_pos.yrate = slew_point.slewYRate;
|
||||
typename hardware_t::error_t hw_err = hardware->setPos(ax_pos);
|
||||
|
||||
if (err) {
|
||||
if constexpr (std::same_as<decltype(err), error_t>) {
|
||||
logError(std::format("An hardware error occured: code = {} ({})", err.value(), err.message()));
|
||||
return err;
|
||||
if (hw_err) {
|
||||
if constexpr (std::same_as<decltype(hw_err), error_t>) {
|
||||
logError(
|
||||
std::format("An hardware error occured: code = {} ({})", hw_err.value(), hw_err.message()));
|
||||
return hw_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(err)>) {
|
||||
logError(std::format("An hardware error occured: code = {}", err));
|
||||
if constexpr (traits::mcc_formattable<decltype(hw_err)>) {
|
||||
logError(std::format("An hardware error occured: code = {}", hw_err));
|
||||
}
|
||||
return MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS;
|
||||
}
|
||||
@ -234,36 +257,23 @@ protected:
|
||||
|
||||
|
||||
typename hardware_t::axes_pos_t::time_point_t prev_time_point{};
|
||||
// typename telemetry_t::mount_telemetry_data_t::time_point_t prev_time_point{};
|
||||
|
||||
auto adj_ax_pos = ax_pos; // to prevent possible effects in hardware 'setPos' method
|
||||
adj_ax_pos.xrate = slew_point.adjustXRate;
|
||||
adj_ax_pos.yrate = slew_point.adjustYRate;
|
||||
|
||||
typename telemetry_t::mount_telemetry_data_t::coord_t xr, yr, coord_diff2,
|
||||
adjRad2 = slew_point.adjustCoordDiff * slew_point.adjustCoordDiff;
|
||||
adj_rad2 = slew_point.adjustCoordDiff * slew_point.adjustCoordDiff,
|
||||
tol_rad2 = slew_point.slewToleranceRadius * slew_point.slewToleranceRadius;
|
||||
|
||||
std::array<bool, Nzones> in_zone_flag;
|
||||
auto start_poll_tm = std::chrono::steady_clock::now();
|
||||
|
||||
size_t i_adj_cycle = 0;
|
||||
size_t i_in_tol_cycle = 0;
|
||||
bool in_adj_mode = false;
|
||||
|
||||
auto iter = telemetry.addCallbackFunc([slew_point = std::move(slew_point), this](auto t_data) {
|
||||
// check prohibited zones
|
||||
|
||||
std::array<bool, Nzones> in_zone_flag;
|
||||
auto t_err = mccCheckInZonePZTuple(*telemetry, p_mount_controls->prohibitedZones, in_zone_flag);
|
||||
|
||||
if (t_err) {
|
||||
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||
logError(
|
||||
std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
||||
return t_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||
}
|
||||
return MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
typename telemetry_t::mount_telemetry_data_t::coord_t xr, yr, coord_diff2,
|
||||
adjRad2 = slew_point.adjustCoordDiff * slew_point.adjustCoordDiff;
|
||||
|
||||
auto coord_diff_func = [](auto& t_data) {
|
||||
typename telemetry_t::mount_telemetry_data_t::coord_t xr, yr;
|
||||
if constexpr (mccIsEquatorialMount(pec_t::mountType)) {
|
||||
xr = t_data.tagRA - t_data.mntHA;
|
||||
yr = t_data.tagDEC - t_data.mntDEC;
|
||||
@ -274,11 +284,76 @@ protected:
|
||||
static_assert(false, "UNSUPPORTED MOUNT TYPE!");
|
||||
}
|
||||
|
||||
coord_diff2 = xr * xr + yr * yr;
|
||||
return xr * xr + yr * yr;
|
||||
};
|
||||
|
||||
if (coord_diff2 < adjRad2) { // switch to adjusting mode
|
||||
auto cycle_func = [&](auto t_data) mutable {
|
||||
// check for prohibited zones
|
||||
auto t_err = mccCheckInZonePZTuple(*telemetry, p_mount_controls->prohibitedZones, in_zone_flag);
|
||||
|
||||
if (t_err) {
|
||||
if constexpr (std::same_as<decltype(t_err), error_t>) {
|
||||
logError(
|
||||
std::format("An telemetry error occured: code = {} ({})", t_err.value(), t_err.message()));
|
||||
res_err = t_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(t_err)>) {
|
||||
logError(std::format("An telemetry error occured: code = {}", t_err));
|
||||
}
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_TELEMETRY_DATA;
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// t_data was updated in caller!!!
|
||||
coord_diff2 = coord_diff_func(t_data);
|
||||
|
||||
if (coord_diff2 < adj_rad2) { // adjusting mode
|
||||
in_adj_mode = true;
|
||||
hw_err = hardware->setPos(adj_ax_pos);
|
||||
|
||||
if (!hw_err) {
|
||||
++i_adj_cycle;
|
||||
if (coord_diff2 < tol_rad2) {
|
||||
++i_in_tol_cycle;
|
||||
|
||||
if (i_in_tol_cycle == slew_point.withinToleranceCycleNumber) {
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_OK;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (i_adj_cycle == slew_point.maxAdjustingCycleNumber) {
|
||||
// res_err = max iter namber was exceeded
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if constexpr (std::same_as<decltype(hw_err), error_t>) {
|
||||
logError(std::format("An hardware error occured: code = {} ({})", hw_err.value(),
|
||||
hw_err.message()));
|
||||
res_err = hw_err;
|
||||
} else {
|
||||
if constexpr (traits::mcc_formattable<decltype(hw_err)>) {
|
||||
logError(std::format("An hardware error occured: code = {}", hw_err));
|
||||
}
|
||||
res_err = MccSimpleSlewModelErrorCode::ERROR_HARDWARE_SETPOS;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (in_adj_mode) { // ?!!!!!!!!!!!!!
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
auto start_poll_tm = std::chrono::steady_clock::now();
|
||||
|
||||
// NOTE: TARGET COORDINATES WILL BE UPDATED FOR CURRENT TIME-POINT IN TELEMETRY-CLASS!!!
|
||||
|
||||
auto iter = telemetry.addCallbackFunc(cycle_func);
|
||||
|
||||
|
||||
while (true) {
|
||||
@ -327,7 +402,7 @@ protected:
|
||||
|
||||
coord_diff2 = xr * xr + yr * yr;
|
||||
|
||||
if (coord_diff2 < adjRad2) { // switch to adjusting mode
|
||||
if (coord_diff2 < adj_rad2) { // switch to adjusting mode
|
||||
}
|
||||
|
||||
// if (prev_time_point == t_data.time_point) {
|
||||
@ -367,7 +442,7 @@ protected:
|
||||
|
||||
prev_time_point = t_data.time_point;
|
||||
|
||||
if ((std::chrono::steady_clock::now() - start_poll_tm) > slew_point.timeout) {
|
||||
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