This repo demonstrates launching a containorized ROS node that communicates with a lidar sensor over USB. While some of this information is specific to the YDLidar x4, much of the information is generally applicable.
Specifically this guide can help you with the following:
- Introduction to running ROS within a docker container
- Creating a reusable dockerfile that downloads an ROS package via git
- Allowing for bidirectional communication between a docker container and docker host hardware
- Using Rviz to visualize ROS data that originates from an containorized ROS node
- Assume host is running Ubuntu 18.04 (specified distro for ROS Melodic release)
- Install docker engine
- ROS Melodic installed or at least RVIZ
- Working YDLidar x4 lidar sensor
-
Clone this repository
git clone git@github.com:patrick--/ROS-YDLidar-x4-docker.git
-
If you haven't gotten the Lidar working on the host OS prior to now, go ahead and run lidar_init_env.sh to create the
udev
rules and appropriate/dev
symlinks for the lidarcd ROS-YDLidar-x4-docker sudo chmod +x lidar_init_env.sh sudo sh +x lidar_init_env.sh
-
Build image from the provided Dockerfile
cd ROS-YDLidar-x4-docker docker build --tag ros:ros-ydlidar-x4 .
-
Launch the container on the host network and ensure to share
/dev/ydlidar
docker run --device /dev/ydlidar --rm --network host --name ydlidar_x4_docker_test ros:ros-ydlidar-x4
Note: We use the default host network here for ease of use. If you need to isolate network communication between containers and or your host, you will need to create a network.
-
In another tab simply launch rviz with default settings
rosrun rviz rviz
-
Change the
Fixed Frame
drop down tolaser_frame
and add theLaserScan
topic to start seeing lidar data in real time.