|
bitsim
Model, simulate, estimate and control robots in C++
|
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:
The first two are maps the robot is given; the last two are maps it builds.
| 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.
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:
BoxWorld::warehouse() is the 8 x 5 m warehouse the planning, mapping and SLAM examples share.
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* |
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.
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.
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.
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.
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.
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.