Skip to content

Localization and Navigation Example

This example implements robot localization and navigation based on LiDAR and IMU sensors, using the hdl_localization algorithm for localization and the move_base package for map-based navigation.

Note: Keep the LiDAR driver running during navigation (refer to the mapping example for LiDAR driver startup).

  1. Open a terminal and start the LiDAR driver (if already started during mapping, no need to restart):
Terminal window
cd /home/ysc/lite_cog/system/scripts/lidar
./start_lslidar.sh # Leishen LiDAR
./start_livox.sh # Livox LiDAR
./start_rslidar.sh # RoboSense LiDAR
  1. Open a terminal and start the navigation node:
Terminal window
cd /home/ysc/lite_cog/system/scripts/nav
./start_nav.sh
  1. Initialize robot localization: RViz Navigation Initialization (ROS1)

a) Click “2D Pose Estimate” in the top toolbar;

b) Determine the robot’s actual position and orientation, move the mouse to the corresponding position on the map, hold left button and drag an arrow in the actual direction, then release;

c) If initialization succeeds, laser point cloud and grid map will overlap, and the terminal prints “initial pose received!!”;

d) If they don’t overlap, the initial position was incorrect. Retry;

e) If no laser point cloud appears and the terminal prints “globalmap has not been received!!”, close with Ctrl+C and retry;

f) The base_link coordinate frame is the robot coordinate frame, x-axis (red) indicates the robot’s heading.

[RViz Tips] In RViz, use the scroll wheel to zoom, left mouse button to rotate, hold Shift + left mouse button to pan.

  1. After successful initialization, set a goal:

a) Click “2D Nav Goal” in the top toolbar; b) Move the mouse to the target position, hold left button and drag an arrow for target orientation, then release; c) If successful, a planned path will appear; if failed, retry.

  1. Enable autonomous mode on the APP and stand up the robot. The robot will follow the global planned path and avoid dynamic obstacles via local planning.

Note: To prevent the robot body from being detected as an obstacle, only objects above a certain height will be recognized as obstacles.

This example provides cyclic navigation through a series of waypoints.

Note: Before recording waypoints, check /home/ysc/lite_cog/pipeline/src/pipeline/data for existing waypoint files and move them to avoid overwriting.

  1. Follow steps 1-3 from single goal navigation to start navigation and set initial pose, then open a terminal to run the waypoint configuration program:
Terminal window
cd /home/ysc/lite_cog/pipeline/src/pipeline_tracking/tools
python3 location_record.py # Chinese version
python3 location_record_en.py # English version

DR Location Recorder Chinese Interface DR Location Recorder English Interface

  1. Manually遥控 the robot to a waypoint, enter 1 at “location number”, click “get location”, then click “record location”. A file named 1.json will appear in /home/ysc/lite_cog/pipeline/src/pipeline/data. Repeat for all waypoints, then close the program.

  2. Open a terminal and run:

Terminal window
cd /home/ysc/lite_cog/pipeline
source devel/setup.bash
cd /home/ysc/lite_cog/pipeline/src/pipeline_tracking/scripts
python3 Task.py

Enable autonomous mode on the APP. The robot will go to the nearest waypoint and navigate cyclically.

  1. For subsequent uses, start navigation, set initial pose, then run step 3.

This example uses hdl_localization for localization and bt_navigator for map-based navigation.

Note: Keep the LiDAR driver running during navigation.

  1. Start the LiDAR driver:
Terminal window
cd ~/lite_cog_ros2/system/scripts/lidar
./start_lslidar.sh # Leishen LiDAR
./start_livox.sh # Livox LiDAR
./start_rslidar.sh # RoboSense LiDAR
  1. Start navigation:
Terminal window
cd /home/ysc/lite_cog_ros2/system/scripts/nav
./start_nav.sh
  1. Initialize localization: RViz Navigation Initialization (ROS2)

a) Click “2D Pose Estimate”; b) Set the robot’s position and orientation on the map; c) If successful, laser point cloud and grid map overlap, terminal prints “initial pose received!!”; d) If not, retry; e) If no point cloud and “globalmap has not been received!!”, retry; f) base_link is the robot frame, x-axis (red) is heading.

  1. Set a goal:

a) Click “Navigation2 Goal”; b) Set target position and orientation; c) A planned path will appear if successful.

  1. Enable autonomous mode and stand up the robot.

Note: Only objects above a certain height are recognized as obstacles.

Note: Check /home/ysc/lite_cog_ros2/pipeline/src/pipeline/data for existing waypoint files.

  1. Start navigation and set initial pose, then run:

a) Chinese version:

Terminal window
cd ~/lite_cog_ros2/pipeline/src/pipeline
python3 LocationRecorder.py

b) English version:

Terminal window
cd ~/lite_cog_ros2/pipeline/src/pipeline
python3 LocationRecorder_EN.py

DR Location Recorder Chinese Interface DR Location Recorder English Interface

  1. Record waypoints as described in the ROS1 section.

  2. Run:

Terminal window
cd /home/ysc/lite_cog_ros2/pipeline/src/pipeline
python3 Task.py
  1. For subsequent uses, run steps 1 and 3.