
.. image:: media/gifs/b2_vac_demo.webp
    :alt: B2 Navigation Demo
    :width: 100%
    :class: mbsrounded

|

The B2W uses the Nav2 navigation stack for autonomous navigation.

SLAM (2D Mapping)
-----------------

Run SLAM to create a 2D occupancy grid map using the LiDAR sensor:

.. code-block:: bash

   ros2 launch b2_nav2 slam.launch.py

Drive the robot slowly (recommended 0.2 m/s) using the joystick controller or keyboard teleop to build the map:

.. code-block:: bash

   ros2 run teleop_twist_keyboard teleop_twist_keyboard \
     cmd_vel:=/b2_unit_001/controls/cmd_vel

Once satisfied with the map, save it using:

.. code-block:: bash

   ros2 run nav2_map_server map_saver_cli -f \
     /opt/mybotshop/src/mybotshop/b2_nav2/maps/custom_map \
     --ros-args --remap map:=/b2_unit_001/map

.. note::
   Replace ``b2_unit_001`` with your robot's namespace. Maps are saved to the ``b2_nav2/maps/`` directory. After saving, rebuild the workspace with ``colcon build --symlink-install`` so the new map can be found.

**SLAM Configuration:**

Configuration file: ``b2_nav2/param/nav2_slam.yaml``

.. code-block:: yaml

   slam_toolbox:
     ros__parameters:
       solver_plugin: solver_plugins::CeresSolver
       resolution: 0.05
       max_laser_range: 40.0
       mode: mapping

Odom Navigation
---------------

Run odometry-based navigation without a pre-built map. This mode navigates in the global map frame using only odometry for localization:

.. code-block:: bash

   ros2 launch b2_nav2 odom_navi.launch.py

This is useful for relative navigation where you don't have a map of the environment yet.

Map-Based Navigation
--------------------

Use a pre-built 2D map for autonomous navigation with AMCL localization:

.. code-block:: bash

   ros2 launch b2_nav2 map_navi.launch.py

This launches the full Nav2 stack including:

- **Map Server** - loads pre-built occupancy grid maps
- **AMCL** - Adaptive Monte Carlo Localization
- **Controller Server** - path following (DWB controller)
- **Planner Server** - global path planning (NavFn)
- **Behavior Server** - recovery behaviors
- **Waypoint Follower** - for multi-point navigation

GPS-Based Navigation
--------------------

For outdoor GPS-based navigation:

.. code-block:: bash

   ros2 launch b2_nav2 gps_navi.launch.py

Launch Files Summary
--------------------

.. list-table::
   :header-rows: 1
   :widths: 30 50

   * - Launch File
     - Description
   * - slam.launch.py
     - 2D SLAM mapping mode
   * - odom_navi.launch.py
     - Odometric navigation (no map)
   * - map_navi.launch.py
     - Full autonomous navigation with map
   * - gps_navi.launch.py
     - GPS-based outdoor navigation
