From 39a6da8f0d4c304421d534a2e1280132649b24ac Mon Sep 17 00:00:00 2001 From: Guillem Date: Mon, 23 Dec 2024 01:02:59 -0800 Subject: [PATCH] Minor changes --- CMakeLists.txt | 2 +- .../example_leader_election_sync_ring.cc | 26 ++++---- include/lupnt/measurements/gnss_receiver.h | 1 + source/cpp/numerics/interpolation.cc | 15 +++-- source/python/bindings/py_math_utils.cc | 13 +--- source/python/pylupnt/_pylupnt.pyi | 66 ------------------- 6 files changed, 25 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d80ad53..061cc2f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON) # ---- Project ---- project(LuPNT LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) diff --git a/examples/cpp/distributed_algorithms/example_leader_election_sync_ring.cc b/examples/cpp/distributed_algorithms/example_leader_election_sync_ring.cc index 53886ad2..6c789b17 100644 --- a/examples/cpp/distributed_algorithms/example_leader_election_sync_ring.cc +++ b/examples/cpp/distributed_algorithms/example_leader_election_sync_ring.cc @@ -22,11 +22,11 @@ class Transponder; class Channel { private: int id_; - double delay_ = 0.5; + Real delay_ = 0.5; vector> transponders_; public: - void Send(double t, const Transmission &transm, const Transponder &sender); + void Send(Real t, const Transmission &transm, const Transponder &sender); void Add(shared_ptr Transponder) { transponders_.push_back(Transponder); } vector> GetTransponders() { return transponders_; } }; @@ -35,24 +35,24 @@ class Channel { class Transponder { private: shared_ptr channel_; - function receive_callback_; + function receive_callback_; public: Transponder(shared_ptr channel) : channel_(channel) {} - void SetReceiveCallback(function callback) { + void SetReceiveCallback(function callback) { receive_callback_ = callback; } - void Send(double t, const Transmission &transm) { channel_->Send(t, transm, *this); } + void Send(Real t, const Transmission &transm) { channel_->Send(t, transm, *this); } - void Receive(double t, const Transmission &transm) { receive_callback_(t, transm); } + void Receive(Real t, const Transmission &transm) { receive_callback_(t, transm); } }; -void Channel::Send(double t, const Transmission &transm, const Transponder &sender) { +void Channel::Send(Real t, const Transmission &transm, const Transponder &sender) { for (const auto &Transponder : transponders_) { if (Transponder.get() != &sender) { Scheduler::Schedule(t + delay_, - [Transponder, transm](double t) { Transponder->Receive(t, transm); }); + [Transponder, transm](Real t) { Transponder->Receive(t.val(), transm); }); } } } @@ -84,9 +84,9 @@ class LeaderElectionSyncRingApp : public Application { public: LeaderElectionSyncRingApp(shared_ptr agent) : agent_(agent), id_(agent->GetId()) {} - double GetFrequency() override { return 1.0; } + Real GetFrequency() override { return 1.0; } void Setup() override {} - void Step(double t) override { + void Step(Real t) override { if (id_received_ == -1) { cout << "[Agent " << id_ << "] Sending " << id_ << " at t = " << t << endl; for (const auto &Transponder : agent_->GetTransponders()) { @@ -107,7 +107,7 @@ class LeaderElectionSyncRingApp : public Application { << " at t = " << t << endl; } } - void TransmissionReceived(double t, const Transmission &transm) { + void TransmissionReceived(Real t, const Transmission &transm) { cout << "[Agent " << id_ << "] Received " << transm.id_ << " at t = " << t << endl; id_received_ = max(id_received_, transm.id_); } @@ -143,8 +143,8 @@ int main() { } // Schedule applications - double t_start = 0.0; - double freq = 1.0; + Real t_start = 0.0; + Real freq = 1.0; for (int i = 0; i < n; i++) { Scheduler::ScheduleApplication(*apps[i], t_start, freq); } diff --git a/include/lupnt/measurements/gnss_receiver.h b/include/lupnt/measurements/gnss_receiver.h index c8cd1e6e..e991d006 100644 --- a/include/lupnt/measurements/gnss_receiver.h +++ b/include/lupnt/measurements/gnss_receiver.h @@ -66,6 +66,7 @@ namespace lupnt { inline Ptr GetAgent() const override { return agent; }; inline void SetAgent(Ptr agent) override { this->agent = agent; }; inline Ptr GetGnssChannel() { return gnss_channel_; }; + inline Ptr GetChannel() const override { return gnss_channel_; }; inline void SetChannel(Ptr channel) override { gnss_channel_ = std::static_pointer_cast(channel); }; diff --git a/source/cpp/numerics/interpolation.cc b/source/cpp/numerics/interpolation.cc index c5086589..9e899659 100644 --- a/source/cpp/numerics/interpolation.cc +++ b/source/cpp/numerics/interpolation.cc @@ -35,15 +35,16 @@ namespace lupnt { /// @param xi x interpolation point double LinearInterp2d(const VecXd& x, const VecXd& y, const MatXd& z, double xi, double yi) { if (x.size() != z.rows() || y.size() != z.cols()) { - std::string msg = std::format("Invalid size: x is {}, y is {}, z is {} x {}", x.size(), - y.size(), z.rows(), z.cols()); - throw std::runtime_error(msg); + std::stringstream msg; + msg << "Invalid size: x is " << x.size() << ", y is " << y.size() << ", z is " << z.rows() + << " x " << z.cols(); + throw std::runtime_error(msg.str()); } if (xi < x(0) || xi > x(x.size() - 1) || yi < y(0) || yi > y(y.size() - 1)) { - std::string msg - = std::format("Out of range: xi is {}, yi is {}, x is {} to {}, y is {} to {}", xi, yi, - x(0), x(x.size() - 1), y(0), y(y.size() - 1)); - throw std::runtime_error(msg); + std::stringstream msg; + msg << "Out of range: xi is " << xi << ", yi is " << yi << ", x is " << x(0) << " to " + << x(x.size() - 1) << ", y is " << y(0) << " to " << y(y.size() - 1); + throw std::runtime_error(msg.str()); } const double *start, *end; diff --git a/source/python/bindings/py_math_utils.cc b/source/python/bindings/py_math_utils.cc index 41607b46..ee8a6b94 100644 --- a/source/python/bindings/py_math_utils.cc +++ b/source/python/bindings/py_math_utils.cc @@ -60,19 +60,10 @@ void init_math_utils(py::module &m) { m.def("rot_z", &RotZ, "Active rotation matrix about the z-axis", py::arg("angle")); m.def("skew", &Skew, "Skew symmetric matrix from a vector", py::arg("x")); m.def( - "rot2quat", - [](const Mat3d &rot) -> Vec4d { - Quatd quat(rot); - quat.normalize(); - if (quat.w() < 0) quat.coeffs() *= -1; - return quat.coeffs(); - }, + "rot2quat", [](const Mat3d &rot) -> Vec4d { return DCMToQuatCoeff(rot).cast(); }, "Convert rotation matrix to quaternion [x, y, z, w]", py::arg("R")); m.def( "quat2rot", - [](const Vec4d &q) -> Mat3d { - Quatd quat(q(3), q(0), q(1), q(2)); - return quat.toRotationMatrix(); - }, + [](const Vec4d &q) -> Mat3d { return QuatCoeffToDCM(q.cast().eval()).cast(); }, "Convert quaternion to rotation matrix", py::arg("q")); } diff --git a/source/python/pylupnt/_pylupnt.pyi b/source/python/pylupnt/_pylupnt.pyi index 7b50b421..a3c5b7e0 100644 --- a/source/python/pylupnt/_pylupnt.pyi +++ b/source/python/pylupnt/_pylupnt.pyi @@ -4,8 +4,6 @@ from typing import Callable, ClassVar, overload A1_TAI_OFFSET: float ARCSEC_DEG: float ARCSEC_RAD: float -AU: float -C: float CARTESIAN: OrbitStateRepres CLASSICAL_OE: OrbitStateRepres DAYS_CENTURY: float @@ -127,35 +125,15 @@ class Animal: def go(self, arg0: int) -> str: ... def name(self) -> str: ... -class Antenna: - def __init__(self, arg0: str) -> None: ... - @overload - def compute_gain(self, theta: float, phi: float) -> float: ... - @overload - def compute_gain(self, theta: numpy.ndarray[numpy.float64[m, 1]], phi: float) -> numpy.ndarray[numpy.float64[m, 1]]: ... - @overload - def compute_gain(self, theta: float, phi: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]: ... - @overload - def compute_gain(self, theta: numpy.ndarray[numpy.float64[m, 1]], phi: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]: ... - def get_gain_matrix(self) -> numpy.ndarray[numpy.float64[m, n]]: ... - def get_phi_vector(self) -> numpy.ndarray[numpy.float64[m, 1]]: ... - def get_theta_vector(self) -> numpy.ndarray[numpy.float64[m, 1]]: ... - @property - def name(self) -> str: ... - class Body: def __init__(self) -> None: ... @staticmethod def Earth(n: int = ..., m: int = ..., gravity_file: str = ...) -> Body: ... @staticmethod - def Jupiter() -> Body: ... - @staticmethod def Mars(n: int = ..., m: int = ..., gravity_file: str = ...) -> Body: ... @staticmethod def Moon(n: int = ..., m: int = ..., gravity_file: str = ...) -> Body: ... @staticmethod - def Saturn() -> Body: ... - @staticmethod def Sun() -> Body: ... @staticmethod def Venus(n: int = ..., m: int = ..., gravity_file: str = ...) -> Body: ... @@ -457,37 +435,6 @@ class SingularROE(OrbitState): adw: float def __init__(self, arg0: numpy.ndarray[numpy.float64[6, 1]], arg1: Frame) -> None: ... -class TLE: - def __init__(self, *args, **kwargs) -> None: ... - @staticmethod - def from_file(filename: str) -> list[TLE]: ... - @staticmethod - def from_lines(line1: str, line2: str, line3: str) -> TLE: ... - @property - def arg_perigee(self) -> float: ... - @property - def bstar(self) -> float: ... - @property - def eccentricity(self) -> float: ... - @property - def epoch_day(self) -> float: ... - @property - def epoch_tai(self) -> float: ... - @property - def epoch_year(self) -> float: ... - @property - def inclination(self) -> float: ... - @property - def mean_anomaly(self) -> float: ... - @property - def mean_motion(self) -> float: ... - @property - def name(self) -> str: ... - @property - def prn(self) -> int: ... - @property - def raan(self) -> float: ... - class Time: __members__: ClassVar[dict] = ... # read-only GPS: ClassVar[Time] = ... @@ -695,8 +642,6 @@ def equinoctial2classical(eqoe: numpy.ndarray[numpy.float64[6, 1]], GM: numpy.nd def equinoctial2classical(eqoe: numpy.ndarray[numpy.float64[m, 6]], GM: float) -> numpy.ndarray[numpy.float64[m, 6]]: ... @overload def equinoctial2classical(eqoe: numpy.ndarray[numpy.float64[m, 6]], GM: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 6]]: ... -def find_file_in_dir(*args, **kwargs): ... -def get_ascii_kernel_dir() -> str: ... @overload def get_body_pos_vel(t_tai: float, center: NaifId, target: NaifId, frame: Frame) -> numpy.ndarray[numpy.float64[6, 1]]: ... @overload @@ -705,9 +650,6 @@ def get_body_pos_vel(t_tai: numpy.ndarray[numpy.float64[m, 1]], center: NaifId, def get_body_pos_vel(t_tai: float, target: NaifId, frame: Frame) -> numpy.ndarray[numpy.float64[6, 1]]: ... @overload def get_body_pos_vel(t_tai: numpy.ndarray[numpy.float64[m, 1]], target: NaifId, frame: Frame) -> numpy.ndarray[numpy.float64[m, 6]]: ... -def get_cspice_kernel_dir() -> str: ... -def get_data_path() -> str: ... -def get_file_path(arg0: str) -> str: ... @overload def get_orbital_period(a: float, GM: float) -> float: ... @overload @@ -716,7 +658,6 @@ def get_orbital_period(a: numpy.ndarray[numpy.float64[m, 1]], GM: float) -> nump def get_orbital_period(a: float, GM: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]: ... @overload def get_orbital_period(a: numpy.ndarray[numpy.float64[m, 1]], GM: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]: ... -def get_output_path(arg0: str) -> str: ... @overload def gps2tai(t_gps: float) -> float: ... @overload @@ -781,7 +722,6 @@ def quasi_nonsingular2classical(qnsoe: numpy.ndarray[numpy.float64[6, 1]], GM: n def quasi_nonsingular2classical(qnsoe: numpy.ndarray[numpy.float64[m, 6]], GM: float) -> numpy.ndarray[numpy.float64[m, 6]]: ... @overload def quasi_nonsingular2classical(qnsoe: numpy.ndarray[numpy.float64[m, 6]], GM: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 6]]: ... -def quat2rot(q: numpy.ndarray[numpy.float64[4, 1]]) -> numpy.ndarray[numpy.float64[3, 3]]: ... @overload def relative_quasi_nonsingular2classical(coe: ClassicalOE, rel_qnsoe: QuasiNonsingROE) -> ClassicalOE: ... @overload @@ -794,11 +734,6 @@ def relative_quasi_nonsingular2classical(coe: numpy.ndarray[numpy.float64[m, 6]] def relative_quasi_nonsingular2classical(coe: numpy.ndarray[numpy.float64[6, 1]], rel_qnsoe: numpy.ndarray[numpy.float64[m, 6]]) -> numpy.ndarray[numpy.float64[m, 6]]: ... @overload def relative_quasi_nonsingular2classical(coe: numpy.ndarray[numpy.float64[m, 6]], rel_qnsoe: numpy.ndarray[numpy.float64[m, 6]]) -> numpy.ndarray[numpy.float64[m, 6]]: ... -def rot2quat(R: numpy.ndarray[numpy.float64[3, 3]]) -> numpy.ndarray[numpy.float64[4, 1]]: ... -def rot_x(angle: float) -> numpy.ndarray[numpy.float64[3, 3]]: ... -def rot_y(angle: float) -> numpy.ndarray[numpy.float64[3, 3]]: ... -def rot_z(angle: float) -> numpy.ndarray[numpy.float64[3, 3]]: ... -def skew(x: numpy.ndarray[numpy.float64[3, 1]]) -> numpy.ndarray[numpy.float64[3, 3]]: ... @overload def synodic2intertial(rv_c: numpy.ndarray[numpy.float64[6, 1]], rv_d: numpy.ndarray[numpy.float64[6, 1]]) -> numpy.ndarray[numpy.float64[6, 1]]: ... @overload @@ -842,7 +777,6 @@ def time2jd(t: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float6 def time2mjd(t: float) -> float: ... @overload def time2mjd(t: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]: ... -def tle2classical(arg0, arg1: float) -> numpy.ndarray[numpy.float64[6, 1]]: ... @overload def true2eccentric_anomaly(nu: float, e: float) -> float: ... @overload