ROS

PREVIOUS: Introduction

Disclaimer: I can confidently say that this has the biggest learning curve of anything I’ve learned–and a lot of people have agreed. I don’t say this to scare you away, but you need to take ROS seriously. But don’t be discouraged! Find the help you need, ask questions, go to office hours, find me in my tutoring sessions!

I also highly recommend installing Ubuntu/Linux on your own laptop and using that instead of the awful school computers. This is the time to do it, if you haven’t done so already. You can find the installation instructions on the ROS wiki.

ROS: Robot Operating System

Contrary to it’s name, ROS is not an operating system. It is comprised of four main components:

  • Nodes: The processes that make up the application. Nodes exchange messages through topics.
  • Topics: Topics are arbitrary “variable” names through which nodes communicate with each other through publishers and subscribers. Like variables, they will also have their own data structures (int, float, string, Pose, Twist, etc.)
  • Publishers: Publishers compact a message and send them to a topic for subscribers to listen to. These are variables that you declare and use in your code.
  • Subscribers: Subscribers listen to the messages/information and do whatever with that information. These are also variables that you declare and use in your code.

Here’s an analogy: Livestreaming. In 2017, League of Legends streamed best of three matches between teams, usually two at a time, call them Stream A and Stream B. Say I only like watching the teams on Stream A, Kevin only watches the teams on Stream B, and Jeremy watches both streams at the same time (gotta be efficient).

In this analogy, ‘League of Legends’ is one node, ‘I’ am a another node, and likewise with ‘Kevin’ and ‘Jeremy.’ LoL has two publishers: ‘StreamA’ and ‘StreamB’. I have one subscriber that listens to the topic, ‘StreamA.’ Kevin has one subscriber that listens to ‘StreamB.’ Jeremy subscribes to both ‘StreamA’ and ‘StreamB.’ I don’t want to promote the idea that nodes can only be either publishers or subscribers– they can be both. For example, LoL might subscribe to some topic ‘numberOfViewers.’ I might publish some text to ‘commentsSection.’

For a robot, your nodes would be the different sensors on the robot. Say I have a node that publishes camera data through the topic ‘cameraInfo.’ Maybe I’d have a second node that I want to write that subscribes to ‘cameraInfo,’ and outputs what the camera sees. Or I could do some Image processing on what the I receive from that topic.

In this example, we have two nodes, /teleop_turtle and /turtlesim. /teleop_turtle publishes to the topic /turtle1/cmd_vel and /turtlesim subscribes to /turtle1/cmd_vel. Thus, the information that /teleop_turtle has is being sent to /turtlesim. Again, /turtle1/cmd_vel is only one of infinite topics of which /turtle_teleop could be sending to /turtlesim. The data type of /turtle1/cmd_vel is a Twist, which is essentially velocity, but we will discuss that later on as well.

GET THESE IDEAS. UNDERSTAND THEM. KNOW THEM.

There were several people in my class that didn’t understand them even towards the end of the class. If you fully understand this subscribe/publish system, you’re off to a great start. And like any other CS class, if you don’t understand something, create a problem with it and solve it via coding.

Catkin: Packages and Workspace

ROS uses a tool called catkin to handle all the packages, compiling, etc. Let’s stop talking and get into some of the stuff!

  mkdir -p ~/catkin_ws/src
  cd ~/catkin_ws/src
  catkin_init_workspace
  cd ..
  catkin_make

BOOM! You just made a catkin workspace and compiled all of your 0 projects! Congratulations! Notice that you now have a build and devel inside your catkin_ws. The build folder will just contain some of the stuff that catkin needs to work, but the devel folder will include all of your compiled programs, libraries, etc. However, you will almost never need to go into these folders. ROS handles it all for you!

However, first, you need to tell ROS to look inside your catkin_ws folder for packages.

  echo source ~/catkin_ws/devel/setup.bash >> ~/.bashrc
  source ~/.bashrc

Your .bashrc file is a hidden (because it starts with a .) text file that essentially types in everything inside of it in a terminal window whenever you open one. So now, every time you open a new terminal window, you will tell ROS to look inside your catkin_ws folder. Neat! Notice that if you didn’t do this, every time you need a new terminal window (which is extremely often with ROS), you would have to type in:

  source ~/catkin_ws/devel/setup.bash