Build An Autonomous ROSAI Robot With Hector SLAM
This article provides a step-by-step guide to building a low-cost autonomous robot using a Raspberry Pi, ESP32, LiDAR, and camera for real-time mapping with Hector SLAM and AI object detection. The project aims to teach readers about ROS, SLAM, sensor integration, and web-based control dashboards, though it does not provide independent verification of the system's performance or safety in uncontrolled environments.
Why spend ₹120,000 on a ROS kit? Tackle this ₹14,990, 12-14-hour intermediate-to-advanced build for a real-time LiDAR mapping and AI vision robot.
Have you ever wondered how a robot vacuum maps your living room or how self-driving cars navigate busy streets without crashing? Behind almost every modern autonomous machine—from indoor rovers to full-scale autonomous vehicles—is the Robot Operating System (ROS). ROS acts as the central nervous system of robots, seamlessly coordinating mapping, navigation, object detection, and artificial intelligence (AI) processing across independent software nodes. If you want to move beyond basic remote-controlled bots and master real-world intelligent robotics, building a ROS-powered system from the ground up is the best place to start.
Here, we present the design for a very efficient and low-cost simple wheeled robotics platform (2- or 4-wheel drive) with light detection and ranging (LiDAR). A basic commercial learning version typically costs around ₹100,000 to ₹200,000, whereas our design builds everything from scratch without any pre-coded software. We will program the robot with ROS and add advanced functions like AI and Hector simultaneous localisation and mapping (SLAM). Hector SLAM is critical for robot navigation, movement, data collection, and surveying because it allows the robot to build a map of the environment in real-time using LiDAR data while simultaneously determining its own location inside that map. Fig. 1 shows the author’s prototype.
Fig. 2 shows the block diagram of the LiDAR robot. It consists of two main parts. The first part is the Raspberry Pi with LiDAR and a camera, running Wi-Fi, Python, ROS, RViz, and Gazebo. The camera captures video while the LiDAR creates a point cloud of the environment. Using Hector SLAM, it builds and saves the scanned map, tracks the robot’s path and location on the map in real time, and transmits the scanned data wirelessly. All this information is also provided on a WebSocket application so the robot can perform autonomous movement as well as be manually controlled. AI handles object detection and other image processing tasks, and everything is displayed together on a single dashboard.
The second part is the robot movement system connected over WebSocket. This ROS setup with WebSocket can create a mesh network so multiple robots can be connected together and used for learning and development. We have already published the base robot platform (wheel drive over WebSocket) in a previous issue; now, we are simply adding the ROS and AI layers on top of it.
As shown in the block diagram, the Raspberry Pi runs ROS with RViz and Gazebo, receives data from the LiDAR, creates the map using Hector SLAM, and displays everything wirelessly on the web dashboard. Finally, the ESP32 robot chassis is connected to the main Raspberry Pi web dashboard for manual or autonomous control based on the mapping and LiDAR data.
The camera captures the video livestream, and the web app receives this stream to perform object detection or any other computer vision tasks you want. Image processing can run independently on the Raspberry Pi if it has more RAM, or on an NVIDIA Jetson or Orange Pi. However, running ROS, Hector SLAM, RViz, and AI detection at the same time creates parallel processing loads that can make the hardware lag and reduce frame rates (FPS). Therefore, a better approach is to transmit the video and let the web app handle the heavy image processing on the device where the dashboard is running. To build this project, the required components are listed in the bill of materials (Table A).
| Bill of Materials | |||
| Name | Designator | Quantity | Estimated Price (₹) |
| ESP32-C3/ESP32-S2 | MOD1 | 1 | 400 |
| DRV8833 Motor Driver | MOD2 | 1 | 80 |
| Raspberry Pi 4/5 (2GB)/Nvidia Jetson Nano | MOD3 | 1 | 6,000 |
| 5-10MP Raspberry Pi Camera | MOD4 | 1 | 500 |
| Raspberry Pi Camera FPC Connector | CAM1 | 1 | 10 |
| N20 Motors | M1-M4 | 4 | 200 |
| Four-Wheel Robot Chassis | — | 1 | 200 |
| YDLIDAR X2/Similar (8m or greater range) | S1 | 1 | 7,000 |
| 5V Power Bank/5V DC Power Adapter (2A) | — | 1 | 100 |
| USB Type-C Cable | — | 1 | 100 |
| 32GB SD Card | — | 1 | 400 |
| Total | 14,990 | ||
EFY note: Prices are approximate and may vary depending on the supplier and specifications.
What will you learn?
- Learn the fundamentals of ROS and understand how it is used in robotics development.
- Explore RViz and Gazebo for robot visualisation, simulation, and testing.
- Understand the fundamentals of SLAM and learn how to implement Hector SLAM.
- Learn how a robot uses LiDAR data to scan its surroundings, estimate its position, and generate 2D maps.
- Understand LiDAR interfacing with a Raspberry Pi and how to process real-time sensor data using Python.
- Learn Python programming for robotics, sensor communication, and data processing.
- Create a web-based robot monitoring and control dashboard using HTML, CSS, and JavaScript.
- Understand WebSocket communication and how to transmit real-time camera, LiDAR, and SLAM data over Wi-Fi.
- Learn how to stream live video from a Raspberry Pi camera to a web application.
- Explore AI-based object detection using you only look once (YOLO) and understand how computer vision is integrated into robotics.
- Understand how AI object detection and LiDAR data work together for obstacle detection and autonomous navigation.
- Learn ESP32 interfacing and motor control using a motor driver to operate a mobile robot.
How it works
The ROS Hector SLAM AI Robot uses a Raspberry Pi 4 as its main processing unit, running ROS, Hector SLAM, RViz, and Gazebo for mapping and visualisation. The LiDAR continuously scans the surroundings and sends laser scan data to ROS nodes, where Hector SLAM uses scan matching to generate a real-time 2D map and estimate the robot’s position and movement. RViz displays the generated map, LiDAR scan points, robot position, and estimated path, while the map can be saved for future use. The Raspberry Pi Camera captures live video, which, along with the Hector SLAM map and position data, is transmitted to a laptop through WebSocket communication. A browser-based web application displays the live camera feed, SLAM map, LiDAR scan data, and robot position. It also performs AI-based image processing and object detection to identify objects in the robot’s surroundings.
The laptop application combines AI detection results with LiDAR data and map information to make navigation decisions. Movement commands such as forward, reverse, left, right, and stop are sent through a separate WebSocket connection to the ESP32-C3 robot controller. The ESP32-C3 controls the DRV8833 motor driver, which operates the DC motors and moves the robot chassis. As the robot explores, LiDAR continuously provides updated scans to the Raspberry Pi, allowing ROS and Hector SLAM to keep updating the map and estimating the robot’s position in parallel with AI processing and motor control. This creates a continuous autonomous exploration cycle of mapping, localisation, object detection, and movement. During prototyping and testing, the system can be powered using a suitable 5V USB power adapter or power bank, with an appropriately rated motor supply and proper power distribution. Fig. 3 shows the flow chart of the project.
Circuit diagram
Fig. 4 shows the circuit diagram of the LiDAR robot. It is built around an ESP32-C3 or ESP32-S2 module, a DRV8833 motor driver, and a Raspberry Pi 4/5 (2GB) or NVIDIA Jetson Nano single-board computer. The robot also incorporates a Raspberry Pi camera, a YDLIDAR X2 sensor, four N20 motors, and a four-wheel chassis. A 32GB SD card and a suitable 5V power supply complete the setup.
The robot’s wheel motors are connected to the output terminals of the DRV8833 motor driver, while its input pins are connected to the GPIO pins of the ESP32-C3. When using the XIAO ESP32-C3, the GPIO pins D0 to D3 can be used for motor control, according to the firmware pin configuration.
The ESP32-C3 and robot chassis electronics can be powered through the USB/VIN power input using a USB power bank or a 5V USB power adapter. During testing, a laptop USB port or a mobile phone charger can also be used as a power source, provided it meets the board’s power requirements. The Raspberry Pi can be powered separately using the same power bank or a suitable 5V, 2A USB power adapter. The power bank can be mounted underneath the Raspberry Pi on the robot chassis or placed at any convenient location.
For the LiDAR and ROS setup, connect the Raspberry Pi camera directly to the Raspberry Pi’s CSI camera port. Connect the LiDAR to its supplied USB converter module, then connect the converter’s USB output to any available USB port on the Raspberry Pi. This allows the Raspberry Pi to receive LiDAR scan data through USB while simultaneously capturing live video through the camera interface.
| What SLAM and ROS are |
| SLAM. It is a fundamental problem in robotics and computer vision, where the goal is for an autonomous system (such as a robot or a self-driving car) to simultaneously build a map of its environment and accurately determine its own position within that map in real time. Hector SLAM. It is a popular and efficient open source SLAM algorithm designed for mobile robots. The key feature of Hector SLAM is that it is a feature-based algorithm, meaning it focuses on detecting and tracking features (such as lines or edges) in the environment to build the map and estimate the robot’s pose. Dead Reckoning. This is an essential navigation technique for estimating the current position of a moving object based on its previous known position (last fix) and movement data (speed, heading, and time). It is commonly employed when GPS data is unavailable. It is also known as ‘deduced reckoning’ or ‘DR’. |
Assembly
The circuit can be assembled and mounted on the robot chassis, with the Raspberry Pi and LiDAR mounted on the top. Alternatively, you can use our previously designed robot chassis platform, which integrates the motor driver directly into the PCB. In this design, the PCB itself acts as the robot chassis, eliminating the need for a separate chassis platform.
For learning and experimentation, you do not need to purchase a ready-made motor driver module. We have also designed a motor driver module from scratch, which you can build yourself to gain practical experience in circuit design and electronics. The following designs are available:
Robot chassis
- N20 Motor Controller and Gesture Robot
- Compact Robotic Platform with Motor Driver on Chassis PCB
Motor driver
- DIY N20 Motor Driver
Most of the hardware designs used in this project were designed and developed in-house at EFY Labs by the author. You can explore and use these open-source designs and modules to build your own robot, customise the hardware, and gain hands-on experience in electronics and embedded systems development.
Next, mount the LiDAR carefully to ensure correct robot orientation and accurate mapping. Align the LiDAR’s zero-degree reference position with the robot’s forward direction, according to the chassis orientation. Maintaining the correct zero-angle alignment is important for accurate directional interpretation, scan matching, and mapping using Hector SLAM. Finally, mount the camera at the front of the robot to capture the surroundings in the direction of movement. Fig. 5 shows the LiDAR mounting, while Fig. 6 shows the ROS-based robot with LiDAR and camera mounted on the assembled chassis.
Software system integration
EFY++ CONTENT: ACCESS TO THIS CONTENT IS FREE! BUT YOU NEED TO BE A REGISTERED USER.
Oops! This is an EFY++ article, which means it's our Premium Content. You need to be a Registered User of our website to read its complete content.
Good News: You can register to our website for FREE! REGISTER NOW
Already a registered member? If YES, then simply login to you account below. (TIP: Use 'forgot password' feature and reset and save your new password in your browser, if you forgot the last one!)
Loading form…