bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
Maps

A map is what a robot knows about where it can go. A planner searches it for a path; an estimator measures the robot against it. bitsim holds a map in one of four ways:

  • geometry, the obstacles as exact shapes: BoxWorld;
  • an occupancy grid, the floor cut into cells that are free or occupied: OccupancyGrid;
  • a probabilistic occupancy grid, each cell the probability that it is occupied, built from range scans: ProbabilityGrid;
  • a landmark map, the positions of things the robot can recognise, built together with the robot's own pose by SLAM: EKFSlam.

The first two are maps the robot is given; the last two are maps it builds.

The maps at a glance

Map Holds Built from Used by Examples
BoxWorld a rectangle with box obstacles, a robot radius, a start and a goal the shapes, by hand RRT, through its point test; and as the true world a simulated sensor measures Planning a path with a random tree, Building a map from range scans, Mapping with EKF-SLAM
OccupancyGrid free or occupied, a cell a BoxWorld, rectangles and circles, or a ProbabilityGrid the grid planners Planning a path on a grid
ProbabilityGrid the probability a cell is occupied, or unknown range scans from known poses an OccupancyGrid, by a threshold Building a map from range scans
EKFSlam the robot's pose and every landmark's position, with one covariance odometry, and sightings of the landmarks the robot itself, to know where it is Mapping with EKF-SLAM, EKF-SLAM without landmark ids: data association

All of them are in metres, in the plane.

Geometry: BoxWorld

BoxWorld is the world [0, width] x [0, height] with axis-aligned boxes in it, the shelves and walls of a warehouse, and a round robot of a given radius. It answers three questions, one for each kind of user:

  • is_free(p): is the robot's centre clear of everything at p? This is all a sampling planner, RRT, needs;
  • occupancy_grid(cell_size): the world cut into cells, the obstacles and walls grown by the robot's radius, for a grid planner;
  • ray_cast(origin, angle, max_range): how far a beam goes before it hits something, which is what a range sensor would measure.
using namespace bitsim::planning;
// 4 x 3 m with one box, a robot of radius 0.2 m, from (0.5, 0.5) to (3.5, 2.5)
const BoxWorld world(4.0, 3.0, {{1.5, 0.0, 2.0, 2.0}}, 0.2, {0.5, 0.5}, {3.5, 2.5});
const bool clear = world.is_free({1.0, 1.0});
const OccupancyGrid grid = world.occupancy_grid(0.1); // 40 x 30 cells of 10 cm
const auto beam = world.ray_cast({0.5, 1.0}, 0.0, 5.0); // beam.hit, beam.distance: 1.0 m
A rectangular slice of the plane with axis-aligned box obstacles, a start and a goal.
Definition box_world.h:29
bool is_free(const Point &p) const
True if a disc of the given radius centred at p touches no obstacle and no outer wall....
Definition box_world.h:68
A rectangle of the plane cut into square cells, each free or occupied.
Definition occupancy_grid.h:43
Definition a_star_search.cpp:8
grid(layout_path, episode_path, out, title)
Definition multi_agent_gif.py:36

BoxWorld::warehouse() is the 8 x 5 m warehouse the planning, mapping and SLAM examples share.

Occupancy grids

OccupancyGrid cuts a rectangle of the plane into square cells, each free or occupied. Cell (0, 0) has its lower left corner at the grid's origin; columns grow with x, rows with y. Obstacles go on as rectangles and circles: every cell whose centre is inside one is occupied.

A robot is not a point. To plan it as one, the obstacles are grown by its radius before they go on the grid; then any free cell is a place its centre can be. BoxWorld::occupancy_grid grows the boxes as rectangles. Growing each occupied cell by a disc of the radius instead, as Building a map from range scans does, is the exact clearance of a round robot, and rounds the corners.

From a cell the robot moves to its 8 neighbours, or to the 4 that share a side, but never diagonally past the corner of an occupied cell. The grid planners all search these moves:

