Table of Contents

Homework 03 - ICP SLAM

Error in aro_slam/launch/icp_slam.launch:
Line loss: point_to_point should read loss: $(arg loss)

Simultaneous Localization and Mapping (SLAM)

When a robot explores an unknown environment, it has to simultaneously acquire a map of the environment and localize itself within the map, hence the name Simultaneous Localization and Mapping (SLAM). We will focus on the online SLAM problem in which we are interested only in the current robot pose and map given all previous measurements. In other words, past robot poses are not updated when new measurements arrive.

One can find many approaches both in literature and deployed in field. Main differences come from the sensors used (camera, lidar, sonar, etc.) and the assumptions taken (2D vs 3D, static vs dynamic world). A few of them can be seen in action below:

We will implement a ROS node similar to the ICP Mapper above but we will restrict ourselves to two dimensions, localizing and mapping only in horizontal x-y plane, as the TurtleBots in the labs are only equipped with 2D lidar and can operate only on a flat ground.

The main building block for localization is an algorithm for alignment of two point clouds. Robot can be localized either by aligning each new input point cloud to some previous input point cloud (frame-to-frame) or to a map built from previously aligned measurements (frame-to-map).

Iterative Closest Point (ICP)

Optimal least-squares alignment $\mathtt{R}^*, \mathtt{t}^* = \mathrm{argmin}_{\mathtt{R}, \mathtt{t}} \sum_i \|\mathtt{R}\mathtt{x}_i + \mathtt{t} - \mathtt{y}_i \|^2$ of corresponding points $\{(\mathtt{x}_i, \mathtt{y}_i)\}_i$, $\mathtt{x}_i \in \mathcal{X} \subseteq \mathbb{R}^D$, $\mathtt{y}_i \in \mathcal{Y} \subseteq \mathbb{R}^D$, can be found using the absolute orientation [1] algorithm described in the lecture.

The Iterative Closest Point (ICP) [2] algorithm provides an approximate solution when the correspondences $(\mathtt{x}_i, \mathtt{y}_i)$ are not known in advance. Instead, it solves the correspondence and alignment problem iteratively, with ad hoc correspondences $(\mathtt{x}_i, \mathrm{argmin}_{\mathtt{y}\in\mathcal{Y}}\|\mathtt{R}\mathtt{x}_i + \mathtt{t} - \mathtt{y}\|)$ using alignment $\mathtt{R}, \mathtt{t}$ from the previous iteration. In the first iteration, an initial estimate or identity $\mathtt{R} = \mathtt{I}$, $\mathtt{t} = \mathtt{0}$ can be used.

Recall the ICP algorithm from the lecture. Note that we will provide the ICP algorithm with an initial estimate of the transform which does not have to be identity. This initial alignment is to be applied to the input points $\mathtt{x}_i$ prior the nearest neighbor search.

Algorithm Outline

Outlier Rejection

When the robot is exploring an unknown environment, some measured points correspond to the previously unseen areas and for these points true correspondences cannot be found. In some cases, such as going through a narrow opening such as a door, the relative overlap can easily decrease almost to a half. To handle incomplete overlaps between the point clouds, we will employ the following outlier rejection strategy in the ICP algorithm.

Let $\mathcal{C} = \{(\mathtt{x}_i$, $\mathtt{y}_i)\}_i$ be the set of correspondences from the nearest neighbor search and $d_i$ the distance between corresponding points, $d_i = \|\mathtt{x}_i - \mathtt{y}_i\|$. Inlier distance threshold can be adjusted adaptively using $p$-quantile of the distances $d_i$, $Q_d(p)$: $d_\mathrm{inl} = \min(r Q_d(p), d_\mathrm{max})$ where $r$ is a multiplier and $d_\mathrm{max}$ the maximum allowed inlier distance.

In our icp_slam node, these constants corresponds to the following parameters:

Improvements

Occupancy Mapping

Localization is used to build occupancy grid map for frontier detection and path planning from registered scans. Occupancy mapping is implemented in a separate node, occupancy_mapper, which is provided and need not be changed.

The occupancy model of each grid cell $b_i$ is updated with every scan: the cells containing the measured points have their probability of being occupied increased and other cells incident with the rays from the sensor towards these points have their probability of being occupied decreased.

Additive updates take form of $\Delta b_i = \log \frac{p(o_i|\mathtt{z}_{t})}{p(\neg o_i|\mathtt{z}_{t})} + \log \frac{p(\neg o_i)}{p(o_i)} $. See the lecture.

