ROS Workspace and Packages – Week II

Refer to: Martinez’s Learning ROS Chap. 2, Gentle Intro to ROS 2.4 ~ 4

Note: We have ROS version Jade in both the computer and the laptop – there shouldn’t be too much differences yet, but nonetheless I should have informed you all earlier.

The distributed nature of ROS development (allowing different developers to contribute to ROS) required ROS to adapt to an effective package system. Without such system, the difficulty involved with integration and compilation of external code would have prevented ROS from taking off.

Accordingly, ROS has a convenient (relatively) package system called Catkin, and ROS’s promotion of Github allows for an easy integration with the external code. Catkin is a variant of the Makefile system – a program/format that automates a large part of the compiling task. With Catkin and Make systems, you just need to specify the C++/Python files with the respective libraries in text files. For Catkin system in ROS, the text file used is called CMakeLists.txt and package.xml, which are in each ROS packages.

ROS packages, each represented by the folders in Catkin Workspace (catkin_ws), contains the compiling instructions (the two text files above), as well as the source files of the package. Furthermore, they could contain msg files (for specifying topic), launch files (files that can be used to launch multiple programs at once), and so on – containing every code or configuration that is needed to do a specific task. Given that ROS packages largely exist for organization purposes, it is considered a good practice to only specify one function to each of the packages.

With all the files set up in the packages, the typical workflow goes as follows:

  1. First, I type out the program in C++ or Python and place it in the correct folder (src for C++, scripts for Python is recommended). Note that I am talking about src and scripts folder inside the package folder! So like ~/catkin_ws/package/src/ ...
  2. I specify the files and the libraries they need in CMakeLists.txt so that Catkin system may find them and compile/turn files executable.
  3. In the catkin_ws folder, I run source devel/setup.bash, which sets up the Catkin system so that it may be able to detect all the packages.
  4. I run catkin_make in the catkin_ws folder – which causes the Catkin system to start compiling all the packages in the src directory of catkin_ws. Also, msg and srv files are made into C++ header files, allowing you to import the topic messages into the program (by header files, just know for now that it would provide specification/type/function that the message requires to function).
  5. The compiled programs (if compilation was successful) end up in the build directory, able to be executed via rosrun <package_name> <file_name>.
  6. As a side note, you can disable compilation of certain packages by making an empty file called CATKIN_IGNORE in the package folder. To easily do that in the directory, use the command touch CATKIN_IGNORE.

Here is the workflow I use for integrating another package from Github into my project:

  1. I find the Github page for the package I want to download – let’s say – usually the Github page is at the top of the ROS wiki.
  2. I enter ~/catkin_ws/src.
  3. I make sure that the package is for the right ROS version (in our case, Jade) and I use the command git clone, which copies over the contents of the git repository into the ~/catkin_ws/src/ros_tutorials folder.
  4. EXTRA: I remove the .git file in the ros_tutorials (not one inside the src folder!!). .git file contains the git information (file changes, etc) and indicates that the folder with it is a separate git repository. To integrate the package into our own repository, we need to remove it. If not, you can keep it in.

Do read Martinez’s Learning ROS Chapter 2 – it has a detailed information about ROS package system.

Task: Download turtle_sim package and make a publisher that makes the turtle move in place in “circles”.


Introduction to Git and Github – Week 2


When discussing tools used for the open-source programs, git and Github are the two tools that inevitably come up.

What is git and Github and why are they so prominent in the open-source world?

Git is a distributed version control software, which means that you can access and modify your code on your own computer in the version of the program you see fit.

By contrast, the alternative to git is a centralized version control software, which requires you to connect to a server with the code to make changes to the program.

As you might guess, this distributed approach not only allows greater flexibility of how you could work but also leads to fewer conflicts that may arise from people sharing the same “workspace”.

Of course, git still involves the main code base (referred to as the master repository). Github is a free and open platform that is often used to host this repository, along with other versions of the code known as “branches”.

If you are confused at this point, have no fear – while git is somewhat infamous for its difficult user interface, there are only a few commands and workflows that you need to know to make use of git (as with all tools). I, for one, just know about and use ~10 commands.