Planner Finds Expands
bfs_grid, breadth-first a path with the fewest moves; not the shortest in metres everything within the goal's number of moves, in every direction
a_star_grid with weight 0, Dijkstra a shortest path everything closer than the goal, in every direction
a_star_grid, A* a shortest path far fewer cells, led by the straight-line distance to the goal
a_star_grid with weight > 1 a path, perhaps longer fewer still
theta_star_grid, Theta* a shorter path, at any angle, through a few corners about as many as A*
const GridCell start = grid.to_cell(world.start()[0], world.start()[1]);
const GridCell goal = grid.to_cell(world.goal()[0], world.goal()[1]);
const auto path = a_star_grid(grid, start, goal); // path.found, path.path, path.cost
const auto any_angle = theta_star_grid(grid, start, goal); // its path is the corners
SearchResult< GridCell > theta_star_grid(const OccupancyGrid &grid, const GridCell &start, const GridCell &goal)
Theta*: any-angle search on an occupancy grid.
Definition grid_search.cpp:136
SearchResult< GridCell > a_star_grid(const OccupancyGrid &grid, const GridCell &start, const GridCell &goal, bool diagonal, real_t weight)
A* on an occupancy grid, moving to the neighbours of a cell (see OccupancyGrid::neighbours) with the ...
Definition a_star_search.cpp:10
A cell of an OccupancyGrid: its column, along x, and row, along y.
Definition occupancy_grid.h:21

a_star itself works on any graph: give it the start, the goal, and functions for the neighbours, the cost of a move and the heuristic.

Building a grid from range scans

A robot does not start with a grid; it measures one. ProbabilityGrid keeps, for every cell, the probability that it is occupied. Each beam of a range scan makes the cells it passed through a little more likely free, and the cell it ended on, if it struck something, a little more likely occupied. The probabilities are kept as log-odds, \(\log\frac{p}{1-p}\), so that folding in a beam is an addition, and clamped, so that a cell can change its mind. A cell no beam has reached stays unknown: the inside of a shelf, the far side of a wall.

// a little larger than the room, so that its walls land inside the grid
ProbabilityGrid map(50, 40, 0.1, -0.5, -0.5);
// a scan from the pose (x, y, heading): beam i along heading + bearings[i] measured ranges[i]
map.integrate_scan({2.0, 1.5, 0.0}, bearings, ranges, 6.0);
// for a planner: occupied if at least 0.5 likely; unknown cells occupied, the safe choice
const OccupancyGrid built = map.to_occupancy_grid(0.5, true);
An occupancy map built from range sensors, each cell holding the probability that it is occupied.
Definition probability_grid.h:33

The poses of the scans have to be known. When they are not, the map and the poses have to be worked out together: that is SLAM.

Landmark maps and SLAM

A landmark map is a list of things the robot can recognise, posts, markers, corners, and where they are. It says nothing about the free space between them, but it is small, and it is what a robot needs to find itself.

EKFSlam is simultaneous localisation and mapping with an extended Kalman filter. Its state is the robot's pose followed by the position of every landmark mapped so far, with one covariance over all of it, and it grows with each new landmark. Odometry moves the robot and makes it less sure of where it is; a sighting of a landmark, its range and bearing, maps the landmark the first time and corrects the robot, and every landmark tied to it, the next. When the robot comes back to where it started and sees its first landmarks again, the correction runs through the whole map: the loop closes.

EKFSlam slam({0.5, 0.5, 0.0}, EKFSlam::Parameters{}); // the start is the map's origin
slam.predict(0.03, 0.01); // the odometry of a step: 3 cm, 0.01 rad
slam.update({{7, 2.1, 0.4}}); // landmark 7 at 2.1 m, 0.4 rad to the left
const auto where = slam.landmark(7); // its position, and landmark_covariance(7)
const auto robot = slam.pose(); // and pose_covariance()
Simultaneous localisation and mapping with an extended Kalman filter: a robot works out where it is a...
Definition ekf_slam.h:145
void predict(real_t distance, real_t turn)
Move the robot with the odometry of one step: it drove distance [m] and turned by turn [rad].
Definition ekf_slam.cpp:166
where(plane)
Definition grid_world_gif.py:37

With update() every landmark has an id, as a fiducial marker does. Without ids the filter has to decide which landmark a sighting is of, or whether it is a new one, data association, and update_unknown() does it by the Mahalanobis distance: the difference between what was seen and what was expected, measured against how uncertain both are. A threshold in metres cannot be right everywhere, as EKF-SLAM without landmark ids: data association shows: a tight one maps the same landmark again when the robot has drifted, a wide one confuses landmarks that stand close together.

Which map

  • The world is known, a warehouse with a plan: give it as a BoxWorld, and plan on its OccupancyGrid, or with RRT on its point test when the space has more dimensions than a grid can hold.
  • The poses are known, the world is not, a robot with good localisation surveying a room: build a ProbabilityGrid from its scans, and plan on the grid it thresholds to.
  • Neither is known: SLAM. EKFSlam builds a landmark map and keeps the robot in it; its cost grows as the cube of the number of landmarks, which is fine for tens of them.

Distance fields, which hold each cell's distance to the nearest obstacle, quadtrees, and graphs of places are other common maps that bitsim does not have yet.