Skip to content

Commit

Permalink
fix lint & mavlink url not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Lentz committed Apr 17, 2024
1 parent c853223 commit 33ad4dd
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 85 deletions.
4 changes: 2 additions & 2 deletions include/core/obc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "core/mission_state.hpp"
#include "network/gcs.hpp"
#include "network/mavlink.hpp"
#include "utilities/OBCConfig.hpp"
#include "utilities/obc_config.hpp"

/*
* The highest level class for the entire OBC
Expand All @@ -29,7 +29,7 @@ class OBC {
std::thread connectMavThread;
std::thread connectAirdropThread;

void connectMavlink(const char* mavlink_url);
void connectMavlink(std::string mavlink_url);
void connectAirdrop();
};

Expand Down
2 changes: 1 addition & 1 deletion include/network/mavlink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MavlinkClient {
* example:
* MavlinkClient("tcp://192.168.65.254:5762")
*/
explicit MavlinkClient(const char* link);
explicit MavlinkClient(std::string link);

/*
* BLOCKING. Continues to try to upload the mission based on the passed through MissionConfig
Expand Down
22 changes: 0 additions & 22 deletions include/utilities/OBCConfig.hpp

This file was deleted.

19 changes: 19 additions & 0 deletions include/utilities/obc_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef INCLUDE_UTILITIES_OBC_CONFIG_HPP_
#define INCLUDE_UTILITIES_OBC_CONFIG_HPP_

#include <string>

struct OBCConfig {
std::string network_mavlink_connect;
int network_gcs_port;

// Load user specified config json, or make a new one
OBCConfig(int argc, char* argv[]);

private:
const std::string configsPath = "/workspaces/obcpp/configs/";

void makeDefault();
};

#endif // INCLUDE_UTILITIES_OBC_CONFIG_HPP_
2 changes: 1 addition & 1 deletion protos
Submodule protos updated 4 files
+4 −4 .gitignore
+1 −1 README.md
+35 −35 houston.proto
+89 −79 obc.proto
9 changes: 4 additions & 5 deletions src/core/obc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
#include "network/mavlink.hpp"
#include "network/airdrop_client.hpp"
#include "utilities/logging.hpp"
#include "utilities/obc_config.hpp"
extern "C" {
#include "network/airdrop_sockets.h"
}

// TODO: allow specifying config filename
OBC::OBC(OBCConfig config) {
const char* mavlink_url= config.network_mavlink_connect.c_str();
int gcs_port = config.network_gcs_port;

LOG_F(INFO, mavlink_url);

this->state = std::make_shared<MissionState>();
this->state->setTick(new MissionPrepTick(this->state));

Expand All @@ -31,7 +29,8 @@ OBC::OBC(OBCConfig config) {
// Don't need to look at these futures at all because the connect functions
// will set the global mission state themselves when connected, which everything
// else can check.
this->connectMavThread = std::thread([this, mavlink_url]{this->connectMavlink(mavlink_url);});
this->connectMavThread = std::thread([this, config]
{this->connectMavlink(config.network_mavlink_connect);});
this->connectAirdropThread = std::thread([this]{this->connectAirdrop();});
}

Expand All @@ -42,7 +41,7 @@ void OBC::run() {
}
}

void OBC::connectMavlink(const char* mavlink_url) {
void OBC::connectMavlink(std::string mavlink_url) {
loguru::set_thread_name("mav connect");

// TODO: pull mav ip from config file
Expand Down
11 changes: 3 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ extern "C" {
#include "core/obc.hpp"
#include "utilities/constants.hpp"
#include "utilities/logging.hpp"
#include "utilities/OBCConfig.hpp"
#include "utilities/obc_config.hpp"


int main(int argc, char* argv[]) {
OBCConfig config(argc, argv);

// TODO: pull logging folder from config
initLogging("/workspaces/obcpp/logs", true, argc, argv);

// START: My Code
LOG_F(INFO, "HEEEELLLLLOOOOOOOOO");
OBCConfig config(argc, argv);
// END: My Code

// In future, load configs, perhaps command line parameters, and pass
// into the obc object
OBC obc(config);
obc.run();
}
6 changes: 3 additions & 3 deletions src/network/mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#include "utilities/logging.hpp"
#include "core/mission_state.hpp"

MavlinkClient::MavlinkClient(const char* link) {
LOG_F(INFO, "Connecting to Mav at %s", link);
MavlinkClient::MavlinkClient(std::string link) {
LOG_F(INFO, "Connecting to Mav at %s", link.c_str());

while (true) {
LOG_F(INFO, "Attempting to add mav connection...");
const auto conn_result = this->mavsdk.add_any_connection(link);
if (conn_result == mavsdk::ConnectionResult::Success) {
LOG_F(INFO, "Mavlink connection successfully established at %s", link);
LOG_F(INFO, "Mavlink connection successfully established at %s", link.c_str());
break;
}

Expand Down
3 changes: 2 additions & 1 deletion src/pathing/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pathing/environment.hpp"
#include "utilities/datatypes.hpp"
#include "utilities/rng.hpp"
#include "utilities/logging.hpp"

RRTNode::RRTNode(const RRTPoint& point, double cost, double path_length,
const std::vector<XYZCoord> path)
Expand Down Expand Up @@ -363,7 +364,7 @@ void RRTTree::RRTStar(RRTNode* sample, double rewire_radius) {

void RRTTree::setCurrentHead(RRTNode* goal) {
if (goal == nullptr) {
std::cout << "FAILURE: Goal is not in the tree\n" << std::endl;
LOG_F(ERROR, "FAILURE: Goal is not in the tree");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SET(FILES
common.cpp
datatypes.cpp
logging.cpp
OBCConfig.cpp
obc_config.cpp
rng.cpp
)

Expand Down
41 changes: 0 additions & 41 deletions src/utilities/OBCConfig.cpp

This file was deleted.

41 changes: 41 additions & 0 deletions src/utilities/obc_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "utilities/obc_config.hpp"

#include <fstream>
#include <stdexcept>
#include <string>

#include "nlohmann/json.hpp"

using json = nlohmann::json;


OBCConfig::OBCConfig(int argc, char* argv[]) {
// If config-json name is passed in
if (argc > 1) {
// Load in json file
std::ifstream configStream(configsPath + std::string(argv[1]));
if (!configStream.is_open()) {
throw std::invalid_argument("Invalid config-json name");
}
json configs = json::parse(configStream);

// Set configs
this->network_mavlink_connect = configs["network"]["mavlink"]["connect"];
this->network_gcs_port = configs["network"]["gcs"]["port"];
} else {
makeDefault(); // Detect if there is already a default-config.json?
}
}

void OBCConfig::makeDefault() {
// Set configs
this->network_mavlink_connect = "tcp://172.17.0.1:5760";
this->network_gcs_port = 5010;

// Create default configs
json configs;
configs["network"]["mavlink"]["connect"] = this->network_mavlink_connect;
configs["network"]["gcs"]["port"] = this->network_gcs_port;
std::ofstream configFile(configsPath + "default-config.json");
configFile << configs.dump(4); // Dump to file with 4 space indents
}

0 comments on commit 33ad4dd

Please sign in to comment.