[Dprglist] Need help with getting a map of the house using RPLidarwith RPi
Chris N
netterchris at gmail.com
Sun Nov 21 10:52:02 PST 2021
Kumar,
What you are looking for is called an “occupancy grid map”. There are other types of maps, but the occupancy grid map is conceptually the easiest one to understand and work with I believe.
Conceptually, its straight forward how it is created. This type of map is really no different from an image – every pixel corresponds to, for example, one square inch of space, and the pixel values correspond to definitely empty (black), definitely something there (white), unsure (grey).
In a way, it is just an extension of the real-time display code that you have running. The key differences between real-time display of lidar data and using this data to build a map are:
a) For map making, you need to take the robot’s actual current pose (x, y, theta) into account. (For real-time display, you essentially pretend your robot is always at x,y=0,0 and orientation= 0 degrees)
b) For map making, you remember the point that is drawn into the map, instead of starting with a clean canvas every cycle
c) For map making, the size of your map needs to be larger than the range of your Lidar, otherwise it won’t be of much use.
You have 3 options:
1) Create the algorithm more or less completely from scratch or adapt some sample code that seems to be easy enough to work with. I’m sure such sample code for python and C++ is out there…. Quick google search found this python code for example: An occupancy grid mapping example · GitHub. It says “# This is an implementation of Occupancy Grid Mapping as Presented in Chapter 9 of "Probabilistic Robotics" By Sebastian Thrun et al. In particular, this is an implementation of Table 9.1 and 9.2”
2) Find a library that contains the necessary building blocks. Maybe all you need is a ready to use grid map data structure along with an API for putting things into that grid map. Or maybe the library also provides functions that take care of all the processing of the laser scan data. Etc, etc. Then figure out how to use this library. MRPT comes to mind but there are probably others. MRPT – Empowering C++ development in robotics. OpenSLAM.org (openslam-org.github.io) is also a possible resource.
3) Use ROS and pick one of the mapping algorithms that are available, such as
a. Gmapping
b. Google cartographer
c. etc
I have gone down road # 1 and road # 2 some 5+ years ago, but I did not reach my destination ☹ I probably didn’t try hard enough…..
I have also started going down road #3 on more than one occasion, but find my self often going in circles and not getting anywhere ☹
I find that no matter which road you take, it requires a substantial time commitment to fully master the underlying technologies. I find that unless I’m at it every day, I start to forget things I’ve learned….
Chris.
From: Thalanayar Muthukumar via DPRGlist
Sent: Sunday, November 21, 2021 12:36 PM
To: DPRG
Subject: [Dprglist] Need help with getting a map of the house using RPLidarwith RPi
https://learn.adafruit.com/slamtec-rplidar-on-pi/cpython-on-raspberry-pi - The relevant code is below
def process_data(data):
global max_distance
lcd.fill((0,0,0))
for angle in range(360):
distance = data[angle]
if distance > 0: # ignore initially ungathered data points
max_distance = max([min([5000, distance]), max_distance])
radians = angle * pi / 180.0
x = distance * cos(radians)
y = distance * sin(radians)
point = (160 + int(x / max_distance * 119), 120 + int(y / max_distance * 119))
lcd.set_at(point, pygame.Color(255, 255, 255))
pygame.display.update()
This code is used to update the TFT display and is working for me. Instantaneously, the RPLidar's surroundings are displayed on the TFT display. I would like to adapt this to move the RPLidar through the rooms of the house to create a map. @Chris - Any suggestions or pointers? I do not have ROS installed. Regards. - Kumar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dprg.org/pipermail/dprglist-dprg.org/attachments/20211121/062a90b3/attachment.html>
More information about the DPRGlist
mailing list