[Dprglist] Need help with getting a map of the house usingRPLidarwith RPi

Chris N netterchris at gmail.com
Sun Nov 21 20:06:00 PST 2021


Cyrill Stachniss has a number of 5-minute video “lectures” on different topics, including one on occupancy grid maps.  https://youtu.be/8ckhPViqneg

With a bit of searching, I’m sure you’ll find enough bits and pieces of python code that illustrate how to do generate a grid map, given the robot’s pose and the laser scan as inputs.

If your odometry is very good, this will probably produce decent results.  Big if…..

In practice, odometry will be less than perfect, and that’s why many of the “name-brand” mapping solutions (gmapping, hector mapping,  google cartographer, etc.) employ localization, i.e. they are doing SLAM.  This essentially allows them to deal with odometry drift (and some will even work w/ out any wheel odometry).  

My point is this:  putting something together for scratch or semi-from-scratch that illustrates the principle of occupancy grid mapping is probably not that hard, and surely satisfying, but making it work well is probably more effort than figuring out how to use / integrate an existing solution.

“existing solution” doesn’t need to imply ROS – most of the algorithms that are available in “ROS format”, also exist as standalone implementations somewhere……

Chris.

From: Thalanayar Muthukumar
Sent: Sunday, November 21, 2021 2:17 PM
To: Chris N
Cc: DPRG
Subject: Re: [Dprglist] Need help with getting a map of the house usingRPLidarwith RPi

Thanks Chris for sharing your experiences.
https://www.youtube.com/watch?v=qT5PWlmwydc (~30 secs) - RPLidar mounted on my robot 
It is ready to move around the house

"you need to take the robot’s actual current pose (x, y, theta) into account" - need to figure out how to do this

On Sun, Nov 21, 2021 at 12:52 PM Chris N <netterchris at gmail.com> wrote:
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/a35c50fd/attachment.html>


More information about the DPRGlist mailing list