VL53L0X ToF sensor integrated as Nav2 obstacle layer via ESP32
A $3 sensor becomes a functional obstacle detector for ROS 2 robots.
Developed by Arjun_R and shared on the ROS Discourse, this open-source project bridges a low-cost VL53L0X Time-of-Flight sensor (≈$3) with NAV2's obstacle layer using an ESP32 microcontroller. The hardware pipeline is straightforward: the VL53L0X communicates over I2C to the ESP32, which streams distance readings over USB serial. On the ROS 2 side, an rclpy serial-bridge node publishes sensor_msgs/Range messages, which are then converted to a synthetic sensor_msgs/LaserScan via the tof_to_scan converter. This scan is fed into the nav2_costmap_2d::ObstacleLayer for both marking and clearing obstacles. The code is built and tested on ROS 2 Humble / Ubuntu 22.04 and released under MIT license on GitHub.
The project also addresses a common pitfall: users reported that obstacle clearing silently failed until they set obstacle_max_range < raytrace_max_range (with raytrace_max_range equal to the sensor's true max range). Without this, obstacles would persist. Additionally, the author notes limitations: the single narrow-FOV beam (configurable ±0.15 rad, 31 rays) creates residual clearing cells when the robot is stationary. Widening the FOV helps but feels like a workaround. The project is not a LiDAR replacement but a supplementary sensor for small robots. It includes ESP32 firmware with disconnect recovery, automatic serial reconnection, and an RViz config.
- Pipeline: VL53L0X → I2C → ESP32 → USB serial → serial_bridge → sensor_msgs/Range → tof_to_scan → LaserScan → Nav2 ObstacleLayer.
- Critical config gotcha: obstacle_max_range must be less than raytrace_max_range for clearing to work; otherwise obstacles never disappear.
- Not a LiDAR replacement – single narrow FOV (configurable ±0.15 rad) leaves residual cells when stationary, resolved by movement.
Why It Matters
Enables ultra-low-cost obstacle detection for hobby and educational robots using standard ROS 2 tools.