Monthly Archives: January 2023

Centring and Increasing the Size of your Global Costmap – ROS2, RVIZ2 and NAV2

Hi everyone,

I’ve been following the Articulated Robots tutorial series which has helped me to create a self navigating diff drive robot.

One issue I ran into after implementing Nav2 was that my Global Costmap was offset from the robot.

This ended up being a pretty easy fix. In your Nav2 configuration you can simply set rolling_window to true. This will centre the costmap on the robot as it moves around.

A second issue was the size of the costmap. I was only able to set navigation waypoints that were within 5m (note the size of the grey shading). To get around this you can use nav2 parameters again to increase the width and height. In my case I doubled the default (from 5m to 10m).

This is the config I ended up with:

global_costmap:
  global_costmap:
    ros__parameters:
      rolling_window: true
      width: 10
      height: 10

Thanks to these links for putting me on the right track:

Nav2 Localisation not Loading a Default Map

Hi everyone,

I finally have my diffdrive robot navigating with waypoints using Nav2 and this great tutorial. However, while trying to use a saved map for localization I ran into the following error:

ros2 launch my_bot localization_launch.py use_sim_time:=false
....
ocalization]: Configuring map_server
[map_server-1] [INFO] [1673064055.126698671] [map_server]: Configuring
[map_server-1] [ERROR] [map_io]: Failed processing YAML file /home/chris/Desktop/dev_ws/install/my_bot/share/my_bot/maps/chris_room_07012023/chris_room_save.yaml at position (-1:-1) for reason: bad file
[map_server-1] [ERROR] [1673064055.126801797] []: Caught exception in callback for transition 10
[map_server-1] [ERROR] [1673064055.126805589] []: Original error: Failed to load map yaml file: /home/chris/Desktop/dev_ws/install/my_bot/share/my_bot/maps/chris_room_07012023/chris_room_save.yaml
[map_server-1] [WARN] [1673064055.126811964] []: Error occurred while doing error handling.
[map_server-1] [FATAL] [1673064055.126815339] [map_server]: Lifecycle node map_server does not have error state implemented
[map_server-1] [INFO] [map_io]: Loading yaml file: /home/chris/Desktop/dev_ws/install/my_bot/share/my_bot/maps/chris_room_07012023/chris_room_save.yaml
[lifecycle_manager-3] [ERROR] [1673064055.127951438] [lifecycle_manager_localization]: Failed to change state for node: map_server
[lifecycle_manager-3] [ERROR] [1673064055.128136607] [lifecycle_manager_localization]: Failed to bring up all requested nodes. Aborting bringup.
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)

I had the following entry in my launch file:

        DeclareLaunchArgument(
            'map',
            default_value=os.path.join(bringup_dir, 'maps', 'chris_room_07012023/chris_room_save.yaml'),
            description='Full path to map yaml file to load'),

My map was also in the correct folder and valid output from the slam_toolbox plugin in rviz2. I had also run `colcon build –symlink-install`.

Initially I thought that I’d used the wrong settings in rviz but eventually I realised that the file was missing from the install directory. Despite running colcon build it was not building my new map files.

Luckily, this ended up being a fairly easy fix. I’d simply missed adding the directory to CMakeLists.txt.

# Add maps to the end of the DIRECTORY line.
install(
  DIRECTORY config description launch worlds maps
  DESTINATION share/${PROJECT_NAME}
)

After updating CMakeLists.txt and re-running colcon build --symlink-install I was finally able to start localization with a default map.