The occupancy values are clipped to interval $[b_\mathrm{low}, b_\mathrm{high}]$ to avoid accumulating overconfident occupancy belief and allow to handle dynamic objects. We use unit updates $\Delta b_i \in \{-1, 1\}$ and let parameters $b_\text{low}$, $b_\text{high}$, $b_\text{occupied}$ be tuned to get the required trade-off between noise removal and response time to dynamic changes in the environment.

Major limitation of the provided implementation is the fact that the scene is discretized to cells of a given size and spatial distribution of surfaces within the cells are not modeled. As a result, a ray with high angle of incidence may pass through many cells, which it marks as empty, before it reaches the measured cell, and the previously occupied cells it passes through may incorrectly switch to empty state. A workaround in frontier detection may be needed to deal with such cases.

Prerequisities

TF Transforms

Point Cloud Representation

Nearest neighbors can efficiently be found using KD-tree and its query method.

Assignment

Workspace Configuration

Enter Singularity shell:

singularity shell /opt/singularity/robolab/noetic

Configure workspace with the provided aro_slam package:

ws=~/workspace/aro
mkdir -p "${ws}/src"
cd "${ws}/src"
curl -sSL https://cw.fel.cvut.cz/b212/_media/courses/b3m33aro/tutorials/hw_02_pkgs.zip -O
unzip hw_02_pkgs.zip
curl -sSL https://cw.fel.cvut.cz/b212/_media/courses/b3m33aro/tutorials/aro_slam.zip -O
unzip aro_slam.zip
wstool init
wstool merge aro_slam/dependencies.rosinstall
wstool up -j 4
cd "${ws}"
catkin init
catkin config --extend /opt/ros/aro
catkin config --cmake-args -DCMAKE_BUILD_TYPE=Release
catkin build -c

Package Structure

Get familiar with the package. The structure of the package is as follows:

Package Usage

Don't forget to source your workspace:

source "${ws}/devel/setup.bash"

To test the icp_slam node in simulator:

roslaunch aro_slam sim.launch odom:=true world:=aro_maze_1 keyboard:=true
It also runs keyboard (and joypad) controls, so you can manually move the robot using keyboard (keys WASDX) if the terminal is focused. Worlds to test: stage_1, stage_2, stage_3, stage_4, world, aro_maze_1, aro_maze_2.

Or, launch the SLAM pipeline alone (no controls):

roslaunch aro_slam aro_slam.launch

See the launch files for possible arguments.

Absolute Orientation (2 point)

Implement (and test) absolute orientation algorithm for alignment with known correspondences in the absolute_orientation function in file aro_slam/src/aro_slam/icp.py.

Point-to-Point ICP (3 points)

Implement (and test) the ICP algorithm for alignment without known correspondences using position descriptors and point-to-point loss in the icp function in file aro_slam/src/aro_slam/icp.py.

Test and debug above functionality within the icp_slam node.

Point-to-Plane ICP (2 point)

Add point-to-plane loss to the icp function as described above.

Custom Descriptor (1 point)

Allow using a custom descriptor in the icp function. Use estimated surface normal vectors along with point positions as descriptors. See the position function used as the default descriptor in the icp function as an example.

Mapping with Frame-to-Map Alignment (1 point)

Build a map from registered measurements and use it as a reference for aligning the input point clouds, instead of a previous key frame. Add only the points which are at least mapping_min_dist (= node parameter) meters far from the current points in the map. Implement this functionality in the icp_slam node itself (file path aro_slam/scripts/icp_slam).

SLAM Accuracy Evaluation (1 point)

Record bag files with robot exploring various worlds and evaluate various SLAM configurations on the bag files. You can use scripts/eval_slam script as a template for testing various parameter settings and computing accuracy statistics. Include the CSV file with reported results, aro_slam/data/results/summary.csv, and briefly summarize the results in text file aro_slam/data/results/summary.txt.

Recording can be done using the additional record:=true argument to sim.launch:

roslaunch aro_slam sim.launch odom:=true world:=aro_maze_1 keyboard:=true record:=true

Instructions

Compress the whole aro_slam package with your implementation and results excluding bag files into a zip archive and upload it into Brute.

The implementation should be based on the provided ''aro_slam'' package template.

See video for an example run with the robot.

References

[1] K. Arun, T. S. Huang, and S. D. Blostein, “Least-squares fitting of two 3-d point sets,” Pattern Analysis and Machine Intelligence, IEEE Transactions on, vol. PAMI-9, no. 5, pp. 698–700, 1987.

[2] Y. Chen and G. Medioni, “Object modelling by registration of multiple range images,” Image and Vision Computing, vol. 10, no. 3, pp. 145–155, 1992.