|
bitsim
Model, simulate, estimate and control robots in C++
|
A rapidly exploring random tree in the plane. More...
#include <rrt.h>
Classes | |
| struct | Parameters |
| struct | Node |
| A node of the tree: where it is, and the index of its parent; the root is its own parent. More... | |
Public Types | |
| using | Point = std::array<real_t, 2> |
| using | FreeTest = std::function<bool(const Point &)> |
| Whether a point is free of obstacles. | |
Public Member Functions | |
| RRT (const Point &lower, const Point &upper, FreeTest is_free, const Parameters ¶meters, uint_t seed=42) | |
| bool | plan (const Point &start, const Point &goal) |
| Grow a tree from start to goal. Returns whether it reached the goal. | |
| const std::vector< Node > & | tree () const noexcept |
| The tree of the last plan(). | |
| std::vector< Point > | path () const |
| The path of the last plan() from the start to the goal, both included; empty if the goal was not reached. | |
| uint_t | n_iterations () const noexcept |
| The iterations the last plan() took. | |
| bool | is_segment_free (const Point &a, const Point &b) const |
| Whether the straight segment from a to b is free, checked every collision_step. | |
| std::vector< Point > | shortcut (const std::vector< Point > &path) const |
| A shorter path through the same free space: from each point of the path, go straight to the furthest later point that a free segment reaches. RRT paths zigzag, and this takes most of the zigzag out. | |
Static Public Member Functions | |
| static real_t | length (const std::vector< Point > &path) |
| The length of a path [m]. | |
A rapidly exploring random tree in the plane.
The tree starts at the start. At each iteration it picks a random point of the bounds, or the goal with probability goal_bias, finds the node of the tree nearest to it, and grows a branch of at most step towards it, if the branch is free. It stops when a new node is within goal_radius of the goal and the last stretch to the goal is free, or after max_iterations.
The tree samples the free space instead of cutting it into cells, so it needs only a test of whether a point is free, and it works as well in many dimensions as in two. Its paths are not the shortest, and each run with a different seed finds a different one.
| using bitsim::planning::RRT::FreeTest = std::function<bool(const Point &)> |
Whether a point is free of obstacles.
| using bitsim::planning::RRT::Point = std::array<real_t, 2> |
| bitsim::planning::RRT::RRT | ( | const Point & | lower, |
| const Point & | upper, | ||
| FreeTest | is_free, | ||
| const Parameters & | parameters, | ||
| uint_t | seed = 42 ) |
| lower | The lower left corner of the space to sample [m] |
| upper | The upper right corner [m] |
| is_free | The test of a point |
| parameters | How to grow the tree |
| seed | For the random points, so that a run can be repeated |
Whether the straight segment from a to b is free, checked every collision_step.
The length of a path [m].
|
inlinenoexcept |
The iterations the last plan() took.
| std::vector< RRT::Point > bitsim::planning::RRT::path | ( | ) | const |
The path of the last plan() from the start to the goal, both included; empty if the goal was not reached.
Grow a tree from start to goal. Returns whether it reached the goal.
| std::vector< RRT::Point > bitsim::planning::RRT::shortcut | ( | const std::vector< Point > & | path | ) | const |
A shorter path through the same free space: from each point of the path, go straight to the furthest later point that a free segment reaches. RRT paths zigzag, and this takes most of the zigzag out.
|
inlinenoexcept |
The tree of the last plan().