The YDLidar X4 Project is a C++ application designed to interface with the YDLidar X4 LiDAR sensor, enabling real-time data acquisition, communication, and visualization.
The project reads raw serial data from the LiDAR, parses it into LaserScan messages (containing angles and distances), and publishes these messages using ZeroMQ’s publisher/subscriber pattern. A subscriber node receives the data, and an SFML-based visualization node plots the LiDAR scans as a 2D Cartesian point cloud.
This project demonstrates robust serial communication, distributed messaging, and graphical rendering, making it a valuable learning tool for robotics and sensor interfacing.
- Serial Data Parsing: Reads and validates YDLidar X4 packets (header
0xAA 0x55, CT, LSN, FSA/LSA, checksum, samples) to extract angles (degrees) and distances (millimeters). - ZeroMQ Messaging: Publishes
LaserScanmessages overtcp://*:5555and subscribes to them, enabling decoupled data exchange. - SFML Visualization: Renders LiDAR points in a real-time 2D Cartesian view using SFML, displaying green dots scaled to fit an 800x600 window.
- Modular Design: Organized into
ydlidar,zmq, andplotmodules for maintainability.
- C++17 for core logic
- ZeroMQ (
libzmq) for publisher/subscriber communication - SFML (
libsfml) for graphical visualization - CMake for build management
- YDLidar X4 LiDAR sensor connected to
/dev/ttyUSB0 - USB-to-serial adapter
(Ensure permissions with:sudo usermod -a -G dialout $USERand then log out/in)
- Ubuntu 20.04 or later (tested)
- C++ compiler (e.g.,
g++with C++17 support) - CMake 3.10 or higher
- Required Libraries:
sudo apt-get install build-essential cmake libzmq3-dev libsfml-dev
Ensure the user has access to /dev/ttyUSB0:
sudo usermod -a -G dialout $USER
# Log out and log back in for the group change to take effectgit clone https://github.com/Tofigh-Tevfik/ydlidar_x4_project.git
cd ydlidar_x4_projectmkdir build && cd buildcmake ..
makesudo ./ydlidar_x4_publisher- Requires
sudofor access to/dev/ttyUSB0 - Outputs parsed angles and distances to the terminal
./ydlidar_x4_subscriber- Run in a separate terminal
./ydlidar_x4_plotter- Displays a window with green points representing LiDAR scans
- Close the window to exit
To visualize LiDAR data from another device on the same local network, update the plotter's endpoint from:
"tcp://localhost:5555"
to the IP address of the remote device, for example:
"tcp://192.168.1.21:5555"
Replace 192.168.1.21 with the actual IP address of the device running the LiDAR publisher.
For questions, issues, or contributions:
- EMAIL: Mail me
The project is complete in its current form, but the following documentation efforts are planned:
- Project Summary Document: A detailed report summarizing the project’s architecture, implementation, and lessons learned. (Done)
- Demonstrative Video: A short video showcasing the LiDAR data acquisition, ZeroMQ messaging, and SFML visualization in action.
No additional code updates are planned at this time.