Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/refactor-keidai' into guillemc
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasadesus committed Dec 23, 2024
2 parents 39a6da8 + 119bcfc commit eb110af
Show file tree
Hide file tree
Showing 82 changed files with 10,855 additions and 1,721,399 deletions.
26 changes: 13 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
#- id: trailing-whitespace
- id: mixed-line-ending

- repo: https://github.com/psf/black
Expand All @@ -24,18 +24,18 @@ repos:
# hooks:
# - id: clang-format

- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
# - id: clang-tidy
# args:
# - --checks=-modernize-use-trailing-return-type,-readability-identifier-length,-readability-magic-numbers
# - id: oclint
# - id: uncrustify
# - id: cppcheck
# - id: cpplint
# - id: include-what-you-use
# - repo: https://github.com/pocc/pre-commit-hooks
# rev: v1.3.5
# hooks:
# - id: clang-format
# # - id: clang-tidy
# # args:
# # - --checks=-modernize-use-trailing-return-type,-readability-identifier-length,-readability-magic-numbers
# # - id: oclint
# # - id: uncrustify
# # - id: cppcheck
# # - id: cpplint
# # - id: include-what-you-use

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
Expand Down
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
)
endif()

# ---- Add dependencies ----
# ---- Options ----
option(UseTorch "Use LibTorch" OFF)

