Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/utilities/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
#define INCLUDE_UTILITIES_COMMON_HPP_

#include <chrono>
#include <utility>
#include <vector>

// #include <gen_protos/protos/obc.pb.h>
#include "protos/obc.pb.h"


std::chrono::seconds getUnixTime_s();
std::chrono::milliseconds getUnixTime_ms();

int checkCounterClockwise(std::vector<GPSCoord> coords);

#endif // INCLUDE_UTILITIES_COMMON_HPP_
16 changes: 14 additions & 2 deletions src/network/gcs_routes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <google/protobuf/util/json_util.h>
#include <httplib.h>
#include <iostream>

#include <filesystem>
#include <memory>
Expand All @@ -21,6 +22,7 @@
#include "ticks/path_validate.hpp"
#include "ticks/tick.hpp"
#include "ticks/wait_for_takeoff.hpp"
#include "utilities/common.hpp"
#include "utilities/http.hpp"
#include "utilities/logging.hpp"
#include "utilities/serialize.hpp"
Expand Down Expand Up @@ -118,17 +120,27 @@ DEF_GCS_HANDLE(Post, mission) {
Mission mission;
google::protobuf::util::JsonStringToMessage(request.body, &mission);

state->setCartesianConverter(CartesianConverter(mission.waypoints()));

std::vector<GPSCoord> coord_Vector(
mission.flightboundary().begin(),
mission.flightboundary().end()
);

if(checkCounterClockwise(coord_Vector) == 0){
LOG_RESPONSE(ERROR, "Not CounterClockwise", BAD_REQUEST);
}

// Update the cartesian converter to be centered around the new flight boundary
state->setCartesianConverter(CartesianConverter(mission.flightboundary()));

auto err = state->mission_params.setMission(mission, state->getCartesianConverter().value());
if (err.has_value()) {
LOG_RESPONSE(WARNING, err.value().c_str(), BAD_REQUEST);
} else {
LOG_RESPONSE(INFO, "Mission uploaded", OK);
}
}

DEF_GCS_HANDLE(Post, targets, locations) {
LOG_REQUEST("POST", "/targets/locations");

Expand Down
35 changes: 33 additions & 2 deletions src/utilities/common.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#include "utilities/common.hpp"

#include <iostream>
#include <chrono>
#include <utility>
#include <vector>

#include "utilities/datatypes.hpp"
#include "pathing/mission_path.hpp"
#include "ticks/path_gen.hpp"
#include "pathing/mission_path.hpp"
#include "ticks/path_validate.hpp"
#include "network/gcs_routes.hpp"
#include "protos/obc.pb.h"


std::chrono::seconds getUnixTime_s() {
const auto now = std::chrono::system_clock::now();
Expand All @@ -15,3 +21,28 @@ std::chrono::milliseconds getUnixTime_ms() {
const auto now = std::chrono::system_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
}

int checkCounterClockwise(std::vector<GPSCoord> coords) {
double tot_sign = 0;
double xnplus1 = 0;
double ynplus1 = 0;
for(int i = 0; i < coords.size(); i++){
double xn = coords[i].latitude();
double yn = coords[i].longitude();
if(i == coords.size() - 1){
xnplus1 = coords[0].latitude();
ynplus1 = coords[0].longitude();
} else {
xnplus1 = coords[i+1].latitude();
ynplus1 = coords[i+1].longitude();
}
tot_sign += ((xn *ynplus1) - (yn * xnplus1));
}
std::cout << tot_sign;
if(tot_sign < 0){
return 0; // 0 is counter clockwise
}else {
return 1; // 1 is not counterclockwise
}
}
//checks coordinates if they're in counter clockwise
2 changes: 1 addition & 1 deletion tests/integration/path_plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ int main() {

plotter.output("test_static", PathOutputType::STATIC);
plotter.output("test_animated", PathOutputType::ANIMATED);
}
}
41 changes: 40 additions & 1 deletion tests/unit/pathing/tree_test.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
#include "pathing/tree.hpp"

#include <iostream>
#include <gtest/gtest.h>

#include "pathing/dubins.hpp"
#include "pathing/environment.hpp"
#include "utilities/constants.hpp"
#include "utilities/datatypes.hpp"
#include "utilities/common.hpp"

/*
* very bad tests, was too lazy to check if every parameter was correct, aka didn't bother to find
* the hardcoded values for the expected values.
*/
#include <iostream>

TEST(CheckCounterClockwiseTest, CounterClockwiseTest){
// testing if flightbounds counter clockwise returns correctly
GPSCoord GPS4 = makeGPSCoord(0,0,0);
GPSCoord GPS3 = makeGPSCoord(10,0,0);
GPSCoord GPS2 = makeGPSCoord(10,10,0);
GPSCoord GPS1 = makeGPSCoord(0,10,0);

std::vector<GPSCoord> coords_Test1 = {GPS1, GPS2, GPS3, GPS4};

int expected_val1 = checkCounterClockwise(coords_Test1);

EXPECT_TRUE(expected_val1 == 0);
//test with actual coords
GPSCoord GEISEL = makeGPSCoord(32.88146, -117.23772,0);
std::cout << "If this appears coordinate1 was created propely" << std::endl;
GPSCoord PINES = makeGPSCoord(32.87886,-117.24249,0);
std::cout << "If this appears coordinate2 was created propely" << std::endl;
GPSCoord FAH = makeGPSCoord(32.88354,-117.23496,0);
std::cout << "If this appears coordinate3 was created propely" << std::endl;
GPSCoord SUNGOD = makeGPSCoord(32.87864,-117.23977,0);
std::cout << "If this appears coordinate4 was created propely" << std::endl;

std::vector<GPSCoord> coords_Test2 = {GEISEL, PINES, SUNGOD, FAH};

std::cout << "If this appears coord list was created properly" << std::endl;

int expected_val2 = checkCounterClockwise(coords_Test2);
std::cout << "If this appears Triple C ran" << std::endl;

EXPECT_TRUE(expected_val2 == 0);

std::vector<GPSCoord> coords_Test3 = {GEISEL, SUNGOD, PINES, FAH};

int expected_val3 = checkCounterClockwise(coords_Test3);

EXPECT_TRUE(expected_val3 == 1);
}

TEST(SimpleTreeTest, addNodeTest) {
Dubins dubins{5, 0.1};
Polygon valid_region;
Expand Down
Loading