Skip to content

Commit 8240f1e

Browse files
committed
Add rrt and rrt*
1 parent 3845f8d commit 8240f1e

File tree

14 files changed

+675
-907
lines changed

14 files changed

+675
-907
lines changed
File renamed without changes.

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: 4 additions & 4 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

@@ -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.

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/SamplingBased/RRT/RRT.h

Lines changed: 78 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,84 @@ 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;
3222

3323
// override render functions
34-
void renderBackground() override;
35-
void renderAlgorithm() override;
24+
virtual void renderPlannerData() override;
3625

3726
// override algorithm function
38-
void solveConcurrently(
39-
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,
4029
std::shared_ptr<MessageQueue<bool>> message_queue) override;
4130

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

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

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,69 @@
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

3319
// override initialization functions
34-
void initialize() override;
35-
void initAlgorithm() override;
36-
37-
// override render functions
38-
void renderBackground() override;
39-
void renderAlgorithm() override;
20+
virtual void initialize() override;
21+
virtual void initPlanner() override;
4022

4123
// override algorithm function
42-
void solveConcurrently(
43-
std::shared_ptr<Point> start_point, std::shared_ptr<Point> goal_point,
24+
virtual void solveConcurrently(
25+
std::shared_ptr<Vertex> start_point, std::shared_ptr<Vertex> goal_point,
4426
std::shared_ptr<MessageQueue<bool>> message_queue) override;
4527

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);
28+
/**
29+
* @brief Find all the nearest neighbours inside the radius of particular
30+
* vertex provided
31+
* @param x_new Target vertex
32+
* @param X_near Vector of nearest neighbours
33+
*/
34+
void near(const std::shared_ptr<const Vertex>& x_new,
35+
std::vector<std::shared_ptr<Vertex>>& X_near);
36+
37+
/**
38+
* @brief Calculate r_rrt_ based on current measure
39+
*/
40+
void updateRewiringLowerBounds();
41+
42+
protected:
43+
/**
44+
* @brief Find best goal parent at every n iteration
45+
*/
46+
unsigned int update_goal_every_;
47+
48+
/**
49+
* @brief Rewiring lower bound constant
50+
*/
51+
double r_rrt_;
52+
53+
/**
54+
* @brief Rewiring factor
55+
*/
56+
double rewire_factor_;
57+
58+
/**
59+
* @brief Measure (i.e., n-dimensional volume) of the current state space
60+
*/
61+
double current_measure_;
62+
63+
/**
64+
* @brief Vertices that lie within the goal radius
65+
*/
66+
std::vector<std::shared_ptr<Vertex>> x_soln_;
6367
};
68+
69+
} // namespace sampling_based
70+
} // namespace path_finding_visualizer

0 commit comments

Comments
 (0)