Before the robot can drive anywhere on its own, it has to answer two questions all the time. How far have I moved since a moment ago? And where am I in the room? The first answer is called odometry. The second comes from a map. This chapter builds the first answer, three kinds of odometry, and sets up the mapping tools and the map the robot keeps. It does not give you a tested way to make a map of your own room. The only map I put on the robot was one I already had, and "The map itself" below says what that means for you.
Most of this chapter runs with the robot on its stand. One part needs it on the floor, with you next to it and the power switch in reach. Plan on an afternoon.
Most small robots know how far they've driven by counting wheel turns with encoders. This one can't. Its controller board has no encoders, and the motor command you met in chapter 6 is write-only: the board never reports anything back about the motors. So the driver does the only thing it can. It publishes the speed it told the wheels to go, on wheel/odom, after its own limits, ramps and deadman. When the wheels are disabled or e-stopped, that speed is zero. Hiwonder's factory software did the same thing.
A commanded speed is a guess, and mecanum wheels make it a poor one. On my hard floor a sideways move covered 73 to 81 percent of the commanded distance, and a forward move about 102 percent. On a rug the sideways number fell anywhere between 25 and 88 percent. The driver already multiplies the sideways speed by 0.765 for odometry only (the motors still get the full command), which is the average of four measured strafes. No single number is right every time.
Two cases make the guess plainly wrong. On the stand the wheels spin in the air, the commanded speed says the robot is moving, and wheel/odom happily drives away while the robot sits still. And when a wheel stalls against something, the command still says "moving". Once, at the edge of a rug, my robot was commanded at 0.11 m/s and really moved at 0.007 m/s. Only a sensor that looks at the room can catch that. That's why the robot also runs two real measurements next to the guess: one from the LiDAR and one from the camera.
The guess doesn't stand alone. The robot's gyro measures turning correctly, even on the stand. So the main odometry combines the commanded forward and sideways speeds with the gyro's turn rate. That combination is what the rest of the robot uses.
The combining is done by an extended Kalman filter, or EKF, from the robot_localization package. It keeps one best estimate of the robot's motion and updates it each time an input reports. Every input says how much to trust each number it sends, as a covariance, which is the square of the expected error. The driver says its speeds are good to about 0.05 m/s, so it sends 0.0025. For the position it integrated itself it sends 1000, which tells the filter to ignore it. The filter runs 50 times a second and publishes the result as /odometry/filtered and as the transform odom to base_link. That transform reads as "since I started, I've moved this far and turned this much".
Chapter 6 installed robot_localization with the other ROS packages. Check, and install only if it's missing:
dpkg -l ros-humble-robot-localization | tail -1
sudo apt-get install -y --no-install-recommends ros-humble-robot-localization
On my robot dpkg showed ii ros-humble-robot-localization 3.5.4, so the install had nothing to do. If apt then suggests apt autoremove, don't run it. On this robot it offers to remove initramfs-tools, which the Jetson needs to boot.
The filter's settings are in ~/ros2_ws/src/rosorin_base/config/ekf.yaml, which arrived with the package you copied in chapter 6. These are the lines that matter:
frequency: 50.0
two_d_mode: true
publish_tf: true
world_frame: odom
odom0: wheel/odom
odom0_config: [false, false, false, false, false, false,
true, true, false, false, false, false,
false, false, false]
imu0: imu/data_raw
imu0_config: [false, false, false, false, false, false,
false, false, false, false, false, true,
false, false, false]
two_d_mode tells the filter the robot lives on a flat floor, so it ignores height, roll and pitch. Each input gets a table of fifteen true or false values in a fixed order: position x, y, z, roll, pitch, yaw, then the same six as speeds, then three accelerations. From the wheels the filter takes only the forward and sideways speeds, the first two values of the second row. From the IMU it takes only the turn rate, the last value of the second row. The commanded turn rate is left out on purpose: the gyro measures turning, and the command only says what was asked for.
The filter runs inside the base launch file, so it's up whenever rosorin-base is. If your launch/base.launch.py doesn't have it yet, add this Node to the list, right after the robot_state_publisher Node:
Node(package='robot_localization', executable='ekf_node', name='ekf_filter_node',
parameters=[os.path.join(share, 'config', 'ekf.yaml')]),
Then rebuild, restart the base and look. The touch makes colcon copy the edited launch file, as in chapter 7:
cd ~/ros2_ws && touch src/rosorin_base/launch/base.launch.py
source /opt/ros/humble/setup.bash && colcon build --packages-select rosorin_base
sudo systemctl restart rosorin-base
sleep 12
source ~/ros2_ws/install/setup.bash
timeout 8 ros2 topic hz /odometry/filtered 2>/dev/null | tail -2
timeout 5 ros2 topic echo --once /odometry/filtered 2>&1 | head -12
timeout 6 ros2 run tf2_ros tf2_echo odom base_link 2>&1 | grep -A2 Translation | head -3
On my robot it printed:
average rate: 49.997
min: 0.019s max: 0.021s std dev: 0.00046s window: 304
frame_id: odom
child_frame_id: base_link
- Translation: [0.000, 0.000, 0.000]
About 50 Hz, the right two frames, and a translation of zero for a robot that hasn't moved. The base journal also shows [INFO] [ekf_node-3]: process started. If every topic reads nothing while rosorin-base is active, the Fast DDS shared memory was deleted when your last SSH session closed. That's the RemoveIPC=no setting from chapter 4; check that it's in place.
scripts/odom_test.py enables the wheels, drives three seconds forward, three seconds sideways and three seconds turning, disables the wheels after each move, and prints how far wheel/odom and the EKF each think the robot went. It shows you, in numbers, what the guess gets wrong.
Put the robot on its stand, wheels in the air, with nothing in reach of the arm and your hand near the power switch. Enabling the wheels moves the arm to the drive pose first, so keep clear of it. Nothing else may publish cmd_vel while it runs: the driver latches an e-stop the moment it sees a second publisher. If you've already installed navigation from chapter 10, stop rosorin-nav first and start it again afterwards.
From your laptop, copy the script over:
cd ~/CCode/rosorin-pro
scp scripts/odom_test.py rosorin:setup/
Then on the robot. The restart makes each run start from zero:
source /opt/ros/humble/setup.bash; source ~/ros2_ws/install/setup.bash
sudo systemctl restart rosorin-base && sleep 15 # each run starts from odom = 0
python3 ~/setup/odom_test.py
On my robot the forward move read 0.295 m from the wheels and 0.308 m from the EKF. I don't know where the extra 13 mm comes from. The sideways move read 0.227 m in both; 0.295 times the 0.765 scale is 0.226. The turn is the line to look at: the wheels claimed 84.35 degrees and the EKF said 0.04 degrees, because the gyro on a stand sees no turn. That's the filter doing its job. Afterwards the driver's state should read "enabled": false.
If the script aborts before sending anything, it waited ten seconds for the driver's topics and gave up; see the DDS note above. If an enable comes back False, the arm couldn't reach the drive pose, an e-stop is latched, or there is a second cmd_vel publisher.
Take two LiDAR scans a moment apart and slide one over the other until the walls line up. The slide is how far the sensor moved. That's scan matching, and it measures real motion, so a stalled wheel shows up as zero. Its weakness is geometry. If the walls look the same after the move, like a sideways slide along a plain wall, it can't tell that anything happened.
rf2o does this for 2D LiDARs. It isn't in apt for Humble, so you build it from source in its own workspace, ~/ext_ws, kept apart from your own code. The checkout pins the exact commit I built, so a change upstream can't change your build:
mkdir -p ~/ext_ws/src
git clone -b ros2 https://github.com/MAPIRlab/rf2o_laser_odometry.git ~/ext_ws/src/rf2o_laser_odometry
git -C ~/ext_ws/src/rf2o_laser_odometry checkout b38c68e
git -C ~/ext_ws/src/rf2o_laser_odometry log -1 --format="commit %h %cd"
source /opt/ros/humble/setup.bash
cd ~/ext_ws && colcon build --packages-select rf2o_laser_odometry --cmake-args -DCMAKE_BUILD_TYPE=Release
The checkout prints git's note about a "detached HEAD". That's expected. Then:
commit b38c68e Fri Apr 28 17:29:49 2023 +0200
Finished <<< rf2o_laser_odometry [58.3s]
Summary: 1 package finished [58.9s]
It needs Eigen, which was already on my robot (libeigen3-dev 3.4.0).
rf2o doesn't read range_min. So it sees the robot's own body, the 50 or so self-returns between 5 and 11 cm that you met in chapter 7, and matches them as part of the room. A body that never moves relative to the sensor pins the estimate. On my robot, with plain /scan, rf2o read 8 cm of a true 80 cm on every straight leg. The same scan with those beams set to infinity read 86 cm.
So the LiDAR reader publishes a second copy for rf2o, /scan_rf2o, with everything closer than range_min set to infinity. Check that your lidar_reader.py has these two pieces. The first goes after self.pub:
self.pub_rf2o = self.create_publisher(LaserScan, 'scan_rf2o', 10)
and the second at the end of publish(), after self.pub.publish(m):
m.ranges = [float('inf') if r < self.range_min else r for r in ranges]
self.pub_rf2o.publish(m)
/scan itself is unchanged. slam_toolbox and the costmaps skip short ranges on their own.
rf2o reads its settings from ~/ros2_ws/src/rosorin_base/config/rf2o.yaml. The important values are laser_scan_topic: /scan_rf2o, the copy above; publish_tf: false, because only one node may own odom to base_link and that's the EKF; odom_frame_id: odom_rf2o, its own frame name so its pose never gets mixed up with the EKF's; freq: 10.0, the LiDAR's own rate; and base_frame_id: laser. That last one makes rf2o report how the LiDAR itself moved, without ever asking TF where the LiDAR is mounted. When it asked, its single lookup at boot raced the static transform, and the sign of its output flipped from one restart to the next.
Because rf2o now reports the LiDAR's motion, a small node turns that into the motion of base_link. It's rosorin_base/rf2o_fix.py, already in your package. The LiDAR sits 4.8 cm ahead of base_link and is turned 180 degrees (chapter 7), so the node rotates the velocity by 180 degrees and removes the lever arm: when the body turns, a point 4.8 cm ahead of its centre also moves sideways. It works from velocities over a 0.3 s window instead of rf2o's own integrated pose, because that pose's translation came out reversed. A measured sign fix, SIGN = -1.0, came from one floor check. It publishes /odom_lidar.
Both nodes start from the base launch file. If yours doesn't have them, add these two Nodes right after the static_tf('tf_base_laser', ...) entry:
Node(package='rf2o_laser_odometry', executable='rf2o_laser_odometry_node', name='rf2o_laser_odometry',
parameters=[os.path.join(share, 'config', 'rf2o.yaml')], arguments=['--ros-args', '--log-level', 'warn']),
Node(package='rosorin_base', executable='rf2o_fix', name='rf2o_fix'),
rf2o is the first part of the base that lives in ~/ext_ws, so the base service has to source that workspace too, before your own, in both its start and its stop command. If you add the Nodes without this, the base, driver included, restarts forever with package 'rf2o_laser_odometry' not found. This edits the unit, and running it twice changes nothing:
sudo sed -i 's|source /opt/ros/humble/setup.bash \&\& source /home/burgerbarn/ros2_ws|source /opt/ros/humble/setup.bash \&\& source /home/burgerbarn/ext_ws/install/setup.bash \&\& source /home/burgerbarn/ros2_ws|' /etc/systemd/system/rosorin-base.service
sudo systemctl daemon-reload
grep -c ext_ws /etc/systemd/system/rosorin-base.service
The last line should print 2. Rebuild, restart and look:
cd ~/ros2_ws && touch src/rosorin_base/launch/base.launch.py
source /opt/ros/humble/setup.bash && colcon build --packages-select rosorin_base
sudo systemctl restart rosorin-base
sleep 12
source ~/ext_ws/install/setup.bash; source ~/ros2_ws/install/setup.bash
ros2 topic info /odom_rf2o
timeout 6 ros2 topic hz /odom_lidar 2>&1 | grep -m1 "average rate"
On my robot /odom_rf2o showed Publisher count: 1 and Subscription count: 1 (the subscriber is rf2o_fix), and /odom_lidar ran at average rate: 10.002. Standing still, its position stayed within about a millimetre of zero. The base was active with no failed units.
rf2o is not an input to the EKF. I tried it as one and took it out the same day, because it hadn't been proven on its own. /odom_lidar has no reader today. The raw /odom_rf2o is read by the contact reflex in chapter 10, which uses it with the camera odometry to notice commanded motion that isn't happening.
The third source tracks points in the camera image from frame to frame. With a depth value for each point, it works out how the camera moved from how the points shift. Like scan matching it measures real motion, and it sees sideways motion that a 2D LiDAR can miss. It needs a scene with some texture that stays still.
NVIDIA's cuVSLAM does this on the Jetson's GPU. The version in the Isaac ROS apt packages (chapter 10) bundles cuVSLAM 12, which only takes a stereo pair of images. Version 17, NVIDIA's Python wheel, has an RGB-D mode: one colour image plus an aligned depth image, which is exactly what the Aurora gives. I almost ruled cuVSLAM out after trying only the apt version. Check the current release and its modes before you decide an NVIDIA part can't do something.
The wheel is built for CUDA 12. It needs the CUDA 12.6 libraries and pip3, which chapter 8's install_vision.sh put on the robot. If you skipped that chapter, run that script first.
Download the wheel, check its hash and install it for your user. The wheel stays in ~/setup/wheels, so a reinstall doesn't depend on GitHub:
W=cuvslam-17.0.0+cu12-cp310-cp310-manylinux_2_35_aarch64.whl
mkdir -p ~/setup/wheels && cd ~/setup/wheels
[ -f "$W" ] || curl -sfL -o "$W" "https://github.com/nvidia-isaac/cuVSLAM/releases/download/v17.0.0/cuvslam-17.0.0%2Bcu12-cp310-cp310-manylinux_2_35_aarch64.whl"
ls -l; sha256sum "$W"
pip3 install --user "$W"
python3 -c "import cuvslam as v; print(v.__version__)"
The file should be 113,375,996 bytes, and the hash exactly this:
658250d97c96c5db0d61ed68d8c0e99514c130574339367f0d917ad60f05d315 cuvslam-17.0.0+cu12-cp310-cp310-manylinux_2_35_aarch64.whl
Successfully installed cuvslam-17.0.0+cu12
17.0.0
If Python says No module named 'cuvslam', the wheel went in for a different user. It's installed for burgerbarn, and the node has to run as that user.
rosorin_base/vslam_odom.py, already in your package, feeds the Aurora's colour and depth images to cuVSLAM and publishes how base_link moved on /odom_vslam. A few things in it matter.
It sets OPENBLAS_NUM_THREADS=1 before numpy loads. numpy's maths library otherwise starts worker threads that spin after every small matrix call. On my robot three of them burned 1.9 of the eight cores, while cuVSLAM itself used 0.16 of one.
It ignores the arm's own motion. The camera rides on the arm, so every frame the node asks TF where the camera is on the body. If the camera moved more than 3 mm or half a degree relative to the body since the last frame, the head is moving, and that frame and the next 0.4 s aren't counted. Whatever cuVSLAM says the camera did is then turned into how the body moved, keeping only x, y and heading. A step faster than 1.5 m/s or 4 rad/s is a tracking jump, far beyond what this robot can do, and is dropped. After 15 failed frames in a row, about a second, it starts a fresh tracker.
It uses the colour image, not the infrared one. The IR image looks like the obvious input, since it comes from the same sensor as the depth, pixel for pixel. But it also shows the camera's own projected dot pattern. The dots move with the camera, so cuVSLAM locks onto them and decides the camera isn't moving. During a 14.2 degree head turn the IR version measured 0.5 degrees. The colour image doesn't contain the pattern, and it measured 14.2 degrees for a 13.8 degree turn. The colour frame arrives about 70 ms after its depth frame, so the node pairs them within 0.09 s.
The node runs as its own service, systemd/rosorin-vslam.service:
[Unit]
Description=ROSOrin measured odometry from the depth camera (NVIDIA cuVSLAM RGB-D on the Aurora RGB + depth -> /odom_vslam)
After=rosorin-base.service rosorin-camera.service
Wants=rosorin-base.service rosorin-camera.service
[Service]
User=burgerbarn
Environment=ROS_DOMAIN_ID=0
ExecStart=/bin/bash -c 'source /opt/ros/humble/setup.bash && source /home/burgerbarn/ros2_ws/install/setup.bash && exec ros2 run rosorin_base vslam_odom'
KillSignal=SIGINT
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
It runs as burgerbarn because that's where the wheel is installed. Copy it from your laptop:
cd ~/CCode/rosorin-pro
scp systemd/rosorin-vslam.service rosorin:/tmp/
and install it on the robot:
sudo cp /tmp/rosorin-vslam.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now rosorin-vslam
sleep 12
systemctl is-active rosorin-vslam
journalctl -u rosorin-vslam -n 3 --no-pager -o cat
source /opt/ros/humble/setup.bash; source ~/ros2_ws/install/setup.bash
timeout 6 ros2 topic hz /odom_vslam 2>&1 | tail -2
On my robot:
Created symlink /etc/systemd/system/multi-user.target.wants/rosorin-vslam.service → /etc/systemd/system/rosorin-vslam.service.
active
Started ROSOrin measured odometry from the depth camera (NVIDIA cuVSLAM RGB-D on the Aurora RGB + depth -> /odom_vslam).
average rate: 13.561
Once a minute the journal shows a line like tracked 789 frames, head moves 0, jumps dropped 0, tracker restarts 0. The node used about a third of one core. Expect anywhere from 9 to 14 Hz. On an earlier build, with more programs reading the camera, it ran at 9.2 Hz, because readers of the large images lose frames through Fast DDS's default buffer. Nothing else read the camera when I measured the 13.6.
If vslam_odom uses one and a half to two cores while the robot stands still, the OPENBLAS_NUM_THREADS line isn't coming before import numpy. If there's no /odom_vslam at all, check the camera first with ros2 topic hz /aurora/rgb/image_raw, then TF: the node publishes nothing until it knows where the camera is on the body.
The stand can't tell you whether any of this is right, because nothing moves. This part drives the robot on the floor and compares all three sources. Two scripts do it. scripts/floor_odom_test.py compares the odometry with LiDAR scan matching between standing scans. scripts/tests/odom_truth.py drives out and back at two speeds, then four turns, and prints what the EKF, rf2o and the camera each measured, next to a LiDAR range taken straight ahead and the gyro. Neither needs anything from later chapters.
Take the robot off the stand and the charger, unplug the network cable, and set it on the floor with open space ahead. Stay next to it with the power switch in reach; that's the stop to count on. Any gamepad button except MODE is meant to latch an e-stop, but chapter 6 left that untested. Keep people out of the LiDAR's view, since someone walking past spoils the numbers.
Put the arm in the drive pose (chapter 7) with the camera straight ahead first. After the tuck, arm joint 1 has no torque, and on my first run the turns swung it 37 degrees to one side, which pointed the camera at the wall. The tuck can't be undone with arm/enable. The driver parameter drive_pan sets where joint 1 goes in the drive pose: 500 is straight ahead, and -1, the normal setting, leaves joint 1 where it is. This block moves the arm. The first line stops navigation; before chapter 10 there is no such unit, and its error is harmless:
sudo systemctl stop rosorin-nav
source /opt/ros/humble/setup.bash
ros2 param set /rosorin_board_driver drive_pan 500
timeout 30 ros2 service call /rosorin_board_driver/arm/drive std_srvs/srv/Trigger | grep -o "success=[A-Za-z]*"
ros2 param set /rosorin_board_driver drive_pan -- -1
You should see success=True, and joint 1 now holds. The last line puts drive_pan back to its normal setting.
From your laptop, copy the scripts. On the floor there's no cable, so use the Wi-Fi alias rosorin-wifi from chapter 5, here and for the session you run the tests in:
cd ~/CCode/rosorin-pro
ssh rosorin-wifi 'mkdir -p ~/setup/tests'
scp scripts/floor_odom_test.py scripts/stop_proof_floor.py rosorin-wifi:setup/ && scp scripts/tests/odom_truth.py rosorin-wifi:setup/tests/
odom_truth.py imports stop_proof_floor.py from the folder above its own, which is why both go over. Both scripts need numpy; odom_truth.py also needs OpenCV and floor_odom_test.py SciPy. floor_odom_test.py refuses a move with less than 0.6 m free in that direction. Run them one at a time. Each drives the wheels, so be ready at the power switch:
source /opt/ros/humble/setup.bash && source ~/ros2_ws/install/setup.bash
python3 ~/setup/floor_odom_test.py # moves 0 1 2: forward 0.3 m, strafe left 0.3 m, rotate +90 deg
python3 ~/setup/tests/odom_truth.py # out and back at 0.2 and 0.35 m/s, then four turns; or 'strafe', 'one <seconds>'
From floor_odom_test.py I got, forward: wheels 0.293 m, EKF 0.306 m, LiDAR 0.294 m. Sideways: wheels and EKF 0.226 m, LiDAR 0.241 m. Turning: wheels 89.0 degrees, EKF 84.9, and the LiDAR's angular shift 84 degrees. For the turn, the two lines labelled lidar as-is and mirror-y didn't converge; the angular-shift line is the one to read for turns. That line is also the check of the LiDAR's angle direction from chapter 7: its sign must match the gyro's turn, as mine did. Opposite signs mean the reader's clockwise setting is wrong.
From odom_truth.py, the four straight legs at 0.2 and 0.35 m/s read 80.2, 80.1, 103.8 and 94.6 cm on the camera, 78.7, 76.6, 101.9 and 99.1 cm on rf2o, and 79.8 to 102.6 cm on the EKF. rf2o's turns were within 2.2 degrees of the gyro and the camera's within 1.0. Standing still for ten seconds, rf2o drifted 0.1 cm. What you're looking for is rf2o within about 5 percent of the camera on every straight leg. If rf2o reads a few centimetres of an 80 cm leg, it's reading /scan, not /scan_rf2o; check with grep laser_scan_topic ~/ros2_ws/src/rosorin_base/config/rf2o.yaml. Get this right before chapter 10: its contact reflex trusts rf2o.
Don't trust the column labelled truth(LiDAR ray) blindly. It measures the change in one range straight ahead, and when something in that direction moves, or the target is uneven, it reads nonsense. Mine once said 288 cm for an 80 cm leg. The robot can't go further than it was commanded, so when that column reads more than the commanded distance, judge the leg against the camera instead. If a run prints NOT RUN - corridor ahead nearest ..., there was less than the leg's length plus 1.2 m clear ahead. A person standing in front does that too.
When you're done, start navigation again if you'd stopped it: sudo systemctl start rosorin-nav.
One more check, standing still. Read the heading from ros2 run tf2_ros tf2_echo odom base_link (the RPY line), leave the robot alone for five minutes, and read it again. Mine went from 0.351 to 0.369 degrees. Without the driver's gyro bias tracking (chapter 6), a standing robot's heading drifted 11.4 degrees in eight minutes.
Everything from here on was tested only with a map of my own room that I already had. The mapping tools below install and start, and a standing robot gets a small map of what one scan sees. Past that point the steps put my map in place, and they're no use for your room. Making a new map was never run on this build; what I know about it is under "Doesn't work yet".
A map here is a picture of the floor plan in 5 cm squares, called cells. Each cell is free, occupied (a wall, or a chair leg at LiDAR height) or unknown. It's stored as an image, white for free, black for occupied and grey for unknown, plus a small YAML file that says how big a cell is and where the image's corner sits in the room.
The map gets its own frame, map, which is fixed to the room and doesn't drift. Whatever finds the robot on the map publishes the transform map to odom. That's the correction that keeps pulling the drifting odometry back onto the room. The full chain is map to odom to base_link, then on to the LiDAR and the camera frames you set up in chapter 7.
Finding the robot on a map that isn't changing is called localization. Doing that while adding to the map is SLAM, simultaneous localization and mapping. slam_toolbox does both. It doesn't store the map as a picture. It stores a pose graph: the places where the robot stood, the LiDAR scan it saw at each, and how the places connect. When the robot comes back to a place it has seen, the matcher finds the overlap and adds a link, a loop closure, and the whole graph shifts slightly so the old and new views agree. The picture is drawn from the graph. The graph is saved as two files, <name>.posegraph and <name>.data, about 4 MB and 0.6 MB for my first room map. Only those two let slam_toolbox continue a map later. The image alone doesn't.
Chapter 6 installed it with the other ROS packages. Check, and install only if it's missing:
dpkg -l ros-humble-slam-toolbox | tail -1
sudo apt-get install -y --no-install-recommends ros-humble-slam-toolbox
dpkg -l | grep -c "^hi.*nvidia-l4t"
ls /opt/ros/humble/lib/slam_toolbox/
Mine showed version 2.6.10. The count of held NVIDIA packages must not drop. After chapter 8 it reads 46. Mine read 45 here, because I ran this step before the vision install, which holds one more package. The last line lists the programs:
async_slam_toolbox_node
localization_slam_toolbox_node
map_and_localization_slam_toolbox_node
merge_maps_kinematic
sync_slam_toolbox_node
This robot uses two of them: async_slam_toolbox_node to make a map from scratch, and map_and_localization_slam_toolbox_node for the map it keeps.
~/ros2_ws/src/rosorin_base/config/slam.yaml is slam_toolbox's own mapper_params_online_async.yaml from the apt package with six lines changed, each marked # rosorin. base_frame is base_link, because this robot has no base_footprint frame. min_laser_range is 0.12, the same as the LiDAR reader's range_min, so the robot's own body is ignored. max_laser_range is 8.0, about what the LiDAR reaches. enable_interactive_mode is off, since there's no RViz on the robot. minimum_travel_distance 0.2 and minimum_travel_heading 0.3 add a new place to the graph after 20 cm of travel or 0.3 radians of turning, which suits small rooms and a slow robot. The stock values worth knowing are 5 cm cells, map to odom published 50 times a second, and the /map picture republished every 5 seconds whether it changed or not.
launch/slam.launch.py starts only the mapping node, on top of the running base:
"""Online async SLAM (slam_toolbox, apt) on top of base.launch.py (scan + EKF odom->base_link).
Publishes map->odom and /map. Not started by rosorin-base.service: run on demand."""
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
share = get_package_share_directory('rosorin_base')
return LaunchDescription([
Node(package='slam_toolbox', executable='async_slam_toolbox_node', name='slam_toolbox',
output='screen', parameters=[os.path.join(share, 'config', 'slam.yaml')]),
])
Both files came with the package. Rebuild:
cd ~/ros2_ws && source /opt/ros/humble/setup.bash && colcon build --packages-select rosorin_base
With the wheels disabled, run the mapper for 40 seconds and see what it publishes. Standing still it can only map what one scan sees, which is enough to prove the chain works. If navigation from chapter 10 is already installed, stop rosorin-nav first, because it runs its own slam_toolbox under the same name.
source /opt/ros/humble/setup.bash; source ~/ros2_ws/install/setup.bash
timeout 40 ros2 launch rosorin_base slam.launch.py
In a second SSH session while it runs:
source /opt/ros/humble/setup.bash
timeout 8 ros2 topic echo --once /map --field info
timeout 6 ros2 run tf2_ros tf2_echo map base_link 2>&1 | grep -m2 -E "Translation|RPY \(deg"
On my robot, still on its stand, /map came back with resolution: 0.05, width: 77 and height: 122, and the transform was [0.307, 0.228, 0.000]. That translation isn't zero because the stand test spun the wheels, and wheel/odom believed it. The size depends on where your robot stands. What matters is that tf2_echo map base_link prints a transform at all: then map to odom to base_link is complete. After the 40 seconds the launch ends with process has finished cleanly.
If tf2_echo says frame map doesn't exist, slam_toolbox isn't running or isn't getting /scan or the EKF's transform. If you look for the process with pgrep, write the pattern as "[s]lam_toolbox". Without the brackets it also matches your own SSH command line and never comes back empty.
The robot needs a map of its room before chapter 10 can do anything, and this is where the tested path ends for a new robot. Mine was made earlier, on a previous build of this system, by driving the robot slowly round the room with the gamepad while the mapper ran. That drive belongs after chapter 10's stop proofs, because it puts the wheels on the floor with nothing but you to stop them. I didn't redo it for this build, so there is no map-making step here.
The rest of this section and the next two put my saved map back. The repository has my map's image, but not its pose graph, and without the graph slam_toolbox can't continue a map. If you're building for your own room, read on to see how the kept map and the keepout mask fit together, but don't copy my files; a map of my room would put your robot in the wrong place.
My previous system was still on p16, next to the new one, so I mounted it read-only and copied the two pose graph files out. On a robot set up as in chapter 4 the layout is the other way round: p16 is the system you're running and p1 is the factory system, which has no map. This block only makes sense if a previous build with a map sits on p16:
sudo mkdir -p /mnt/p16ro && sudo mount -o ro,noload /dev/nvme0n1p16 /mnt/p16ro
mkdir -p ~/maps && cp -v /mnt/p16ro/home/burgerbarn/maps/room_20260928.posegraph /mnt/p16ro/home/burgerbarn/maps/room_20260928.data ~/maps/
sudo umount /mnt/p16ro && sudo rmdir /mnt/p16ro
The .posegraph was 4,016,097 bytes and the .data 609,055. Whatever the source of a graph, keep the base name room_20260928. That's the name the next script looks for; the date in it is only a label.
I keep the map's image and YAML in the repo's maps folder, next to its keepout mask. They belong to my graph. From my laptop I copied them into ~/maps on the robot, where the mask step below and chapter 10 read them:
scp ~/CCode/rosorin-pro/maps/room_20260928.pgm ~/CCode/rosorin-pro/maps/room_20260928.yaml rosorin:maps/
Navigation doesn't work on that original. It continues one graph, ~/maps/room.posegraph and room.data, which grows a little with every real drive. scripts/install_live_map.sh creates it once from the original and never overwrites it afterwards, so it can't destroy a map the robot has been growing. It's three working lines: if ~/maps/room.posegraph already exists it says so and stops, otherwise it copies room_20260928.posegraph and room_20260928.data to room.posegraph and room.data. Copy it from your laptop and run it on the robot:
cd ~/CCode/rosorin-pro
scp scripts/install_live_map.sh rosorin:setup/
bash ~/setup/install_live_map.sh
'/home/burgerbarn/maps/room_20260928.posegraph' -> '/home/burgerbarn/maps/room.posegraph'
'/home/burgerbarn/maps/room_20260928.data' -> '/home/burgerbarn/maps/room.data'
kept graph installed from room_20260928
room_20260928.* stays as the untouched original. Right after this, md5sum ~/maps/room.posegraph ~/maps/room_20260928.posegraph gives the same sum for both. If the script says kept graph exists, it's protecting a graph that's already there; move room.posegraph and room.data aside yourself if you really want to start over.
Here's how chapter 10 uses the kept graph, because the rules it follows protect the map. Navigation runs slam_toolbox's map_and_localization_slam_toolbox_node on ~/maps/room, starting from the last pose the robot remembered, or from home. A supervisor node keeps it in localization only while it places the robot. It switches to mapping only once the scan confirms the pose, and only when the robot isn't plugged in. On the charger or the stand the wheels aren't meant to move, so any odometry there is false: ten seconds of spinning wheels on the stand once put phantom places into my kept graph and grew it from 4.0 to 8.5 MB. A graph continued from the wrong start pose is just as bad; it draws every wall twice. While mapping, the supervisor saves the graph and its picture (room_live.*) after every drive and every ten minutes, and copies the previous version into ~/maps/history/ first, keeping the newest ten. Going back to an older map means stopping navigation and copying the files back from one of those folders.
Two quirks of slam_toolbox 2.6.10 cost me time. The map-and-localization node starts in mapping mode whatever its mode: setting says, and only listens for a starting pose after a call to /slam_toolbox/set_localization_mode with true. The supervisor always makes that call first. And the node publishes the robot's pose with volatile durability: a subscriber that asks for the latched kind never gets a message and logs no error. Subscribe with the default settings.
A keepout mask is a second map image, the same size and position as the map, that marks where the robot must never plan to go. Nav2 turns those cells into walls in its planning map (chapter 10), so no path ever crosses them. It doesn't stop the robot by itself; it shapes the paths. I added mine after the robot's first exploration chose a goal through the open door, because the LiDAR had seen floor beyond the doorway. The room's boundary is now part of the map, not something the robot has to learn.
The mask is made from the map image with a flood fill: start from a free spot inside the room, spread through free cells, and everything not reached (walls, the space behind them, whatever lies past the door) is keepout. Black is keepout and near-white is allowed. Mine sits in the repo next to my map. A mask made for a different map sits in the wrong place, so mine is only any use with my map, and the flood fill that made it wasn't re-run on this build.
Navigation finds the mask by name. It takes the map file, ~/maps/room_live.yaml, and looks for room_live_keepout.yaml beside it. If that's missing, it plans without the filter. From my laptop I copied my mask:
cd ~/CCode/rosorin-pro
scp maps/room_20260928_keepout.pgm maps/room_20260928_keepout.yaml rosorin:maps/
then put it in place under the name navigation looks for, on the robot:
cd ~/maps
cp room_20260928_keepout.pgm room_live_keepout.pgm; sed 's/room_20260928_keepout.pgm/room_live_keepout.pgm/' room_20260928_keepout.yaml > room_live_keepout.yaml
head -5 room_live_keepout.yaml
After two comment lines, head should show:
image: room_live_keepout.pgm
mode: scale
resolution: 0.050
The mask's YAML must carry the same resolution and origin as the map it was made for. Don't edit the origin by hand.
rf2o failed the floor test the first time. With plain /scan it read 8 cm of every true 80 cm leg while the EKF and the camera read about 80. The cause was the robot's own body in the scan, and the /scan_rf2o copy above fixed it. What I can't explain is why an earlier build of this same code read 88 to 100 percent on the floor.
rf2o's sign and scale aren't settled. SIGN = -1 comes from one floor check, and earlier self-checks read 66 to 76 percent of the true distance. It's also blind to sideways motion. Neither rf2o nor the camera odometry feeds the EKF yet. The plan was to drive a long measured path and make the camera odometry the EKF's speed input if it holds up. I haven't done that drive, so the EKF still runs on commanded speed plus the gyro. It can't see a slip, a stall or a push. The 13 mm extra that the EKF reported on the stand's forward move is also unexplained.
The truth(LiDAR ray) column in odom_truth.py is unreliable whenever anything moves ahead of the robot. Three times it read more than the commanded distance, once 288 cm for an 80 cm leg, and twice less than zero. Use the camera odometry as the reference.
There is no tested way in this guide to make a map of your own room. Every map step that passed copied my existing map: the pose graph from my previous system's partition and the image, YAML and keepout mask from the repo. A new robot in a new room has none of those, and the repo doesn't hold the pose graph at all. Until a map-making drive has been run and checked, chapter 10's navigation has no map of your room to run on.
The map-making drive wasn't re-run on this build. On the earlier build it went like this: on the floor, unplugged, ros2 launch rosorin_base slam.launch.py in one session, the gamepad teleop node ros2 run rosorin_base gamepad_teleop in a second (at most 0.2 m/s and 0.8 rad/s), a check in a third that each stick does what you expect with the wheels still disabled, then enable the wheels, drive slowly along every wall and back past places already seen, finish where you started, and disable the wheels. The pose graph was saved with slam_toolbox's serialize_map service under the name room_20260928; the image and YAML came from a short script that read /map, not from save_map. The new map's origin is wherever rosorin-base last started, not where you start driving. The driver has changed a lot since that drive, and gamepad_teleop hasn't been used for mapping with the current driver. Treat it as untested. A map of a new room also needs its own keepout mask and its own home pose; my repo files for both sit in my map's frame. Making the map with the robot exploring on its own, using the explore script's REMAP=1, has never been run at all. From reading the code, that path saves only the image and not the pose graph, so navigation would keep running on the old graph afterwards.
The flood-fill script that made my keepout mask wasn't re-run on this build either; I copied the finished mask. And the mask covers only the original 4.5 by 7.0 metre map. My kept map has since grown to 8.45 by 14.85 metres, and how the filter treats ground outside the mask's own image hasn't been tested.
The map image that slam_toolbox saves is a PGM. NVIDIA's GPU localizer won't read a PGM; it wants PNG or JPEG. Chapter 10 has what that does to navigation.
You're ready for chapter 10 when /odometry/filtered runs at about 50 Hz and tf2_echo odom base_link prints a transform, the heading of a standing robot moves less than about a tenth of a degree in five minutes, the stand test shows the wheels claiming a turn the EKF doesn't believe, /odom_rf2o has one publisher, python3 -c "import cuvslam as v; print(v.__version__)" prints 17.0.0 and /odom_vslam runs at 9 to 14 Hz, rf2o's straight legs on the floor are within about 5 percent of the camera's, a standing slam.launch.py gives a /map and a map to base_link transform, and ~/maps holds the original room_20260928.* files, the kept room.posegraph and room.data, and a room_live_keepout.yaml that names room_live_keepout.pgm. Those map files only exist if you already have a pose graph of your room from an earlier build; for a new room there is no tested way to make them yet, and chapter 10 needs them. Remember the two map rules: map only on the floor and unplugged, and only once the pose is confirmed.