Skip to content

Commit 2f9976c

Browse files
authored
Merge pull request #21 from mlsdpk/sampling-based
Add rrt and rrt*
2 parents 7a359ca + d6ba714 commit 2f9976c

File tree

18 files changed

+784
-916
lines changed

18 files changed

+784
-916
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ include_directories(include/States/Algorithms/GraphBased/BFS)
1111
include_directories(include/States/Algorithms/GraphBased/DFS)
1212
include_directories(include/States/Algorithms/GraphBased/DIJKSTRA)
1313
include_directories(include/States/Algorithms/GraphBased/ASTAR)
14+
include_directories(include/States/Algorithms/SamplingBased)
15+
include_directories(include/States/Algorithms/SamplingBased/RRT)
16+
include_directories(include/States/Algorithms/SamplingBased/RRT_STAR)
1417

1518
set(EXECUTABLE_NAME "main")
1619

@@ -24,6 +27,9 @@ add_executable(${EXECUTABLE_NAME}
2427
src/States/Algorithms/GraphBased/DFS/DFS.cpp
2528
src/States/Algorithms/GraphBased/DIJKSTRA/DIJKSTRA.cpp
2629
src/States/Algorithms/GraphBased/ASTAR/ASTAR.cpp
30+
src/States/Algorithms/SamplingBased/SamplingBased.cpp
31+
src/States/Algorithms/SamplingBased/RRT/RRT.cpp
32+
src/States/Algorithms/SamplingBased/RRT_STAR/RRT_STAR.cpp
2733
)
2834

