Skip to content

Commit

Permalink
Initial Conversion of RRT pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
AskewParity committed Apr 18, 2024
1 parent ac4e301 commit e079ea1
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 47 deletions.
13 changes: 13 additions & 0 deletions configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@
"gcs": {
"port": 5010
}
},
"static-pathing": {
"rrt": {
"iterations_per_waypoint": 200,
"rewire_radius": 200.0,
"k_closest_nodes": 50,
"total_options_for_goal_connection": 2048
},
"cpp": {
"vertical": false,
"one-way": true,
"optimize": false
}
}
}
13 changes: 13 additions & 0 deletions configs/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@
"mavlink": {
"connect": "tcp://172.17.0.1:5760"
}
},
"static-pathing": {
"rrt": {
"iterations_per_waypoint": 200,
"rewire_radius": 200.0,
"k_closest_nodes": 50,
"total_options_for_goal_connection": 2048
},
"cpp": {
"vertical": false,
"one-way": true,
"optimize": false
}
}
}
13 changes: 13 additions & 0 deletions configs/dev-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@
"gcs": {
"port": 5010
}
},
"static-pathing": {
"rrt": {
"iterations_per_waypoint": 200,
"rewire_radius": 200.0,
"k_closest_nodes": 50,
"total_options_for_goal_connection": 2048
},
"cpp": {
"vertical": false,
"one-way": true,
"optimize": false
}
}
}
7 changes: 4 additions & 3 deletions include/pathing/static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

class RRT {
public:
RRT(RRTPoint start, std::vector<XYZCoord> goals, int iterations_per_waypoint,
double search_radius, double rewire_radius, Polygon bounds,
RRT(RRTPoint start, std::vector<XYZCoord> goals, double search_radius, Polygon bounds,
std::vector<Polygon> obstacles = {},
RRTConfig config = {.optimize = false,
RRTConfig config = {.iterations_per_waypoint = ITERATIONS_PER_WAYPOINT,
.rewire_radius = REWIRE_RADIUS,
.optimize = false,
.point_fetch_method = POINT_FETCH_METHODS::NONE,
.allowed_to_skip_waypoints = false});

Expand Down
4 changes: 3 additions & 1 deletion include/utilities/datatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ enum POINT_FETCH_METHODS {
};

struct RRTConfig {
bool optimize; // run RRT* if true
int iterations_per_waypoint; // number of iterations run between two waypoints
double rewire_radius; // maximum distance from sampled point to optimize during RRT*
bool optimize; // run RRT* if true
POINT_FETCH_METHODS point_fetch_method;
bool allowed_to_skip_waypoints; // if true, will skip waypoints if it can not connect after 1
// RRT iteration
Expand Down
81 changes: 40 additions & 41 deletions src/pathing/static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
#include "utilities/datatypes.hpp"
#include "utilities/rng.hpp"

RRT::RRT(RRTPoint start, std::vector<XYZCoord> goals, int iterations_per_waypoint,
double search_radius, double rewire_radius, Polygon bounds, std::vector<Polygon> obstacles,
RRTConfig config)
: iterations_per_waypoint(iterations_per_waypoint),
RRT::RRT(RRTPoint start, std::vector<XYZCoord> goals, double search_radius, Polygon bounds,
std::vector<Polygon> obstacles, RRTConfig config)
: iterations_per_waypoint(config.iterations_per_waypoint),
search_radius(search_radius),
rewire_radius(rewire_radius),
rewire_radius(config.rewire_radius),
tree(start, Environment(bounds, {}, goals, obstacles),
Dubins(TURNING_RADIUS, POINT_SEPARATION)),
config(config) {}
Expand Down Expand Up @@ -238,42 +237,6 @@ RRTNode *RRT::parseOptions(const std::vector<std::pair<RRTNode *, RRTOption>> &o

void RRT::optimizeTree(RRTNode *sample) { tree.RRTStar(sample, rewire_radius); }

std::vector<GPSCoord> generateInitialPath(std::shared_ptr<MissionState> state) {
// first waypoint is start
RRTPoint start(state->config.getWaypoints().front(), 0);

// the other waypoitns is the goals
if (state->config.getWaypoints().size() < 2) {
loguru::set_thread_name("Static Pathing");
LOG_F(ERROR, "Not enough waypoints to generate a path, required 2+, existing waypoints: %s",
std::to_string(state->config.getWaypoints().size()).c_str());
return {};
}

std::vector<XYZCoord> goals;

// Copy elements (reference) from the second element to the last element of source into
// destination all other methods of copying over crash???
for (int i = 1; i < state->config.getWaypoints().size(); i++) {
goals.emplace_back(state->config.getWaypoints()[i]);
}

RRT rrt(start, goals, ITERATIONS_PER_WAYPOINT, SEARCH_RADIUS, REWIRE_RADIUS,
state->config.getFlightBoundary(), {}, RRTConfig{true, POINT_FETCH_METHODS::NONE});

rrt.run();

std::vector<XYZCoord> path = rrt.getPointsToGoal();
std::vector<GPSCoord> output_coords;
int count = 0;

for (XYZCoord wpt : path) {
output_coords.push_back(state->getCartesianConverter().value().toLatLng(wpt));
}

return output_coords;
}

AirdropSearch::AirdropSearch(const RRTPoint &start, double scan_radius, Polygon bounds,
Polygon airdrop_zone, std::vector<Polygon> obstacles,
AirdropSearchConfig config)
Expand Down Expand Up @@ -371,3 +334,39 @@ std::vector<XYZCoord> AirdropSearch::run() const {

return path;
}

std::vector<GPSCoord> generateInitialPath(std::shared_ptr<MissionState> state) {
// first waypoint is start
RRTPoint start(state->config.getWaypoints().front(), 0);

// the other waypoitns is the goals
if (state->config.getWaypoints().size() < 2) {
loguru::set_thread_name("Static Pathing");
LOG_F(ERROR, "Not enough waypoints to generate a path, required 2+, existing waypoints: %s",
std::to_string(state->config.getWaypoints().size()).c_str());
return {};
}

std::vector<XYZCoord> goals;

// Copy elements (reference) from the second element to the last element of source into
// destination all other methods of copying over crash???
for (int i = 1; i < state->config.getWaypoints().size(); i++) {
goals.emplace_back(state->config.getWaypoints()[i]);
}

RRT rrt(start, goals, SEARCH_RADIUS, state->config.getFlightBoundary(), {},
RRTConfig{ITERATIONS_PER_WAYPOINT, REWIRE_RADIUS, true, POINT_FETCH_METHODS::NONE});

rrt.run();

std::vector<XYZCoord> path = rrt.getPointsToGoal();
std::vector<GPSCoord> output_coords;
int count = 0;

for (XYZCoord wpt : path) {
output_coords.push_back(state->getCartesianConverter().value().toLatLng(wpt));
}

return output_coords;
}
4 changes: 2 additions & 2 deletions tests/integration/path_planning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ int main() {
int num_iterations = 512;
double search_radius = 9999;
double rewire_radius = 256;
RRTConfig config = RRTConfig { true, POINT_FETCH_METHODS::NONE, true };
RRTConfig config = RRTConfig { num_iterations, rewire_radius, true, POINT_FETCH_METHODS::NONE, true };

RRT rrt = RRT(start, goals, num_iterations, search_radius, rewire_radius,
RRT rrt = RRT(start, goals, search_radius,
state->config.getFlightBoundary(), obstacles, config);

// print out stats
Expand Down

0 comments on commit e079ea1

Please sign in to comment.