User Tools

Site Tools


reading_data_from_a_hokuyo_lidar_using_ros2

Reading data from a Hokuyo LiDAR using ROS2

Author: Amalia Ullman Email: mali.ullman@gmail.com
Date: Last modified on 08/05/2024
Keywords: Hokuyo, ROS, ROS2, Laser Rangefinder, Scan, LiDAR

This tutorial covers the installation of ROS2 Foxy on an Ubuntu 20.04 (Focal Fossa) system, as well as the steps necessary for receiving data from a Hokuyo UTM-30LX-EW LiDAR. ROS2 (robot operating system 2) is a popular robot operating system and is usually utilized alongside Linux machines. The Hokuyo is the LiDAR most commonly found on F1Tenth cars. It is a lightweight 2D scanner.

The following is based on my experiences and information from:

http://wiki.ros.org/indigo/Installation/Ubuntu, http://wiki.ros.org/hokuyo_node/Tutorials/UsingTheHokuyoNode, https://defendtheplanet.net/2014/11/04/step-step-guide-working-ros-indigo-ubuntu-14-04-laptoppc/, and https://en.wikipedia.org/wiki/Laser_rangefinder.

Information was sourced from:

https://github.com/Hokuyo-aut/urg_node2 https://docs.ros.org/en/foxy/Installation/Ubuntu-Install-Debians.html https://sourceforge.net/p/urgnetwork/wiki/urg_node2_en/ https://www.hokuyo-aut.jp/products/data.php?id=4

This tutorial was based on a previous DASL tutorial that read data from a Hokuyo LiDAR on a ROS1 system. Check out the previous tutorial if you’d like a deeper explanation of the theory of operation.

Motivation and Audience

The Hokuyo sensors are widely used for pathplanning and navigation, especially for autonomous or mobile robots like F1Tenth vehicles. Within the past couple of years, Hokuyo has added support for ROS2, allowing them to be utilized in the newer ROS environment. ROS2 is considered more robust, has better support for multiple programming languages (and newer versions of those languages), and allows you to create a fully distributed system, eliminating the ROS Master single point of failure. Additionally, the last version of ROS 1 (ROS Noetic, released in 2020) will reach end-of-life in 2025.

This tutorial is for those with:

  • a basic understanding of Linux Bash
  • an interest in laser rangefinders and navigation
  • projects requiring the use of ROS2 over ROS1

The rest of the tutorial is organized as follows:

  1. Parts List and Sources
  2. Programming
  3. Final Words

Parts List and Sources

This tutorial utilizes the Hokuyo UTM-30LX-EW, but should also work for the UST-10LX, UTM-30LX, URG-04LX-UG01, UAM-05LP, and UAM-05LPA models. We also require a computer. In this case, a Linux Ubuntu 20.04 system, which can be installed using this tutorial: https://ubuntu.com/tutorials/install-ubuntu-desktop#1-overview

Programming

First, install and configure ROS2.

1. Install ROS2 Foxy

The following commands enable the Ubuntu Universe repository.

sudo apt install software-properties-common
sudo add-apt-repository universe

Next add the download key.

sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

Add the repository to the sources list.

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

Ensure apt is up to date.

sudo apt update
Sudo apt upgrade

Install the full ROS2 Foxy Desktop

sudo apt install ros-foxy-desktop python3-argcomplete

Use ROS environment variables

source /opt/ros/foxy/setup.bash

2. Install Hokuyo Node

Create the ROS workspace.

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src

Clone the repository.

git clone --recursive https://github.com/Hokuyo-aut/urg_node2.git

Install Dependencies.

rosdep update
rosdep install -i --from-paths urg_node2
cd ..

Now you should be outside of src and can run.

rosdep install -i --from-path src --rosdistro foxy -y

Note: Some of the dependencies required do not have a rosdep definition. They must be installed manually using apt. You can then rerun rosdep install to check that all dependencies are installed. For example:

sudo apt search laser_proc
sudo apt install ros-foxy-laser-proc
rosdep install -i --from-path src --rosdistro foxy -y

Build the Node.

colcon build --symlink-install

3. Configure Ethernet Port

The LiDAR comes with the default address 192.168.0.10. The ethernet port you plug the Hokuyo into must be on the same network. Otherwise, connectivity issues may occur. I set the ethernet port ip address to 192.168.0.15. However, you can use any number from 1-254 (except 10) for the host address (the 4th octet). Make sure to replace ethx with the name of your ethernet port (can use the command “ip add” to show the interface name even if it is down).

ip link set dev ethx up
ifconfig ethx 192.168.0.15 netmask 255.255.255.0

4. Run the Node

Connect your Hokuyo via Ethernet. In a new terminal run

source /opt/ros/foxy/setup.bash
cd ~/ros2_ws
source install/local_setup.bash

Finally, launch the node.

ros2 launch urg_node2 urg_node2.launch.py

To check that the Hokuyo is publishing data, use

ros2 topic list

Scan should be present in the topics listed.

You can see the messages published by using

ros2 topic echo /scan

5. Visualize data

This data can be visualized using rviz, which comes with the full desktop version of ROS2.

ros2 run rviz2 rviz2

At the bottom left of the rviz menu, select Add. Then switch to the “By Topic” tab.

Select “Laser Scan” under the “/scan” topic.

Back on the main window, change the fixed frame to “laser.” You should have mapped points from the Hokuyo sensor readings.

Final Thoughts

Possible next steps include:

  • Creating Nodes that utilize the Hokuyo laser rangefinder scans.
  • Connecting the Hokuyo to a microprocessor, such as a Jetson

For questions, clarifications, etc, Email: mali.ullman@gmail.com

reading_data_from_a_hokuyo_lidar_using_ros2.txt · Last modified: by mullman