2935
target_link_libraries(

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
A tool for visualizing numerous pathfinding algorithms in two dimensions.
66

7-
This project involves minimal implementations of the popular planning algorithms, including both graph-based and sampling-based planners. We provide an easy-to-use GUI to control the animation process and explore different planner configurations. This is an ongoing work and current implementation of the project only involves four search-based planning algorithms: BFS, DFS, DIJKSTRA and A-Star. The project extensively uses SFML, ImGui and Modern C++ features such as smart pointers, lamda expressions along with multi-threading concepts.
7+
This project involves minimal implementations of the popular planning algorithms, including both graph-based and sampling-based planners. We provide an easy-to-use GUI to control the animation process and explore different planner configurations. This is an ongoing work and current implementation of the project only involves four search-based planning algorithms: BFS, DFS, DIJKSTRA and A-Star and two sampling-based planners: RRT and RRT*. The project extensively uses SFML, ImGui and Modern C++ features such as smart pointers, lamda expressions along with multi-threading concepts.
88

99
![](figures/img0.png)
1010

@@ -25,7 +25,7 @@ The project depends on [SFML](https://github.com/SFML/SFML), [Dear ImGui](https:
2525

2626
## TODO
2727

28-
### Search-based planners
28+
### Graph-based planners
2929
- [x] BFS
3030
- [x] DFS
3131
- [x] DIJKSTRA
@@ -35,9 +35,9 @@ The project depends on [SFML](https://github.com/SFML/SFML), [Dear ImGui](https:
3535
- [ ] LPA*
3636

3737
### Sampling-based planners
38-
- [ ] RRT
38+
- [x] RRT
3939
- [ ] RRT-Connect
40-
- [ ] RRT*
40+
- [x] RRT*
4141
- [ ] Informed-RRT*
4242
- [ ] FMT*
4343
- [ ] BIT*
@@ -48,5 +48,5 @@ The project depends on [SFML](https://github.com/SFML/SFML), [Dear ImGui](https:
4848
- [DIJKSTRA](https://ir.cwi.nl/pub/9256/9256D.pdf): A Note on Two Problems in Connexion with Graphs
4949
- [A*](https://ieeexplore.ieee.org/abstract/document/4082128?casa_token=0ltx8josfO0AAAAA:nA2z0T2qvr00C6rIhIM3Z7GhWJTQpFrYsdzpY9xc_VicZ0DZr5Q9KcclJT1215N3If6pae87MXRHHd0): A Formal Basis for the Heuristic Determination of Minimum Cost Paths
5050
- [LPA*](https://www.cs.cmu.edu/~maxim/files/aij04.pdf): Lifelong Planning A*
51-
- [RRT](https://www.cs.csustan.edu/~xliang/Courses/CS4710-21S/Papers/06%20RRT.pdf): Rapidly-exploring random trees: A new tool for path planning
51+
- [RRT](https://journals.sagepub.com/doi/pdf/10.1177/02783640122067453?casa_token=fgVkbBjl93wAAAAA:xatnfEy0HmRWnZyzPcPMHoWpW2ch4WIFYY1SSVT-OjyVKidKavkiE7D3QMl3cHSpof4BlXQcSVzhbvo): Randomized kinodynamic planning
5252
- [RRT*](https://journals.sagepub.com/doi/abs/10.1177/0278364911406761): Sampling-based algorithms for optimal motion planning

config/rrt.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

config/rrt_star.ini

Lines changed: 0 additions & 5 deletions
This file was deleted.

figures/img0.png

44.2 KB
Loading

include/Game.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace path_finding_visualizer {
1515

1616
static const std::vector<std::string> PLANNER_NAMES{"BFS", "DFS", "DIJKSTRA",
17-
"A*"};
18-
enum PLANNERS_IDS { BFS, DFS, DIJKSTRA, AStar };
17+
"A*", "RRT", "RRT*"};
18+
enum PLANNERS_IDS { BFS, DFS, DIJKSTRA, AStar, RRT, RRT_STAR };
1919

2020
class Game {
2121
public:

include/States/Algorithms/GraphBased/BFS/BFS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BFS : public GraphBased {
2424

2525
// override render functions
2626
virtual void renderNodes() override;
27+
virtual void renderParametersGui() override;
2728

2829
// BFS algorithm function
2930
virtual void solveConcurrently(

include/States/Algorithms/GraphBased/GraphBased.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class GraphBased : public State {
3333
void render() override;
3434

3535
// virtual functions
36+
virtual void clearObstacles();
3637
virtual void renderGui();
38+
// render planner specific parameters
39+
virtual void renderParametersGui() = 0;
3740
virtual void renderNodes() = 0;
3841
virtual void updateNodes() = 0;
3942
virtual void initAlgorithm() = 0;

include/States/Algorithms/SamplingBased/RRT/RRT.h

Lines changed: 80 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
#include <random>
44
#include <set>
55

6-
#include "SamplingBased.h"
6+
#include "States/Algorithms/SamplingBased/SamplingBased.h"
77

8-
class RRT : public SamplingBased {
9-
private:
10-
// vertices & edges
11-
std::vector<std::shared_ptr<Point>> vertices_;
12-
std::vector<std::pair<std::shared_ptr<Point>, std::shared_ptr<Point>>> edges_;
13-
14-
int max_vertices_;
15-
double delta_q_;
16-
double goal_radius_;
17-
18-
// background text
19-
sf::Text maxVerticesText_;
20-
sf::Text noOfVerticesText_;
8+
namespace path_finding_visualizer {
9+
namespace sampling_based {
2110

11+
class RRT : public SamplingBased {
2212
public:
2313
// Constructor
2414
RRT(sf::RenderWindow *window, std::stack<std::unique_ptr<State>> &states);
@@ -27,28 +17,86 @@ class RRT : public SamplingBased {
2717
virtual ~RRT();
2818

2919
// override initialization functions
30-
void initialize() override;
31-
void initAlgorithm() override;
20+
virtual void initialize() override;
21+
virtual void initPlanner() override;
22+
virtual void initParameters() override;
3223

3324
// override render functions
34-
void renderBackground() override;
35-
void renderAlgorithm() override;
25+
virtual void renderPlannerData() override;
26+
virtual void renderParametersGui() override;
3627

3728
// override algorithm function
38-
void solveConcurrently(
39-
std::shared_ptr<Point> start_point, std::shared_ptr<Point> goal_point,
29+
virtual void solveConcurrently(
30+
std::shared_ptr<Vertex> start_point, std::shared_ptr<Vertex> goal_point,
4031
std::shared_ptr<MessageQueue<bool>> message_queue) override;
4132

42-
// new background related functionsm
43-
void initBackgroundText();
44-
void updateBackgroundText();
45-
46-
// new functions
47-
void sample_free(Point &point);
48-
void nearest(std::shared_ptr<Point> &x_near, const Point &x_rand);
49-
void steer(std::shared_ptr<Point> &x_new,
50-
const std::shared_ptr<Point> &x_near, const Point &x_rand);
51-
bool isCollision(const std::shared_ptr<Point> &x_near,
52-
const std::shared_ptr<Point> &x_new);
53-
std::vector<double> linspace(double start, double end, int num);
33+
/**
34+
* @brief Randomly sample a vertex
35+
* @param v Sampled vertex
36+
*/
37+
void sample(const std::shared_ptr<Vertex> &v);
38+
39+
/**
40+
* @brief Find the nearest neighbour in a tree
41+
* @param v Nearest vertex
42+
*/
43+
void nearest(const std::shared_ptr<const Vertex> &x_rand,
44+
std::shared_ptr<Vertex> &x_near);
45+
46+
/**
47+
* @brief The cost to come of a vertex (g-value)
48+
*/
49+
double cost(std::shared_ptr<Vertex> v);
50+
51+
/**
52+
* @brief The euclidean distance between two vertices
53+
*/
54+
double distance(const std::shared_ptr<const Vertex> &v1,
55+
const std::shared_ptr<const Vertex> &v2);
56+
57+
/**
58+
* @brief Check whether collision or not between two vertices
59+
* This function assumes from_v vertex is collision-free
60+
* @param from_v Starting vertex
61+
* @param to_v Ending vertex
62+
* @return true if there is a collision otherwise false
63+
*/
64+
bool isCollision(const std::shared_ptr<const Vertex> &from_v,
65+
const std::shared_ptr<const Vertex> &to_v);
66+
67+
/**
68+
* @brief Find the new interpolated vertex from from_v vertex to to_v
69+
* vertex
70+
* @param from_v Starting vertex
71+
* @param to_v Ending vertex
72+
* @param t Interpolation distance
73+
* @param v New vertex
74+
*/
75+
void interpolate(const std::shared_ptr<const Vertex> &from_v,
76+
const std::shared_ptr<const Vertex> &to_v, const double t,
77+
const std::shared_ptr<Vertex> &v);
78+
79+
/**
80+
* @brief Check whether a vertex lies within goal radius or not
81+
*/
82+
bool inGoalRegion(const std::shared_ptr<const Vertex> &v);
83+
84+
protected:
85+
/**
86+
* @brief Interpolation distance during collsion checking
87+
*/
88+
double interpolation_dist_;
89+
90+
/**
91+
* @brief Maximum distance allowed between two vertices
92+
*/
93+
double range_;
94+
95+
/**
96+
* @brief Distance between vertex and goal
97+
*/
98+
double goal_radius_;
5499
};
100+
101+
} // namespace sampling_based
102+
} // namespace path_finding_visualizer

include/States/Algorithms/SamplingBased/RRT_STAR/RRT_STAR.h

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,72 @@
22

33
#include <random>
44

5-
#include "SamplingBased.h"
6-
7-
class RRT_STAR : public SamplingBased {
8-
private:
9-
// vertices & edges
10-
std::vector<std::shared_ptr<Point>> vertices_;
11-
std::vector<std::pair<std::shared_ptr<Point>, std::shared_ptr<Point>>> edges_;
12-
13-
// rrt-star related
14-
int max_vertices_;
15-
double delta_q_;
16-
double goal_radius_;
17-
double rewireFactor_;
18-
double maxDistance_;
19-
double r_rrt_;
5+
#include "States/Algorithms/SamplingBased/RRT/RRT.h"
206

21-
// background text
22-
sf::Text maxVerticesText_;
23-
sf::Text noOfVerticesText_;
7+
namespace path_finding_visualizer {
8+
namespace sampling_based {
249

10+
class RRT_STAR : public RRT {
2511
public:
2612
// Constructor
27-
RRT_STAR(sf::RenderWindow *window,
28-
std::stack<std::unique_ptr<State>> &states);
13+
RRT_STAR(sf::RenderWindow* window,
14+
std::stack<std::unique_ptr<State>>& states);
2915

3016
// Destructor
3117
virtual ~RRT_STAR();
3218

33-
// override initialization functions
34-
void initialize() override;
35-
void initAlgorithm() override;
19+
virtual void renderParametersGui() override;
3620

37-
// override render functions
38-
void renderBackground() override;
39-
void renderAlgorithm() override;
21+
// override initialization functions
22+
virtual void initialize() override;
23+
virtual void initPlanner() override;
24+
virtual void initParameters() override;
4025

4126
// override algorithm function
42-
void solveConcurrently(
43-
std::shared_ptr<Point> start_point, std::shared_ptr<Point> goal_point,
27+
virtual void solveConcurrently(
28+
std::shared_ptr<Vertex> start_point, std::shared_ptr<Vertex> goal_point,
4429
std::shared_ptr<MessageQueue<bool>> message_queue) override;
4530

46-
// new background related functionsm
47-
void initBackgroundText();
48-
void updateBackgroundText();
49-
50-
// new functions
51-
void sample_free(Point &point);
52-
void nearest(std::shared_ptr<Point> &x_near, const Point &x_rand);
53-
void near(std::vector<std::shared_ptr<Point>> &X_near,
54-
const std::shared_ptr<Point> &x_new);
55-
void steer(std::shared_ptr<Point> &x_new,
56-
const std::shared_ptr<Point> &x_near, const Point &x_rand);
57-
bool isCollision(const std::shared_ptr<Point> &x_near,
58-
const std::shared_ptr<Point> &x_new);
59-
std::vector<double> linspace(double start, double end, int num);
60-
double cost(std::shared_ptr<Point> p);
61-
double l2_Distance(const std::shared_ptr<Point> &p1,
62-
const std::shared_ptr<Point> &p2);
31+
/**
32+
* @brief Find all the nearest neighbours inside the radius of particular
33+
* vertex provided
34+
* @param x_new Target vertex
35+
* @param X_near Vector of nearest neighbours
36+
*/
37+
void near(const std::shared_ptr<const Vertex>& x_new,
38+
std::vector<std::shared_ptr<Vertex>>& X_near);
39+
40+
/**
41+
* @brief Calculate r_rrt_ based on current measure
42+
*/
43+
void updateRewiringLowerBounds();
44+
45+
protected:
46+
/**
47+
* @brief Find best goal parent at every n iteration
48+
*/
49+
unsigned int update_goal_every_;
50+
51+
/**
52+
* @brief Rewiring lower bound constant
53+
*/
54+
double r_rrt_;
55+
56+
/**
57+
* @brief Rewiring factor
58+
*/
59+
double rewire_factor_;
60+
61+
/**
62+
* @brief Measure (i.e., n-dimensional volume) of the current state space
63+
*/
64+
double current_measure_;
65+
66+
/**
67+
* @brief Vertices that lie within the goal radius
68+
*/
69+
std::vector<std::shared_ptr<Vertex>> x_soln_;
6370
};
71+
72+
} // namespace sampling_based
73+
} // namespace path_finding_visualizer

0 commit comments

Comments
 (0)