Provides quick access and useful resources for ROS.

Quick Access

Before Installing

First, make sure which version of ROS is preferred. (i.e., ROS 1 or ROS 2)

In most cases, if the version is not specified in a open source project, it means ROS 1.

Then, decide which distribution you want to use.

  • ROS distributions As of 2021, Noetic is the newest release, and Melodic are used in most open source projects.
  • ROS 2 distributions As of 2021, Galactic is the newest release, and Foxy has the latest End-Of-Life date.

Quick Start for ROS 2

If you want to use ROS 2, follow the installation guide.

The rest of this article focus on ROS 1 only.

Quick Start

I strongly suggest not to use Windows 10, unless you are entirely sure that all packages are supported. This is due to the fact that many open source projects only supports Ubuntu/Debian. If you do use Windows, you may refer to ms-iot/ROSOnWindows for further information.

The rest of this article focus on ROS 1 on Ubuntu only.

  1. Open the installation page.
  2. Choose the preferred distribution.
  3. Select the preferred platform.
  4. Follow the installation instructions.
  5. Follow the tutorials until 13. Examining the Simple Publisher and Subscriber.

You should now know how to communicate using ROS between nodes.

For more details, see the tutorial.

Environment Setup

To access ROS, make sure to run:

# ROS
source /opt/ros/<distro>/setup.bash
# For your ROS workspace
source devel/setup.bash

Using Python3

Correct Method

Execute the followings:

sudo apt update
sudo apt install python3-catkin-pkg-modules python3-rospkg-modules python3-empy python-catkin-tools

mkdir -p ./catkin_ws/src; cd ./catkin_ws
catkin_make
source devel/setup.bash

sudo apt install -y virtualenv
virtualenv venv -p python3
source venv/bin/activate
python3 -m pip install pyyaml rospkg

# Put sources under src/
# For example, opencv:
#
#     git clone -b melodic https://github.com/ros-perception/vision_opencv.git src/vision_opencv
#

rosdep install --from-paths src --ignore-src -y -r

catkin_make --cmake-args \
            -DCMAKE_BUILD_TYPE=Release \
            -DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
            -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
            -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so

catkin config \
  -DPYTHON_EXECUTABLE=./venv/bin/python \
  -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
  -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so

catkin config --install

I’m not sure whether the last PYTHON_EXECUTABLE environment variable correctly install the package for the virtual environment…

Further references: this, this, and this.

Deprecated Method

Note: This method does not work if you need to catkin_make a Python package.

By default, ROS uses Python2. To change it to Python3, first cd into your workspace, then:

# ROS
source /opt/ros/<distro>/setup.bash
# For your ROS workspace
source devel/setup.bash
sudo apt install -y virtualenv
virtualenv venv -p python3
source venv/bin/activate
# For ROS in Python3
pip install pyyaml rospkg

alternatively:

# ROS
source /opt/ros/<distro>/setup.bash
# For your ROS workspace
source devel/setup.bash
# For ROS in Python3
python3 -m pip install pyyaml rospkg
# And simply use python3 afterwards

Run Across Multiple Machines

Assume you have two machines: machine A (192.168.50.101) and machine B (192.168.50.102). Machine A is the master which will run roscore on port 11311.

  • On machine A (192.168.50.101):
    systemctl stop ros.service
    roscore # keep this process running
    rosrun rospy_tutorials listener.py
    
  • On machine B (192.168.50.102):
    # Make machine `B` know the address of machine `A`
    export ROS_MASTER_URI=http://192.168.50.101:11311
    # Make machine `A` know the address of machine `B`
    export ROS_HOSTNAME=192.168.50.102
    # You may want to use ROS_IP instead: http://wiki.ros.org/ROS/EnvironmentVariables
    # But since ROS_HOSTNAME has higher precedence, we use it here.
    rosrun rospy_tutorials talker.py
    

If you want to connect with host names, see this post for more details.

Publish & Subscribe Long Latency Issue

This happens when you have a fast publisher (e.g., 60Hz) transfering a large image to a slow subscriber (e.g., 1Hz).

Sometimes the latency becomes extremely large even if the queue_size is set to 1 according to the article Choosing a good queue size.

The issue may reside on the buff_size in the Subscriber API being too small. The solution is to increase the buff_size to slightly larger than queue_size * max_message_size as mentioned in the API description.

More discussions on this issue can be found on this GitHub issue.

Troubleshooting

FAQs:

  • In the Tutorials 6. Understanding ROS Topics, using Ctrl+C to terminate the turtle node may not perform cleanup successfully, you should close the window by clicking the X button instead. (See this post)
  • Topics vs. Services vs. Actions
  • Make sure your /etc/hosts contains the correct IP (ifconfig).
  • Make sure you are running roscore, or ros.service if you are using rosrun.
  • roslaunch does not need roscore running.
  • Use rosnode and rostopic command to quickly isolate where the issue resides.
  • Solution to Security issue on ROS build farm
  • Solution to ROS GPG Key Expiration Incident
  • If you encountered XXX Package not found, run apt-get install ros-<distro>-<package>
  • Manually inspect and run the setup scripts to ensure no error occurs.
  • Here is the solution to the Gazebo issue:
    The following packages have unmet dependencies:
     libgazebo9-dev : Depends: libgazebo9 (= 9.19.0-1~bionic) but it is not going to be installed
                      Depends: gazebo9-plugin-base (= 9.19.0-1~bionic) but it is not going to be installed
    

Some commands for troubleshooting:

  • roswtf to quickly find potential issues.
  • rostopic
    • rostopic list to list all topics.
    • rostopic echo /topic_name to subscribe to a topic.
    • rostopic pub /topic_name std_msgs/String hello to publish to a topic.
    • rostopic list to list all topics.
  • dmesg -wH to check the USB port connection.
  • udevadm monitor to check installed udev rules (e.g., in /etc/udev/rules.d/ or /lib/udev/rules.d/).
  • Log may be found in /tmp/latest/*.log.
  • ping -c1 <hostname/IP> to check if the host is responsive.
  • sudo nmap -sn -PE -T5 -n <IP-CIDR> to ping multiple hosts at once.

More troubleshooting techniques:

Tags:

Updated:

Posted: