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

A rectangle of the plane cut into square cells, each free or occupied. More...

#include <occupancy_grid.h>

Public Member Functions

 OccupancyGrid (uint_t n_cols, uint_t n_rows, real_t cell_size, real_t x0=0.0, real_t y0=0.0)
uint_t n_cols () const noexcept
uint_t n_rows () const noexcept
real_t cell_size () const noexcept
bool in_bounds (const GridCell &c) const noexcept
bool is_free (const GridCell &c) const noexcept
 True if the cell is in the grid and not occupied.
void set_occupied (const GridCell &c, bool occupied=true)
void add_rectangle (real_t x_min, real_t y_min, real_t x_max, real_t y_max)
 Occupy the cells whose centres are in the rectangle [x_min, x_max] x [y_min, y_max].
void add_circle (real_t x, real_t y, real_t radius)
 Occupy the cells whose centres are within radius of (x, y).
GridCell to_cell (real_t x, real_t y) const noexcept
 The cell that the point (x, y) is in. It may be out of bounds.
std::array< real_t, 2 > to_world (const GridCell &c) const noexcept
 The centre of a cell [m].
std::vector< GridCell > neighbours (const GridCell &c, bool diagonal=true) const
 The free cells next to c: the four that share a side, and with diagonal the four that share a corner as well. A diagonal move is left out when either cell it passes between is occupied, so a path never cuts the corner of an obstacle.
uint_t n_occupied () const
 The number of occupied cells.

Detailed Description

A rectangle of the plane cut into square cells, each free or occupied.

Cell (0, 0) has its lower left corner at the origin given to the constructor; columns grow with x and rows with y. Obstacles are added as rectangles and circles: every cell whose centre is inside one is occupied. To keep a robot of radius r clear of the obstacles, grow them by r when adding them.

Constructor & Destructor Documentation

◆ OccupancyGrid()

bitsim::planning::OccupancyGrid::OccupancyGrid ( uint_t n_cols,
uint_t n_rows,
real_t cell_size,
real_t x0 = 0.0,
real_t y0 = 0.0 )
Parameters
n_colsThe number of columns, along x
n_rowsThe number of rows, along y
cell_sizeThe side of a cell [m]
x0The x of the lower left corner of the grid [m]
y0The y of the lower left corner of the grid [m]

Member Function Documentation

◆ add_circle()

void bitsim::planning::OccupancyGrid::add_circle ( real_t x,
real_t y,
real_t radius )

Occupy the cells whose centres are within radius of (x, y).

◆ add_rectangle()

void bitsim::planning::OccupancyGrid::add_rectangle ( real_t x_min,
real_t y_min,
real_t x_max,
real_t y_max )

Occupy the cells whose centres are in the rectangle [x_min, x_max] x [y_min, y_max].

◆ cell_size()

real_t bitsim::planning::OccupancyGrid::cell_size ( ) const
inlinenoexcept

◆ in_bounds()

bool bitsim::planning::OccupancyGrid::in_bounds ( const GridCell & c) const
noexcept

◆ is_free()

bool bitsim::planning::OccupancyGrid::is_free ( const GridCell & c) const
noexcept

True if the cell is in the grid and not occupied.

◆ n_cols()

uint_t bitsim::planning::OccupancyGrid::n_cols ( ) const
inlinenoexcept

◆ n_occupied()

uint_t bitsim::planning::OccupancyGrid::n_occupied ( ) const

The number of occupied cells.

◆ n_rows()

uint_t bitsim::planning::OccupancyGrid::n_rows ( ) const
inlinenoexcept

◆ neighbours()

std::vector< GridCell > bitsim::planning::OccupancyGrid::neighbours ( const GridCell & c,
bool diagonal = true ) const

The free cells next to c: the four that share a side, and with diagonal the four that share a corner as well. A diagonal move is left out when either cell it passes between is occupied, so a path never cuts the corner of an obstacle.

◆ set_occupied()

void bitsim::planning::OccupancyGrid::set_occupied ( const GridCell & c,
bool occupied = true )

◆ to_cell()

GridCell bitsim::planning::OccupancyGrid::to_cell ( real_t x,
real_t y ) const
noexcept

The cell that the point (x, y) is in. It may be out of bounds.

◆ to_world()

std::array< real_t, 2 > bitsim::planning::OccupancyGrid::to_world ( const GridCell & c) const
noexcept

The centre of a cell [m].


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