C++ implementation of RRT, RRT*, and Informed-RRT* as a shared library which are sampling-based path planning methods, and it supports any dimensions
- Implement
examples/path-planner-3D
- adopt python API (Python.h) and use matplotlib in order to plot 3D graph
- Provided as a shared library usable in C++14 or higher
- You can execute at any dimensions without recompiling the shared library
The following software packages are required for building the shared library
- A C++ compiler with C++14 or higher support
- CMake 3.0 or higher
- Eigen 3.0 or higher
If you would like to compile the example programs, add the following:
- OpenCV 3.0 or higher
The shared library (libplanner.so) can be build with following commands
$ git clone git@github.com:kyk0910/sampling-based-planners.git
$ cd sampling-based-planners/lib
$ mkdir build && cd build
$ cmake ..
$ make
The example program can be run with following commands after build the shared library
$ cd <top of this repository>
$ git submodule update --init
$ cd examples/<example program directory>
$ mkdir build && cd build
$ cmake ..
$ make
#include <planner.h>
namespace planner = pln
// difinition of two-dimensional space
const int DIM = 2;
pln::EuclideanSpace space(DIM);
// definition of bounds of each dimension
std::vector<pln::Bound> bounds{pln::Bound(0, 100.0),
pln::Bound(0, 100.0)};
// set bounds to space
space.setBound(bounds);
// definition of obstacle (point cloud type)
std::vector<pln::PointCloudConstraint::Hypersphere> obstacles;
obstacles.emplace_back(pln::State(10.0, 20.0), 10.0); // x : 10.0, y : 20.0, radius : 10.0
obstacles.emplace_back(pln::State(50.0, 70.0), 20.0); // x : 50.0, y : 70.0, radius : 20.0
obstacles.emplace_back(pln::State(-10.0, 120.0), 30.0); // there is no probrem out of range
// definition of constraint using std::shared_ptr
auto constraint = std::make_shared<pln::PointCloudConstraint>(space, obstacles)
// read image
auto world = cv::imread("./example.png", CV_8UC1);
// definition of constraint array
std::vector<pln::ConstraintType> map(world.cols * world.rows, pln::ConstraintType::ENTAERABLE);
for(int yi = 0; yi < world.rows; yi++) {
for(int xi = 0; xi < world.cols; xi++) {
if(world.data[xi + yi * world.cols] != 255) {
map[xi + yi * world.cols] = pln::ConstraintType::NOENTRY;
}
}
}
std::vector<uint32_t> each_dim_size{(uint32_t)world.cols, (uint32_t)world.rows};
// definition of constraint using std::shared_ptr
auto constraint = std::make_shared<pln::SemanticSegmentConstraint>(space, map, each_dim_size);
// definition of planner (you can set some parameters at optional argument)
pln::RRTStar planner(DIM);
// set constraint
planner.setProblemDefinition(constraint);
// definition of start and goal state
pln::State start(5.0, 5.0);
pln::State goal(90.0, 90.0);
// solve
bool status = planner.solve(start, goal);
if(status) {
auto result = planner.getResultRef();
for(const auto& r : result) {
std::cout << r << std::endl;
}
}
else {
std::cout << "Could not find path" << std::endl;
}
Execute path planning on two-dimensional space
MIT