Go to the documentation of this file.
53 return 1.0 - (1.0 / (1.0 + std::exp(l)));
63 return std::log(p / (1.0 - p));
78 const sensor_msgs::LaserScan::ConstPtr& scan,
81 const auto psg = grid.
world2Grid(pose(0), pose(1));
84 std::cout <<
"WARNING: Cannot update map robot is not within bounds" << std::endl;
91 const auto range_max = scan->range_max;
92 const auto range_min = scan->range_min;
94 auto beam_angle = scan->angle_min;
97 for (
unsigned int i = 0; i < scan->ranges.size(); i++)
99 if ((scan->ranges.at(i) > range_max) || (scan->ranges.at(i) < range_min))
101 beam_angle += scan->angle_increment;
107 const auto ptg = grid.
world2Grid(pt(0), pt(1));
113 rayTrace(grid, psg.at(1), psg.at(0), ptg.at(1), ptg.at(0));
121 std::cout <<
"WARNING: Skipping range measurement, not within bounds" << std::endl;
124 beam_angle += scan->angle_increment;
143 for (
auto y = y0; y > y1; y--)
152 for (
auto y = y0; y < y1; y++)
168 for (
auto x = x0; x > x1; x--)
177 for (
auto x = x0; x < x1; x++)
187 else if (std::abs(dy) < std::abs(dx))
210 else if (std::abs(dy) > std::abs(dx))
233 else if (std::abs(dy) == std::abs(dx))
241 throw std::invalid_argument(
"Invalid Bresenham's Line Algorithm State");
257 auto D = 2 * dy - dx;
263 for (
auto x = x0; x < x1; x++)
295 auto D = 2 * dx - dy;
301 for (
auto y = y0; y < y1; y++)
323 const auto dx = x1 - x0;
324 const auto dy = y1 - y0;
326 const auto xi = (dx < 0) ? -1 : 1;
327 const auto yi = (dy < 0) ? -1 : 1;
332 while (x != x1 and y != y1)
bool gridBounds(unsigned int i, unsigned int j) const
Test if coordinates are within the grid.
unsigned int grid2RowMajor(unsigned int i, unsigned int j) const
Converts grid indices to row major order index.
void rayTrace(GridMap &grid, int x0, int y0, int x1, int y1) const
Bresenham's line algorithm on occupancy map.
double prob2LogOdds(double p)
Convert probability to log odds.
void updateCell(GridMap &grid, int x, int y, double log) const
Update grid cell probability of occupancy.
void lineHigh(GridMap &grid, int x0, int y0, int x1, int y1) const
Bresenham's algorithm for drawing lines upward.
void lineLow(GridMap &grid, int x0, int y0, int x1, int y1) const
Bresenham's algorithm for drawing lines downward.
std::vector< unsigned int > world2Grid(double x, double y) const
Convert world coordinates to row and column index in grid.
bool updateMap(GridMap &grid, const sensor_msgs::LaserScan::ConstPtr &scan, const vec &pose)
Update the occupancy grid map.
vec polar2CartesianHomo(double angle, double range)
Convert polar to cartesian homogenous coordinates.
Useful numerical utilities.
void lineDiag(GridMap &grid, int x0, int y0, int x1, int y1) const
Bresenham's algorithm for drawing lines at +/- 45 deg.
mat transform2d(double x, double y, double angle)
Construct 2D transformation matrix.
double logOdds2Prob(double l)
Convert log odds to a probability.
double getCell(double x, double y) const
Get the value of the cell at a specified position.
OccupancyMapper(const mat &Tbs)
Constructor.