Skip to content

[EN] Mapping and Navigation

CaptainHarlockSSX edited this page Jun 17, 2023 · 4 revisions

Mapping and navigation using SLAM, RViz and Nav2

Generate a map with SLAM

To generate a map, you will need to run SLAM and navigate the robot through the place you want to map.

We followed this official tutorial by running SLAM and RViz2 on our host machine, to see how the map is generated, and by controling the robot with keyboard teleop. We performed this without changing default parameters and on the robot pro_1.

⚠️We experienced issues where RViz wasn't able to preview anything. It may have been fixed since then, but ensure the received map topic is /robot_namespace/map, and not just /map or empty.

Update : Even though we launched Rviz with a namespace, we had to manually change EVERY SINGLE TOPIC NAME that RViz use in order to make its functionality work. We were able to define a base position for the robot, and make it navigate. We were also able to see the robot model and see trough the camera. It seems like this makes Rviz usable

Navigate with a map

Introduction

After generating a map, you can load it within RViz2 to plan a trajectory, then launch an antonomous navigation.

You will need 4 terminal windows :

  • One to run the localization, using the map you previewsly generate

  • One to run the navigation with the nav2 tool

  • One to run the ros node you implemented

  • One to run RViz2 and get a visual feedback of robot sensors

As ROS2 work on network, you should be able to run everything on your host machine. However, due to the lags we encountered, we ran localization, navigation and RViz2 on our host machine, then the ros node on the robot using a SSH session.

Running navigation with code

First, locate the path to your map.yaml and load it using the following command (don't forget to add the namespace of your robot at the end of the command):

ros2 launch turtlebot4_navigation localization.launch.py map:=path_to_map.yaml namespace:=/robot_namespace

Then, launch nav2.

ros2 launch turtlebot4_navigation nav2.launch.py namespace:=/robot_namespace

Lauch your custom node to navigate (You can find tutorials about writing ros node for navigation on the official page TurtleBot 4 Navigator · User Manual).

Tip: to find the coordinates of waypoints to write in your code, read the part Navigation with RViz below.

Watch out, the namespace parameter has a different syntax between ros2 run and ros2 launch

ros2 run my_navigation_pkg my_navigation_node --ros-args --remap __ns:=/robot_namespace

You can now launch another terminal and run RViz2 to view the map :

rviz2

or run this command if you want to launch all the views related to robot :

ros2 launch turtlebot4_viz view_robot.launch.py namespace:=/robot_namespace

In RViz, ensure you have the correct topic name for the map, taking account of the robot namespace :

⚠️We experienced huge latency where RViz2 takes very long time to load sensor data from the robot, as well as the model, and even report some errors like missing frame [map]. Actually if you run the commands as indicated in this page, the navigation should work even if the terminals or RViz are reporting errors.

Update : We found out that turtlebot diagnostics were having really high CPU usage, slowing the rasp way to much, we deactivated it by setting the variable TURTLEBOT4_DIAGNOSTICS=0 on the file /etc/turtlebot4/setup.bash The diagnostic is disable on the pro_1 and the lite_1

Also we found that due that we had timestamp issue between the create and the rasp, running the command turtlebot4-ntpd-sync on the pi make the clock resync, this is most likely due to the fact that the create 3 likes to go to 100% cpu usage sometimes (tips found here)

Important Note: We were only able to perform navigation with the Turtlebot Light 1

Running navigation with RViz2

Following the same steps as above expect for launching the ros node of your custom navigation package, you should be able to navigate using in-built nav2 tools within RViz2.

  • Set up the initial pose on the map, according to the real position where the robot stands

  • Use the nav2 goal to choose a direction

You can use Publish Point and see its relative coordinates to the original pose you setup by echoing the topic clicked_point. This tool may be useful if you plan to write waypoints to follow in a python / c++ node.

ros2 topic echo /clicked_point