image thumbnail

2D Local Grid Map

version (1.15 MB) by Alireza
This code is a Matlab implementation of 2D Local Grid Map


Updated 31 Aug 2015

View License

In this experiment, L by L meters surrounding environment of a mobile robot is presented in the form of a grid. The data is acquired using a 2D laser range finder (LRF) mounted in front of a robot to scan horizontal plane. The 2D laser range finder provides 180 points per reading, 1 point per degree. Range data further than 40 meters is disregarded since it may contain false measurement caused by laser beam passing through glass or mirror reflection. Laser hitting points located inside the local grid are directly used for computing the local grid, and points outside the local grid (> 10m) and within the threshold (< 40m) are interpolated and points on the border of the local grid are used instead. The desired end points input to the Bresenham's line algorithm to indicate free and occupied cells. Bresenham's line algorithm determines which cells on the 2-dimensional grid should be selected to form a close approximation to a straight line between laser origin and end point. The end points on the boarder of the local grid map are used to determine free cells and end points positioned inside the grid are used to determine free and occupied cells. For having a consistent local map it is needed to continuously integrate a new local grid into the previous local grid map. This is done by rotation and translation of the previous grid map on the new computed grid. The difference between the robot poses in two consecutive frames is used to compute the transformation matrix. The odometry data provides robot's pose. The robot pose is defined by (x, y, \theta) where x and y are coordinates relative to some known start point and \theta is the robot's heading. After transformation, it is needed to update the map values. Free and occupancy counters are defined, and counter values are updated using Reflectation mapping policy: C = hit /(hit + miss). Where hit represents the number of times a beam ended in that cell while miss stands for the number of times a beam passed through that grid cell.
Inputs are: laser range data (L) and estimated odometry (X)
Output is: local occupancy grid map
The functions are:
init - initialize mapping
mp - build current local grid map from laser data
prc - load and pre-process data
shw - show grid map, laser points, robot locations, and current robot direction
trns - transform map t-1 on map t
upd - update current local map
The code runs on Linux/Windows with MATLAB R2013a
it needs "Piotr's Image&Video Toolbox Version 3.01" for transformation
a dataset "" is included so you can simply run Demo.m
The data used in this work comes from the robotics course by Dr. Mohan Sridharan
Here you can see the video result:

Cite As

Alireza (2022). 2D Local Grid Map (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Bresenham's Line

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!