TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
FrontierExplorer< T > Class Template Reference

Generic exploration and frontier-based SLAM utility for grid or occupancy maps. More...

#include <FrontierExplorer.h>

Inheritance diagram for FrontierExplorer< T >:
Inheritance graph
[legend]
Collaboration diagram for FrontierExplorer< T >:
Collaboration graph
[legend]

Public Member Functions

 FrontierExplorer (IMap< T > &map)
 Construct a FrontierExplorer with a given map (by reference).
 
void setCurrentPosition (const Coordinate< T > &pos)
 Set the current position of the explorer.
 
Coordinate< T > getCurrentPosition () const
 Get the current position of the explorer.
 
void setStrategy (FrontierSelectionStrategy strategy)
 Set the strategy for selecting the next frontier cell.
 
FrontierSelectionStrategy getStrategy () const
 Get the current frontier selection strategy.
 
bool getNextFrontier (Coordinate< T > &nextCell)
 Provides the next frontier cell to explore based on the current strategy.
 
size_t size () const
 Provides the number of potential frontier cells found in the last search.
 
virtual void setCurrentPosition (const Coordinate< T > &pos)=0
 
virtual Coordinate< T > getCurrentPosition () const =0
 
virtual bool getNextFrontier (Coordinate< T > &nextCell)=0
 

Protected Member Functions

bool selectRandom (Coordinate< T > &nextCell)
 
bool selectNearest (Coordinate< T > &nextCell)
 
bool selectFarthest (Coordinate< T > &nextCell)
 
bool selectFirst (Coordinate< T > &nextCell)
 
bool selectLast (Coordinate< T > &nextCell)
 
bool selectCustom (Coordinate< T > &nextCell)
 
void setSelectCallback (int(*cb)(std::vector< Coordinate< T > > &frontiers, void *ref), void *ref=nullptr)
 Set a custom callback for selecting the next frontier cell. You can implement your own optimization strategy here.
 
void collectFrontiers ()
 Find all frontier cells in the map (cells adjacent to unknown space).
 

Protected Attributes

Coordinate< T > current_pos {}
 
FrontierSelectionStrategy strategy_ = FrontierSelectionStrategy::RANDOM
 
bool switchFirstLast = false
 
size_t record_count_ = 0
 
IMap< T > & map_
 
std::vector< Coordinate< T > > frontiers
 
void * ref = this
 
int(* select_callback )(std::vector< Coordinate< T > > &frontiers, void *ref) = nullptr
 

Detailed Description

template<typename T = DistanceM>
class tinyrobotics::FrontierExplorer< T >

Generic exploration and frontier-based SLAM utility for grid or occupancy maps.

Implements IFrontierExplorer for flexible autonomous exploration.

Template Parameters
TScalar type for coordinates and map (e.g., float, DistanceM). Default: DistanceM.

Constructor & Destructor Documentation

◆ FrontierExplorer()

FrontierExplorer ( IMap< T > &  map)
inline

Construct a FrontierExplorer with a given map (by reference).

Parameters
mapThe map to explore (must outlive this object).

Member Function Documentation

◆ collectFrontiers()

void collectFrontiers ( )
inlineprotected

Find all frontier cells in the map (cells adjacent to unknown space).

A frontier cell is defined as a cell that is FREE (traversable) and has at least one neighboring cell (in any of the 8 directions) that is UNKNOWN (unexplored). This method iterates over every cell in the map, and for each FREE cell, checks all 8 neighbors. If any neighbor is UNKNOWN, the cell is added to the internal frontiers vector. Each cell is considered only once, so no duplicates occur.

This is a key step in frontier-based exploration and SLAM, as it identifies the boundary between explored and unexplored space, guiding the robot to new areas.

After calling this method, the frontiers vector will contain all current frontier coordinates, which can then be used by the exploration strategy to select the next goal.

◆ getCurrentPosition()

Coordinate< T > getCurrentPosition ( ) const
inlinevirtual

Get the current position of the explorer.

Returns
The current position.

Implements IFrontierExplorer< T >.

◆ getNextFrontier()

bool getNextFrontier ( Coordinate< T > &  nextCell)
inlinevirtual

Provides the next frontier cell to explore based on the current strategy.

Parameters
nextCellOutput parameter for the selected frontier cell.
Returns
true if a frontier was found, false otherwise.

Implements IFrontierExplorer< T >.

◆ getStrategy()

FrontierSelectionStrategy getStrategy ( ) const
inline

Get the current frontier selection strategy.

Returns
The current strategy.

◆ setCurrentPosition()

void setCurrentPosition ( const Coordinate< T > &  pos)
inlinevirtual

Set the current position of the explorer.

Parameters
posThe current position.

Implements IFrontierExplorer< T >.

◆ setSelectCallback()

void setSelectCallback ( int(*)(std::vector< Coordinate< T > > &frontiers, void *ref)  cb,
void *  ref = nullptr 
)
inlineprotected

Set a custom callback for selecting the next frontier cell. You can implement your own optimization strategy here.

Parameters
cbThe callback function (returns index of selected cell).

◆ setStrategy()

void setStrategy ( FrontierSelectionStrategy  strategy)
inline

Set the strategy for selecting the next frontier cell.

Parameters
strategyThe selection strategy to use.

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