bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::planning::RRT Class Reference

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 &parameters, 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].

Detailed Description

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.

Member Typedef Documentation

◆ FreeTest

using bitsim::planning::RRT::FreeTest = std::function<bool(const Point &)>

Whether a point is free of obstacles.

◆ Point

using bitsim::planning::RRT::Point = std::array<real_t, 2>

Constructor & Destructor Documentation

◆ RRT()

bitsim::planning::RRT::RRT ( const Point & lower,
const Point & upper,
FreeTest is_free,
const Parameters & parameters,
uint_t seed = 42 )
Parameters
lowerThe lower left corner of the space to sample [m]
upperThe upper right corner [m]
is_freeThe test of a point
parametersHow to grow the tree
seedFor the random points, so that a run can be repeated

Member Function Documentation

◆ is_segment_free()

bool bitsim::planning::RRT::is_segment_free ( const Point & a,
const Point & b ) const

Whether the straight segment from a to b is free, checked every collision_step.

◆ length()

real_t bitsim::planning::RRT::length ( const std::vector< Point > & path)
static

The length of a path [m].

◆ n_iterations()

uint_t bitsim::planning::RRT::n_iterations ( ) const
inlinenoexcept

The iterations the last plan() took.

◆ path()

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.

◆ plan()

bool bitsim::planning::RRT::plan ( const Point & start,
const Point & goal )

Grow a tree from start to goal. Returns whether it reached the goal.

◆ shortcut()

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.

◆ tree()

const std::vector< Node > & bitsim::planning::RRT::tree ( ) const
inlinenoexcept

The tree of the last plan().


The documentation for this class was generated from the following files: