Skip to content

Commit 0b6e3ac

Browse files
committed
Added PassCalculator.
1 parent 1813938 commit 0b6e3ac

File tree

3 files changed

+288
-5
lines changed

3 files changed

+288
-5
lines changed

LibDegorasSLR/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ source_group("Alias Files" FILES ${ALIAS})
112112
macro_setup_shared_lib("${LIB_NAME}" "${LIB_INCLUDES_DIR}" "${LIB_VER}"
113113
${SOURCES1} ${SOURCES2} ${HEADERS} ${TEMPLTS} ${INL} ${ALIAS})
114114

115-
target_sources(LibDegorasSLR
116-
PRIVATE
117-
includes/LibDegorasSLR/TrackingMount/predictors/data/mount_tracking_slr.h
118-
)
119-
120115
# Link with LibNovasCPP.
121116
macro_link_libnovascpp_default(${LIB_NAME})
122117

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/***********************************************************************************************************************
2+
* LibDegorasSLR (Degoras Project SLR Library). *
3+
* *
4+
* A modern and efficient C++ base library for Satellite Laser Ranging (SLR) software and real-time hardware *
5+
* related developments. Developed as a free software under the context of Degoras Project for the Spanish Navy *
6+
* Observatory SLR station (SFEL) in San Fernando and, of course, for any other station that wants to use it! *
7+
* *
8+
* Copyright (C) 2024 Degoras Project Team *
9+
* < Ángel Vera Herrera, avera@roa.es - angeldelaveracruz@gmail.com > *
10+
* < Jesús Relinque Madroñal > *
11+
* *
12+
* This file is part of LibDegorasSLR. *
13+
* *
14+
* Licensed under the European Union Public License (EUPL), Version 1.2 or subsequent versions of the EUPL license *
15+
* as soon they will be approved by the European Commission (IDABC). *
16+
* *
17+
* This project is free software: you can redistribute it and/or modify it under the terms of the EUPL license as *
18+
* published by the IDABC, either Version 1.2 or, at your option, any later version. *
19+
* *
20+
* This project is distributed in the hope that it will be useful. Unless required by applicable law or agreed to in *
21+
* writing, it is distributed on an "AS IS" basis, WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND; without even the *
22+
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the EUPL license to check specific *
23+
* language governing permissions and limitations and more details. *
24+
* *
25+
* You should use this project in compliance with the EUPL license. You should have received a copy of the license *
26+
* along with this project. If not, see the license at < https://eupl.eu/ >. *
27+
**********************************************************************************************************************/
28+
29+
/** ********************************************************************************************************************
30+
* @file pass_calculator.h
31+
* @author Degoras Project Team
32+
* @brief This file contains the declaration of the PassCalculator class.
33+
* @copyright EUPL License
34+
***********************************************************************************************************************/
35+
36+
// =====================================================================================================================
37+
#pragma once
38+
// =====================================================================================================================
39+
40+
// C++ INCLUDES
41+
// =====================================================================================================================
42+
#include <vector>
43+
// =====================================================================================================================
44+
45+
// LIBRARY INCLUDES
46+
// =====================================================================================================================
47+
#include "LibDegorasSLR/libdegorasslr_global.h"
48+
#include "LibDegorasSLR/UtilitiesSLR/predictors/predictor_slr_base.h"
49+
// =====================================================================================================================
50+
51+
// DPSLR NAMESPACES
52+
// =====================================================================================================================
53+
namespace dpslr{
54+
namespace slr{
55+
namespace utils{
56+
// =====================================================================================================================
57+
58+
/**
59+
* @brief The Pass struct contains data about a space object pass
60+
*/
61+
struct LIBDPSLR_EXPORT Pass
62+
{
63+
struct LIBDPSLR_EXPORT Step
64+
{
65+
timing::dates::MJDateTime mjd; ///< Modified julian date of step.
66+
math::units::Degrees azim; ///< Azimuth of the step in degrees.
67+
math::units::Degrees elev; ///< Elevation of the step in degrees.
68+
long double azim_rate; ///< Azimuth rate of step in deg/s
69+
long double elev_rate; ///< Elevation rate of step in deg/s
70+
};
71+
72+
math::units::Seconds interval; ///< Interval between two steps in seconds
73+
math::units::Degrees min_elev; ///< Minimum elevation for pass.
74+
std::vector<Step> steps; ///< Steps of the pass
75+
};
76+
77+
/**
78+
* @brief This class implements a utility that calculates passes using a SLR predictor.
79+
*/
80+
class LIBDPSLR_EXPORT PassCalculator
81+
{
82+
public:
83+
84+
enum ResultCode
85+
{
86+
NOT_ERROR,
87+
PREDICTOR_NOT_VALID,
88+
INTERVAL_OUTSIDE_OF_PREDICTOR,
89+
SOME_PREDICTIONS_NOT_VALID,
90+
OTHER_ERROR
91+
92+
};
93+
94+
/**
95+
* @brief PassCalculator constructs the pass calculator.
96+
* @param predictor the predictor used to calculate the passes.
97+
* @param min_elev minimum elevation of the pass in degrees. By default is 0, i.e., above the horizon.
98+
* @param interval interval between two steps of the pass in seconds. By default is 1 second.
99+
*/
100+
PassCalculator(predictors::PredictorSlrPtr predictor, math::units::Degrees min_elev = 0,
101+
math::units::Seconds interval = 1.L);
102+
103+
104+
/**
105+
* @brief Setter for minimum elevation.
106+
* @param min_elev the minimum elevation in degrees.
107+
*/
108+
void setMinElev(math::units::Degrees min_elev);
109+
/**
110+
* @brief Getter for minimum elevation.
111+
* @return the minimum elevation in degrees.
112+
*/
113+
math::units::Degrees minElev() const;
114+
/**
115+
* @brief Setter for interval.
116+
* @param interval the interval for interpolation in seconds.
117+
*/
118+
void setInterval(math::units::Seconds interval);
119+
/**
120+
* @brief Getter for interval.
121+
* @return the interval for interpolation in seconds.
122+
*/
123+
math::units::Seconds interval() const;
124+
125+
/**
126+
* @brief Get passes within the given interval of time.
127+
* @param mjd_start the modified julian date of interval start.
128+
* @param mjd_end the modified julian date of interval end.
129+
* @param passes the returned passes.
130+
* @return The result of the operation.
131+
*/
132+
ResultCode getPasses(const timing::dates::MJDateTime &mjd_start,
133+
const timing::dates::MJDateTime &mjd_end,
134+
std::vector<Pass> &passes) const;
135+
136+
137+
private:
138+
math::units::Degrees min_elev_;
139+
math::units::Seconds interval_;
140+
predictors::PredictorSlrPtr predictor_;
141+
};
142+
143+
144+
}}} // END NAMESPACES.
145+
// =====================================================================================================================
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/***********************************************************************************************************************
2+
* Copyright 2023 Degoras Project Team
3+
*
4+
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the
5+
* European Commission - subsequent versions of the EUPL (the "Licence");
6+
*
7+
* You may not use this work except in compliance with the Licence.
8+
* You may obtain a copy of the Licence at:
9+
*
10+
* https://joinup.ec.europa.eu/software/page/eupl
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on
13+
* an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licence for the
14+
* specific language governing permissions and limitations under the Licence.
15+
**********************************************************************************************************************/
16+
17+
/** ********************************************************************************************************************
18+
* @file pass_calculator.cpp
19+
* @see pass_calculator.h
20+
* @author DEGORAS PROJECT TEAM
21+
* @copyright EUPL License
22+
***********************************************************************************************************************/
23+
24+
// C++ INCLUDES
25+
// =====================================================================================================================
26+
// =====================================================================================================================
27+
28+
// LIBRARY INCLUDES
29+
// =====================================================================================================================
30+
#include "LibDegorasSLR/UtilitiesSLR/utils/pass_calculator.h"
31+
// =====================================================================================================================
32+
33+
// DPSLR NAMESPACES
34+
// =====================================================================================================================
35+
namespace dpslr{
36+
namespace slr{
37+
namespace utils{
38+
// =====================================================================================================================
39+
40+
PassCalculator::PassCalculator(predictors::PredictorSlrPtr predictor, math::units::Degrees min_elev,
41+
math::units::Seconds interval) :
42+
min_elev_(min_elev),
43+
interval_(interval),
44+
predictor_(std::move(predictor))
45+
{
46+
47+
}
48+
49+
void PassCalculator::setMinElev(math::units::Degrees min_elev)
50+
{
51+
this->min_elev_ = min_elev;
52+
}
53+
54+
math::units::Degrees PassCalculator::minElev() const
55+
{
56+
return this->min_elev_;
57+
}
58+
59+
void PassCalculator::setInterval(math::units::Seconds interval)
60+
{
61+
this->interval_ = interval;
62+
}
63+
64+
math::units::Seconds PassCalculator::interval() const
65+
{
66+
return this->interval_;
67+
}
68+
69+
PassCalculator::ResultCode PassCalculator::getPasses(const timing::dates::MJDateTime &mjd_start,
70+
const timing::dates::MJDateTime &mjd_end,
71+
std::vector<Pass> &passes) const
72+
{
73+
// Clear passes vector
74+
passes.clear();
75+
76+
// Check if predictor is valid and has data for the time window.
77+
if (this->predictor_->isReady())
78+
return ResultCode::PREDICTOR_NOT_VALID;
79+
80+
if (this->predictor_->isInsideTimeWindow(mjd_start, mjd_end))
81+
return ResultCode::INTERVAL_OUTSIDE_OF_PREDICTOR;
82+
83+
// Calculate all the predictions.
84+
auto predictions = this->predictor_->predict(mjd_start, mjd_end, this->interval_ * 1000.L);
85+
86+
// Auxiliary variables.
87+
bool pass_started = false;
88+
Pass current_pass;
89+
current_pass.interval = this->interval_;
90+
current_pass.min_elev = this->min_elev_;
91+
Pass::Step current_step;
92+
93+
// Check the predictions to get all the passes within the time window.
94+
for (const auto &pred : predictions)
95+
{
96+
if (0 != pred.error)
97+
{
98+
passes.clear();
99+
return PassCalculator::ResultCode::SOME_PREDICTIONS_NOT_VALID;
100+
}
101+
102+
if (pred.instant_data->altaz_coord.el >= this->min_elev_)
103+
{
104+
if (!pass_started)
105+
{
106+
pass_started = true;
107+
current_step.azim_rate = 0;
108+
current_step.elev_rate = 0;
109+
}
110+
else
111+
{
112+
current_step.azim_rate = (pred.instant_data->altaz_coord.az - current_pass.steps.back().azim) /
113+
this->interval_;
114+
current_step.elev_rate = (pred.instant_data->altaz_coord.el - current_pass.steps.back().elev) /
115+
this->interval_;
116+
}
117+
current_step.mjd = pred.instant_data->mjdt;
118+
current_step.azim = pred.instant_data->altaz_coord.az;
119+
current_step.elev = pred.instant_data->altaz_coord.el;
120+
current_pass.steps.push_back(std::move(current_step));
121+
current_step = {};
122+
123+
}
124+
else if(pass_started)
125+
{
126+
pass_started = false;
127+
passes.push_back(std::move(current_pass));
128+
current_pass = {};
129+
}
130+
131+
}
132+
133+
// Close pass if it is cut in the middle.
134+
if (pass_started)
135+
{
136+
passes.push_back(current_pass);
137+
}
138+
139+
return PassCalculator::ResultCode::NOT_ERROR;
140+
}
141+
142+
}}} // END NAMESPACES.
143+
// =====================================================================================================================

0 commit comments

Comments
 (0)