Instead of attempting to learn about all the git commands (of which there are many), I would recommend that one prioritize learning about the git workflow (how to use the commands effectively).

Here are the three links I recommend, in order:

Essential Git Commands

Git Workflow

How to Use Github

As always, do inform me if the coverage of the materials are too brief/long/quick/slow – I’ll try to adjust accordingly.

How I Learned to Stop Worrying and Love the Terminal

zGiven that most of you will access ROS through the terminal (the -X next to ssh indicates that you can try to run GUI tools, but the speed is excessively slow), here are some terminal commands and tools that will make working in the terminal a lot easier.


Tmux is a terminal multiplexer, which means that you can run multiple terminal shells in one window. Type tmux  into the terminal, and it should take you a nearly identical terminal window.

Commands are

  • Ctrl-b + % – Split the terminal vertically into two panes
  • Ctrl-b + " – Split the terminal horizontally into two panes
  • Ctrl-b (with continued press) + arrow_key – Resize the pane
  • Ctrl-b + arrow_key – Change pane selection
  • Ctrl-b + x – terminal the current selected pane
  • Ctrl-b + [ – Read mode (ESC and move cursor to escape)

vim (or nano)

Vim is a text editor that requires the users to use key commands. You could either type vimtutor for practice (which will take about 10 minutes), or google for basic vim commands. You only really use ~10 commands, so I think it’s worth learning vim.
I highly recommend you go through vimtutor multiple times.
Currently, there is a file explorer pane in vim (called netrw) – you can switch between panes using Ctrl-W + Arrow_keys  and terminate each pane using Esc and typing :wq (for editor) and :q (file explorer).
Terminal commands

To redirect the terminal output to a file (so you can read the error output)

some_command >file.log 2>&1 

Run a command in the background:

some_command & 

Move out of current folder

cd ..

How to run a command every terminal launch

Modify ~/.bashrc (e.g. vim ~/.bashrc) and put commands at the bottom.

~/.bashrc is essentially a shell (bash) command that runs when you first open the terminal, which means that you can put setup commands in ~/.bashrc so that you would not have to type them over and over again.

In ~/.bashrc, you can put ~/catkin_ws/devel/setup.bash (which is within ROS workspace) as one of the setup files to execute at launch. Whatsetup.bash does is that it sets up the path variables for ROS, allowing commands like roscd to find where the directory with packages is.

For those who are not so familiar with the terminal language, a “shell” is the terminal – a way for the user to interact with the operating system (Linux, in this case).

ROS commands

roscd <package_name> <folder_name>

rosed <pacakge_name> <file_name> – Opens file for editing

Commands like roscd (ros + cd) and rosed (ros + ed), they are essentially shortcuts for cd and ed to edit ROS package files quickly.


Independently Learning Robotics

Of course, learning ROS without the robotics knowledge is useless. So how can a person independently learn robotics? While I will cover or point to some of the ideas of robotics, here are the resources you should use.

As I recommended before, I think Artificial Intelligence for Robotics class in Udacity is really helpful in developing the understanding of the essence of robotics (if I had any sense of it at all). I found that standard robotics class or courseware focuses too much on the mechanics of the robot rather than its intelligence (joints and angles everywhere!). Even if you are not familiar with the programming part of the Udacity course, skimming through the idea part of the course is, I think, a good idea.

ROS wiki itself is a good resource. Go through each of the packages in our code repository and read what each package do – it is easier than you would think.

ROS have truly transformed the job of the programmers in the robotics field, as much of the robot functions are implemented in the aggregate of the ROS libraries. Just as programmers don’t necessarily need to understand the string representation in a language to use it, robotic programmers do not need to know the implementation details of each and every robot parts – just of its utility.

Independently Learning ROS

For people who wants to get ahead on the Independent Study (be independent, in others words), I would recommend that you cover two texts simultaneously:

Lentin Joseph’s Mastering ROS and

Gentle Intro to ROS by Jason M. O’Kane.

Mastering ROS covers the practical applications of ROS (essentially building the same differential-drive (two motorized wheel) robot), and Gentle Intro to ROS covers the technical details of ROS.

Going through the applications and occasionally looking at the technical details of ROS is, I think, the way to go.

Introduction to Linux- Week 1

As of this moment, ROS can only run on the operating system called Linux (specifically on a distribution called Ubuntu), so it is essential to be familiar, or at least comfortable with Linux to be able to use ROS effectively.

Linux, in its entirety, is an enormous topic, so let me just cover the enough materials to make you dangerous.

You will largely interact with ROS through a program called terminal, which can be launched with keys CTRL-ALT-T.

Terminal allows you to interact with the OS through text commands, as determined by the ‘shell’ you are running. Most Linux distributions, as well as Ubuntu, runs a shell called bash shell. Type help into the terminal to see the list of commands (which isn’t that many).

The bash commands are programming language themselves and can be used to write simple programs that are often suffixed with .sh. For example, many program installations in Linux is done by running ./, which usually contain the bash commands is needed for installation of the pogram.

The dot front of the slash indicates that the file is in the current directory, which you can change by typing cd.

All of the linux commands run in such format: <command> <arg 1> <arg 2> .... <arg n>. For example, I can run

Other commands or marks to know is

..  indicates the directory above the current one.

~/  indicates the home directory of the user, e.g. ~/Downloads

ls   lists all directory and files in the current directory

chmod +x <file name allows the file to be executable.

ssh allows you to connect to a remote Linux machine using ssh protocol

Other commands can be referenced by a simple Google search.




Meanwhile, you can connect to the computers with ROS (within the school network) using ssh -x <username>@<ip_address>. Both username and IP is specified on this site, as well as the password.

Introduction to ROS – Week 1

By: Jin Pyo Jeon

Recommended Reading: A Gentle Introduction to ROS (Chapter 1), ROS Wiki on Publisher and Subscriber.

Robot Operating System, commonly abbreviated as ROS, is a misnomer – after all, it is not an operating system like Windows and Linux, nor does it perform various tasks that ‘proper’ OS do, like file management.

However, it is an operating system in a sense that it helps manage the difficulties of running multiple programs in a collaborative fashion.

What do I mean? Since there are many technical descriptions of ROS online, let me instead tell you of the problems that ROS solves.

ROS solves problems like:

  • the need to develop a communication scheme between programs, either within one computer or across multiple computers
  • the need to develop and implement tools, algorithms, and hardware drivers that are commonly used in Robotics
  • the problem of programs of different sources having a different interface – and thus being difficult to ‘stitch’ together
  • the difficulty of building, developing and launching several programs (or, more accurately, processes)

There are, of course, other frameworks and libraries that solve some, maybe even most, of these problems, but you should use ROS because it is

  • rapidly becoming industry standard due to its open-source nature
  • and its emphasis on distributed computing (that is, ROS is focused on being able to run on multiple computers and devices, ranging from laptops to microcontrollers like Arduino).

Of course, these introductions do not mean anything if we can’t do anything practical, so let’s dive in immediately.

ROS supports both C++ and Python (and for some, Lisp), but I recommend that you use Python for all but really computationally intensive tasks (like image processing or rapid calculations), as programs in Python do not need to involve a relatively complicated build system called Catkin in order to run. Nor is it fun to resolve pointer issues when you just want the robot to run.

However, you can indeed use both languages in the same robot by using the communication interface provided in ROS. ROS programs primarily communicate using two interfaces: topic and service.

Communicating through a topic is a many-to-many communication, that is, multiple programs can read and write to the same topic, done by programs called subscribers and publishers respectively. The communications through topics are managed by a node (term for programs in ROS) called master node.

Service is one-to-one communication in that one node sends a request for a service and another responds (using a function specified called callback); however, many nodes (called client) can call a service.

As an example, topics are commonly used for the streaming of the sensor data, and services are used to occasionally request for a specific state or data.

For more info on the applications, refer to:

Now, given that most functions could be done with a publisher & subscriber (but not so with service & request), refer to the ROS wiki on writing publisher and subscriber (preferrably in Python).

Challenge: Write a publisher that publishes random odometry data (message name is nav_msgs/Odometry) and a subscriber that echoes the message.