Ubuntu Linux for Robotics · Lesson 77 of 96
Map server
Map files, loading them with nav2_map_server and checking the origin and resolution.
Estimated time · 30–45 min
Learning goals
What you will understand
- Explain map server in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
A map is an image plus a YAML file with the image name, resolution (metres per pixel), origin and thresholds. nav2_map_server loads it and publishes nav_msgs/OccupancyGrid on /map with transient-local QoS, so late subscribers still receive it. It is a lifecycle node and must be configured and activated (the lifecycle manager does this).
Wrong resolution or origin shifts every plan. Check with ros2 topic echo /map --once --field info and in RViz2 that known walls are where you expect. Store maps together with the world they describe and give them versions.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the map server commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
ros2 run nav2_map_server map_server --ros-args -p yaml_filename:=$HOME/maps/office.yaml
# Load a map.
ros2 lifecycle set /map_server configure
# Configure the server.
ros2 lifecycle set /map_server activate
# Activate it so it publishes /map.
ros2 topic echo /map --once --qos-durability transient_local --field info
# Check the map size, resolution and origin.
cat ~/maps/office.yaml
# Read the map's YAML file.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · Mobile robot
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Map server. Expected result: resolution: 0.05
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: print only the info field of one /map message (transient_local durability)Expected output
resolution: 0.05Stuck? Show the full solution (try it yourself first)
ros2 topic echo /map --once --qos-durability transient_local --field infoExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Load a map, read its info from the topic, compare the resolution and origin with the YAML file, and place a marker in RViz2 at a known location to check it.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.