# ---- Add dependencies ----
include(cmake/FindOpenMP.cmake)
include(cmake/CPM.cmake)
add_subdirectory(thirdparty)
Expand Down Expand Up @@ -101,7 +103,18 @@ endfunction(target_link_libraries_system)
target_link_libraries_system(${PROJECT_NAME} Eigen3::Eigen matplot autodiff::autodiff cspice)
# Link HighFive
target_link_libraries(${PROJECT_NAME} PUBLIC HighFive)
# Link Torch
if (UseTorch)
find_package(Torch REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC ${TORCH_LIBRARIES})
target_include_directories(LuPNT PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/_deps/libtorch-src/include>
$<INSTALL_INTERFACE:include>
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
endif()

#Link OpenMP
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${OpenMP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)

Expand Down
13 changes: 11 additions & 2 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ file(
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.cc
)
# Remove example_ekf_elfo.cc from the list to compile
list(REMOVE_ITEM examples "example_ekf_elfo.cc")

if (NOT UseTorch)
# Remove example_torch.cc from the list to compile
set(NEW_EXAMPLES "")
foreach(item IN LISTS examples)
if(NOT item MATCHES "^torch/.*")
list(APPEND NEW_EXAMPLES "${item}")
endif()
endforeach()
set(examples "${NEW_EXAMPLES}")
endif()

find_package(OpenMP REQUIRED)

Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/basics/ex_autodiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {
bool flag = false;

Vec3 y;
MatX dydx = jacobian(func, wrt(x), at(x, flag), y);
MatX dydx = jacobian(func, wrt(x), autodiff::at(x, flag), y);
std::cout << dydx << std::endl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ struct Transmission {
int id_;
};

class Transponder;
class MyTransonder;

// Channel class
class Channel {
private:
int id_;
Real delay_ = 0.5;
vector<shared_ptr<Transponder>> transponders_;
vector<shared_ptr<MyTransonder>> transponders_;

public:
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_; }
void Send(Real t, const Transmission &transm, const MyTransonder &sender);
void Add(shared_ptr<MyTransonder> MyTransonder) { transponders_.push_back(MyTransonder); }
vector<shared_ptr<MyTransonder>> GetMyTransonders() { return transponders_; }
};

// Transponder class
class Transponder {
// MyTransonder class
class MyTransonder {
private:
shared_ptr<Channel> channel_;
function<void(Real, const Transmission &)> receive_callback_;

public:
Transponder(shared_ptr<Channel> channel) : channel_(channel) {}
MyTransonder(shared_ptr<Channel> channel) : channel_(channel) {}
void SetReceiveCallback(function<void(Real, const Transmission &)> callback) {
receive_callback_ = callback;
}
Expand All @@ -48,11 +48,11 @@ class Transponder {
void Receive(Real t, const Transmission &transm) { receive_callback_(t, transm); }
};

void Channel::Send(Real t, const Transmission &transm, const Transponder &sender) {
for (const auto &Transponder : transponders_) {
if (Transponder.get() != &sender) {
void Channel::Send(Real t, const Transmission &transm, const MyTransonder &sender) {
for (const auto &MyTransonder : transponders_) {
if (MyTransonder.get() != &sender) {
Scheduler::Schedule(t + delay_,
[Transponder, transm](Real t) { Transponder->Receive(t.val(), transm); });
[MyTransonder, transm](Real t) { MyTransonder->Receive(t, transm); });
}
}
}
Expand All @@ -62,14 +62,14 @@ class RingAgent {
private:
static int id_counter_;
const int id_;
vector<shared_ptr<Transponder>> transponders_;
vector<shared_ptr<MyTransonder>> transponders_;

public:
RingAgent() : id_(id_counter_++), transponders_(vector<shared_ptr<Transponder>>()) {}
RingAgent() : id_(id_counter_++), transponders_(vector<shared_ptr<MyTransonder>>()) {}
int GetId() { return id_; }

void Add(shared_ptr<Transponder> Transponder) { transponders_.push_back(Transponder); }
vector<shared_ptr<Transponder>> GetTransponders() { return transponders_; }
void Add(shared_ptr<MyTransonder> MyTransonder) { transponders_.push_back(MyTransonder); }
vector<shared_ptr<MyTransonder>> GetMyTransonders() { return transponders_; }
};

int RingAgent::id_counter_ = 0;
Expand All @@ -89,14 +89,14 @@ class LeaderElectionSyncRingApp : public Application {
void Step(Real t) override {
if (id_received_ == -1) {
cout << "[Agent " << id_ << "] Sending " << id_ << " at t = " << t << endl;
for (const auto &Transponder : agent_->GetTransponders()) {
for (const auto &MyTransonder : agent_->GetMyTransonders()) {
// transmittion instance with _id
Transponder->Send(t, Transmission{id_});
MyTransonder->Send(t, Transmission{id_});
}
} else if (id_received_ > id_) {
cout << "[Agent " << id_ << "] Sending " << id_received_ << " at t = " << t << endl;
for (const auto &Transponder : agent_->GetTransponders()) {
Transponder->Send(t, Transmission{id_received_});
for (const auto &MyTransonder : agent_->GetMyTransonders()) {
MyTransonder->Send(t, Transmission{id_received_});
}
} else if (id_received_ < id_) {
cout << "[Agent " << id_ << "] Doing nothing"
Expand Down Expand Up @@ -126,12 +126,12 @@ int main() {
channels[i] = make_shared<Channel>();
}

// Create Transponders and add them to agents and channels
// Create MyTransonders and add them to agents and channels
for (int i = 0; i < n; i++) {
auto ch1 = channels[i];
auto ch2 = channels[(i + 1) % n];
auto transc1 = make_shared<Transponder>(ch1);
auto transc2 = make_shared<Transponder>(ch2);
auto transc1 = make_shared<MyTransonder>(ch1);
auto transc2 = make_shared<MyTransonder>(ch2);
transc1->SetReceiveCallback(bind(&LeaderElectionSyncRingApp::TransmissionReceived,
apps[i].get(), placeholders::_1, placeholders::_2));
transc2->SetReceiveCallback(bind(&LeaderElectionSyncRingApp::TransmissionReceived,
Expand Down
21 changes: 21 additions & 0 deletions examples/cpp/other/example_ground_station.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <lupnt/lupnt.h>

using namespace lupnt;

int main() {
GroundStationDataMap gs_data = LoadGroundStationData();

// print the ground station latitude, longitude, and altitude
std::cout << "GS Name Latitude Longitude Altitude" << std::endl;
for (auto& [gs_id, gs] : gs_data) {
std::cout << gs.name << " " << gs.latitude << " " << gs.longitude << " " << gs.altitude_m
<< std::endl;
}

std::cout << " " << std::endl;
GroundStation gs = GroundStation(gs_data[0]);
std::cout << "GS Name : " << gs.GetName() << std::endl;
std::cout << "Lat, Lon : " << gs.GetLatitudeDouble() * DEG << " , "
<< gs.GetLongitudeDouble() * DEG << std::endl;
std::cout << "PosVel : " << gs.GetRvState()->GetVec().transpose() << std::endl;
}
Loading

0 comments on commit eb110af

Please sign in to comment.