Raspberry Pi based LiDAR Robot using ROS & SLAM
The objective of this project is to build and program a Raspberry Pi based LiDAR Robot using Robot operating system to SLAM technology (simultaneously localize and mapping).
Components Used for Robot :
Tank Robot Frame
DC Motors
Arduino uno
LCD
Motor Driver
Ultrasonic Sensor
Servo Motor
7.4v Batteries
Arduino Sheild
Arduino Adapter Cable
LDR
Raspberry Pi 4B
RP LiDAR
Power Bank
Building Blocks
Initially, I embarked on the task of assembling an obstacle-avoiding robot using an Arduino Uno, ensuring it could navigate without colliding with obstacles.
Later on, I wanted my robot to avoid bumping into obstacle using a 2D-LiDAR, and also wanted to integrate it with ROS and SLAM technology. So, I started with installing Ubuntu 20.04 onto a raspberry pi which will act as a main processor / master node controlling all other components / slave nodes, resulting in autonomous robot for mapping.
The process for installing ROS on Ubuntu 20.04 based Raspberry pi :
Components required:
· Laptop
· Raspberry Pi 4B
· Raspberry Pi power adapter
· SD card
· Micro HDMI cable
· Keyboard
· Mouse
· Card reader
Step 1: Install Raspberry pi imager from google and click on download for windows. To do this use the link https://www.raspberrypi.com/software/
Step 2: Connect the memory card to your laptop using a card reader and click on choose device/storage on the raspberry pi imager and select the card.
Step 3: Now click on the choose OS button on the RPI Imager and go to other general purpose OS and choose Ubuntu, then select Ubuntu server 20.04.5 LTS (64 bit )and then click on write.
Step 4: Now insert the SD card into the raspberry pi and connect it to the power supply using the power adapter and also connect a keyboard and mouse and wait until the Raspberry boots up
Step 5: Now you will be prompted with a login screen, use Ubuntu as username and Ubuntu as password as well. You will be asked to change the password, so please type and re-type a new password.
Step 6: After logging in we need to connect the raspberry pi to a Wi-Fi. To do this type the command sudo nano /etc/wpa_supplicant.conf in the terminal and type the data given in the pic 4, in the file and ctrl+x to write the file, now press y to save the file and press enter to exit.
Step 7: Now enter the commands in the terminal to ensure that we are connected to Wi-Fi.
· sudo killall wpasupplicant
· sudo wpa_supplicant –B –iwlan0 –c/etc/wpa_supplicant.conf
· sudo dhclient –v
· ping –c5 google.com -> after this you should be seeing that the google.com is pinged 5 times showing that you are connected to the internet.
Step 8: Type sudo apt install Ubuntu-desktop and type y when asked to download the full desktop version. Now type sudo apt update to update all the packages and then type sudo apt upgrade to upgrade all the packages. In the process you will be asked if you want to continue, Press y when asked. It will upgrade all the packages taking some time to process.
Step 9: After the process is complete, reboot the raspberry pi 4 by typing the command sudo reboot in the terminal to complete the installation process. You will see the Ubuntu 20.04 environment is open, use the same credentials to login and use.
Step 10: Now, to install ROS on the Ubuntu 20.04 based raspberry pi follow the instructions given using the link https://wiki.ros.org/noetic/Installation/Ubuntu
Configure your Ubuntu repositories to allow "restricted," "universe," and "multiverse." You can follow the Ubuntu guide for instructions on doing this.
Setup your computer to accept software from packages.ros.org.
· sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
· sudo apt install curl # if you haven't already installed curl
· curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
First, make sure your Debian package index is up-to-date:
· sudo apt update
Now pick how much of ROS you would like to install.
· Desktop-Full Install: (Recommended) : Everything in Desktop plus 2D/3D simulators and 2D/3D perception packages
o sudo apt install ros-noetic-desktop-full
or click here
· Desktop Install: Everything in ROS-Base plus tools like rqt and rviz
o sudo apt install ros-noetic-desktop
or click here
· ROS-Base: (Bare Bones) ROS packaging, build, and communication libraries. No GUI tools.
o sudo apt install ros-noetic-ros-base
or click here
There are even more packages available in ROS. You can always install a specific package directly.
· sudo apt install ros-noetic-PACKAGE
e.g.
sudo apt install ros-noetic-slam-gmapping
To find available packages, see ROS Index or use:
apt search ros-noetic
You must source this script in every bash terminal you use ROS in.
source /opt/ros/noetic/setup.bash
It can be convenient to automatically source this script every time a new shell is launched. These commands will do that for you.
Bash
If you have more than one ROS distribution installed, ~/.bashrc must only source the setup.bash for the version you are currently using.
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
zsh
echo "source /opt/ros/noetic/setup.zsh" >> ~/.zshrc
source ~/.zshrc
Up to now you have installed what you need to run the core ROS packages. To create and manage your own ROS workspaces, there are various tools and requirements that are distributed separately. For example, rosinstall is a frequently used command-line tool that enables you to easily download many source trees for ROS packages with one command.
To install this tool and other dependencies for building ROS packages, run:
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
Initialize rosdep
Before you can use many ROS tools, you will need to initialize rosdep. rosdep enables you to easily install system dependencies for source you want to compile and is required to run some core components in ROS. If you have not yet installed rosdep, do so as follows.
sudo apt install python3-rosdep
With the following, you can initialize rosdep.
sudo rosdep init
rosdep update
The Process for installing SLAM using RPlidar and ROS is :
Download the ROS package on github and follow the instructions on the read
Rplidar Ros Package:
- https://github.com/robopeak/rplidar_ros.git
Step 1 - the first step is to connect the LiDAR to the laptop/ raspberry pi and giving the USB port the authority of writing
- sudo chmod 666 /dev/ttyUSB0
Step 2 - download the RP lidar package in our catkin workspace
Step 3 - to enter into the catkin workspace
- cd catkin_ws/src
Step 4 - clone the packages from git hub using the code
- git clone https://github.com/robopeak/rplidar_ros.git
Step 5 - after the packages are downloaded, go back to catkin workspace
- cd ...
Step 6 - make sure to be in the catkin workspace and type
- catkin _make
Step 7 - Once everything is setup, now you have to source it using the command
- source devel/setup.bash
Step 8 - on another teminal launch the ROS, using the command
- roscore
Step 9 - on the previous terminal launch the rplidar using the command
- roslaunch rplidar_ros view_rplidar.launch
Step 10 - as soon as you give the command on step 9, the lidar stops rotating for 2
seconds and starts rortating again, simulataneously, Rviz will open and
you can see the lidar scanning the surroundings. Also change the size in
the left side of the software for better visibility.
Step 11 - to get the values/data from the lidar, you can type,
- rostopic list -> gives you a list of all the topics that are available
Step 12 - to get the parameters and working range of the lidar along with the lidar data .
- rostopic echo /scan
Step 13 - now download the hector-slam- ros package in the catkin_ws/src from the github repository using the code
- git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.git
Step 14- come out from the src by typing
- cd ..
Step 15 - to initialize all the packages
- catkin_make
Step 16 – Now you need to make some changes in the code. Go to catking_ws ->
src -> hector_slam -> hector_mapping -> launch -> mapping.launch
make sure that the base_frame and odom_frame are set to base_link
Step 17: now you need to make some changes in the code for the launch file.
So, go to the hector_slam -> hector_slam_launch -> launch ->
tutorial.launch and change the use_sim_time from true to false, and save.
Step 18: we are all set, Now open a terminal and run Roscore in it using the command,
- roscore
Step 19: Now, open an another terminal and run the command below to launch
the rplidar
- roslaunch rplidar_ros rplidar.launch
Step 20: now open an another terminal and run the command below to launch the
SLAM
- roslaunch hector_slam_launch tutorial.launch
Step 21: That’s it, now you will see your LiDAR throwing lasers and mapping the
surroundings.