Product
October 30, 2023

Looking to build a map for your autonomous robot? Here’s your guide to SLAM and Cartographer

Written by
Esha Maharishi
Product Manager

The next time you step into your local burger joint, your burger may be served up with a side of blinking digital lights and the gentle whir of wheels. That is, you may find that your waiter is actually a delivery robot!

Autonomous robots are increasingly present in our everyday human environments—they’re delivering food to tables at restaurants, bringing towels and toiletries to guests in hotels, and greeting customers at banking locations.
Naturally, for robots to operate efficiently in any given environment, they need a map to guide them. That’s why we’re exploring how to quickly create a navigational map for an autonomous robot using Viam.

In this post, we’ll cover the following:

  • What is SLAM?
  • What is Cartographer?
  • How do you make a map using Cartographer?

Let’s dive in.

What is SLAM?

SLAM is a technological mapping method that allows robots and other autonomous vehicles to build a map and localize themselves on that map at the same time. In general, a SLAM algorithm:

  • Takes input from cameras and sensors.
  • Outputs a map of the surveyed area.
  • Defines the robot’s position in the map.

To learn more about SLAM and Viam’s approach to it, check out our documentation.

What is Cartographer?

Released by Google in 2016, Cartographer is a type of SLAM algorithm that uses a process called scan matching to create a map. It’s generally considered one of the best open-source SLAM algorithms available for use! 

For Cartographer in particular, the main inputs are scans from a 2D or 3D LiDAR.

LiDARs are sensors that send out laser beams and measure how long it takes for the light to be reflected back. They output a “point cloud” of points around the LiDAR that represent occupied space.

2D LiDAR output of a hallway
3D LiDAR output of a hallway

This algorithm can also optionally take data from an inertial measurement unit (IMU) and odometry source. An IMU provides another estimate of the robot’s angular velocity and linear acceleration, and an odometry source provides another estimate of the robot’s position and orientation relative to where it started. These help Cartographer refine the map and trajectory estimates made based on the LiDAR.

Now that you know the basics, let’s make a map with it.

How do you make a map using Cartographer?

To show the ease of creating a Cartographer map with Viam, I’m mapping our office—a large space with a series of complex V-shapes for the robot to explore.

The final map I created using Cartographer on Viam.

Since Viam’s Cartographer module runs in the cloud (to avoid overloading the CPU on the robot), it does involve a small cost–see Viam’s pricing for more info.

But before I could start making the map, I had to set up my hardware and software.

Putting together the hardware

Since I was mapping Viam’s whole office, which is a fairly large space, I used mid-range hardware. For a smaller, less complex space (like an NYC apartment), less expensive hardware would work just fine. 

Here’s the hardware I used:

Once I plugged the RPlidar and IMU via the USB cord to the Jetson Nano, I was ready to tackle the software side of the build.

The rover that would be tasked to map our office.

Connecting it to the software

Moving on to the software integration, my journey was relatively turnkey, thanks to Viam's comprehensive built-in resources and the Modular Registry. With these features, the whole process took me a few hours versus the typical several days to complete.

Viam's Modular Registry stands out as a key feature, allowing developers to publish, exchange, and utilize modules tailored for enhancing hardware components and services in smart machines. It transforms the integration of new components and services into a process as intuitive as software coding itself.

The module for Cartographer found in the Modular Registry.

After I created a robot on app.viam.com, I used not one but three modules–two components and one algorithm—alongside built-in hardware components all found easily through app.viam.com’s web UI.

When my robot was configured with the appropriate elements, it was time for the fun part: driving around and making the map!

Making the map

I drove around the office slowly, making smooth turns:

And the map continued to update in the UI:

The map from my session was saved to my online “library” of maps, so if I needed to update it further or wanted to deploy it down for a robot to use for localization, it would be easily accessible.

Wrapping it all up

While making a map is just the first step in building the kinds of autonomous robots that will become increasingly a part of our lives, it was amazing to see how simple and accessible it can be to do so with Viam’s platform.

We’re so excited to continue building out the platform–to make the mapping experience even more smooth and joyful and create a simple way to manage a fleet of autonomous robots

Dive into our documentation to create your own map using Cartographer, then drop us a line on Viam’s Discord. We’d love to see the maps you create.

on this page

Get started with Viam today!