Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasadesus committed Dec 23, 2024
1 parent c2d1681 commit 39a6da8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 98 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Transponder;
class Channel {
private:
int id_;
double delay_ = 0.5;
Real delay_ = 0.5;
vector<shared_ptr<Transponder>> 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> Transponder) { transponders_.push_back(Transponder); }
vector<shared_ptr<Transponder>> GetTransponders() { return transponders_; }
};
Expand All @@ -35,24 +35,24 @@ class Channel {
class Transponder {
private:
shared_ptr<Channel> channel_;
function<void(double, const Transmission &)> receive_callback_;
function<void(Real, const Transmission &)> receive_callback_;

public:
Transponder(shared_ptr<Channel> channel) : channel_(channel) {}
void SetReceiveCallback(function<void(double, const Transmission &)> callback) {
void SetReceiveCallback(function<void(Real, const Transmission &)> 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); });
}
}
}
Expand Down Expand Up @@ -84,9 +84,9 @@ class LeaderElectionSyncRingApp : public Application {

public:
LeaderElectionSyncRingApp(shared_ptr<RingAgent> 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()) {
Expand All @@ -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_);
}
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions include/lupnt/measurements/gnss_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace lupnt {
inline Ptr<Agent> GetAgent() const override { return agent; };
inline void SetAgent(Ptr<Agent> agent) override { this->agent = agent; };
inline Ptr<GnssChannel> GetGnssChannel() { return gnss_channel_; };
inline Ptr<SpaceChannel> GetChannel() const override { return gnss_channel_; };
inline void SetChannel(Ptr<SpaceChannel> channel) override {
gnss_channel_ = std::static_pointer_cast<GnssChannel>(channel);
};
Expand Down
15 changes: 8 additions & 7 deletions source/cpp/numerics/interpolation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 2 additions & 11 deletions source/python/bindings/py_math_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,10 @@ void init_math_utils(py::module &m) {
m.def("rot_z", &RotZ<double>, "Active rotation matrix about the z-axis", py::arg("angle"));
m.def("skew", &Skew<double>, "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<double>(); },
"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<Real>().eval()).cast<double>(); },
"Convert quaternion to rotation matrix", py::arg("q"));
}
66 changes: 0 additions & 66 deletions source/python/pylupnt/_pylupnt.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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] = ...
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 39a6da8

Please sign in to comment.