Home Basic usage of ROS (1)
Post
Cancel

Basic usage of ROS (1)

Introduction and Installation of ROS

Part 1 What is ROS?

ROS (Robot Operating System) is a kind of software characteristic of operating system. Currently most developers use Ubuntu to run ROS. Actually it can be used to build a real robot, not only simulations.

If you want to learn ROS by yourself, you can go to ROS wiki for details.

Part 2 Installation

In this essay, we recommend Ubuntu 20.04, because this is the latest version compatible with both ROS 1 and 2. Even though we do not use ROS 2 here,  since ROS 1 has already stopped updating, we are almost sure that ROS 2 might replace ROS 1 in the future.

Step 1: Choose your ROS version

You may look up the correspondence between ROS and Ubuntu versions in ROS wiki. For Ubuntu 20.04 we choose Noetic.

Step 2: Setup your source.list

Add packages.ros.org to your ubuntu source list:

1
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Step 3: Setup your keys and check your source

Make sure that you’ve installed curl first. No matter whether you are sure or not, just run the following command:

1
sudo apt install curl

Do not worry that you may get two curls in your Ubuntu. If you’ve installed curl before, this command will do the update check only.

Then add keys:

1
2
3
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc 
# Use curl to download ros.asc
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

Don’t just copy the command from ros wiki, because the command provided didn’t provide the  pubkey, if you cmd c+v unquestioningly, you may see an error report like this when you try the next step: ros_installation_error_key

Now you can check your sources:

1
sudo apt update

Step 4 Install ROS

Here we recommend Desktop-full Install, because the features in this version are the most complete, and it also contains tutorial projects.

1
sudo apt install ros-noetic-desktop-full

If you want to install more other packages ROS doesn’t have, use the following command:

1
sudo apt install ros-noetic-PACKAGE # Replace PACKAGE with target package name

Step 5 Setup the environment

ROS environment is quite like bash, use the following command to source ros-bash:

1
2
3
4
5
source /opt/ros/noetic/setup.bash
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc 
source ~/.bashrc 
# Whenever you open your local bash, 'setup.bash' will be sourced automatically
# If you use zsh, replace 'bashrc' with 'zshrc'

Step 6 Install dependencies

The work we’ve already done before allows us to run ros core packages. To make more convenience for your work, here some useful tools that are necessary. To install them, run the following command:

1
2
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
# rosdep, rosinstall, wstool, etc.

Before you use the tools, you need to initialize rosdep:

1
2
sudo rosdep init
rosdep update

Some times you may get an error report like this: ros_installation_error_rosdep_init

If you encounter this problem, follow the following steps:

  1. Ping the domain:
1
2
ping raw.githubusercontent.com
# 'raw.githubusercontent.com' is mainly used to store files (except source code), we download non-code files from here.

If it can’t work, please check your network status. If it works,  go to the next step.

  1. Find ip address of the domain:

Here we recommend ipaddress.com, which is useful when looking up the ip address of one URL. As for raw.githubusercontent.com, here are several common ip addresses:

  • 185.199.108.133
  • 185.199.109.133
  • 185.199.110.133
  • 185.199.111.133 The tip is just my experience, the ip may change sometimes, anyway, the core task is to find out the IP address.Add the IP address to ~/etc/hosts, save and close the file.
  1. Retry step 1. If it doesn’t work, you may need to complete the process of ‘rosdep init’ command manually.

In linux, everything is file. If a command cannot work, the most possible reason is file loss. Therefore, if we can recover the missing files, most of the problems can be solved. Just find another computer with ros,  compare the files and directories in /ros of the two computers, and add the file by yourself.

This is extremely unrecommended ! Because you are not sure whether other tools have the same problem. Also, keeping your network active is necessary for all work, so trying step 1 and step 2 is enough, if it can’t work, I highly suggest you to change a computer…

HOORAY !!!!!!!! You've already finished all the steps, and now you can explore ROS as you wish !

This post is licensed under CC BY 4.0 by the author.

-

Basic usage of ROS (2)