Assignment: ROS

This assignment focuses on ROS (Robot Operating System). ROS is a framework used to program robots. It is quite complicated (some might say too complicated). However it is widely used on both industrial and commercial settings.

Problem 1: Networking and Environment Variables (30 points)

GNU/Linux uses environment variables to store configuration information about a variety of things. You can use env to view the environment variables in your shell on the Rasberry Pi. In bash (and most shells), environment variables are local to your bash session, so they are often set in configuration files that are run every time your shell starts, such as .bashrc.

  1. Log into your Rasperry Pi. Use X=3 to set the value of an environment variable named X to the value 3. Use echo $X to display the variable. Note that you must prepend $ to the variable name when reading it, but not when setting it.
  2. Log into your drone again in a separate SSH session. Use echo $X to see the value of the environment variable X. What happens? Does this work? Why or why not?

    Answer: This will not work because an environment variable is local to a shell session. To set an environment variable in another shell, it must be set separately in that shell, or it must be a subshell.

  3. Use env to see all the environment variables set in your shell. Pick one. Research the one that you picked. Describe 1) What program sets the environment variable and 2) What the variable controls. For example, the EDITOR environment variable is set in the .bashrc file when you log in. 2) It is the name of the program called by sudoedit, git commit, and other programs when they need to edit a file.
  4. Start screen in one of your SSH sessions. Our script sets the ROS_MASTER_URI and ROS_HOSTNAME or ROS_IP environment variables in your session. In a second SSH session in which you have not run screen (so just after you log in), assess the value of the environment variables. Are they set to the correct values? What is setting ROS_MASTER_URI? What is setting ROS_IP or ROS_HOSTNAME? How did you figure this out? (You might find the grep command useful. Use man grep to find out how to use it.)

    Answer: You can figure this out by using grep to search the file system for places where environment variables are set. I ran grep ROS_MASTER_URI but it didn't find any results. Then I tried grep ROS_IP and found it was set in .bashrc. I noticed that .bashrc was sourcing a few ROS configuration files. I searched each of those files for ROS_MASTER_URI and found it was set in /opt/ros/indigo/setup.bash as a default value if it was not already set.

Problem 2: Creating a Publisher and Subscriber (50 points)

For this section, commit the package into the git repository you use for handing in the assignment. You do not need to commit the whole workspace; just the package.

  1. Follow the ROS tutorials to create a package.
  2. Do the building packages tutorial.
  3. Read the Understanding Nodes tutorial. You will not be able to do all of the tutorial - do not try to install the ros-tutorials package. Also skip Section 7 about using rosrun. You do not have to hand in anything for this question.
  4. Use rosnode list to display what nodes are running when you start the screen session. Use rosnode info to find out more about each node. What topics does /flow_pub publish?

    pi@bat42:~ $ rosnode info /flow_pub
    Node [/flow_pub]
     * /pidrone/set_mode_vel [pidrone_pkg/Mode]
     * /pidrone/plane_err [pidrone_pkg/axes_err]
     * /rosout [rosgraph_msgs/Log]
     * /pidrone/picamera/camera_info [sensor_msgs/CameraInfo]
     * /pidrone/picamera/image_raw [sensor_msgs/Image]

  5. Finally, follow the ROS publisher/subscriber tutorial using the workspace and package you created above. Commit the code you used to the git repository for the assignment.
  6. Use rostopic list to examine the publisher and subscriber you wrote (while they are running). Use rostopic echo to display the results of the publishing topic. Submit a screenshot showing the results of these two commands.
  7. Start the screen session we use to fly the drone. Use rostopic echo and rostopic hz to examine the results of various topics. What is the frame rate we are publishing images from the camera?

    Use rostopic hz on the camera info topic to find the answer.

Problem 3: Reading the IR Sensor (15 points)

Now write a ROS subscriber to read the values from the infrared sensor topic. Use rostopic list to determine the value of the infrared topic. Compute the mean and variance of the sensor values over a ten second window. You can store the data in memory in your Python program and then compute statistics based on the stored data. (For longer windows, you might want to log to disk.) What is the standard deviation of the sensor when pointed at the same surface for ten seconds? You can use NumPy to compute the statistics.

Problem 4: Services (5 points)

ROS also supports services with a more traditional function call abstraction so that you can send a remote procedure call and receive a response. Describe when services might be a good idea to use? Describe problems that services might have related to robotics? Especially think through issues such as timing and failure modes.


Services are nice because they support the function call abstraction that we are all used to as computer scientists. However the function call abstraction is particularly leaky for robotics for a few reasons. First, the time imposed by the overhead for an RPC is not what you expect, simply because of the network overhead. Second, an RPC on a robot might take a long time to execute. For example, if you call a function like “takeoff” as a function, it might take the drone 10 seconds to finish executing the function. In the meantime, you


Hand in your answers using this link. For problems 1, 2, and 3, we would like you to upload a screenshot for each question that asks you to do some action in the command line. For each question that asks you to write code, we would like you to upload the raw code. For problem 4, we would like a written response in a pdf.