Learning the basics of ROS (part 1)
ROS stands for Robotic Operating System. This article will act as a tutorial for anyone interested in taking a crash course into the world of ROS. What are we waiting for, let’s dive right in!
Lesson 1: Setting up ROS
The best way to set up ROS is by following the installation tutorial on www.ros.org. The 2 main long term support software available right now are ROS Kinetic Kame and ROS Melodic Morenia. Depending on your Ubuntu distribution, you will have to choose either one. To check your Ubuntu distribution, type:
If it shows: Ubuntu 18.04.4 LTS, then you should proceed with ROS Melodic Morenia. If it shows: Ubuntu 16.04 LTS, the proceed with ROS Kinetic Kame. Follow the steps shown in http://wiki.ros.org/ROS/Installation and you should have your ROS distribution up and running in no time. To confirm this, type the following command and you should get the output reflecting your ROS version:
One gripe I had with installing Ubuntu 16.04 on my previous laptop was that the synaptic touchpad tap-to-click was not working anymore compared to my Windows OS. After some digging I found out that Gnome starting at 3.20 only allows configuring devices using the libinput driver. So if you are not using the libinput driver, it won’t show up in the GUI. Fret not, in order to change your settings you can use gsettings using the following link: https://www.ostechnix.com/configure-touchpad-settings-using-gsettings-commandline-utility/. More specifically type the following code into your terminal:
gsettings set org.gnome.desktop.peripherals.touchpad tap-to-click true
Lesson 2: Successful set-up of workspace
Congrats! You have completed your first Lesson of this tutorial and now that you have ROS installed it’s time to begin our journey.
One of the first few steps in properly running a ROS program is to have a work space that is properly set-up. This lesson will teach us how to set-up a functional ROS workspace. First let’s source our environment. This allows the terminal to understand where it needs to look to execute the ROS and catkin commands. Type in either one of the following commands depending on your distribution.
source /opt/ros/kinetic/setup.bashor source /opt/ros/melodic/setup.bash
There will not be any output from this command. After this is done, we can proceed to set-up your work space. Use the following commands found in http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment.
mkdir -p ~/catkin_ws/src
The first line creates a folder called catkin_ws and another folder within that called src. The ‘-p’ command is to make parent directories as needed. In this case catkin_ws is the parent directory of src. After which, shift your current folder into the newly created catkin_ws and proceed to catkin_make all the relevant folders. Alternatively if python3 is the main language to be used for your ROS developments run this command instead of catkin_make:
After your workspace has been properly created, use the commands below. The first command is used when you are within the catkin_ws directory and the second command is used in any directory
source devel/setup.bashor . ~/catkin_ws/devel/setup.bash
Lesson 3: Debugging ROS
For those of you who managed to get through Lesson 2 without any hiccups — Good Job! Unfortunately, part of ROS is being able to debug any problems that happen along the way. When I ran the catkin_make command in Lesson 2, I ran into an error that read:
ImportError: “from catkin_pkg.package import parse_package” failed: No module named ‘catkin_pkg’
The error was because I had catkin_pkg installed from when I had installed ROS, however the PYTHONPATH was not pointed to the directory this catkin_pkg was located in. I realised this when I ran the command:
The output I received was
Furthermore, when I ran the command:
/opt/ros/kinetic/lib/python2.7/dist-packages which was different from where the package catkin_pkg was located. So I had to add this file path into the .bashrc file which is a file that is run everytime a new terminal window or tab is opened.
In order to add this command to the .bashrc, first return back to the home directory and use vim to edit the file:
sudo vim .bashrc
Add the line
export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages. At the same time, take the time to also add source devel/setup.bash from Lesson 2 so that we do not have to keep running this command every time we open up our terminal window or tab.
The link I referred to, to solve this problem is https://stackoverflow.com/questions/43024337/why-this-error-when-i-try-to-create-workspaces-in-ros.
This is how a successful catkin_make command should look like (skip to 3:10):
Lesson 4: Creating a package
After creating the work space we can proceed to create some ROS packages. Start with the command below:
cd catkin_ws/srccatkin_create_pkg beginner_tutorials std_msgs rospy roscpp
After this is complete remember to catkin_make your work space once more by going to the catkin_ws directory and invoking the catkin_make command as we have learnt in Lesson 2.
However, sometimes this may lead to errors. One of the main errors this may lead to is a lack of dependencies. In order to circumvent this, run the command below. It tries to download all the dependencies needed in a package so that catkin_make can be run smoothly thereafter.
rosdep install --from-paths src --ignore-src -r -y
Once the above command has been run, you can repeat the commands above that we have learnt in lesson to invoke the catkin_make workspace:
Remember that it is important to source your workspace after you are done.
Instead of having to consistently source the workspace every time one has to work with a new terminal, it is possible to export the source command into the .bashrc script which is a script that is run everytime a new terminal is opened. Run the following command:
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
echo "source /home/den/catkin_ws/devel/setup.bash" >> ~/.bashrcsource ~/.bashrc
Once again “kinetic” can be replaced with your distribution, which is either “melodic” or “lunar”.