Day 02

Today: Starting the Journey to "becoming a ROS boss"

    • ROS fundamentals
    • Creating a remote control for your Neato

For Next Time

Today we will learn about two of the most important tools we will be using the semester: ROS and the Neato XV. By today you should either have your environment setup as described on the course webpage or have a partner that you can go through the exercises today with. The topics we will cover today are ROS tools for interacting with ROS packages, ROS nodes, ROS topics, and controlling the motors on the Neato. Note that these notes are not intended to replace the tutorials, but instead to be a supplement.

As part of setting up your environment, you should have already created your catkin workspace by following the tutorial on the ROS website.

Almost all of the features of ROS are organized into packages. A package is a coherent unit of code and documentation that provides a useful piece of functionality. Packages specify a number of things: instructions on building them, instructions on their dependence on other packages, documentation, and source code to implement the package itself. As an example, let's take a look at the contents of a SLAM package named hector_slam.

include/        <--- C++ header files
CMakeLists.txt  <--- build instructions
package.xml     <--- includes package information
src/            <--- C++ source code

A detailed description of package.xml can be found in this ROS tutorial. A detailed explanation of CMakeLists.txt can be found here.

include/        <--- C++ header files
CMakeLists.txt  <--- build instructions
package.xml     <--- includes package information
src/            <--- C++ source code
scripts/        <--- Python code is placed here

Navigating the ROS Filesystem

ROS provides a number of very useful tools for navigating the filesystem. A few things to keep in mind: roscd allows you to effectively navigate around ROS packages. This is not to say that good old fashion cd will no longer be useful, but roscd is aware of all of the ROS packages that are installed on the system and above all else has excellent tab completion. With the people seated around you, please go through the tutorial Navigating the ROS Filesystem.

More on ROS Packages

With those seated around you, go through the following tutorials related to ROS Packages:

ROS Nodes and Topics

ROS Nodes are processes that provide some functionality within ROS. Nodes communicate with each other using a publish / subscribe architecture. Go through the tutorial on ROS Nodes and ROS Topics and we will work through a few of the advantages of this architecture.

Note: When going through the tutorial on understanding ROS Topics you will be instructed to execute the following command

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'

As stated later in the tutorial, the message of type geometry_msgs/Twist are specified using YAML syntax. If you read the documentation on you will see that the following is an equivalent way to

the same Twist message:

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist  '{linear:  {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 1.8}}'

The wikipedia page provides some advantages for the Pub/Sub architecture:

Loose coupling: Publishers are loosely coupled to subscribers, and need not even know of their existence. With the topic being the focus, publishers and subscribers are allowed to remain ignorant of system topology. Each can continue to operate normally regardless of the other. In the traditional tightly coupled client-server paradigm, the client cannot post messages to the server while the server process is not running, nor can the server receive messages unless the client is running.
...
Scalability: Pub/sub provides the opportunity for better scalability than traditional client-server, through parallel operation, message caching, tree-based or network-based routing, etc.

Imagine you are programming the Neato robot. What sort of topics might you include in your design? What design decisions did you face in creating your design?

Writing your First ROS Nodes

With the people seated around you, go through the following ROS tutorial on Writing a Simple Publisher and Subscriber (Python)

Neato Remote Control

Next, we are going to get our hands dirty and play with some actual robots! Start by reading this page on running the Neatos. With two other people in the class, grab one of the Neatos and start it up. Choose one person's laptop to be the one that connects to the Neato (let's call this person "person A", however, you can each code your own remote control.

Following the instructions linked above, person A should run roslaunch to startup the Neato node. The other two members of the team should set ROS to connect to the roscore instance running on person A's laptop. To do so, run the following command from a terminal window (Note: unless you put this line in your .bashrc, you will have to repeat this for each terminal you open)

$ export ROS_MASTER_URI=http://ip_address_of_person_A's_laptop:11311/

Next, run rostopic list to show all of the topics that are now being published / subscribed to now that the Neato is up and running. Is it clear what each of these topics do? Are there any that you are particularly confused about?

It turns out that the way you control the velocity of the Neato is by publishing to the topic /cmd_vel (in fact this is the standard name for sending velocity commands to a robot in ROS). Next, with your group investigate the /cmd_vel topic. what type of message does it take? What do the parameters of the message do? Test out your theories using rostopic pub.

Finally, write a ROS node to act as a keyboard controller for the Neato by publishing different messages to /cmd_vel based on the user's key presses. Be creative in your design, there is no one right answer.

Useful helper function:

def getch():
    """ Return the next character typed on the keyboard """
    import sys, tty, termios
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

Neato Sensors

We won't have time to delve into this too much, but take a few minutes to start to explore Neato's sensors:

To view video data from the Neato:

$ rosrun image_view image_view image:=/camera/image_raw

To view the distance to the nearest obstacle for a particular angle relative to the Neato, use the command below (where you replace angle_in_degrees with the angle you'd like to show):

$ rostopic echo /scan/ranges[angle_in_degrees]

This picture shows how the Neato LIDAR angles are measured relative to the Neato base.